diff options
author | Brenden Blanco <bblanco@gmail.com> | 2018-08-08 21:00:18 -0700 |
---|---|---|
committer | yonghong-song <ys114321@gmail.com> | 2018-08-08 21:00:18 -0700 |
commit | a296e1e3cc57797843986886d7e6e135ad08483e (patch) | |
tree | 81251d742c39ded0bea832bd2b0eeaab952b1462 /src | |
parent | b84714a47a3a1ec646bbd489442b305c84b35e15 (diff) | |
download | bcc-a296e1e3cc57797843986886d7e6e135ad08483e.tar.gz |
python3 fixes and testing support (#1916)
* python3: check ksymname calls with _assert_is_bytes
Fixes a bytes/string concatenation error when get/fix_syscall_fnname is
called from a python3 system.
* python3: use env python invocation in tools
In order to facilitate testing, but not necessarily as an example of
good practice, I am changing the invocation of the test tools to use
`/usr/bin/env python`, so that we can control which python (2 vs 3)
gets invoked for the test. On the buildbots, I plan to add an optional
`ln -s /usr/bin/python3 /usr/local/bin/python` on systems that have
python3-bcc package built. This way, we get more test coverage. Having a
cmake mechanism to enable both python2 and python3 testing could be a
further enhancement.
* tools/memleak: add an explicit stdout.flush to print loop
The stdout flush behavior seems to have changed in python3, breaking one
of the tests. I think it makes sense to flush stdout at the end of each
timed interval loop anyway, so adding that to the tool itself.
* 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.
Diffstat (limited to 'src')
-rw-r--r-- | src/python/bcc/__init__.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py index e9802f89..943e1556 100644 --- a/src/python/bcc/__init__.py +++ b/src/python/bcc/__init__.py @@ -551,7 +551,7 @@ class BPF(object): # would probably lead to error in later API calls. def get_syscall_prefix(self): for prefix in self._syscall_prefixes: - if self.ksymname("{}bpf".format(prefix)) != -1: + if self.ksymname(b"%sbpf" % prefix) != -1: return prefix return self._syscall_prefixes[0] @@ -559,12 +559,14 @@ class BPF(object): # system's syscall prefix. For example, given "clone" the helper would # return "sys_clone" or "__x64_sys_clone". def get_syscall_fnname(self, name): + name = _assert_is_bytes(name) return self.get_syscall_prefix() + name # Given a Kernel function name that represents a syscall but already has a # prefix included, transform it to current system's prefix. For example, # if "sys_clone" provided, the helper may translate it to "__x64_sys_clone". def fix_syscall_fnname(self, name): + name = _assert_is_bytes(name) for prefix in self._syscall_prefixes: if name.startswith(prefix): return self.get_syscall_fnname(name[len(prefix):]) |