aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouy@google.com>2018-04-11 11:19:58 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-04-27 14:36:56 -0700
commit2bf1a34ed9bed661399740582ee6b8738599182b (patch)
tree521ad627ff51a0d361115b334e47d73bc619b15e
parentfeb442e92538196083a7bb9b19265c7dd65b84cd (diff)
downloadtoolchain-utils-2bf1a34ed9bed661399740582ee6b8738599182b.tar.gz
debug_info_test: add a test to check DW_AT_producer
This patch introduces two tests, one to check whether debug info section exists in the elf file, the other to check whether DW_AT_producer exists in each compile unit of debug info. BUG=chromium:813271 TEST=debug_info_test /build/kip/usr/lib/debug Change-Id: I3c207abe05c55182ddcc1910073c15a40b0844bf Reviewed-on: https://chromium-review.googlesource.com/1007968 Commit-Ready: Zhizhou Yang <zhizhouy@chromium.org> Tested-by: Zhizhou Yang <zhizhouy@chromium.org> Reviewed-by: Ting-Yuan Huang <laszio@chromium.org>
-rw-r--r--debug_info_test/check_exist.py90
-rwxr-xr-xdebug_info_test/debug_info_test.py4
-rw-r--r--debug_info_test/exist_debug_info.whitelist11
-rw-r--r--debug_info_test/exist_producer.whitelist8
4 files changed, 112 insertions, 1 deletions
diff --git a/debug_info_test/check_exist.py b/debug_info_test/check_exist.py
new file mode 100644
index 00000000..5e7cce19
--- /dev/null
+++ b/debug_info_test/check_exist.py
@@ -0,0 +1,90 @@
+# Copyright 2018 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import subprocess
+
+from whitelist import is_whitelisted
+
+def check_debug_info(dso_path, readelf_content):
+ """check whether debug info section exists in the elf file.
+
+ Args:
+ readelf: debug info dumped by command readelf
+
+ Returns:
+ True if debug info section exists, otherwise False.
+ """
+
+ # Return True if it is whitelisted
+ if is_whitelisted('exist_debug_info', dso_path):
+ return True
+
+ for l in readelf_content:
+ if 'debug_info' in l:
+ return True
+ return False
+
+def check_producer(dso_path, readelf_content):
+ """check whether DW_AT_producer exists in each compile unit.
+
+ Args:
+ readelf: debug info dumped by command readelf
+
+ Returns:
+ True if DW_AT_producer exists in each compile unit, otherwise False.
+ Notice: If no compile unit in DSO, also return True.
+ """
+
+ # Return True if it is whitelisted
+ if is_whitelisted('exist_producer', dso_path):
+ return True
+
+ # Indicate if there is a producer under each cu
+ cur_producer = False
+
+ first_cu = True
+ producer_exist = True
+
+ for l in readelf_content:
+ if 'DW_TAG_compile_unit' in l:
+ if not first_cu and not cur_producer:
+ producer_exist = False
+ break
+ first_cu = False
+ cur_producer = False
+ elif 'DW_AT_producer' in l:
+ cur_producer = True
+
+ # Check whether last producer of compile unit exists in the elf,
+ # also return True if no cu in the DSO.
+ if not first_cu and not cur_producer:
+ producer_exist = False
+
+ return producer_exist
+
+def check_exist_all(dso_path):
+ """check whether intended components exists in the given dso.
+
+ Args:
+ dso_path: path to the dso
+ Return:
+ True if everything looks fine otherwise False.
+ """
+
+ readelf = subprocess.Popen(['readelf', '--debug-dump=info',
+ '--dwarf-depth=1', dso_path],
+ stdout=subprocess.PIPE,
+ stderr=open(os.devnull, 'w'))
+ readelf_content = list(readelf.stdout)
+
+ exist_checks = [check_debug_info, check_producer]
+
+ for e in exist_checks:
+ if not e(dso_path, readelf_content):
+ check_failed = e.__module__ + ': ' + e.__name__
+ print('%s failed check: %s' % (dso_path, check_failed))
+ return False
+
+ return True
diff --git a/debug_info_test/debug_info_test.py b/debug_info_test/debug_info_test.py
index cf3148db..99b8e010 100755
--- a/debug_info_test/debug_info_test.py
+++ b/debug_info_test/debug_info_test.py
@@ -9,8 +9,10 @@ import subprocess
import sys
import check_cus
+import check_exist
-elf_checks = [check_cus.check_compile_units]
+elf_checks = [check_exist.check_exist_all,
+ check_cus.check_compile_units]
def scanelf(root):
"""find ELFs in root
diff --git a/debug_info_test/exist_debug_info.whitelist b/debug_info_test/exist_debug_info.whitelist
new file mode 100644
index 00000000..48080830
--- /dev/null
+++ b/debug_info_test/exist_debug_info.whitelist
@@ -0,0 +1,11 @@
+# To hide existing failures that some DSOs may have no debug info.
+.*/usr/bin/memdiskfind\.debug
+.*/usr/bin/isohybrid\.debug
+.*/usr/bin/gethostip\.debug
+.*/usr/lib.*/libevent-.*\.so.*\.debug
+.*/usr/lib.*/libcares\.so.*\.debug
+.*/usr/lib64/libdcerpc-samr\.so.*\.debug
+.*/usr/lib64/libGLESv2\.so.*\.debug
+.*/usr/lib64/python2.7/site-packages/selenium/webdriver/firefox/.*/x_ignore_nofocus\.so\.debug
+.*/lib.*/libiptc\.so.*\.debug
+# todos:
diff --git a/debug_info_test/exist_producer.whitelist b/debug_info_test/exist_producer.whitelist
new file mode 100644
index 00000000..ee75de72
--- /dev/null
+++ b/debug_info_test/exist_producer.whitelist
@@ -0,0 +1,8 @@
+# To hide existing failures that producer not in certain compiler units.
+.*/opt/google/chrome/libosmesa\.so\.debug
+.*/opt/google/chrome/chrome-sandbox\.debug
+.*/opt/google/chrome/chrome\.debug
+.*/opt/google/chrome/libosmesa\.so\.debug
+.*/opt/google/chrome/nacl_helper\.debug
+.*/usr/local/chromedriver/chromedriver\.debug
+# todos: