27 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_invalid_loader()
31 auto ret = bfelf_loader_resolve_symbol(
nullptr,
"foo", reinterpret_cast<void **>(&func));
36 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_invalid_name()
40 bfelf_loader_t loader;
41 memset(&loader, 0,
sizeof(loader));
43 auto ret = bfelf_loader_resolve_symbol(&loader,
nullptr, reinterpret_cast<void **>(&func));
48 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_invalid_addr()
50 bfelf_loader_t loader;
51 memset(&loader, 0,
sizeof(loader));
53 auto ret = bfelf_loader_resolve_symbol(&loader,
"foo",
nullptr);
58 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_no_files_added()
62 bfelf_loader_t loader;
63 memset(&loader, 0,
sizeof(loader));
65 ret = bfelf_loader_relocate(&loader);
70 ret = bfelf_loader_resolve_symbol(&loader,
"foo", reinterpret_cast<void **>(&func));
75 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_uninitialized_files()
78 bfelf_file_t dummy_misc_ef;
79 bfelf_file_t dummy_code_ef;
81 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
83 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
86 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
87 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
89 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
90 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
92 bfelf_loader_t loader;
93 memset(&loader, 0,
sizeof(loader));
95 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
97 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
100 memset(&dummy_misc_ef, 0,
sizeof(dummy_misc_ef));
101 memset(&dummy_code_ef, 0,
sizeof(dummy_code_ef));
103 ret = bfelf_loader_relocate(&loader);
108 ret = bfelf_loader_resolve_symbol(&loader,
"foo", reinterpret_cast<void **>(&func));
113 bfelf_loader_ut::test_bfelf_loader_resolve_no_such_symbol()
116 bfelf_file_t dummy_misc_ef;
117 bfelf_file_t dummy_code_ef;
119 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
121 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
124 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
125 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
127 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
128 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
130 bfelf_loader_t loader;
131 memset(&loader, 0,
sizeof(loader));
133 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
135 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
138 ret = bfelf_loader_relocate(&loader);
143 ret = bfelf_loader_resolve_symbol(&loader,
"invalid_sym", reinterpret_cast<void **>(&func));
148 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_success()
151 bfelf_file_t dummy_misc_ef;
152 bfelf_file_t dummy_code_ef;
154 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
156 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
159 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
160 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
162 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
163 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
165 bfelf_loader_t loader;
166 memset(&loader, 0,
sizeof(loader));
168 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
170 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
173 ret = bfelf_loader_relocate(&loader);
178 ret = bfelf_loader_resolve_symbol(&loader,
"foo", reinterpret_cast<void **>(&func));
183 bfelf_loader_ut::test_bfelf_loader_resolve_no_such_symbol_no_hash()
186 bfelf_file_t dummy_misc_ef;
187 bfelf_file_t dummy_code_ef;
189 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
191 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
194 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
195 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
197 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
198 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
200 bfelf_loader_t loader;
201 memset(&loader, 0,
sizeof(loader));
203 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
205 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
208 dummy_misc_ef.hash =
nullptr;
209 dummy_code_ef.hash =
nullptr;
211 ret = bfelf_loader_relocate(&loader);
216 ret = bfelf_loader_resolve_symbol(&loader,
"invalid_sym", reinterpret_cast<void **>(&func));
221 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_success_no_hash()
224 bfelf_file_t dummy_misc_ef;
225 bfelf_file_t dummy_code_ef;
227 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
229 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
232 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
233 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
235 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
236 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
238 bfelf_loader_t loader;
239 memset(&loader, 0,
sizeof(loader));
241 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
243 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
246 dummy_misc_ef.hash =
nullptr;
247 dummy_code_ef.hash =
nullptr;
249 ret = bfelf_loader_relocate(&loader);
254 ret = bfelf_loader_resolve_symbol(&loader,
"foo", reinterpret_cast<void **>(&func));
262 { (void)info;
return -1; }
265 { (void)info;
return -1; }
268 bfelf_loader_ut::test_bfelf_loader_resolve_symbol_real_test()
271 bfelf_file_t dummy_misc_ef;
272 bfelf_file_t dummy_code_ef;
278 ret = bfelf_file_init(m_dummy_misc.get(), m_dummy_misc_length, &dummy_misc_ef);
280 ret = bfelf_file_init(m_dummy_code.get(), m_dummy_code_length, &dummy_code_ef);
283 auto &&dummy_misc_pair = get_elf_exec(&dummy_misc_ef);
284 auto &&dummy_code_pair = get_elf_exec(&dummy_code_ef);
286 m_dummy_misc_exec = std::move(std::get<0>(dummy_misc_pair));
287 m_dummy_code_exec = std::move(std::get<0>(dummy_code_pair));
289 bfelf_loader_t loader;
290 memset(&loader, 0,
sizeof(loader));
292 ret = bfelf_loader_add(&loader, &dummy_misc_ef, m_dummy_misc_exec.get(), m_dummy_misc_exec.get());
294 ret = bfelf_loader_add(&loader, &dummy_code_ef, m_dummy_code_exec.get(), m_dummy_code_exec.get());
297 ret = bfelf_loader_relocate(&loader);
304 ret = bfelf_file_get_section_info(&dummy_misc_ef, &info);
307 ret = bfelf_loader_resolve_symbol(&loader,
"local_init", reinterpret_cast<void **>(&local_init));
312 ret = bfelf_file_get_section_info(&dummy_code_ef, &info);
315 ret = bfelf_loader_resolve_symbol(&loader,
"local_init", reinterpret_cast<void **>(&local_init));
324 ret = bfelf_loader_resolve_symbol(&loader,
"foo", reinterpret_cast<void **>(&func));
334 ret = bfelf_file_get_section_info(&dummy_misc_ef, &info);
337 ret = bfelf_loader_resolve_symbol(&loader,
"local_fini", reinterpret_cast<void **>(&local_fini));
342 ret = bfelf_file_get_section_info(&dummy_code_ef, &info);
345 ret = bfelf_loader_resolve_symbol(&loader,
"local_fini", reinterpret_cast<void **>(&local_fini));
int64_t(* local_init_t)(struct section_info_t *info)
void * memset(void *block, int c, size_t size)
#define BFELF_ERROR_INVALID_ARG
#define BFELF_ERROR_NO_SUCH_SYMBOL
int64_t dummy_fini(section_info_t *info)
int64_t local_init(struct section_info_t *info)
int64_t(* local_fini_t)(struct section_info_t *info)
int64_t dummy_init(section_info_t *info)
int64_t local_fini(struct section_info_t *info)