OSDN Git Service

simpleperf: fix failed python tests on Android O.
authorYabin Cui <yabinc@google.com>
Sat, 9 Nov 2019 00:04:05 +0000 (16:04 -0800)
committerYabin Cui <yabinc@google.com>
Sat, 9 Nov 2019 00:04:05 +0000 (16:04 -0800)
Fix *.test_pprof_proto_generator tests by allowing elf files
not having build id.

Fix TestExamplePureJavaTraceOffCpu.test_smoke by loosing check.

Bug: none
Test: run test.py on Android O.
Change-Id: I5a796f433a56735989b90a2339765d1e70e3939f

simpleperf/scripts/pprof_proto_generator.py
simpleperf/scripts/test.py

index c635594..2b8b8e2 100755 (executable)
@@ -424,21 +424,27 @@ class PprofProfileGenerator(object):
         # So read build id from the binary in binary_cache, and check it with build id in
         # perf.data.
         build_id_in_perf_data = self.lib.GetBuildIdForPath(dso_name)
-        if build_id_in_perf_data:
-            # Try elf_path in binary cache.
-            elf_path = find_real_dso_path(dso_name, self.config['binary_cache_dir'])
-            if elf_path:
-                elf_build_id = self.read_elf.get_build_id(elf_path, False)
-                if build_id_in_perf_data == self.read_elf.pad_build_id(elf_build_id):
-                    build_id = elf_build_id
-                    binary_path = elf_path
-
-            if not build_id and build_id_in_perf_data.startswith('0x'):
-                # Fallback to the way used by TrimZeroesFromBuildIDString() in quipper.
-                build_id = build_id_in_perf_data[2:]  # remove '0x'
-                padding = '0' * 8
-                while build_id.endswith(padding):
-                    build_id = build_id[:-len(padding)]
+        # Try elf_path in binary cache.
+        elf_path = find_real_dso_path(dso_name, self.config['binary_cache_dir'])
+        if elf_path:
+            elf_build_id = self.read_elf.get_build_id(elf_path, False)
+            if build_id_in_perf_data:
+                match = build_id_in_perf_data == self.read_elf.pad_build_id(elf_build_id)
+            else:
+                # odex files generated by ART on Android O don't contain build id.
+                match = not elf_build_id
+            if match:
+                build_id = elf_build_id
+                binary_path = elf_path
+
+        # When there is no matching elf_path, try converting build_id in perf.data.
+        if not build_id and build_id_in_perf_data.startswith('0x'):
+            # Fallback to the way used by TrimZeroesFromBuildIDString() in quipper.
+            build_id = build_id_in_perf_data[2:]  # remove '0x'
+            padding = '0' * 8
+            while build_id.endswith(padding):
+                build_id = build_id[:-len(padding)]
+
         self.binary_map[dso_name] = (binary_path, build_id)
         return (binary_path, build_id)
 
index b60d54d..4ef1706 100755 (executable)
@@ -595,7 +595,7 @@ class TestExamplePureJavaTraceOffCpu(TestExampleBase):
                 ("run", 80, 0),
                 ("RunFunction", 20, 20),
                 ("SleepFunction", 20, 0),
-                ("line 24", 20, 0),
+                ("line 24", 1, 0),
                 ("line 32", 20, 0)])
         self.run_cmd([INFERNO_SCRIPT, "-sc"])
         self.check_inferno_report_html(