test_common_dump.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <test.h>
23 
24 #include <entry.h>
25 #include <common.h>
26 #include <platform.h>
27 #include <driver_entry_interface.h>
28 
30 
31 void
32 driver_entry_ut::test_common_dump_invalid_drr()
33 {
34  this->expect_true(common_dump_vmm(nullptr, 0) == BF_ERROR_INVALID_ARG);
35 }
36 
37 void
38 driver_entry_ut::test_common_dump_invalid_vcpuid()
39 {
40  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
41  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
42  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
43  this->expect_true(common_add_module(m_dummy_get_drr_success.get(), m_dummy_get_drr_success_length) == BF_SUCCESS);
44  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
46  this->expect_true(common_dump_vmm(&g_drr, 100000) == BF_SUCCESS);
48 }
49 
50 void
51 driver_entry_ut::test_common_dump_dump_when_unloaded()
52 {
53  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
54  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
55  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
56  this->expect_true(common_add_module(m_dummy_get_drr_success.get(), m_dummy_get_drr_success_length) == BF_SUCCESS);
57  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
60 }
61 
62 void
63 driver_entry_ut::test_common_dump_dump_when_corrupt()
64 {
65  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
66  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
67  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
68  this->expect_true(common_add_module(m_dummy_get_drr_success.get(), m_dummy_get_drr_success_length) == BF_SUCCESS);
69  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
73  this->expect_true(common_dump_vmm(&g_drr, 0) == BF_SUCCESS);
75 
76  common_reset();
77 }
78 
79 void
80 driver_entry_ut::test_common_dump_dump_when_loaded()
81 {
82  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
83  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
84  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
85  this->expect_true(common_add_module(m_dummy_get_drr_success.get(), m_dummy_get_drr_success_length) == BF_SUCCESS);
86  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
88  this->expect_true(common_dump_vmm(&g_drr, 0) == BF_SUCCESS);
90 }
91 
92 void
93 driver_entry_ut::test_common_dump_get_drr_missing()
94 {
95  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
96  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
97  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
98  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
101  this->expect_true(common_fini() == BF_SUCCESS);
102 }
103 
104 void
105 driver_entry_ut::test_common_dump_get_drr_failure()
106 {
107  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
108  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
109  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
110  this->expect_true(common_add_module(m_dummy_get_drr_failure.get(), m_dummy_get_drr_failure_length) == BF_SUCCESS);
111  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
113  this->expect_true(common_dump_vmm(&g_drr, 0) == GET_DRR_FAILURE);
114  this->expect_true(common_fini() == BF_SUCCESS);
115 }
debug_ring_resources_t * g_drr
#define BF_SUCCESS
Definition: error_codes.h:105
int64_t common_add_module(const char *file, uint64_t fsize)
Definition: common.c:305
int64_t common_load_vmm(void)
Definition: common.c:357
int64_t common_fini(void)
Definition: common.c:273
#define BFELF_ERROR_NO_SUCH_SYMBOL
Definition: error_codes.h:89
#define BF_ERROR_VMM_INVALID_STATE
Definition: error_codes.h:110
int64_t common_dump_vmm(struct debug_ring_resources_t **drr, uint64_t vcpuid)
Definition: common.c:592
#define GET_DRR_FAILURE
Definition: error_codes.h:74
int64_t common_stop_vmm(void)
Definition: common.c:543
int64_t common_start_vmm(void)
Definition: common.c:490
#define ENTRY_ERROR_VMM_STOP_FAILED
Definition: error_codes.h:52
#define BF_ERROR_INVALID_ARG
Definition: error_codes.h:106
#define BF_ERROR_VMM_CORRUPTED
Definition: error_codes.h:114
#define expect_true(a)
int64_t common_reset(void)
Definition: common.c:233