fuzz_with_unicorn: Speed up tests by not initializing/tearing down constantly

This commit is contained in:
MerryMage 2018-02-12 21:48:29 +00:00
parent a38f35eef6
commit f6a2104ab3
2 changed files with 12 additions and 7 deletions

View file

@ -90,27 +90,31 @@ restart:
} }
static void RunTestInstance(const std::array<u64, 31>& regs, const std::array<Vector, 32>& vecs, const size_t instructions_offset, const std::vector<u32>& instructions, const u32 pstate) { static void RunTestInstance(const std::array<u64, 31>& regs, const std::array<Vector, 32>& vecs, const size_t instructions_offset, const std::vector<u32>& instructions, const u32 pstate) {
TestEnv jit_env; static TestEnv jit_env;
TestEnv uni_env; static TestEnv uni_env;
std::copy(instructions.begin(), instructions.end(), jit_env.code_mem.begin() + instructions_offset); std::copy(instructions.begin(), instructions.end(), jit_env.code_mem.begin() + instructions_offset);
std::copy(instructions.begin(), instructions.end(), uni_env.code_mem.begin() + instructions_offset); std::copy(instructions.begin(), instructions.end(), uni_env.code_mem.begin() + instructions_offset);
jit_env.code_mem[instructions.size() + instructions_offset] = 0x14000000; // B . jit_env.code_mem[instructions.size() + instructions_offset] = 0x14000000; // B .
uni_env.code_mem[instructions.size() + instructions_offset] = 0x14000000; // B . uni_env.code_mem[instructions.size() + instructions_offset] = 0x14000000; // B .
jit_env.modified_memory.clear();
uni_env.modified_memory.clear();
Dynarmic::A64::Jit jit{Dynarmic::A64::UserConfig{&jit_env}}; static Dynarmic::A64::Jit jit{Dynarmic::A64::UserConfig{&jit_env}};
Unicorn uni{uni_env}; static Unicorn uni{uni_env};
jit.SetRegisters(regs); jit.SetRegisters(regs);
jit.SetVectors(vecs); jit.SetVectors(vecs);
jit.SetPC(instructions_offset * 4); jit.SetPC(instructions_offset * 4);
jit.SetSP(0x08000000); jit.SetSP(0x08000000);
jit.SetPstate(pstate); jit.SetPstate(pstate);
jit.ClearCache();
uni.SetRegisters(regs); uni.SetRegisters(regs);
uni.SetVectors(vecs); uni.SetVectors(vecs);
uni.SetPC(instructions_offset * 4); uni.SetPC(instructions_offset * 4);
uni.SetSP(0x08000000); uni.SetSP(0x08000000);
uni.SetPstate(pstate); uni.SetPstate(pstate);
uni.ClearPageCache();
jit_env.ticks_left = instructions.size(); jit_env.ticks_left = instructions.size();
jit.Run(); jit.Run();

View file

@ -28,9 +28,7 @@ Unicorn::Unicorn(TestEnv& testenv) : testenv(testenv) {
} }
Unicorn::~Unicorn() { Unicorn::~Unicorn() {
for (const auto& page : pages) { ClearPageCache();
CHECKED(uc_mem_unmap(uc, page->address, 4096));
}
CHECKED(uc_hook_del(uc, intr_hook)); CHECKED(uc_hook_del(uc, intr_hook));
CHECKED(uc_hook_del(uc, mem_invalid_hook)); CHECKED(uc_hook_del(uc, mem_invalid_hook));
CHECKED(uc_close(uc)); CHECKED(uc_close(uc));
@ -135,6 +133,9 @@ void Unicorn::SetPstate(u32 value) {
} }
void Unicorn::ClearPageCache() { void Unicorn::ClearPageCache() {
for (const auto& page : pages) {
CHECKED(uc_mem_unmap(uc, page->address, 4096));
}
pages.clear(); pages.clear();
} }