From 6e56828dfd851d60427d168dc01df5667c6f57b7 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Sun, 24 Sep 2023 17:38:11 +0530 Subject: [PATCH] tests/arm/exec: test conditions Signed-off-by: Amneesh Singh --- tests/cpu/arm/exec.cc | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/tests/cpu/arm/exec.cc b/tests/cpu/arm/exec.cc index c968f7d..a487876 100644 --- a/tests/cpu/arm/exec.cc +++ b/tests/cpu/arm/exec.cc @@ -13,7 +13,6 @@ class CpuFixture { std::vector(Header::HEADER_SIZE)))) {} protected: - // TODO: test with other conditions void exec(arm::InstructionData data, Condition condition = Condition::AL) { arm::Instruction instruction(condition, data); cpu.exec_arm(instruction); @@ -804,29 +803,41 @@ TEST_CASE_METHOD(CpuFixture, "Data Processing", TAG) { processing->rn = 7; } - auto flags = [this](bool n, bool z, bool v, bool c) { - CHECK(cpu.cpsr.n() == n); - CHECK(cpu.cpsr.z() == z); - CHECK(cpu.cpsr.v() == v); - CHECK(cpu.cpsr.c() == c); - + auto reset_flags = [this]() { cpu.cpsr.set_n(false); cpu.cpsr.set_z(false); cpu.cpsr.set_v(false); cpu.cpsr.set_c(false); }; + auto flags = [this, reset_flags](bool n, bool z, bool v, bool c) { + CHECK(cpu.cpsr.n() == n); + CHECK(cpu.cpsr.z() == z); + CHECK(cpu.cpsr.v() == v); + CHECK(cpu.cpsr.c() == c); + reset_flags(); + }; + // immediate operand processing->operand = static_cast(54924809); // rs cpu.gpr[12] = 2; cpu.gpr[5] = 0; + reset_flags(); - SECTION("AND") { + SECTION("AND (with condition check)") { processing->opcode = OpCode::AND; - exec(data); + cpu.cpsr.set_z(false); + exec(data, Condition::EQ); + + // condition is false + CHECK(cpu.gpr[5] == 0); + + cpu.cpsr.set_z(true); + exec(data, Condition::EQ); // -28717 & 54924809 + // condition is true now CHECK(cpu.gpr[5] == 54920705); // check set flags @@ -846,11 +857,19 @@ TEST_CASE_METHOD(CpuFixture, "Data Processing", TAG) { flags(false, false, false, false); } - SECTION("EOR") { + SECTION("EOR (with condition check)") { processing->opcode = OpCode::EOR; - exec(data); + cpu.cpsr.set_c(true); + exec(data, Condition::CC); + + // condition fails + CHECK(cpu.gpr[5] == 0); + + cpu.cpsr.set_c(false); + exec(data, Condition::CC); // -28717 ^ 54924809 + // condition is true now CHECK(cpu.gpr[5] == 4240021978); // check set flags