test_common_unload.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 <common.h>
25 #include <platform.h>
26 #include <driver_entry_interface.h>
27 
28 // -----------------------------------------------------------------------------
29 // Expose Private Functions
30 // -----------------------------------------------------------------------------
31 
32 extern "C"
33 {
34  int64_t execute_symbol(const char *sym, uint64_t arg1, uint64_t arg2, uint64_t cpuid);
35 }
36 
37 // -----------------------------------------------------------------------------
38 // Tests
39 // -----------------------------------------------------------------------------
40 
41 void
42 driver_entry_ut::test_common_unload_unload_when_already_unloaded()
43 {
45 }
46 
47 void
48 driver_entry_ut::test_common_unload_unload_when_running()
49 {
50  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
51  this->expect_true(common_add_module(m_dummy_stop_vmm_success.get(), m_dummy_stop_vmm_success_length) == BF_SUCCESS);
52  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
53  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
58 }
59 
60 void
61 driver_entry_ut::test_common_unload_unload_when_corrupt()
62 {
63  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
64  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
65  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
66  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
72 
73  common_reset();
74 }
75 
76 void
77 driver_entry_ut::test_common_unload_execute_symbol_failed()
78 {
79  this->expect_true(common_add_module(m_dummy_start_vmm_success.get(), m_dummy_start_vmm_success_length) == BF_SUCCESS);
80  this->expect_true(common_add_module(m_dummy_stop_vmm_failure.get(), m_dummy_stop_vmm_failure_length) == BF_SUCCESS);
81  this->expect_true(common_add_module(m_dummy_add_md_success.get(), m_dummy_add_md_success_length) == BF_SUCCESS);
82  this->expect_true(common_add_module(m_dummy_misc.get(), m_dummy_misc_length) == BF_SUCCESS);
84 
85  {
86  MockRepository mocks;
87  mocks.ExpectCallFunc(execute_symbol).Return(-1);
88 
89  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
90  {
91  this->expect_true(common_unload_vmm() == -1);
92  });
93  }
94 
95  common_reset();
96 }
#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 BF_ERROR_VMM_INVALID_STATE
Definition: error_codes.h:110
int64_t common_start_vmm(void)
Definition: common.c:490
int64_t execute_symbol(const char *sym, uint64_t arg1, uint64_t arg2, uint64_t cpuid)
Definition: common.c:108
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