49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
/**
|
|
* Tests for ArgTranslator stack argument support and ImportFunction isolation.
|
|
*/
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <rex/ppc/context.h>
|
|
#include <rex/ppc/function.h>
|
|
|
|
using namespace rex::ppc;
|
|
|
|
// Fake 64KB guest memory block for tests
|
|
alignas(64) static uint8_t g_test_mem[0x10000] = {};
|
|
|
|
TEST_CASE("SetIntegerArgumentValue writes stack args for index > 7", "[ppc][arg_translator]") {
|
|
PPCContext ctx{};
|
|
ctx.r1.u32 = 0x8000;
|
|
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 8, 0xDEADBEEF);
|
|
|
|
uint64_t readback = ArgTranslator::GetIntegerArgumentValue(ctx, g_test_mem, 8);
|
|
CHECK(readback == 0xDEADBEEF);
|
|
}
|
|
|
|
TEST_CASE("SetIntegerArgumentValue writes multiple stack args at correct offsets",
|
|
"[ppc][arg_translator]") {
|
|
PPCContext ctx{};
|
|
ctx.r1.u32 = 0x8000;
|
|
std::memset(g_test_mem + 0x8000, 0, 0x100);
|
|
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 8, 0x11111111);
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 9, 0x22222222);
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 10, 0x33333333);
|
|
|
|
CHECK(ArgTranslator::GetIntegerArgumentValue(ctx, g_test_mem, 8) == 0x11111111);
|
|
CHECK(ArgTranslator::GetIntegerArgumentValue(ctx, g_test_mem, 9) == 0x22222222);
|
|
CHECK(ArgTranslator::GetIntegerArgumentValue(ctx, g_test_mem, 10) == 0x33333333);
|
|
}
|
|
|
|
TEST_CASE("SetIntegerArgumentValue still works for register args 0-7", "[ppc][arg_translator]") {
|
|
PPCContext ctx{};
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 0, 0xAAAA);
|
|
ArgTranslator::SetIntegerArgumentValue(ctx, g_test_mem, 7, 0xBBBB);
|
|
CHECK(ctx.r3.u64 == 0xAAAA);
|
|
CHECK(ctx.r10.u64 == 0xBBBB);
|
|
}
|