(self)
| 50 | @unittest.skipUnless(kernel_version_ge(4,17), "requires kernel >= 4.17") |
| 51 | class TestStackBuildid(unittest.TestCase): |
| 52 | def test_simple(self): |
| 53 | b = bcc.BPF(text=b""" |
| 54 | #include <uapi/linux/ptrace.h> |
| 55 | struct bpf_map; |
| 56 | BPF_STACK_TRACE_BUILDID(stack_traces, 10240); |
| 57 | BPF_HASH(stack_entries, int, int); |
| 58 | BPF_HASH(stub); |
| 59 | int 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 | |
| 82 | if __name__ == "__main__": |
| 83 | unittest.main() |
nothing calls this directly
no test coverage detected