diff options
| author | Ben Vanik <ben.vanik@gmail.com> | 2014-08-23 15:46:01 -0700 |
|---|---|---|
| committer | Ben Vanik <ben.vanik@gmail.com> | 2014-08-23 15:46:01 -0700 |
| commit | 7ebba018ada2c0239c8a6d421da3569c355beea8 (patch) | |
| tree | 8ab1d433e02615e98ee59b8f2db58fbbf2e6280e /tools | |
| parent | 2a9f164f8e247647e6efe3cc7948bcc0550a235e (diff) | |
Run tests on both IVM and x64.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/alloy-test/alloy-test.cc | 28 | ||||
| -rw-r--r-- | tools/alloy-test/test_util.h | 85 |
2 files changed, 68 insertions, 45 deletions
diff --git a/tools/alloy-test/alloy-test.cc b/tools/alloy-test/alloy-test.cc index da558735a..295f8a1bf 100644 --- a/tools/alloy-test/alloy-test.cc +++ b/tools/alloy-test/alloy-test.cc @@ -17,29 +17,35 @@ using namespace alloy::hir; using namespace alloy::runtime; 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) { - auto r = b.Add(b.LoadContext(offsetof(PPCContext, r) + 5 * 8, INT64_TYPE), - b.LoadContext(offsetof(PPCContext, r) + 25 * 8, INT64_TYPE)); - b.StoreContext(offsetof(PPCContext, r) + 11 * 8, r); + auto v = b.Add(LoadGPR(b, 4), LoadGPR(b, 5)); + StoreGPR(b, 3, v); b.Return(); - return true; }); test.Run([](PPCContext* ctx) { - ctx->r[5] = 10; - ctx->r[25] = 25; + ctx->r[4] = 10; + ctx->r[5] = 25; }, [](PPCContext* ctx) { - auto result = ctx->r[11]; + auto result = ctx->r[3]; REQUIRE(result == 0x23); }); test.Run([](PPCContext* ctx) { - ctx->r[5] = 10; - ctx->r[25] = 25; + ctx->r[4] = 10; + ctx->r[5] = 25; }, [](PPCContext* ctx) { - auto result = ctx->r[11]; + auto result = ctx->r[3]; REQUIRE(result == 0x24); }); } diff --git a/tools/alloy-test/test_util.h b/tools/alloy-test/test_util.h index 34f4964b4..c2406a925 100644 --- a/tools/alloy-test/test_util.h +++ b/tools/alloy-test/test_util.h @@ -36,7 +36,8 @@ int main(std::vector<std::wstring>& args) { narrow_argv[i] = const_cast<char*>(narrow_arg.data()); 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 { @@ -89,57 +90,73 @@ class ThreadState : public alloy::runtime::ThreadState { class TestFunction { public: - TestFunction(std::function<bool(hir::HIRBuilder& b)> generator) { + TestFunction(std::function<void(hir::HIRBuilder& b)> generator) { memory_size = 16 * 1024 * 1024; memory.reset(new SimpleMemory(memory_size)); - runtime.reset(new Runtime(memory.get())); - - auto frontend = - std::make_unique<alloy::frontend::ppc::PPCFrontend>(runtime.get()); - std::unique_ptr<alloy::backend::Backend> backend; - // backend = - // 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)); - - auto module = std::make_unique<alloy::runtime::TestModule>( - runtime.get(), "Test", - [](uint64_t address) { return address == 0x1000; }, - [generator](hir::HIRBuilder& b) { return generator(b); }); - runtime->AddModule(std::move(module)); - - runtime->ResolveFunction(0x1000, &fn); + + { + 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::ivm::IVMBackend>(runtime.get()); + 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>( + runtime.get(), "Test", + [](uint64_t address) { return address == 0x1000; }, + [generator](hir::HIRBuilder& b) { + generator(b); + return true; + }); + runtime->AddModule(std::move(module)); + } } ~TestFunction() { - runtime.reset(); + runtimes.clear(); memory.reset(); } void Run(std::function<void(PPCContext*)> pre_call, std::function<void(PPCContext*)> post_call) { - memory->Zero(0, memory_size); + for (auto& runtime : runtimes) { + memory->Zero(0, memory_size); + + alloy::runtime::Function* fn; + runtime->ResolveFunction(0x1000, &fn); - uint64_t stack_size = 64 * 1024; - uint64_t stack_address = memory_size - stack_size; - uint64_t thread_state_address = stack_address - 0x1000; - auto thread_state = std::make_unique<ThreadState>( - runtime.get(), 100, stack_address, stack_size, thread_state_address); - auto ctx = thread_state->context(); - ctx->lr = 0xBEBEBEBE; + uint64_t stack_size = 64 * 1024; + uint64_t stack_address = memory_size - stack_size; + uint64_t thread_state_address = stack_address - 0x1000; + auto thread_state = std::make_unique<ThreadState>( + runtime.get(), 100, stack_address, stack_size, thread_state_address); + auto ctx = thread_state->context(); + ctx->lr = 0xBEBEBEBE; - pre_call(ctx); + pre_call(ctx); - fn->Call(thread_state.get(), ctx->lr); + fn->Call(thread_state.get(), ctx->lr); - post_call(ctx); + post_call(ctx); + } } size_t memory_size; std::unique_ptr<Memory> memory; - std::unique_ptr<Runtime> runtime; - alloy::runtime::Function* fn; + std::vector<std::unique_ptr<Runtime>> runtimes; }; } // namespace test |
