From d7348adbba6dd054b91f2cecfc45753ee95143c0 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 5 Apr 2016 12:13:28 +0100 Subject: [PATCH] fixup! Tests/JitX64: Use std::generate_n and factor pass-testing into DoesBehaviorMatch --- .../core/arm/jit_x64/fuzz_arm_common.cpp | 34 +++++++++++-------- src/tests/core/arm/jit_x64/fuzz_thumb.cpp | 31 ++++++++++------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/tests/core/arm/jit_x64/fuzz_arm_common.cpp b/src/tests/core/arm/jit_x64/fuzz_arm_common.cpp index fb908e928..5f5138d83 100644 --- a/src/tests/core/arm/jit_x64/fuzz_arm_common.cpp +++ b/src/tests/core/arm/jit_x64/fuzz_arm_common.cpp @@ -80,12 +80,27 @@ public: void Write64(VAddr addr, u64 data) override { recording.emplace_back(8, addr, data); } }; +static bool DoesBehaviorMatch(const ARM_DynCom& interp, const JitX64::ARM_Jit& jit, std::vector interp_mem_recording, std::vector jit_mem_recording) { + if (interp.GetCPSR() != jit.GetCPSR()) + return false; + + for (int i = 0; i <= 15; i++) { + if (interp.GetReg(i) != jit.GetReg(i)) + return false; + } + + if (interp_mem_recording != jit_mem_recording) + return false; + + return true; +} + void FuzzJit(const int instruction_count, const int instructions_to_execute_count, const int run_count, const std::function instruction_generator) { // Init core Core::Init(); SCOPE_EXIT({ Core::Shutdown(); }); - // Prepare memory + // Prepare memory (we take over the entire address space) std::shared_ptr test_mem = std::make_shared(); Memory::MapIoRegion(0x00000000, 0x80000000, test_mem); Memory::MapIoRegion(0x80000000, 0x80000000, test_mem); @@ -120,10 +135,7 @@ void FuzzJit(const int instruction_count, const int instructions_to_execute_coun interp.SetPC(0); jit.SetPC(0); - for (int i = 0; i < instruction_count; i++) { - u32 inst = instruction_generator(); - test_mem->code_mem[i] = inst; - } + std::generate_n(test_mem->code_mem.begin(), instruction_count, instruction_generator); test_mem->code_mem[instruction_count] = 0xEAFFFFFE; // b +#0 // busy wait loop @@ -135,15 +147,7 @@ void FuzzJit(const int instruction_count, const int instructions_to_execute_coun jit.ExecuteInstructions(instructions_to_execute_count); auto jit_mem_recording = test_mem->recording; - bool pass = true; - - if (interp.GetCPSR() != jit.GetCPSR()) pass = false; - for (int i = 0; i <= 15; i++) { - if (interp.GetReg(i) != jit.GetReg(i)) pass = false; - } - if (interp_mem_recording != jit_mem_recording) pass = false; - - if (!pass) { + if (!DoesBehaviorMatch(interp, jit, interp_mem_recording, jit_mem_recording)) { printf("Failed at execution number %i\n", run_number); printf("\nInstruction Listing: \n"); @@ -199,4 +203,4 @@ void FuzzJit(const int instruction_count, const int instructions_to_execute_coun fflush(stdout); } } -} \ No newline at end of file +} diff --git a/src/tests/core/arm/jit_x64/fuzz_thumb.cpp b/src/tests/core/arm/jit_x64/fuzz_thumb.cpp index 35c00c5a5..22eb49f2a 100644 --- a/src/tests/core/arm/jit_x64/fuzz_thumb.cpp +++ b/src/tests/core/arm/jit_x64/fuzz_thumb.cpp @@ -83,6 +83,21 @@ public: void Write64(VAddr addr, u64 data) override { recording.emplace_back(8, addr, data); } }; +static bool DoesBehaviorMatch(const ARM_DynCom& interp, const JitX64::ARM_Jit& jit, std::vector interp_mem_recording, std::vector jit_mem_recording) { + if (interp.GetCPSR() != jit.GetCPSR()) + return false; + + for (int i = 0; i <= 15; i++) { + if (interp.GetReg(i) != jit.GetReg(i)) + return false; + } + + if (interp_mem_recording != jit_mem_recording) + return false; + + return true; +} + void FuzzJitThumb(const int instruction_count, const int instructions_to_execute_count, const int run_count, const std::function instruction_generator) { // Init core Core::Init(); @@ -141,15 +156,7 @@ void FuzzJitThumb(const int instruction_count, const int instructions_to_execute jit.ExecuteInstructions(instructions_to_execute_count + 1); auto jit_mem_recording = test_mem->recording; - bool pass = true; - - if (interp.GetCPSR() != jit.GetCPSR()) pass = false; - for (int i = 0; i <= 15; i++) { - if (interp.GetReg(i) != jit.GetReg(i)) pass = false; - } - if (interp_mem_recording != jit_mem_recording) pass = false; - - if (!pass) { + if (!DoesBehaviorMatch(interp, jit, interp_mem_recording, jit_mem_recording)) { printf("Failed at execution number %i\n", run_number); printf("\nInstruction Listing: \n"); @@ -207,7 +214,6 @@ void FuzzJitThumb(const int instruction_count, const int instructions_to_execute // Things not yet tested: // // FromBitString16("10111110xxxxxxxx"), // BKPT -// FromBitString16("10110110011x0xxx"), // CPS // FromBitString16("11011111xxxxxxxx"), // SWI // FromBitString16("1011x101xxxxxxxx"), // PUSH/POP (R = 1) @@ -273,7 +279,7 @@ TEST_CASE("Fuzz Thumb instructions set 1", "[JitX64][Thumb]") { } TEST_CASE("Fuzz Thumb instructions set 2 (affects PC)", "[JitX64][Thumb]") { - const std::array, 18> instructions = {{ + const std::array, 19> instructions = {{ FromBitString16("01000111xxxxx000"), // BLX/BX FromBitString16("1010oxxxxxxxxxxx"), // add to pc/sp FromBitString16("11100xxxxxxxxxxx"), // B @@ -292,6 +298,7 @@ TEST_CASE("Fuzz Thumb instructions set 2 (affects PC)", "[JitX64][Thumb]") { FromBitString16("11011010xxxxxxxx"), // B FromBitString16("11011011xxxxxxxx"), // B FromBitString16("11011100xxxxxxxx"), // B + FromBitString16("10110110011x0xxx"), // CPS }}; auto instruction_select = [&](int) -> u16 { @@ -326,4 +333,4 @@ TEST_CASE("Fuzz Thumb instructions set 3 (32-bit BL/BLX)", "[JitX64][Thumb]") { }; FuzzJitThumb(2, 2, 1000, instruction_select); -} \ No newline at end of file +}