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_dump_success_multiple_times() { 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_SUCCESS); EXPECT_TRUE(common_unload_vmm() == BF_SUCCESS); }
void driver_entry_ut::test_common_dump_get_drr_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_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_dump_vmm(&g_drr) == BFELF_ERROR_NO_SUCH_SYMBOL); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_dump_dump_when_unloaded() { 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_dump_vmm(&g_drr) == BF_ERROR_VMM_INVALID_STATE); EXPECT_TRUE(common_fini() == BF_SUCCESS); }
void driver_entry_ut::test_common_dump_status_unloaded() { MockRepository mocks; mocks.OnCallFunc(vmm_status).Return(VMM_UNLOADED); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_dump_vmm() == BF_ERROR_VMM_INVALID_STATE); }); }
void driver_entry_ut::test_common_dump_status_corrupt() { MockRepository mocks; mocks.OnCallFunc(vmm_status).Return(VMM_CORRUPT); RUN_UNITTEST_WITH_MOCKS(mocks, [&] { EXPECT_TRUE(common_dump_vmm() == BF_ERROR_VMM_CORRUPTED); }); }
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); }
static long ioctl_dump_vmm(struct debug_ring_resources_t *user_drr) { int64_t ret; ret = common_dump_vmm(&user_drr); if (ret != BF_SUCCESS) { ALERT("IOCTL_DUMP_VMM: failed to dump vmm: %lld\n", ret); return BF_IOCTL_FAILURE; } DEBUG("IOCTL_DUMP_VMM: succeeded\n"); return BF_IOCTL_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 int64_t ioctl_dump_vmm(struct debug_ring_resources_t *user_drr) { int64_t ret; struct debug_ring_resources_t *drr = 0; ret = common_dump_vmm(&drr, g_vcpuid); if (ret != BF_SUCCESS) { ALERT("IOCTL_DUMP_VMM: common_dump_vmm failed: %p - %s\n", (void *)ret, ec_to_str(ret)); return BF_IOCTL_FAILURE; } platform_memcpy(user_drr, drr, sizeof(struct debug_ring_resources_t)); DEBUG("IOCTL_DUMP_VMM: succeeded\n"); return BF_IOCTL_SUCCESS; }
static long ioctl_dump_vmm(struct debug_ring_resources_t *user_drr) { int64_t ret; struct debug_ring_resources_t *drr = 0; ret = common_dump_vmm(&drr, g_vcpuid); if (ret != BF_SUCCESS) { ALERT("IOCTL_DUMP_VMM: common_dump_vmm failed: %p - %s\n", \ (void *)ret, ec_to_str(ret)); return BF_IOCTL_FAILURE; } ret = copy_to_user(user_drr, drr, sizeof(struct debug_ring_resources_t)); if (ret != 0) { ALERT("IOCTL_DUMP_VMM: failed to copy memory from userspace\n"); return BF_IOCTL_FAILURE; } DEBUG("IOCTL_DUMP_VMM: succeeded\n"); return BF_IOCTL_SUCCESS; }
void driver_entry_ut::test_common_dump_invalid_drr() { EXPECT_TRUE(common_dump_vmm(0) == BF_ERROR_INVALID_ARG); }