test_common_fini.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_fini_unloaded()
31 {
35 }
36 
37 void
38 driver_entry_ut::test_common_fini_successful_start()
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_success.get(), m_dummy_stop_vmm_success_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_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
48 }
49 
50 void
51 driver_entry_ut::test_common_fini_successful_load()
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_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
60 }
61 
62 void
63 driver_entry_ut::test_common_fini_successful_add_module()
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_success.get(), m_dummy_stop_vmm_success_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_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
71 }
72 
73 void
74 driver_entry_ut::test_common_fini_corrupted()
75 {
76  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
77  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
78  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
79  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
84 
85  common_reset();
86 }
87 
88 void
89 driver_entry_ut::test_common_fini_failed_load()
90 {
91  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
92  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
96 }
97 
98 void
99 driver_entry_ut::test_common_fini_failed_start()
100 {
101  this->expect_true(common_add_module(m_dummy_start_vmm_failure.get(), m_dummy_start_vmm_failure_length) == BF_SUCCESS);
102  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
103  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
104  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
107  this->expect_true(common_fini() == BF_SUCCESS);
109 }
110 
111 void
112 driver_entry_ut::test_common_fini_unload_failed()
113 {
114  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
115  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
116  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
117  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
119 
120  {
121  MockRepository mocks;
122  mocks.ExpectCallFunc(common_unload_vmm).Return(-1);
123 
124  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
125  {
126  this->expect_true(common_fini() == BF_SUCCESS);
127  });
128  }
129 
130  this->expect_true(common_fini() == BF_SUCCESS);
132 }
133 
134 void
135 driver_entry_ut::test_common_fini_stop_failed()
136 {
137  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
138  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
139  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
140  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
143 
144  {
145  MockRepository mocks;
146  mocks.ExpectCallFunc(common_stop_vmm).Return(-1);
147 
148  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
149  {
150  this->expect_true(common_fini() == BF_SUCCESS);
151  });
152  }
153 
154  this->expect_true(common_fini() == BF_SUCCESS);
156 }
157 
158 void
159 driver_entry_ut::test_common_fini_reset_failed()
160 {
161  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
162  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
163  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
164  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
167 
168  {
169  MockRepository mocks;
170  mocks.ExpectCallFunc(common_reset).Return(-1);
171  mocks.ExpectCallFunc(common_reset).Return(-1);
172 
173  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
174  {
175  this->expect_true(common_fini() == BF_SUCCESS);
176  });
177  }
178 
179  this->expect_true(common_fini() == BF_SUCCESS);
181 }
#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 common_fini(void)
Definition: common.c:273
#define BFELF_ERROR_NO_SUCH_SYMBOL
Definition: error_codes.h:89
int64_t common_stop_vmm(void)
Definition: common.c:543
#define VMM_UNLOADED
int64_t common_start_vmm(void)
Definition: common.c:490
int64_t common_unload_vmm(void)
Definition: common.c:451
#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