diff options
Diffstat (limited to 'simpleperf/scripts/test/binary_cache_builder_test.py')
-rw-r--r-- | simpleperf/scripts/test/binary_cache_builder_test.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/simpleperf/scripts/test/binary_cache_builder_test.py b/simpleperf/scripts/test/binary_cache_builder_test.py index c17fbe49..5bbbf32a 100644 --- a/simpleperf/scripts/test/binary_cache_builder_test.py +++ b/simpleperf/scripts/test/binary_cache_builder_test.py @@ -16,7 +16,9 @@ import filecmp import os +from pathlib import Path import shutil +import tempfile from binary_cache_builder import BinaryCacheBuilder from simpleperf_utils import ReadElf, remove, find_tool_path @@ -65,3 +67,42 @@ class TestBinaryCacheBuilder(TestBase): self.assertTrue(filecmp.cmp(target_file, source_file)) binary_cache_builder.pull_binaries_from_device() self.assertTrue(filecmp.cmp(target_file, source_file)) + + def test_prefer_binary_with_debug_info(self): + binary_cache_builder = BinaryCacheBuilder(TestHelper.ndk_path, False) + binary_cache_builder.collect_used_binaries( + TestHelper.testdata_path('runtest_two_functions_arm64_perf.data')) + + # Create a symfs_dir, which contains elf file with and without debug info. + with tempfile.TemporaryDirectory() as tmp_dir: + shutil.copy( + TestHelper.testdata_path( + 'simpleperf_runtest_two_functions_arm64_without_debug_info'), + Path(tmp_dir) / 'simpleperf_runtest_two_functions_arm64') + + debug_dir = Path(tmp_dir) / 'debug' + debug_dir.mkdir() + shutil.copy(TestHelper.testdata_path( + 'simpleperf_runtest_two_functions_arm64'), debug_dir) + # Check if the elf file with debug info is chosen. + binary_cache_builder.copy_binaries_from_symfs_dirs([tmp_dir]) + elf_path = (Path(binary_cache_builder.binary_cache_dir) / 'data' / + 'local' / 'tmp' / 'simpleperf_runtest_two_functions_arm64') + self.assertTrue(elf_path.is_file()) + self.assertIn('.debug_info', binary_cache_builder.readelf.get_sections(elf_path)) + + def test_create_build_id_list(self): + symfs_dir = TestHelper.testdata_dir + binary_cache_builder = BinaryCacheBuilder(TestHelper.ndk_path, False) + binary_cache_builder.collect_used_binaries( + TestHelper.testdata_path('runtest_two_functions_arm64_perf.data')) + binary_cache_builder.copy_binaries_from_symfs_dirs([symfs_dir]) + elf_path = (Path(binary_cache_builder.binary_cache_dir) / 'data' / + 'local' / 'tmp' / 'simpleperf_runtest_two_functions_arm64') + self.assertTrue(elf_path.is_file()) + + binary_cache_builder.create_build_id_list() + build_id_list_path = Path(binary_cache_builder.binary_cache_dir) / 'build_id_list' + self.assertTrue(build_id_list_path.is_file()) + with open(build_id_list_path, 'r') as fh: + self.assertIn('simpleperf_runtest_two_functions_arm64', fh.read()) |