Commit 33a3daf0 authored by Brenden Blanco's avatar Brenden Blanco

Use lookup instead of delete in test_stackid

BPF programs aren't allowed to attach to these functions since deadlocks
may occur, thus the test would fail since no stack is collected. Use
update_elem to test instead.
parent de14f4fd
......@@ -24,11 +24,11 @@ class TestStackid(unittest.TestCase):
def test_simple(self):
b = bcc.BPF(text="""
#include <uapi/linux/ptrace.h>
#include <linux/bpf.h>
struct bpf_map;
BPF_STACK_TRACE(stack_traces, 10240);
BPF_HASH(stack_entries, int, int);
BPF_HASH(stub);
int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
int kprobe__htab_map_lookup_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
int id = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID);
if (id < 0)
return 0;
......@@ -40,14 +40,14 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
stub = b["stub"]
stack_traces = b["stack_traces"]
stack_entries = b["stack_entries"]
try: del stub[stub.Key(1)]
try: x = stub[stub.Key(1)]
except: pass
k = stack_entries.Key(1)
self.assertIn(k, stack_entries)
stackid = stack_entries[k]
self.assertIsNotNone(stackid)
stack = stack_traces[stackid].ip
self.assertEqual(b.ksym(stack[0]), "htab_map_delete_elem")
self.assertEqual(b.ksym(stack[0]), "htab_map_lookup_elem")
if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment