tools: Use VM::get_raw_pointer()

This commit is contained in:
Paweł Bylica 2019-12-13 13:03:49 +01:00
parent 347c65ae63
commit 05e3519526
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
2 changed files with 6 additions and 11 deletions

View File

@ -7,15 +7,8 @@
#include <evmc/loader.h> #include <evmc/loader.h>
#include <iostream> #include <iostream>
evmc_vm* evmc_vm_test::vm;
evmc::VM evmc_vm_test::owned_vm; evmc::VM evmc_vm_test::owned_vm;
void evmc_vm_test::init_vm(evmc_vm* _owned_vm) noexcept
{
vm = _owned_vm;
owned_vm = evmc::VM{_owned_vm};
}
class cli_parser class cli_parser
{ {
public: public:
@ -127,7 +120,7 @@ int main(int argc, char* argv[])
std::cout << "Testing " << evmc_module << "\n"; std::cout << "Testing " << evmc_module << "\n";
evmc_loader_error_code ec; evmc_loader_error_code ec;
auto vm_instance = evmc_load_and_configure(evmc_module.c_str(), &ec); auto vm = evmc::VM{evmc_load_and_configure(evmc_module.c_str(), &ec)};
if (ec != EVMC_LOADER_SUCCESS) if (ec != EVMC_LOADER_SUCCESS)
{ {
const auto error = evmc_last_error_msg(); const auto error = evmc_last_error_msg();
@ -138,7 +131,7 @@ int main(int argc, char* argv[])
return static_cast<int>(ec); return static_cast<int>(ec);
} }
evmc_vm_test::init_vm(vm_instance); evmc_vm_test::set_vm(std::move(vm));
std::cout << std::endl; std::cout << std::endl;
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();

View File

@ -9,15 +9,17 @@
class evmc_vm_test : public ::testing::Test class evmc_vm_test : public ::testing::Test
{ {
public: public:
static void init_vm(evmc_vm* owned_vm) noexcept; static void set_vm(evmc::VM _owned_vm) noexcept { owned_vm = std::move(_owned_vm); }
protected: protected:
/// The raw pointer to the loaded VM instance. /// The raw pointer to the loaded VM instance.
/// The C API is used to allow more sophisticated unit tests. /// The C API is used to allow more sophisticated unit tests.
static evmc_vm* vm; evmc_vm* vm = nullptr;
/// The C++ RAII wrapper of the loaded VM instance. /// The C++ RAII wrapper of the loaded VM instance.
static evmc::VM owned_vm; static evmc::VM owned_vm;
evmc_vm_test() : vm{owned_vm.get_raw_pointer()} {}
void SetUp() override { ASSERT_TRUE(vm != nullptr) << "VM instance not loaded"; } void SetUp() override { ASSERT_TRUE(vm != nullptr) << "VM instance not loaded"; }
}; };