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 <memory>
26 
27 #include <unittest.h>
28 #include <test_elf.h>
29 
30 class bfelf_loader_ut : public unittest
31 {
32 public:
33 
35  ~bfelf_loader_ut() override = default;
36 
37 protected:
38 
39  bool init() override;
40  bool fini() override;
41  bool list() override;
42 
43 private:
44 
45  std::pair<std::unique_ptr<char[]>, uint64_t> get_elf_exec(bfelf_file_t *ef);
46  std::pair<std::unique_ptr<char[]>, uint64_t> get_test();
47 
48  void test_bfelf_file_init_success();
49  void test_bfelf_file_init_invalid_file_arg();
50  void test_bfelf_file_init_invalid_file_size_arg();
51  void test_bfelf_file_init_invalid_elf_file();
52  void test_bfelf_file_init_invalid_magic_0();
53  void test_bfelf_file_init_invalid_magic_1();
54  void test_bfelf_file_init_invalid_magic_2();
55  void test_bfelf_file_init_invalid_magic_3();
56  void test_bfelf_file_init_invalid_class();
57  void test_bfelf_file_init_invalid_data();
58  void test_bfelf_file_init_invalid_ident_version();
59  void test_bfelf_file_init_invalid_osabi();
60  void test_bfelf_file_init_invalid_abiversion();
61  void test_bfelf_file_init_invalid_type();
62  void test_bfelf_file_init_invalid_machine();
63  void test_bfelf_file_init_invalid_version();
64  void test_bfelf_file_init_invalid_flags();
65 
66  void test_bfelf_file_get_num_load_instrs_invalid_ef();
67  void test_bfelf_file_get_num_load_instrs_uninitalized();
68  void test_bfelf_file_get_num_load_instrs_success();
69 
70  void test_bfelf_file_get_load_instr_invalid_ef();
71  void test_bfelf_file_get_load_instr_invalid_index();
72  void test_bfelf_file_get_load_instr_invalid_instr();
73  void test_bfelf_file_get_load_instr_success();
74 
75  void test_bfelf_loader_add_invalid_loader();
76  void test_bfelf_loader_add_invalid_elf_file();
77  void test_bfelf_loader_add_invalid_addr();
78  void test_bfelf_loader_add_too_many_files();
79  void test_bfelf_loader_add_fake();
80 
81  void test_bfelf_loader_relocate_invalid_loader();
82  void test_bfelf_loader_relocate_no_files_added();
83  void test_bfelf_loader_relocate_uninitialized_files();
84  void test_bfelf_loader_relocate_twice();
85  void test_bfelf_loader_relocate_no_symbol();
86 
87  void test_bfelf_file_get_section_info_invalid_elf_file();
88  void test_bfelf_file_get_section_info_invalid_info();
89  void test_bfelf_file_get_section_info_expected_misc_resources();
90  void test_bfelf_file_get_section_info_expected_code_resources();
91  void test_bfelf_file_get_section_info_init_fini();
92 
93  void test_bfelf_loader_resolve_symbol_invalid_loader();
94  void test_bfelf_loader_resolve_symbol_invalid_name();
95  void test_bfelf_loader_resolve_symbol_invalid_addr();
96  void test_bfelf_loader_resolve_symbol_no_files_added();
97  void test_bfelf_loader_resolve_symbol_uninitialized_files();
98  void test_bfelf_loader_resolve_no_such_symbol();
99  void test_bfelf_loader_resolve_symbol_success();
100  void test_bfelf_loader_resolve_no_such_symbol_no_hash();
101  void test_bfelf_loader_resolve_symbol_success_no_hash();
102  void test_bfelf_loader_resolve_symbol_real_test();
103 
104  void test_bfelf_file_get_entry_invalid_ef();
105  void test_bfelf_file_get_entry_invalid_addr();
106  void test_bfelf_file_get_entry_success();
107 
108  void test_bfelf_file_get_stack_perm_invalid_ef();
109  void test_bfelf_file_get_stack_perm_invalid_addr();
110  void test_bfelf_file_get_stack_perm_success();
111 
112  void test_bfelf_file_get_relro_invalid_ef();
113  void test_bfelf_file_get_relro_invalid_addr();
114  void test_bfelf_file_get_relro_invalid_size();
115  void test_bfelf_file_get_relro_success();
116 
117  void test_bfelf_file_get_num_needed_invalid_ef();
118  void test_bfelf_file_get_num_needed_success();
119 
120  void test_bfelf_file_get_needed_invalid_ef();
121  void test_bfelf_file_get_needed_invalid_index();
122  void test_bfelf_file_get_needed_invalid_size();
123  void test_bfelf_file_get_needed_success();
124 
125  void test_bfelf_file_get_total_size_invalid_ef();
126  void test_bfelf_file_get_total_size_success();
127 
128  void test_bfelf_file_get_pic_pie_invalid_ef();
129  void test_bfelf_file_get_pic_pie_success();
130 
131  void test_private_hash();
132  void test_private_relocate_invalid_relocation_dyn();
133  void test_private_relocate_invalid_relocation_plt();
134  void test_private_process_dynamic_section();
135 
136 private:
137 
138  std::unique_ptr<char[]> m_dummy_misc;
139  std::unique_ptr<char[]> m_dummy_code;
140  uint64_t m_dummy_misc_length;
141  uint64_t m_dummy_code_length;
142 
143  std::shared_ptr<char> m_dummy_misc_exec;
144  std::shared_ptr<char> m_dummy_code_exec;
145 };
146 
147 #endif
~bfelf_loader_ut() override=default
bool fini() override
Definition: test.cpp:55
bool list() override
Definition: test.cpp:60
bool init() override
Definition: test.cpp:35
bfelf_loader_ut()
Definition: test.cpp:29