MCPcopy Create free account
hub / github.com/iovisor/bcc / test_simple

Method test_simple

tests/python/test_stackid.py:52–80  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

50@unittest.skipUnless(kernel_version_ge(4,17), "requires kernel >= 4.17")
51class TestStackBuildid(unittest.TestCase):
52 def test_simple(self):
53 b = bcc.BPF(text=b"""
54#include <uapi/linux/ptrace.h>
55struct bpf_map;
56BPF_STACK_TRACE_BUILDID(stack_traces, 10240);
57BPF_HASH(stack_entries, int, int);
58BPF_HASH(stub);
59int kprobe__sys_getuid(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
60 int id = stack_traces.get_stackid(ctx, BPF_F_USER_STACK);
61 if (id < 0)
62 return 0;
63 int key = 1;
64 stack_entries.update(&key, &id);
65 return 0;
66}
67""")
68 os.getuid()
69 stub = b[b"stub"]
70 stack_traces = b[b"stack_traces"]
71 stack_entries = b[b"stack_entries"]
72 b.add_module(Get_libc_path())
73 try: x = stub[stub.Key(1)]
74 except: pass
75 k = stack_entries.Key(1)
76 self.assertIn(k, stack_entries)
77 stackid = stack_entries[k]
78 self.assertIsNotNone(stackid)
79 stack = stack_traces[stackid]
80 self.assertTrue(b.sym(stack.trace[0], -1).find(b"getuid")!=-1)
81
82if __name__ == "__main__":
83 unittest.main()

Callers

nothing calls this directly

Calls 5

add_moduleMethod · 0.95
symMethod · 0.95
BPFMethod · 0.80
findMethod · 0.80
Get_libc_pathFunction · 0.70

Tested by

no test coverage detected