|
1 | | -#include <gmock/gmock.h> |
2 | 1 | #include <gtest/gtest.h> |
3 | 2 |
|
4 | 3 | #include <regex> |
|
7 | 6 | // TODO needed?: |
8 | 7 | #include "oi/ContainerInfo.h" |
9 | 8 | #include "oi/OIParser.h" |
10 | | -#include "oi/type_graph/DrgnParser.h" |
11 | 9 | #include "oi/type_graph/Printer.h" |
12 | 10 | #include "oi/type_graph/TypeGraph.h" |
13 | 11 | #include "oi/type_graph/Types.h" |
| 12 | +#include "test_drgn_parser.h" |
14 | 13 |
|
15 | 14 | using namespace type_graph; |
16 | 15 | using ::testing::HasSubstr; |
17 | 16 |
|
18 | 17 | // TODO setup google logging for tests so it doesn't appear on terminal by |
19 | 18 | // default |
20 | 19 |
|
21 | | -class DrgnParserTest : public ::testing::Test { |
22 | | - protected: |
23 | | - static void SetUpTestSuite() { |
24 | | - symbols_ = new SymbolService{TARGET_EXE_PATH}; |
25 | | - } |
26 | | - |
27 | | - static void TearDownTestSuite() { |
28 | | - delete symbols_; |
29 | | - } |
30 | | - |
31 | | - std::string run(std::string_view function, bool chaseRawPointers); |
32 | | - void test(std::string_view function, |
33 | | - std::string_view expected, |
34 | | - bool chaseRawPointers = true); |
35 | | - void testContains(std::string_view function, |
36 | | - std::string_view expected, |
37 | | - bool chaseRawPointers = true); |
38 | | - void testMultiCompiler(std::string_view function, |
39 | | - std::string_view expectedClang, |
40 | | - std::string_view expectedGcc, |
41 | | - bool chaseRawPointers = true); |
42 | | - void testMultiCompilerContains(std::string_view function, |
43 | | - std::string_view expectedClang, |
44 | | - std::string_view expectedGcc, |
45 | | - bool chaseRawPointers = true); |
46 | | - |
47 | | - static SymbolService* symbols_; |
48 | | -}; |
49 | | - |
50 | 20 | SymbolService* DrgnParserTest::symbols_ = nullptr; |
51 | 21 |
|
52 | | -std::string DrgnParserTest::run(std::string_view function, |
53 | | - bool chaseRawPointers) { |
| 22 | +namespace { |
| 23 | +const std::vector<ContainerInfo>& getContainerInfos() { |
| 24 | + static auto res = []() { |
| 25 | + // TODO more container types, with various template parameter options |
| 26 | + ContainerInfo std_vector{"std::vector", SEQ_TYPE, "vector"}; |
| 27 | + std_vector.stubTemplateParams = {1}; |
| 28 | + |
| 29 | + std::vector<ContainerInfo> containers; |
| 30 | + containers.emplace_back(std::move(std_vector)); |
| 31 | + return containers; |
| 32 | + }(); |
| 33 | + return res; |
| 34 | +} |
| 35 | +} // namespace |
| 36 | + |
| 37 | +DrgnParser DrgnParserTest::getDrgnParser(TypeGraph& typeGraph, bool chaseRawPointers) { |
| 38 | + DrgnParser drgnParser{typeGraph, getContainerInfos(), chaseRawPointers}; |
| 39 | + return drgnParser; |
| 40 | +} |
| 41 | + |
| 42 | +drgn_type* DrgnParserTest::getDrgnRoot(std::string_view function) { |
54 | 43 | irequest req{"entry", std::string{function}, "arg0"}; |
55 | | - auto drgnRoot = symbols_->getRootType(req); |
| 44 | + auto* drgnRoot = symbols_->getRootType(req)->type.type; |
| 45 | + return drgnRoot; |
| 46 | +} |
56 | 47 |
|
| 48 | +std::string DrgnParserTest::run(std::string_view function, |
| 49 | + bool chaseRawPointers) { |
57 | 50 | TypeGraph typeGraph; |
58 | | - // TODO more container types, with various template parameter options |
59 | | - ContainerInfo std_vector{"std::vector", SEQ_TYPE, "vector"}; |
60 | | - std_vector.stubTemplateParams = {1}; |
61 | | - |
62 | | - std::vector<ContainerInfo> containers; |
63 | | - containers.emplace_back(std::move(std_vector)); |
| 51 | + auto drgnParser = getDrgnParser(typeGraph, chaseRawPointers); |
| 52 | + auto *drgnRoot = getDrgnRoot(function); |
64 | 53 |
|
65 | | - DrgnParser drgnParser(typeGraph, containers, chaseRawPointers); |
66 | | - Type& type = drgnParser.parse(drgnRoot->type.type); |
| 54 | + Type& type = drgnParser.parse(drgnRoot); |
67 | 55 |
|
68 | 56 | std::stringstream out; |
69 | 57 | Printer printer{out, typeGraph.size()}; |
|
0 commit comments