Run tests on both IVM and x64.

This commit is contained in:
Ben Vanik 2014-08-23 15:46:01 -07:00
parent 2a9f164f8e
commit 7ebba018ad
2 changed files with 66 additions and 43 deletions

View File

@ -17,29 +17,35 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
TEST_CASE("Meta test", "[test]") { Value* LoadGPR(hir::HIRBuilder& b, int reg) {
return b.LoadContext(offsetof(PPCContext, r) + reg * 8, INT64_TYPE);
}
void StoreGPR(hir::HIRBuilder& b, int reg, Value* value) {
b.StoreContext(offsetof(PPCContext, r) + reg * 8, value);
}
TEST_CASE("ADD", "[instr]") {
alloy::test::TestFunction test([](hir::HIRBuilder& b) { alloy::test::TestFunction test([](hir::HIRBuilder& b) {
auto r = b.Add(b.LoadContext(offsetof(PPCContext, r) + 5 * 8, INT64_TYPE), auto v = b.Add(LoadGPR(b, 4), LoadGPR(b, 5));
b.LoadContext(offsetof(PPCContext, r) + 25 * 8, INT64_TYPE)); StoreGPR(b, 3, v);
b.StoreContext(offsetof(PPCContext, r) + 11 * 8, r);
b.Return(); b.Return();
return true;
}); });
test.Run([](PPCContext* ctx) { test.Run([](PPCContext* ctx) {
ctx->r[5] = 10; ctx->r[4] = 10;
ctx->r[25] = 25; ctx->r[5] = 25;
}, },
[](PPCContext* ctx) { [](PPCContext* ctx) {
auto result = ctx->r[11]; auto result = ctx->r[3];
REQUIRE(result == 0x23); REQUIRE(result == 0x23);
}); });
test.Run([](PPCContext* ctx) { test.Run([](PPCContext* ctx) {
ctx->r[5] = 10; ctx->r[4] = 10;
ctx->r[25] = 25; ctx->r[5] = 25;
}, },
[](PPCContext* ctx) { [](PPCContext* ctx) {
auto result = ctx->r[11]; auto result = ctx->r[3];
REQUIRE(result == 0x24); REQUIRE(result == 0x24);
}); });
} }

View File

@ -36,7 +36,8 @@ int main(std::vector<std::wstring>& args) {
narrow_argv[i] = const_cast<char*>(narrow_arg.data()); narrow_argv[i] = const_cast<char*>(narrow_arg.data());
narrow_args.push_back(std::move(narrow_arg)); narrow_args.push_back(std::move(narrow_arg));
} }
return Catch::Session().run(int(args.size()), narrow_argv); int ret = Catch::Session().run(int(args.size()), narrow_argv);
return ret;
} }
class ThreadState : public alloy::runtime::ThreadState { class ThreadState : public alloy::runtime::ThreadState {
@ -89,38 +90,54 @@ class ThreadState : public alloy::runtime::ThreadState {
class TestFunction { class TestFunction {
public: public:
TestFunction(std::function<bool(hir::HIRBuilder& b)> generator) { TestFunction(std::function<void(hir::HIRBuilder& b)> generator) {
memory_size = 16 * 1024 * 1024; memory_size = 16 * 1024 * 1024;
memory.reset(new SimpleMemory(memory_size)); memory.reset(new SimpleMemory(memory_size));
runtime.reset(new Runtime(memory.get()));
{
auto runtime = std::make_unique<Runtime>(memory.get());
auto frontend = auto frontend =
std::make_unique<alloy::frontend::ppc::PPCFrontend>(runtime.get()); std::make_unique<alloy::frontend::ppc::PPCFrontend>(runtime.get());
std::unique_ptr<alloy::backend::Backend> backend; auto backend =
// backend = std::make_unique<alloy::backend::ivm::IVMBackend>(runtime.get());
// std::make_unique<alloy::backend::ivm::IVMBackend>(runtime.get());
// backend =
// std::make_unique<alloy::backend::x64::X64Backend>(runtime.get());
runtime->Initialize(std::move(frontend), std::move(backend)); runtime->Initialize(std::move(frontend), std::move(backend));
runtimes.emplace_back(std::move(runtime));
}
{
auto runtime = std::make_unique<Runtime>(memory.get());
auto frontend =
std::make_unique<alloy::frontend::ppc::PPCFrontend>(runtime.get());
auto backend =
std::make_unique<alloy::backend::x64::X64Backend>(runtime.get());
runtime->Initialize(std::move(frontend), std::move(backend));
runtimes.emplace_back(std::move(runtime));
}
for (auto& runtime : runtimes) {
auto module = std::make_unique<alloy::runtime::TestModule>( auto module = std::make_unique<alloy::runtime::TestModule>(
runtime.get(), "Test", runtime.get(), "Test",
[](uint64_t address) { return address == 0x1000; }, [](uint64_t address) { return address == 0x1000; },
[generator](hir::HIRBuilder& b) { return generator(b); }); [generator](hir::HIRBuilder& b) {
generator(b);
return true;
});
runtime->AddModule(std::move(module)); runtime->AddModule(std::move(module));
}
runtime->ResolveFunction(0x1000, &fn);
} }
~TestFunction() { ~TestFunction() {
runtime.reset(); runtimes.clear();
memory.reset(); memory.reset();
} }
void Run(std::function<void(PPCContext*)> pre_call, void Run(std::function<void(PPCContext*)> pre_call,
std::function<void(PPCContext*)> post_call) { std::function<void(PPCContext*)> post_call) {
for (auto& runtime : runtimes) {
memory->Zero(0, memory_size); memory->Zero(0, memory_size);
alloy::runtime::Function* fn;
runtime->ResolveFunction(0x1000, &fn);
uint64_t stack_size = 64 * 1024; uint64_t stack_size = 64 * 1024;
uint64_t stack_address = memory_size - stack_size; uint64_t stack_address = memory_size - stack_size;
uint64_t thread_state_address = stack_address - 0x1000; uint64_t thread_state_address = stack_address - 0x1000;
@ -135,11 +152,11 @@ class TestFunction {
post_call(ctx); post_call(ctx);
} }
}
size_t memory_size; size_t memory_size;
std::unique_ptr<Memory> memory; std::unique_ptr<Memory> memory;
std::unique_ptr<Runtime> runtime; std::vector<std::unique_ptr<Runtime>> runtimes;
alloy::runtime::Function* fn;
}; };
} // namespace test } // namespace test