test_common_start.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 
29 void
30 driver_entry_ut::test_common_start_start_when_unloaded()
31 {
32  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
33  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
34  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
35  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
38 }
39 
40 void
41 driver_entry_ut::test_common_start_start_when_already_running()
42 {
43  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
44  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
45  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
46  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
51 }
52 
53 void
54 driver_entry_ut::test_common_start_start_when_corrupt()
55 {
56  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
57  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
58  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
59  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
65 
66  common_reset();
67 }
68 
69 void
70 driver_entry_ut::test_common_start_start_when_start_vmm_missing()
71 {
72  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
73  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
74  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
78 }
79 
80 void
81 driver_entry_ut::test_common_start_start_vmm_failure()
82 {
83  this->expect_true(common_add_module(m_dummy_start_vmm_failure.get(), m_dummy_start_vmm_failure_length) == BF_SUCCESS);
84  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
85  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
86  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
90 }
91 
92 void
93 driver_entry_ut::test_common_start_set_affinity_failed()
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);
100 
101  {
102  MockRepository mocks;
103  mocks.ExpectCallFunc(platform_set_affinity).Return(-1);
104 
105  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
106  {
107  this->expect_true(common_start_vmm() == -1);
108  });
109  }
110 
111  this->expect_true(common_fini() == BF_SUCCESS);
112 }
113 
114 void
115 driver_entry_ut::test_common_start_vmcall_failed()
116 {
117  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
118  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
119  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
120  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
122 
123  {
124  MockRepository mocks;
125  mocks.ExpectCallFunc(platform_vmcall).Do([](auto regs)
126  {
127  regs->r01 = 1;
128  });
129 
130  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
131  {
133  });
134  }
135 
136  this->expect_true(common_fini() == BF_SUCCESS);
137 }
#define ENTRY_ERROR_VMM_START_FAILED
Definition: error_codes.h:51
#define BF_SUCCESS
Definition: error_codes.h:105
int64_t common_add_module(const char *file, uint64_t fsize)
Definition: common.c:305
#define RUN_UNITTEST_WITH_MOCKS(a, b)
Definition: unittest.h:229
int64_t common_load_vmm(void)
Definition: common.c:357
int64_t platform_set_affinity(int64_t affinity)
Definition: platform.c:163
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
void platform_vmcall(struct vmcall_registers_t *regs)
Definition: platform.c:162
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 VMM_CORRUPT
int64_t common_vmm_status(void)
Definition: common.c:227
#define BF_ERROR_VMM_CORRUPTED
Definition: error_codes.h:114
#define expect_true(a)
int64_t common_reset(void)
Definition: common.c:233