test: python3 fix for test_uprobes (#1228)
authorBrenden Blanco <bblanco@gmail.com>
Fri, 23 Jun 2017 08:08:07 +0000 (01:08 -0700)
committerSasha Goldshtein <goldshtn@gmail.com>
Fri, 23 Jun 2017 08:08:07 +0000 (01:08 -0700)
Treat strings as bytes. This is independent of the larger refactor
(#1139) from which it is cherry-picked)

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
tests/python/test_uprobes.py

index 3926e35..62a370f 100755 (executable)
@@ -88,9 +88,13 @@ int count(struct pt_regs *ctx) {
         p = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
         for l in p.stdout:
             n = l.split()
-            if n[0] == "libz.so.1":
-                libz_path = n[-1]
+            if n[0] == b"libz.so.1":
+                # if libz was already found, override only if new lib is more
+                # specific (e.g. libc6,x86-64 vs libc6)
+                if not libz_path or len(n[1].split(b",")) > 1:
+                    libz_path = n[-1]
         p.wait()
+        p.stdout.close()
         p = None
 
         self.assertIsNotNone(libz_path)
@@ -104,15 +108,15 @@ int count(struct pt_regs *ctx) {
                 raise OSError(e, errno.errorcode[e])
 
             # Remount root MS_REC|MS_PRIVATE
-            if libc.mount(None, "/", None, (1<<14)|(1<<18) , None) == -1:
+            if libc.mount(None, b"/", None, (1<<14)|(1<<18) , None) == -1:
                 e = ctypes.get_errno()
                 raise OSError(e, errno.errorcode[e])
 
-            if libc.mount("tmpfs", "/tmp", "tmpfs", 0, None) == -1:
+            if libc.mount(b"tmpfs", b"/tmp", b"tmpfs", 0, None) == -1:
                 e = ctypes.get_errno()
                 raise OSError(e, errno.errorcode[e])
 
-            shutil.copy(libz_path, "/tmp")
+            shutil.copy(libz_path, b"/tmp")
 
             libz = ctypes.CDLL("/tmp/libz.so.1")
             time.sleep(1)