diff --git a/tests/A64/fuzz_with_unicorn.cpp b/tests/A64/fuzz_with_unicorn.cpp index 795ab2fd..b7abd46f 100644 --- a/tests/A64/fuzz_with_unicorn.cpp +++ b/tests/A64/fuzz_with_unicorn.cpp @@ -7,7 +7,6 @@ #include #include -#include #include "frontend/A64/location_descriptor.h" #include "frontend/A64/translate/translate.h" @@ -19,72 +18,6 @@ using namespace Dynarmic; -TEST_CASE("A64: Unicorn sanity test", "[a64]") { - TestEnv env; - env.code_mem[0] = 0x8b020020; // ADD X0, X1, X2 - env.code_mem[1] = 0x14000000; // B . - - std::array regs { - 0, 1, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 - }; - - Unicorn unicorn{env}; - - unicorn.SetRegisters(regs); - unicorn.SetPC(0); - - env.ticks_left = 2; - unicorn.Run(); - - REQUIRE(unicorn.GetRegisters()[0] == 3); - REQUIRE(unicorn.GetRegisters()[1] == 1); - REQUIRE(unicorn.GetRegisters()[2] == 2); - REQUIRE(unicorn.GetPC() == 4); -} - -TEST_CASE("A64: Ensure 0xFFFF'FFFF'FFFF'FFFF is readable", "[a64]") { - TestEnv env; - - env.code_mem[0] = 0x385fed99; // LDRB W25, [X12, #0xfffffffffffffffe]! - env.code_mem[1] = 0x14000000; // B . - - std::array regs{}; - regs[12] = 1; - - Unicorn unicorn{env}; - - unicorn.SetRegisters(regs); - unicorn.SetPC(0); - - env.ticks_left = 2; - unicorn.Run(); - - REQUIRE(unicorn.GetPC() == 4); -} - -TEST_CASE("A64: Ensure is able to read across page boundaries", "[a64]") { - TestEnv env; - - env.code_mem[0] = 0xb85f93d9; // LDUR W25, [X30, #0xfffffffffffffff9] - env.code_mem[1] = 0x14000000; // B . - - std::array regs{}; - regs[30] = 4; - - Unicorn unicorn{env}; - - unicorn.SetRegisters(regs); - unicorn.SetPC(0); - - env.ticks_left = 2; - unicorn.Run(); - - REQUIRE(unicorn.GetPC() == 4); -} - static std::vector instruction_generators = []{ const std::vector> list { #define INST(fn, name, bitstring) {#fn, bitstring}, @@ -121,7 +54,7 @@ restart: return instruction; } -static void TestInstance(const std::array& regs, const std::vector& instructions, u32 pstate) { +static void RunTestInstance(const std::array& regs, const std::vector& instructions, u32 pstate) { TestEnv jit_env; TestEnv uni_env; @@ -162,8 +95,8 @@ TEST_CASE("A64: Single random instruction", "[a64]") { instructions.push_back(GenRandomInst(0, true)); u32 pstate = RandInt(0, 0xF) << 28; - // printf("%08x\n", instructions[0]); + INFO("Instruction: " << instructions[0]); - TestInstance(regs, instructions, pstate); + RunTestInstance(regs, instructions, pstate); } } diff --git a/tests/A64/verify_unicorn.cpp b/tests/A64/verify_unicorn.cpp new file mode 100644 index 00000000..04d853c6 --- /dev/null +++ b/tests/A64/verify_unicorn.cpp @@ -0,0 +1,81 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2018 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#include + +#include + +#include "rand_int.h" +#include "testenv.h" +#include "unicorn_emu/unicorn.h" + +using namespace Dynarmic; + +TEST_CASE("Unicorn: Sanity test", "[a64]") { + TestEnv env; + env.code_mem[0] = 0x8b020020; // ADD X0, X1, X2 + env.code_mem[1] = 0x14000000; // B . + + std::array regs { + 0, 1, 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 + }; + + Unicorn unicorn{env}; + + unicorn.SetRegisters(regs); + unicorn.SetPC(0); + + env.ticks_left = 2; + unicorn.Run(); + + REQUIRE(unicorn.GetRegisters()[0] == 3); + REQUIRE(unicorn.GetRegisters()[1] == 1); + REQUIRE(unicorn.GetRegisters()[2] == 2); + REQUIRE(unicorn.GetPC() == 4); +} + +TEST_CASE("Unicorn: Ensure 0xFFFF'FFFF'FFFF'FFFF is readable", "[a64]") { + TestEnv env; + + env.code_mem[0] = 0x385fed99; // LDRB W25, [X12, #0xfffffffffffffffe]! + env.code_mem[1] = 0x14000000; // B . + + std::array regs{}; + regs[12] = 1; + + Unicorn unicorn{env}; + + unicorn.SetRegisters(regs); + unicorn.SetPC(0); + + env.ticks_left = 2; + unicorn.Run(); + + REQUIRE(unicorn.GetPC() == 4); +} + +TEST_CASE("Unicorn: Ensure is able to read across page boundaries", "[a64]") { + TestEnv env; + + env.code_mem[0] = 0xb85f93d9; // LDUR W25, [X30, #0xfffffffffffffff9] + env.code_mem[1] = 0x14000000; // B . + + std::array regs{}; + regs[30] = 4; + + Unicorn unicorn{env}; + + unicorn.SetRegisters(regs); + unicorn.SetPC(0); + + env.ticks_left = 2; + unicorn.Run(); + + REQUIRE(unicorn.GetPC() == 4); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 83a7ce80..59ea2c94 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,6 +38,7 @@ if (DYNARMIC_TESTS_USE_UNICORN) A64/unicorn_emu/unicorn.cpp A64/unicorn_emu/unicorn.h A64/unicorn_emu/unicorn_load.cpp + A64/verify_unicorn.cpp ) target_link_libraries(dynarmic_tests PRIVATE Unicorn) endif()