test_file_get_needed.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_file_get_needed_invalid_ef()
26 {
27  const char *needed;
28  uint64_t index = 0;
29 
30  auto ret = bfelf_file_get_needed(nullptr, index, &needed);
32 }
33 
34 void
35 bfelf_loader_ut::test_bfelf_file_get_needed_invalid_index()
36 {
37  const char *needed;
38  uint64_t index = 0;
39  bfelf_file_t ef = {};
40 
41  auto ret = bfelf_file_get_needed(&ef, index, &needed);
43 }
44 
45 void
46 bfelf_loader_ut::test_bfelf_file_get_needed_invalid_size()
47 {
48  uint64_t index = 0;
49  bfelf_file_t ef = {};
50 
51  auto ret = bfelf_file_get_needed(&ef, index, nullptr);
53 }
54 
55 void
56 bfelf_loader_ut::test_bfelf_file_get_needed_success()
57 {
58  auto ret = 0LL;
59  bfelf_file_t dummy_misc_ef;
60  bfelf_file_t dummy_code_ef;
61 
62  ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
63  this->expect_true(ret == BFELF_SUCCESS);
64  ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
65  this->expect_true(ret == BFELF_SUCCESS);
66 
67  auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
68  auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
69 
70  m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
71  m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
72 
73  bfelf_loader_t loader;
74  memset(&loader, 0, sizeof(loader));
75 
76  ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
77  this->expect_true(ret == BFELF_SUCCESS);
78  ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
79  this->expect_true(ret == BFELF_SUCCESS);
80 
81  ret = bfelf_loader_relocate(&loader);
82  this->expect_true(ret == BFELF_SUCCESS);
83 
84  const char *needed;
85  uint64_t index = 0;
86 
87  ret = bfelf_file_get_needed(&dummy_misc_ef, index, &needed);
88  this->expect_true(ret == BFELF_SUCCESS);
89 }
void * memset(void *block, int c, size_t size)
#define BFELF_ERROR_INVALID_ARG
Definition: error_codes.h:81
#define BFELF_ERROR_INVALID_INDEX
Definition: error_codes.h:83
auto index(const T virt, const F from)
#define BFELF_SUCCESS
Definition: error_codes.h:80
#define expect_true(a)