aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrenden Blanco <bblanco@gmail.com>2018-08-08 14:49:41 -0700
committerBrenden Blanco <bblanco@gmail.com>2018-08-08 14:49:41 -0700
commitf47d437901d11232b86308ebfdb9d8dbb1466b8a (patch)
tree81251d742c39ded0bea832bd2b0eeaab952b1462
parent1951a3bd94f99a7207b00fa2ca0a6c8a49261687 (diff)
downloadbcc-python3-testing.zip
bcc-python3-testing.tar.gz
bcc-python3-testing.tar.bz2
tests: add b'' strings and fix dangling handlespython3-testing
Add b'' strings in a few places in the test tools, and fix one dangling process handle in the memleak test tool runner.
-rwxr-xr-xtests/python/test_tools_memleak.py21
-rwxr-xr-xtests/python/test_trace4.py22
2 files changed, 23 insertions, 20 deletions
diff --git a/tests/python/test_tools_memleak.py b/tests/python/test_tools_memleak.py
index acdc6f6..bbc0a83 100755
--- a/tests/python/test_tools_memleak.py
+++ b/tests/python/test_tools_memleak.py
@@ -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.")
diff --git a/tests/python/test_trace4.py b/tests/python/test_trace4.py
index 68497b3..6836047 100755
--- a/tests/python/test_trace4.py
+++ b/tests/python/test_trace4.py
@@ -9,7 +9,7 @@ from unittest import main, TestCase
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);
@@ -22,23 +22,23 @@ class TestKprobeRgx(TestCase):
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()