void driver_entry_ut::test_common_load_load_when_already_loaded() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_vmm_status() == VMM_LOADED); this->expect_true(common_fini() == BF_SUCCESS); this->expect_true(common_vmm_status() == VMM_UNLOADED); }
void driver_entry_ut::test_common_load_load_when_already_running() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_start_vmm() == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_ERROR_VMM_INVALID_STATE); this->expect_true(common_vmm_status() == VMM_RUNNING); this->expect_true(common_fini() == BF_SUCCESS); this->expect_true(common_vmm_status() == VMM_UNLOADED); }
void driver_entry_ut::test_common_load_load_when_corrupt() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_start_vmm() == BF_SUCCESS); this->expect_true(common_fini() == BF_ERROR_VMM_CORRUPTED); this->expect_true(common_vmm_status() == VMM_CORRUPT); this->expect_true(common_load_vmm() == BF_ERROR_VMM_CORRUPTED); common_reset(); }
void driver_entry_ut::test_common_dump_resolve_symbol_failed() { EXPECT_TRUE(common_add_module(m_dummy1, m_dummy1_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy2, m_dummy2_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy3, m_dummy3_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); // We need to wrap the mocks variable in a temporary stack frame as the // current implementation of HippoMocks does not have a function to undo // it's hooks into c-style functions as the functionality to do this is // in the destructor. { MockRepository mocks; mocks.OnCallFunc(resolve_symbol).Return(-1); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_dump_vmm() == BF_ERROR_FAILED_TO_DUMP_DR); }); } EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_fail_due_to_no_modules_added() { this->expect_true(common_load_vmm() == BF_ERROR_NO_MODULES_ADDED); this->expect_true(common_vmm_status() == VMM_UNLOADED); this->expect_true(common_fini() == BF_SUCCESS); this->expect_true(common_vmm_status() == VMM_UNLOADED); }
void driver_entry_ut::test_common_load_success() { EXPECT_TRUE(common_add_module(m_dummy1, m_dummy1_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy2, m_dummy2_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy3, m_dummy3_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_add_md_failed() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_failure.get(), m_dummy_add_md_failure_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == MEMORY_MANAGER_FAILURE); this->expect_true(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_add_module_add_when_already_loaded() { EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_vmm_status() == VMM_LOADED); EXPECT_TRUE(common_add_module(m_dummy_get_drr_success, m_dummy_get_drr_success_length) == BF_ERROR_VMM_INVALID_STATE); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_fail_due_to_relocation_error() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BFELF_ERROR_NO_SUCH_SYMBOL); this->expect_true(common_vmm_status() == VMM_UNLOADED); this->expect_true(common_fini() == BF_SUCCESS); this->expect_true(common_vmm_status() == VMM_UNLOADED); }
void driver_entry_ut::test_common_start_start_when_start_vmm_missing() { this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_start_vmm() == BFELF_ERROR_NO_SUCH_SYMBOL); this->expect_true(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_start_start_when_start_vmm_missing() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_success, m_dummy_init_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BFELF_ERROR_NO_SUCH_SYMBOL); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_start_start_vmm_failure() { this->expect_true(common_add_module(m_dummy_start_vmm_failure.get(), m_dummy_start_vmm_failure_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_SUCCESS); this->expect_true(common_start_vmm() == ENTRY_ERROR_VMM_START_FAILED); this->expect_true(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_unload_unload_when_running() { EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_md_success, m_dummy_add_md_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BF_SUCCESS); EXPECT_TRUE(common_unload_vmm() == BF_ERROR_VMM_INVALID_STATE); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_status_corrupt() { MockRepository mocks; mocks.OnCallFunc(vmm_status).Return(VMM_CORRUPT); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_load_vmm() == BF_ERROR_VMM_CORRUPTED); }); }
void driver_entry_ut::test_common_load_status_loaded() { MockRepository mocks; mocks.OnCallFunc(vmm_status).Return(VMM_LOADED); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); }); }
void driver_entry_ut::test_common_load_status_running() { MockRepository mocks; mocks.OnCallFunc(vmm_status).Return(VMM_RUNNING); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_load_vmm() == BF_ERROR_VMM_INVALID_STATE); }); }
void driver_entry_ut::test_common_start_init_vmm_failure() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_failure, m_dummy_init_vmm_failure_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == ENTRY_ERROR_VMM_INIT_FAILED); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_loader_init_failed() { MockRepository mocks; mocks.OnCallFunc(bfelf_loader_init).Return(-1); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_load_vmm() == -1); }); }
void driver_entry_ut::test_common_dump_dump_when_loaded() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_success, m_dummy_init_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_get_drr_success, m_dummy_get_drr_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_dump_vmm(&g_drr) == BF_SUCCESS); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_dump_get_drr_failure() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_success, m_dummy_init_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_get_drr_failure, m_dummy_get_drr_failure_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_dump_vmm(&g_drr) == BF_ERROR_FAILED_TO_DUMP_DR); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_start_start_when_already_running() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_success, m_dummy_init_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_success, m_dummy_stop_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BF_SUCCESS); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_unload_unload_when_corrupt() { EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_failure, m_dummy_stop_vmm_failure_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_md_success, m_dummy_add_md_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BF_SUCCESS); EXPECT_TRUE(common_fini() == BF_ERROR_VMM_CORRUPTED); EXPECT_TRUE(common_vmm_status() == VMM_CORRUPT); EXPECT_TRUE(common_unload_vmm() == BF_ERROR_VMM_CORRUPTED); common_reset(); }
void driver_entry_ut::test_common_load_stack_platform_alloc_failed() { g_malloc_fails = STACK_SIZE * 2; auto ___ = gsl::finally([&] { g_malloc_fails = 0; }); this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); this->expect_true(common_load_vmm() == BF_ERROR_OUT_OF_MEMORY); this->expect_true(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_load_loader_add_file_failed() { MockRepository mocks; mocks.OnCallFunc(bfelf_loader_add).Return(-1); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_add_module(m_dummy1, m_dummy1_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy2, m_dummy2_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy3, m_dummy3_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == -1); EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }); }
void driver_entry_ut::test_common_dump_dump_when_corrupt() { EXPECT_TRUE(common_add_module(m_dummy_init_vmm_success, m_dummy_init_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_start_vmm_success, m_dummy_start_vmm_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_stop_vmm_failure, m_dummy_stop_vmm_failure_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_add_mdl_success, m_dummy_add_mdl_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_get_drr_success, m_dummy_get_drr_success_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy_misc, m_dummy_misc_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_start_vmm() == BF_SUCCESS); EXPECT_TRUE(common_stop_vmm() == ENTRY_ERROR_VMM_STOP_FAILED); EXPECT_TRUE(common_dump_vmm(&g_drr) == BF_SUCCESS); EXPECT_TRUE(common_fini() == BF_ERROR_VMM_CORRUPTED); common_reset(); }
void driver_entry_ut::test_common_dump_platform_alloc_failed() { MockRepository mocks; mocks.OnCallFunc(platform_alloc).Return(0); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_add_module(m_dummy1, m_dummy1_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy2, m_dummy2_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy3, m_dummy3_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_dump_vmm() == BF_ERROR_OUT_OF_MEMORY); EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }); }
void driver_entry_ut::test_common_dump_debug_ring_read_failed() { MockRepository mocks; mocks.OnCallFunc(debug_ring_read).Return(-1); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_add_module(m_dummy1, m_dummy1_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy2, m_dummy2_length) == BF_SUCCESS); EXPECT_TRUE(common_add_module(m_dummy3, m_dummy3_length) == BF_SUCCESS); EXPECT_TRUE(common_load_vmm() == BF_SUCCESS); EXPECT_TRUE(common_dump_vmm() == BF_ERROR_FAILED_TO_DUMP_DR); EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }); }
static long ioctl_load_vmm(void) { int64_t ret; ret = common_load_vmm(); if (ret != BF_SUCCESS) { ALERT("IOCTL_LOAD_VMM: failed to load vmm: %lld\n", ret); goto failure; } DEBUG("IOCTL_LOAD_VMM: succeeded\n"); return BF_IOCTL_SUCCESS; failure: ioctl_unload_vmm(); return BF_IOCTL_FAILURE; }
void driver_entry_ut::test_common_load_execute_symbol_failed() { this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS); this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS); { MockRepository mocks; mocks.ExpectCallFunc(execute_symbol).Return(-1); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { this->expect_true(common_load_vmm() == -1); }); } this->expect_true(common_fini() == BF_SUCCESS); }
static int64_t ioctl_load_vmm(void) { int64_t ret; ret = common_load_vmm(); if (ret != BF_SUCCESS) { ALERT("IOCTL_LOAD_VMM: ioctl_load_vmm failed: %p - %s\n", (void *)ret, ec_to_str(ret)); goto failure; } DEBUG("IOCTL_LOAD_VMM: succeeded\n"); return BF_IOCTL_SUCCESS; failure: ioctl_unload_vmm(); return BF_IOCTL_FAILURE; }