mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 07:40:13 +00:00
fixup! Tests/JitX64: Use std::generate_n and factor pass-testing into DoesBehaviorMatch
This commit is contained in:
parent
a9767d514f
commit
d7348adbba
@ -80,12 +80,27 @@ public:
|
|||||||
void Write64(VAddr addr, u64 data) override { recording.emplace_back(8, addr, data); }
|
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<TestMemory::WriteRecord> interp_mem_recording, std::vector<TestMemory::WriteRecord> 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<u32()> instruction_generator) {
|
void FuzzJit(const int instruction_count, const int instructions_to_execute_count, const int run_count, const std::function<u32()> instruction_generator) {
|
||||||
// Init core
|
// Init core
|
||||||
Core::Init();
|
Core::Init();
|
||||||
SCOPE_EXIT({ Core::Shutdown(); });
|
SCOPE_EXIT({ Core::Shutdown(); });
|
||||||
|
|
||||||
// Prepare memory
|
// Prepare memory (we take over the entire address space)
|
||||||
std::shared_ptr<TestMemory> test_mem = std::make_shared<TestMemory>();
|
std::shared_ptr<TestMemory> test_mem = std::make_shared<TestMemory>();
|
||||||
Memory::MapIoRegion(0x00000000, 0x80000000, test_mem);
|
Memory::MapIoRegion(0x00000000, 0x80000000, test_mem);
|
||||||
Memory::MapIoRegion(0x80000000, 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);
|
interp.SetPC(0);
|
||||||
jit.SetPC(0);
|
jit.SetPC(0);
|
||||||
|
|
||||||
for (int i = 0; i < instruction_count; i++) {
|
std::generate_n(test_mem->code_mem.begin(), instruction_count, instruction_generator);
|
||||||
u32 inst = instruction_generator();
|
|
||||||
test_mem->code_mem[i] = inst;
|
|
||||||
}
|
|
||||||
|
|
||||||
test_mem->code_mem[instruction_count] = 0xEAFFFFFE; // b +#0 // busy wait loop
|
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);
|
jit.ExecuteInstructions(instructions_to_execute_count);
|
||||||
auto jit_mem_recording = test_mem->recording;
|
auto jit_mem_recording = test_mem->recording;
|
||||||
|
|
||||||
bool pass = true;
|
if (!DoesBehaviorMatch(interp, jit, interp_mem_recording, jit_mem_recording)) {
|
||||||
|
|
||||||
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) {
|
|
||||||
printf("Failed at execution number %i\n", run_number);
|
printf("Failed at execution number %i\n", run_number);
|
||||||
|
|
||||||
printf("\nInstruction Listing: \n");
|
printf("\nInstruction Listing: \n");
|
||||||
@ -199,4 +203,4 @@ void FuzzJit(const int instruction_count, const int instructions_to_execute_coun
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,21 @@ public:
|
|||||||
void Write64(VAddr addr, u64 data) override { recording.emplace_back(8, addr, data); }
|
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<TestMemory::WriteRecord> interp_mem_recording, std::vector<TestMemory::WriteRecord> 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<u16(int)> instruction_generator) {
|
void FuzzJitThumb(const int instruction_count, const int instructions_to_execute_count, const int run_count, const std::function<u16(int)> instruction_generator) {
|
||||||
// Init core
|
// Init core
|
||||||
Core::Init();
|
Core::Init();
|
||||||
@ -141,15 +156,7 @@ void FuzzJitThumb(const int instruction_count, const int instructions_to_execute
|
|||||||
jit.ExecuteInstructions(instructions_to_execute_count + 1);
|
jit.ExecuteInstructions(instructions_to_execute_count + 1);
|
||||||
auto jit_mem_recording = test_mem->recording;
|
auto jit_mem_recording = test_mem->recording;
|
||||||
|
|
||||||
bool pass = true;
|
if (!DoesBehaviorMatch(interp, jit, interp_mem_recording, jit_mem_recording)) {
|
||||||
|
|
||||||
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) {
|
|
||||||
printf("Failed at execution number %i\n", run_number);
|
printf("Failed at execution number %i\n", run_number);
|
||||||
|
|
||||||
printf("\nInstruction Listing: \n");
|
printf("\nInstruction Listing: \n");
|
||||||
@ -207,7 +214,6 @@ void FuzzJitThumb(const int instruction_count, const int instructions_to_execute
|
|||||||
// Things not yet tested:
|
// Things not yet tested:
|
||||||
//
|
//
|
||||||
// FromBitString16("10111110xxxxxxxx"), // BKPT
|
// FromBitString16("10111110xxxxxxxx"), // BKPT
|
||||||
// FromBitString16("10110110011x0xxx"), // CPS
|
|
||||||
// FromBitString16("11011111xxxxxxxx"), // SWI
|
// FromBitString16("11011111xxxxxxxx"), // SWI
|
||||||
// FromBitString16("1011x101xxxxxxxx"), // PUSH/POP (R = 1)
|
// 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]") {
|
TEST_CASE("Fuzz Thumb instructions set 2 (affects PC)", "[JitX64][Thumb]") {
|
||||||
const std::array<std::pair<u16, u16>, 18> instructions = {{
|
const std::array<std::pair<u16, u16>, 19> instructions = {{
|
||||||
FromBitString16("01000111xxxxx000"), // BLX/BX
|
FromBitString16("01000111xxxxx000"), // BLX/BX
|
||||||
FromBitString16("1010oxxxxxxxxxxx"), // add to pc/sp
|
FromBitString16("1010oxxxxxxxxxxx"), // add to pc/sp
|
||||||
FromBitString16("11100xxxxxxxxxxx"), // B
|
FromBitString16("11100xxxxxxxxxxx"), // B
|
||||||
@ -292,6 +298,7 @@ TEST_CASE("Fuzz Thumb instructions set 2 (affects PC)", "[JitX64][Thumb]") {
|
|||||||
FromBitString16("11011010xxxxxxxx"), // B<cond>
|
FromBitString16("11011010xxxxxxxx"), // B<cond>
|
||||||
FromBitString16("11011011xxxxxxxx"), // B<cond>
|
FromBitString16("11011011xxxxxxxx"), // B<cond>
|
||||||
FromBitString16("11011100xxxxxxxx"), // B<cond>
|
FromBitString16("11011100xxxxxxxx"), // B<cond>
|
||||||
|
FromBitString16("10110110011x0xxx"), // CPS
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto instruction_select = [&](int) -> u16 {
|
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);
|
FuzzJitThumb(2, 2, 1000, instruction_select);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user