forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_uprobes2.py
More file actions
executable file
·47 lines (41 loc) · 1.09 KB
/
Copy pathtest_uprobes2.py
File metadata and controls
executable file
·47 lines (41 loc) · 1.09 KB
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
#!/usr/bin/env python
#
# USAGE: test_uprobe2.py
#
# Copyright 2020 Facebook, Inc
# Licensed under the Apache License, Version 2.0 (the "License")
from bcc import BPF
from unittest import main, TestCase
from subprocess import Popen, PIPE
from tempfile import NamedTemporaryFile
class TestUprobes(TestCase):
def setUp(self):
lib_text = b"""
__attribute__((__visibility__("default"))) void fun()
{
}
"""
self.bpf_text = """
int trace_fun_call(void *ctx) {{
return 1;
}}
"""
# Compile and run the application
self.ftemp = NamedTemporaryFile(delete=False)
self.ftemp.close()
comp = Popen([
"gcc",
"-x", "c",
"-shared",
"-Wl,-Ttext-segment,0x2000000",
"-o", self.ftemp.name,
"-"
], stdin=PIPE)
comp.stdin.write(lib_text)
comp.stdin.close()
self.assertEqual(comp.wait(), 0)
def test_attach1(self):
b = BPF(text=self.bpf_text)
b.attach_uprobe(name=self.ftemp.name, sym="fun", fn_name="trace_fun_call")
if __name__ == "__main__":
main()