

def test_simple(self):
    b = bcc.BPF(text='\n#include <uapi/linux/ptrace.h>\nstruct bpf_map;\nBPF_STACK_TRACE(stack_traces, 10240);\nBPF_HASH(stack_entries, int, int);\nBPF_HASH(stub);\nint kprobe__htab_map_lookup_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {\n    int id = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID);\n    if (id < 0)\n        return 0;\n    int key = 1;\n    stack_entries.update(&key, &id);\n    return 0;\n}\n')
    stub = b['stub']
    stack_traces = b['stack_traces']
    stack_entries = b['stack_entries']
    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_lookup_elem')

dataset/ETHPy150Open iovisor/bcc/tests/python/test_stackid.py TestStackid.test_simple/original