test.h
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 #ifndef TEST_H
23 #define TEST_H
24 
25 #include <unittest.h>
26 
27 class driver_entry_ut : public unittest
28 {
29 public:
30 
32  ~driver_entry_ut() override = default;
33 
34 protected:
35 
36  bool init() override;
37  bool fini() override;
38  bool list() override;
39 
40 private:
41 
42  void test_common_init();
43 
44  void test_common_fini_unloaded();
45  void test_common_fini_successful_start();
46  void test_common_fini_successful_load();
47  void test_common_fini_successful_add_module();
48  void test_common_fini_corrupted();
49  void test_common_fini_failed_load();
50  void test_common_fini_failed_start();
51  void test_common_fini_unload_failed();
52  void test_common_fini_stop_failed();
53  void test_common_fini_reset_failed();
54 
55  void test_common_add_module_invalid_file();
56  void test_common_add_module_invalid_file_size();
57  void test_common_add_module_garbage_module();
58  void test_common_add_module_add_when_already_loaded();
59  void test_common_add_module_add_when_already_running();
60  void test_common_add_module_add_when_corrupt();
61  void test_common_add_module_add_too_many();
62  void test_common_add_module_platform_alloc_fails();
63  void test_common_add_module_load_elf_fails();
64 
65  void test_common_load_successful_load();
66  void test_common_load_load_when_already_loaded();
67  void test_common_load_load_when_already_running();
68  void test_common_load_load_when_corrupt();
69  void test_common_load_fail_due_to_relocation_error();
70  void test_common_load_fail_due_to_no_modules_added();
71  void test_common_load_add_md_failed();
72  void test_common_load_add_md_tls_failed();
73  void test_common_load_tls_platform_alloc_failed();
74  void test_common_load_stack_platform_alloc_failed();
75  void test_common_load_loader_add_failed();
76  void test_common_load_resolve_symbol_failed();
77  void test_common_load_execute_symbol_failed();
78 
79  void test_common_unload_unload_when_already_unloaded();
80  void test_common_unload_unload_when_running();
81  void test_common_unload_unload_when_corrupt();
82  void test_common_unload_execute_symbol_failed();
83 
84  void test_common_start_start_when_unloaded();
85  void test_common_start_start_when_already_running();
86  void test_common_start_start_when_corrupt();
87  void test_common_start_start_when_start_vmm_missing();
88  void test_common_start_start_vmm_failure();
89  void test_common_start_set_affinity_failed();
90  void test_common_start_vmcall_failed();
91 
92  void test_common_stop_stop_when_unloaded();
93  void test_common_stop_stop_when_not_running();
94  void test_common_stop_stop_when_alread_stopped();
95  void test_common_stop_stop_when_corrupt();
96  void test_common_stop_stop_vmm_missing();
97  void test_common_stop_stop_vmm_failure();
98  void test_common_stop_set_affinity_failed();
99  void test_common_stop_vmcall_failed();
100 
101  void test_common_dump_invalid_drr();
102  void test_common_dump_invalid_vcpuid();
103  void test_common_dump_dump_when_unloaded();
104  void test_common_dump_dump_when_corrupt();
105  void test_common_dump_dump_when_loaded();
106  void test_common_dump_get_drr_missing();
107  void test_common_dump_get_drr_failure();
108 
109  void test_common_vmcall_invalid_args();
110  void test_common_vmcall_set_affinity_failure();
111  void test_common_vmcall_success();
112  void test_common_vmcall_success_event();
113  void test_common_vmcall_vmcall_when_unloaded();
114  void test_common_vmcall_vmcall_when_corrupt();
115  void test_common_vmcall_vmcall_when_loaded();
116 
117  void test_helper_common_vmm_status();
118  void test_helper_get_file_invalid_index();
119  void test_helper_get_file_success();
120  void test_helper_symbol_length_null_symbol();
121  void test_helper_symbol_length_success();
122  void test_helper_resolve_symbol_invalid_name();
123  void test_helper_resolve_symbol_invalid_sym();
124  void test_helper_resolve_symbol_no_loaded_modules();
125  void test_helper_resolve_symbol_missing_symbol();
126  void test_helper_execute_symbol_invalid_arg();
127  void test_helper_execute_symbol_missing_symbol();
128  void test_helper_execute_symbol_sym_failed();
129  void test_helper_execute_symbol_sym_success();
130  void test_helper_add_md_to_memory_manager_null_module();
131  void test_helper_load_elf_file_null_module();
132 
133 private:
134 
135  std::unique_ptr<char[]> m_dummy_add_md_failure;
136  std::unique_ptr<char[]> m_dummy_add_md_success;
137  std::unique_ptr<char[]> m_dummy_get_drr_failure;
138  std::unique_ptr<char[]> m_dummy_get_drr_success;
139  std::unique_ptr<char[]> m_dummy_misc;
140  std::unique_ptr<char[]> m_dummy_start_vmm_failure;
141  std::unique_ptr<char[]> m_dummy_start_vmm_success;
142  std::unique_ptr<char[]> m_dummy_stop_vmm_failure;
143  std::unique_ptr<char[]> m_dummy_stop_vmm_success;
144 
145  uint64_t m_dummy_add_md_failure_length;
146  uint64_t m_dummy_add_md_success_length;
147  uint64_t m_dummy_get_drr_failure_length;
148  uint64_t m_dummy_get_drr_success_length;
149  uint64_t m_dummy_misc_length;
150  uint64_t m_dummy_start_vmm_failure_length;
151  uint64_t m_dummy_start_vmm_success_length;
152  uint64_t m_dummy_stop_vmm_failure_length;
153  uint64_t m_dummy_stop_vmm_success_length;
154 };
155 
156 #endif
Definition: test.h:27
driver_entry_ut()
Definition: test.cpp:39
bool init() override
Definition: test.cpp:62
bool fini() override
Definition: test.cpp:118
~driver_entry_ut() override=default
bool list() override
Definition: test.cpp:124