aboutsummaryrefslogtreecommitdiff
path: root/debug_info_test/whitelist.py
diff options
context:
space:
mode:
authorTing-Yuan Huang <laszio@chromium.org>2018-02-28 14:35:48 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-02 20:47:16 -0800
commit340542b21c30cd62a68d19f086edef36d849971b (patch)
treecae122ce8c6126141c298516d0575a067a9efe7d /debug_info_test/whitelist.py
parentedcf3d33a602438104cafd76f534fa8007e9de7b (diff)
downloadtoolchain-utils-340542b21c30cd62a68d19f086edef36d849971b.tar.gz
debug_info_test: Run tests based on debug info
debug_info_test calls tests on the given ELF files. When a directory is supplied, all ELFs will be searched and tested recursively. BUG=chromium:817648 TEST=debug_info_test /build/kip/usr/lib/debug Change-Id: Ibcb1ac2de19df9227eb6e242d611ec841d4b589f Reviewed-on: https://chromium-review.googlesource.com/942465 Commit-Ready: Ting-Yuan Huang <laszio@chromium.org> Tested-by: Ting-Yuan Huang <laszio@chromium.org> Reviewed-by: Ting-Yuan Huang <laszio@chromium.org> Reviewed-by: Yunlian Jiang <yunlian@chromium.org>
Diffstat (limited to 'debug_info_test/whitelist.py')
-rw-r--r--debug_info_test/whitelist.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/debug_info_test/whitelist.py b/debug_info_test/whitelist.py
new file mode 100644
index 00000000..99a457c0
--- /dev/null
+++ b/debug_info_test/whitelist.py
@@ -0,0 +1,57 @@
+# 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 glob
+import re
+
+# Matching a string of length m in an NFA of size n is O(mn^2), but the
+# performance also depends largely on the implementation. It appears to be fast
+# enough according to the tests.
+#
+# The performance bottleneck of this script is readelf. Unless this becomes
+# slower than readelf, don't waste time here.
+def is_whitelisted(list_name, pattern):
+ """chech whether the given pattern is specified in the whitelist.
+
+ Args:
+ list_name: name of the whitelist
+ pattern: the target string
+ Returns:
+ True if matched otherwise False
+ """
+ return pattern and whitelists[list_name].match(pattern)
+
+def prepare_whitelist(patterns):
+ """Join and compile the re patterns.
+
+ Args:
+ patterns: regex patterns.
+ Return:
+ A compiled re object
+ """
+ return re.compile('|'.join(patterns))
+
+def load_whitelists(dirname):
+ """Load whitelists under dirname.
+
+ A whitelist ends with .whitelist.
+
+ Args:
+ dirname: path to the dir.
+ Returns:
+ A dictionary of 'filename' -> whitelist matcher.
+ """
+ wlist = {}
+ for fn in glob.glob(os.path.join(dirname, '*.whitelist')):
+ key = os.path.splitext(os.path.basename(fn))[0]
+ with open(fn, 'r') as f:
+ patterns = f.read().splitlines()
+ patterns = [l for l in patterns if l[0] != '#']
+ patterns = [l for l in patterns if l != '']
+ wlist[key] = prepare_whitelist(patterns)
+ return wlist
+
+
+whitelists = load_whitelists(os.path.dirname(__file__))