aboutsummaryrefslogtreecommitdiff
path: root/debug_info_test/debug_info_test.py
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouy@google.com>2020-02-11 16:56:57 -0800
committerZhizhou Yang <zhizhouy@google.com>2020-02-13 06:50:19 +0000
commit43c9066b1889baaa0a6077399deb6a4d503551e6 (patch)
treedb4575b4aea577e3da2d7bfb3ac17f386b257733 /debug_info_test/debug_info_test.py
parentc4615d189f6b0dc4c116fc0a78ac295f7427170e (diff)
downloadtoolchain-utils-43c9066b1889baaa0a6077399deb6a4d503551e6.tar.gz
toolchain-utils: migrate all in-use projects to python 3
This patch migrates all in-use projects left to python 3. BUG=chromium:1011676 TEST=Passed unittests and launched scripts manually. Change-Id: I7f2de4e1131c05bacfac80667f3064da8adaebfd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2051397 Reviewed-by: George Burgess <gbiv@chromium.org> Tested-by: Zhizhou Yang <zhizhouy@google.com> Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Diffstat (limited to 'debug_info_test/debug_info_test.py')
-rwxr-xr-xdebug_info_test/debug_info_test.py86
1 files changed, 48 insertions, 38 deletions
diff --git a/debug_info_test/debug_info_test.py b/debug_info_test/debug_info_test.py
index 4839e69c..ae7e9f48 100755
--- a/debug_info_test/debug_info_test.py
+++ b/debug_info_test/debug_info_test.py
@@ -1,9 +1,13 @@
-#!/usr/bin/python2
-
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
# 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.
+"""Test for debug info."""
+
+from __future__ import print_function
+
import os
import subprocess
import sys
@@ -12,46 +16,52 @@ import check_icf
import check_cus
import check_exist
-elf_checks = [check_exist.check_exist_all,
- check_cus.check_compile_units,
- check_icf.check_identical_code_folding]
+elf_checks = [
+ check_exist.check_exist_all, check_cus.check_compile_units,
+ check_icf.check_identical_code_folding
+]
+
def scanelf(root):
- """find ELFs in root
+ """Find ELFs in root.
+
+ Args:
+ root: root dir to start with the search.
+
+ Returns:
+ Filenames of ELFs in root.
+ """
+ p = subprocess.Popen(['scanelf', '-y', '-B', '-F', '%F', '-R', root],
+ stdout=subprocess.PIPE,
+ encoding='utf-8')
+ return [l.strip() for l in p.stdout]
- Args:
- root: root dir to start with the search.
- Returns:
- Filenames of ELFs in root.
- """
- p = subprocess.Popen(['scanelf', '-y', '-B', '-F', '%F', '-R', root],
- stdout=subprocess.PIPE)
- return [l.strip() for l in p.stdout]
def Main(argv):
- if len(argv) < 2:
- print('usage: %s [file|dir]')
- return 1
-
- files = []
- cand = argv[1]
- if os.path.isfile(cand):
- files = [cand]
- elif os.path.isdir(cand):
- files = scanelf(cand)
- else:
- print('usage: %s [file|dir]')
- return 1
-
- failed = False
- for f in files:
- for c in elf_checks:
- if not c(f):
- failed = True
-
- if failed:
- return 1
- return 0
+ if len(argv) < 2:
+ print('usage: %s [file|dir]')
+ return 1
+
+ files = []
+ cand = argv[1]
+ if os.path.isfile(cand):
+ files = [cand]
+ elif os.path.isdir(cand):
+ files = scanelf(cand)
+ else:
+ print('usage: %s [file|dir]')
+ return 1
+
+ failed = False
+ for f in files:
+ for c in elf_checks:
+ if not c(f):
+ failed = True
+
+ if failed:
+ return 1
+ return 0
+
if __name__ == '__main__':
- sys.exit(Main(sys.argv))
+ sys.exit(Main(sys.argv))