-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
64 lines (61 loc) · 1.71 KB
/
test.cpp
File metadata and controls
64 lines (61 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "test.h"
#include "asserts.h"
#include "libparser.h"
#include "symbol_database.h"
#include <set>
static void test_symbol_loading() {
const auto &symbols = parse_lib("/usr/lib/x86_64-linux-gnu/libc.a", false, gcc_lib_paths());
const auto symbol_to_find = "__pthread_create";
for (const auto &symbol : symbols) {
if (symbol.mangled_name == symbol_to_find) {
return;
}
}
assume(false);
}
static void test_symbol_database() {
#if 0
const std::vector<std::vector<std::pair<std::string, std::string>>> test_cases{
{{"symbol", "/first library"}},
{{"symbol", "/first library"}, {"other symbol", "/second library"}},
{{"symbol", "/first library"}, {"symbol", "/second library"}},
{{"symbol", "/first library"}, {"other symbol", "/first library"}},
};
auto libs = [](const std::vector<std::pair<std::string, std::string>> &test_case, std::string_view symbol) {
std::set<std::string_view> result;
for (auto &[result_symbol, lib] : test_case) {
if (result_symbol == symbol) {
result.insert(lib);
}
}
return result;
};
const auto &path = "/tmp/symbol_database";
for (auto &test_case : test_cases) {
{
Symbol_database::Writer db;
for (auto &[symbol, library] : test_case) {
db.add(symbol, library);
}
db.write(path);
}
{
Symbol_database::Reader db{path};
for (auto &[symbol, library] : test_case) {
auto result_libs = db.libraries_from_symbol(symbol);
auto test_libs = libs(test_case, symbol);
assume_equal(result_libs.size(), test_libs.size());
for (auto &result : result_libs) {
assume(test_libs.contains(result));
}
}
}
}
#endif
}
bool test() {
for (auto &function : {test_symbol_loading, test_symbol_database}) {
function();
}
return true;
}