File: runtime_error_check.cpp

package info (click to toggle)
bpftrace 0.24.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,496 kB
  • sloc: cpp: 60,982; ansic: 10,952; python: 953; yacc: 665; sh: 536; lex: 295; makefile: 22
file content (107 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "common.h"

namespace bpftrace::test::codegen {

TEST(codegen, runtime_error_check_lookup_percpu)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @ = count(); $a = @; }", NAME);
}

TEST(codegen, runtime_error_check_delete)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @x[1] = 1; delete(@x, 1) }", NAME);
}

TEST(codegen, runtime_error_check_pid_tid)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @x = pid; @y = tid }", NAME);
}

TEST(codegen, runtime_error_check_comm)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @x = comm; }", NAME);
}

TEST(codegen, runtime_error_check_signal)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;
  bpftrace->safe_mode_ = false;

  test(*bpftrace, "kprobe:f { signal(8); }", NAME);
}

TEST(codegen, runtime_error_check_path)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "fentry:filp_close { path((uint8 *)0); }", NAME);
}

TEST(codegen, runtime_error_check_printf)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "iter:task_file { printf(\"%d\", 1); }", NAME);
}

TEST(codegen, runtime_error_check_for_map)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace,
       "begin { @map[16] = 32; for ($kv : @map) { @x = $kv; } }",
       NAME);
}

TEST(codegen, runtime_error_check_stack)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @x = ustack; @y = kstack }", NAME);
}

TEST(codegen, runtime_error_check_lookup_no_warning)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 1;

  test(*bpftrace, "kprobe:f { @++; }", NAME);
}

TEST(codegen, runtime_error_check_lookup)
{
  auto bpftrace = get_mock_bpftrace();

  bpftrace->helper_check_level_ = 2;

  test(*bpftrace, "kprobe:f { @++; }", NAME);
}

} // namespace bpftrace::test::codegen