loader: Add unit tests for load_and_create()

This commit is contained in:
Paweł Bylica 2018-07-13 15:31:49 +02:00
parent edb29b7267
commit 2e2b7f0e81
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 32 additions and 0 deletions

View File

@ -24,6 +24,8 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> _
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> lib_.so
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> ../aaa.evm
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> failure.vm
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> abi42.vm
COMMAND ${CMAKE_COMMAND} -E touch empty.file
)

View File

@ -244,3 +244,19 @@ TEST(loader, lib_)
x = evmc_load(path, nullptr);
EXPECT_EQ(x, nullptr);
}
TEST(loader, load_and_create_failure)
{
evmc_loader_error_code ec;
auto vm = evmc_load_and_create("unittests/failure.vm", &ec);
EXPECT_EQ(vm, nullptr);
EXPECT_EQ(ec, EVMC_LOADER_INSTANCE_CREATION_FAILURE);
}
TEST(loader, load_and_create_abi_mismatch)
{
evmc_loader_error_code ec;
auto vm = evmc_load_and_create("unittests/abi42.vm", &ec);
EXPECT_EQ(vm, nullptr);
EXPECT_EQ(ec, EVMC_LOADER_ABI_VERSION_MISMATCH);
}

View File

@ -3,6 +3,7 @@
* Licensed under the MIT License. See the LICENSE file.
*/
#include <evmc/evmc.h>
#include <evmc/utils.h>
EVMC_EXPORT void* evmc_create_aaa()
@ -14,3 +15,16 @@ EVMC_EXPORT void* evmc_create_eee_bbb()
{
return (void*)0xeeebbb;
}
EVMC_EXPORT void* evmc_create_failure()
{
return NULL;
}
EVMC_EXPORT struct evmc_instance* evmc_create_abi42()
{
static struct evmc_instance instance = {
.abi_version = 42,
};
return &instance;
}