Repository navigation
Expand file tree
/
Copy pathcommon.h
More file actions
68 lines (54 loc) · 1.58 KB
/
Copy pathcommon.h
File metadata and controls
68 lines (54 loc) · 1.58 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
65
66
67
68
#pragma once
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "../mocks.h"
#include "bpffeature.h"
#include "bpforc.h"
#include "bpftrace.h"
#include "clang_parser.h"
#include "codegen_llvm.h"
#include "driver.h"
#include "fake_map.h"
#include "semantic_analyser.h"
#include "tracepoint_format_parser.h"
namespace bpftrace {
namespace test {
namespace codegen {
const std::string header = R"HEAD(; ModuleID = 'bpftrace'
source_filename = "bpftrace"
target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128"
target triple = "bpf-pc-linux"
)HEAD";
static void test(
BPFtrace &bpftrace,
const std::string &input,
const std::string &expected_output)
{
Driver driver(bpftrace);
FakeMap::next_mapfd_ = 1;
ASSERT_EQ(driver.parse_str(input), 0);
ClangParser clang;
clang.parse(driver.root_, bpftrace);
ASSERT_EQ(driver.parse_str(input), 0);
MockBPFfeature feature;
ast::SemanticAnalyser semantics(driver.root_, bpftrace, feature);
ASSERT_EQ(semantics.analyse(), 0);
ASSERT_EQ(semantics.create_maps(true), 0);
std::stringstream out;
ast::CodegenLLVM codegen(driver.root_, bpftrace);
codegen.compile(DebugLevel::kDebug, out);
std::string full_expected_output = header + expected_output;
EXPECT_EQ(full_expected_output, out.str()) << "the following program failed: '" << input << "'";
}
static void test(
const std::string &input,
const std::string &expected_output,
bool safe_mode = true)
{
BPFtrace bpftrace;
bpftrace.safe_mode_ = safe_mode;
test(bpftrace, input, expected_output);
}
} // namespace codegen
} // namespace test
} // namespace bpftrace