예제 #1
0
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);
}
예제 #2
0
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);
}
예제 #3
0
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);
}
예제 #4
0
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);
}
예제 #5
0
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);
    });
}
예제 #6
0
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);
    });
}
예제 #7
0
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);
}
예제 #8
0
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;
}
예제 #9
0
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();
}
예제 #10
0
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);
    });
}
예제 #11
0
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);
    });
}
예제 #12
0
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;
}
예제 #13
0
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;
}
예제 #14
0
void
driver_entry_ut::test_common_dump_invalid_drr()
{
    EXPECT_TRUE(common_dump_vmm(0) == BF_ERROR_INVALID_ARG);
}