A64/tests: Split unicorn sanity checking from other tests

This commit is contained in:
MerryMage 2018-01-17 20:00:42 +00:00
parent 9d42bc3228
commit 7992a319ba
3 changed files with 85 additions and 70 deletions

View file

@ -7,7 +7,6 @@
#include <cstring>
#include <catch.hpp>
#include <unicorn/arm64.h>
#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<u64, 31> 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<u64, 31> 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<u64, 31> 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<InstructionGenerator> instruction_generators = []{
const std::vector<std::tuple<const char*, const char*>> list {
#define INST(fn, name, bitstring) {#fn, bitstring},
@ -121,7 +54,7 @@ restart:
return instruction;
}
static void TestInstance(const std::array<u64, 31>& regs, const std::vector<u32>& instructions, u32 pstate) {
static void RunTestInstance(const std::array<u64, 31>& regs, const std::vector<u32>& 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<u32>(0, 0xF) << 28;
// printf("%08x\n", instructions[0]);
INFO("Instruction: " << instructions[0]);
TestInstance(regs, instructions, pstate);
RunTestInstance(regs, instructions, pstate);
}
}

View file

@ -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 <array>
#include <catch.hpp>
#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<u64, 31> 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<u64, 31> 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<u64, 31> regs{};
regs[30] = 4;
Unicorn unicorn{env};
unicorn.SetRegisters(regs);
unicorn.SetPC(0);
env.ticks_left = 2;
unicorn.Run();
REQUIRE(unicorn.GetPC() == 4);
}

View file

@ -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()