test_loader_add.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 void
25 bfelf_loader_ut::test_bfelf_loader_add_invalid_loader()
26 {
27  auto ret = 0LL;
28  bfelf_file_t dummy_misc_ef;
29 
30  ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
31  this->expect_true(ret == BFELF_SUCCESS);
32 
33  ret = bfelf_loader_add(nullptr, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
35 }
36 
37 void
38 bfelf_loader_ut::test_bfelf_loader_add_invalid_elf_file()
39 {
40  bfelf_loader_t loader;
41  memset(&loader, 0, sizeof(loader));
42 
43  auto ret = bfelf_loader_add(&loader, nullptr, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
45 }
46 
47 void
48 bfelf_loader_ut::test_bfelf_loader_add_invalid_addr()
49 {
50  auto ret = 0LL;
51 
52  bfelf_loader_t loader;
53  memset(&loader, 0, sizeof(loader));
54 
55  bfelf_file_t dummy_misc_ef;
56 
57  ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
58  this->expect_true(ret == BFELF_SUCCESS);
59 
60  ret = bfelf_loader_add(&loader, &dummy_misc_ef, nullptr, m_dummy_misc_exec.get());
62 }
63 
64 void
65 bfelf_loader_ut::test_bfelf_loader_add_too_many_files()
66 {
67  auto ret = 0LL;
68 
69  bfelf_loader_t loader;
70  memset(&loader, 0, sizeof(loader));
71 
72  for (auto i = 0; i < MAX_NUM_MODULES + 1; i++)
73  {
74  bfelf_file_t dummy_misc_ef;
75 
76  ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
77  this->expect_true(ret == BFELF_SUCCESS);
78 
79  auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
80  auto &&dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
81 
82  ret = bfelf_loader_add(&loader, &dummy_misc_ef, dummy_misc_exec.get(), dummy_misc_exec.get());
83 
84  if (i < MAX_NUM_MODULES)
85  {
86  this->expect_true(ret == BFELF_SUCCESS);
87  }
88  else
89  {
91  }
92  }
93 }
94 
95 void
96 bfelf_loader_ut::test_bfelf_loader_add_fake()
97 {
98  auto ret = 0LL;
99  bfelf_file_t ef;
100 
101  auto &&data = get_test();
102  auto &&buff = std::get<0>(data);
103  auto &&size = std::get<1>(data);
104 
105  ret = bfelf_file_init(buff.get(), size, &ef);
106  this->expect_true(ret == BFELF_SUCCESS);
107 
108  bfelf_loader_t loader;
109  memset(&loader, 0, sizeof(loader));
110 
111  char nothing[10] = {};
112 
113  ret = bfelf_loader_add(&loader, &ef, static_cast<char *>(nothing), static_cast<char *>(nothing));
114  this->expect_true(ret == BFELF_SUCCESS);
115 }
void * memset(void *block, int c, size_t size)
#define BFELF_ERROR_INVALID_ARG
Definition: error_codes.h:81
int64_t unsigned long void * data
#define MAX_NUM_MODULES
Definition: constants.h:177
constexpr const auto size
#define BFELF_SUCCESS
Definition: error_codes.h:80
#define BFELF_ERROR_LOADER_FULL
Definition: error_codes.h:88
#define expect_true(a)