test_common_stop.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 
28 void
29 driver_entry_ut::test_common_stop_stop_when_unloaded()
30 {
31  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
32  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
33  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
34  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
37 }
38 
39 void
40 driver_entry_ut::test_common_stop_stop_when_not_running()
41 {
42  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
43  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
44  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
45  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
49 }
50 
51 void
52 driver_entry_ut::test_common_stop_stop_when_alread_stopped()
53 {
54  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
55  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
56  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
57  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
63 }
64 
65 void
66 driver_entry_ut::test_common_stop_stop_when_corrupt()
67 {
68  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
69  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
70  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
71  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
77 
78  common_reset();
79 }
80 
81 void
82 driver_entry_ut::test_common_stop_stop_vmm_missing()
83 {
84  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_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);
91 
92  common_reset();
93 }
94 
95 void
96 driver_entry_ut::test_common_stop_stop_vmm_failure()
97 {
98  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
99  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
100  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
101  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
106 
107  common_reset();
108 }
109 
110 void
111 driver_entry_ut::test_common_stop_set_affinity_failed()
112 {
113  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
114  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
115  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
116  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
119 
120  {
121  MockRepository mocks;
122  mocks.ExpectCallFunc(platform_set_affinity).Return(-1);
123 
124  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
125  {
126  this->expect_true(common_stop_vmm() == -1);
127  });
128  }
129 
130  common_reset();
131 }
132 
133 void
134 driver_entry_ut::test_common_stop_vmcall_failed()
135 {
136  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
137  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
138  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
139  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
142 
143  {
144  MockRepository mocks;
145  mocks.ExpectCallFunc(platform_vmcall).Do([](auto regs)
146  {
147  regs->r01 = 1;
148  });
149 
150  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
151  {
153  });
154  }
155 
156  common_reset();
157 }
#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 BF_ERROR_VMM_CORRUPTED
Definition: error_codes.h:114
#define expect_true(a)
int64_t common_reset(void)
Definition: common.c:233