Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 fixes and testing support #1916

Merged
merged 4 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: add b'' strings and fix dangling handles
Add b'' strings in a few places in the test tools, and fix one dangling
process handle in the memleak test tool runner.
  • Loading branch information
drzaeus77 committed Aug 8, 2018
commit f47d437901d11232b86308ebfdb9d8dbb1466b8a
21 changes: 12 additions & 9 deletions tests/python/test_tools_memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,33 @@ def setUpModule():

@skipUnless(kernel_version_ge(4, 6), "requires kernel >= 4.6")
class MemleakToolTests(TestCase):
def tearDown(self):
if self.p:
del(self.p)
def run_leaker(self, leak_kind):
# Starting memleak.py, which in turn launches the leaking application.
p = subprocess.Popen(cfg.cmd_format.format(leak_kind),
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True)
self.p = subprocess.Popen(cfg.cmd_format.format(leak_kind),
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True)

# Waiting for the first report.
while True:
p.poll()
if p.returncode is not None:
self.p.poll()
if self.p.returncode is not None:
break
line = p.stdout.readline()
if "with outstanding allocations" in line:
line = self.p.stdout.readline()
if b"with outstanding allocations" in line:
break

# At this point, memleak.py have already launched application and set
# probes. Sending command to the leaking application to make its
# allocations.
out = p.communicate(input="\n")[0]
out = self.p.communicate(input=b"\n")[0]

# If there were memory leaks, they are in the output. Filter the lines
# containing "byte" substring. Every interesting line is expected to
# start with "N bytes from"
x = [x for x in out.split('\n') if 'byte' in x]
x = [x for x in out.split(b'\n') if b'byte' in x]

self.assertTrue(len(x) >= 1,
msg="At least one line should have 'byte' substring.")
Expand Down
22 changes: 11 additions & 11 deletions tests/python/test_trace4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestKprobeRgx(TestCase):
def setUp(self):
self.b = BPF(text="""
self.b = BPF(text=b"""
typedef struct { int idx; } Key;
typedef struct { u64 val; } Val;
BPF_HASH(stats, Key, Val, 3);
Expand All @@ -22,23 +22,23 @@ def setUp(self):
return 0;
}
""")
self.b.attach_kprobe(event_re="^" + self.b.get_syscall_prefix() + "bp.*",
fn_name="hello")
self.b.attach_kretprobe(event_re="^" + self.b.get_syscall_prefix() + "bp.*",
fn_name="goodbye")
self.b.attach_kprobe(event_re=b"^" + self.b.get_syscall_prefix() + b"bp.*",
fn_name=b"hello")
self.b.attach_kretprobe(event_re=b"^" + self.b.get_syscall_prefix() + b"bp.*",
fn_name=b"goodbye")

def test_send1(self):
k1 = self.b["stats"].Key(1)
k2 = self.b["stats"].Key(2)
self.assertTrue(self.b["stats"][k1].val >= 2)
self.assertTrue(self.b["stats"][k2].val == 1)
k1 = self.b[b"stats"].Key(1)
k2 = self.b[b"stats"].Key(2)
self.assertTrue(self.b[b"stats"][k1].val >= 2)
self.assertTrue(self.b[b"stats"][k2].val == 1)

class TestKprobeReplace(TestCase):
def setUp(self):
self.b = BPF(text="int empty(void *ctx) { return 0; }")
self.b = BPF(text=b"int empty(void *ctx) { return 0; }")

def test_periods(self):
self.b.attach_kprobe(event_re="^tcp_enter_cwr.*", fn_name="empty")
self.b.attach_kprobe(event_re=b"^tcp_enter_cwr.*", fn_name=b"empty")

if __name__ == "__main__":
main()