diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2020-02-04 13:53:09 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-06 14:54:11 +0000 |
commit | d89779ddd3f7224a1706ae4aa1ab71436e4d2b42 (patch) | |
tree | 56f72dbbf23456fea5fa4fb2b66a9707de6e51b1 | |
parent | 145952b0c162475624b7bec8713724ed449f34c1 (diff) | |
download | toolchain-utils-d89779ddd3f7224a1706ae4aa1ab71436e4d2b42.tar.gz |
binary_search_tool: fix failures in presubmit
This patch is to make binary_search_tool in toolchain-utils pass all
presbumit checks, as a prerequisite for python 3 migration.
BUG=chromium:1011676
TEST=Passed all unittests.
Change-Id: Ie7880982f1ca3ae7e6c3d3f342a7a7c076fa9de9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2037142
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Commit-Queue: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
31 files changed, 274 insertions, 143 deletions
diff --git a/binary_search_tool/README.testing.md b/binary_search_tool/README.testing.md index 139dc087..0f06679b 100644 --- a/binary_search_tool/README.testing.md +++ b/binary_search_tool/README.testing.md @@ -28,7 +28,7 @@ To run the basic unit tests: ``` $ cd toolchain-utils/binary_search_tool/test -$ ./binary_search_tool_tester.py +$ ./binary_search_tool_test.py ``` # Running the bisection tests, testing the compiler wrapper. @@ -59,7 +59,7 @@ Move to the correct directory, then run the test script: ``` $ cd toolchain-utils/binary_search_tool -$ ./run_bisect_test.py +$ ./run_bisect_tests.py ``` If you are testing with the CHROMEOS COMPILER WRAPPER, you MUST run the @@ -82,7 +82,7 @@ $ export PYTHONPATH=`pwd`:${PYTHONPATH} Run the test script: ``` -$ ./run_bisect_test.py +$ ./run_bisect_tests.py ``` diff --git a/binary_search_tool/__init__.py b/binary_search_tool/__init__.py index 8b137891..76500def 100644 --- a/binary_search_tool/__init__.py +++ b/binary_search_tool/__init__.py @@ -1 +1,4 @@ - +# -*- coding: utf-8 -*- +# Copyright 2020 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. diff --git a/binary_search_tool/binary_search_perforce.py b/binary_search_tool/binary_search_perforce.py index a4f8c1c6..18517e64 100755 --- a/binary_search_tool/binary_search_perforce.py +++ b/binary_search_tool/binary_search_perforce.py @@ -1,9 +1,11 @@ #!/usr/bin/env python2 - -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Module of binary serch for perforce.""" +from __future__ import division from __future__ import print_function import math @@ -25,7 +27,7 @@ def _GetP4ClientSpec(client_name, p4_paths): if ' ' not in p4_path: p4_string += ' -a %s' % p4_path else: - p4_string += " -a \"" + (' //' + client_name + '/').join(p4_path) + "\"" + p4_string += ' -a "' + (' //' + client_name + '/').join(p4_path) + '"' return p4_string @@ -50,8 +52,8 @@ def GetP4Command(client_name, p4_port, p4_paths, checkoutdir, p4_snapshot=''): command += ' && cd ' + checkoutdir command += ' && cp ${HOME}/.p4config .' command += ' && chmod u+w .p4config' - command += " && echo \"P4PORT=" + p4_port + "\" >> .p4config" - command += " && echo \"P4CLIENT=" + client_name + "\" >> .p4config" + command += ' && echo "P4PORT=' + p4_port + '" >> .p4config' + command += ' && echo "P4CLIENT=' + client_name + '" >> .p4config' command += (' && g4 client ' + _GetP4ClientSpec(client_name, p4_paths)) command += ' && g4 sync ' command += ' && cd -' @@ -84,7 +86,7 @@ class BinarySearcherForPass(object): # For the first run, update self.hi with total pass/transformation count if self.hi == 0: self.hi = self.total - self.current = (self.hi + self.lo) / 2 + self.current = (self.hi + self.lo) // 2 message = ('Bisecting between: (%d, %d)' % (self.lo, self.hi)) self.logger.LogOutput(message, print_to_console=verbose) message = ('Current limit number: %d' % self.current) @@ -100,7 +102,7 @@ class BinarySearcherForPass(object): If status == 1, it means that runtime error still happens with current pass/ transformation, so we need to decrease upper bound for binary search. - Return: + Returns: True if we find the bad pass/transformation, or cannot find bad one after decreasing to the first pass/transformation. Otherwise False. """ @@ -145,7 +147,7 @@ class BinarySearcher(object): self.logger = logger.GetLogger() def SetSortedList(self, sorted_list): - assert len(sorted_list) > 0 + assert sorted_list self.sorted_list = sorted_list self.index_log = [] self.hi = len(sorted_list) - 1 @@ -174,7 +176,7 @@ class BinarySearcher(object): elif status == 1: self.hi = self.current self.logger.LogOutput('lo: %d hi: %d\n' % (self.lo, self.hi)) - self.current = (self.lo + self.hi) / 2 + self.current = (self.lo + self.hi) // 2 if self.lo == self.hi: message = ('Search complete. First bad version: %s' @@ -194,19 +196,19 @@ class BinarySearcher(object): def GetNextFlakyBinary(self): t = (self.lo, self.current, self.hi) q = [t] - while len(q): + while q: element = q.pop(0) if element[1] in self.skipped_indices: # Go top - to_add = (element[0], (element[0] + element[1]) / 2, element[1]) + to_add = (element[0], (element[0] + element[1]) // 2, element[1]) q.append(to_add) # Go bottom - to_add = (element[1], (element[1] + element[2]) / 2, element[2]) + to_add = (element[1], (element[1] + element[2]) // 2, element[2]) q.append(to_add) else: self.current = element[1] return - assert len(q), 'Queue should never be 0-size!' + assert q, 'Queue should never be 0-size!' def GetNextFlakyLinear(self): current_hi = self.current @@ -225,7 +227,7 @@ class BinarySearcher(object): current_lo -= 1 def GetNext(self): - self.current = (self.hi + self.lo) / 2 + self.current = (self.hi + self.lo) // 2 # Try going forward if current is skipped. if self.current in self.skipped_indices: self.GetNextFlakyBinary() @@ -295,7 +297,7 @@ class VCSBinarySearcher(object): def GetNextRevision(self): pass - def CheckoutRevision(self, revision): + def CheckoutRevision(self, current_revision): pass def SetStatus(self, status): @@ -362,14 +364,14 @@ class P4BinarySearcher(VCSBinarySearcher): if not os.path.isfile(self.checkout_dir + '/.p4config'): command = 'cd %s' % self.checkout_dir command += ' && cp ${HOME}/.p4config .' - command += " && echo \"P4PORT=" + self.p4_port + "\" >> .p4config" - command += " && echo \"P4CLIENT=" + self.client_name + "\" >> .p4config" + command += ' && echo "P4PORT=' + self.p4_port + '" >> .p4config' + command += ' && echo "P4CLIENT=' + self.client_name + '" >> .p4config' self.ce.RunCommand(command) command = 'cd %s' % self.checkout_dir command += '; g4 changes -c %s' % self.client_name _, out, _ = self.ce.RunCommandWOUTPUOT(command) changes = re.findall(r'Change (\d+)', out) - if len(changes) != 0: + if changes: command = 'cd %s' % self.checkout_dir for change in changes: command += '; g4 revert -c %s' % change diff --git a/binary_search_tool/binary_search_state.py b/binary_search_tool/binary_search_state.py index f6c8ac7c..e5b6b5ef 100755 --- a/binary_search_tool/binary_search_state.py +++ b/binary_search_tool/binary_search_state.py @@ -1,10 +1,12 @@ #!/usr/bin/env python2 - -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """The binary search wrapper.""" +from __future__ import division from __future__ import print_function import argparse @@ -20,15 +22,14 @@ import tempfile import time # Adds cros_utils to PYTHONPATH +import binary_search_perforce import common +import pass_mapping # Now we do import from cros_utils from cros_utils import command_executer from cros_utils import logger -import binary_search_perforce -import pass_mapping - GOOD_SET_VAR = 'BISECT_GOOD_SET' BAD_SET_VAR = 'BISECT_BAD_SET' @@ -100,10 +101,10 @@ class BinarySearchState(object): self.cmd_script = None self.mode = None self.PopulateItemsUsingCommand(self.get_initial_items) - self.currently_good_items = set([]) - self.currently_bad_items = set([]) - self.found_items = set([]) - self.known_good = set([]) + self.currently_good_items = set() + self.currently_bad_items = set() + self.found_items = set() + self.known_good = set() self.start_time = time.time() @@ -349,12 +350,12 @@ class BinarySearchState(object): return None def BuildWithPassLimit(self, limit, generate_ir=False): - """ Rebuild bad item with pass level bisect limit + """Rebuild bad item with pass level bisect limit Run command line script generated by GenerateBadCommandScript(), with pass level limit flags. - Return: + Returns: pass_num: current number of the pass, or total number of passes if limit set to -1. pass_name: The debugcounter name of current limit pass. @@ -398,16 +399,19 @@ class BinarySearchState(object): pass_name=None, pass_limit=-1, generate_ir=False): - """ Rebuild bad item with transformation level bisect limit + """Rebuild bad item with transformation level bisect limit Run command line script generated by GenerateBadCommandScript(), with pass level limit flags and transformation level limit flags. Args: - limit: transformation level limit for bad item - pass_name: name of bad pass debugcounter from pass level bisect result - pass_limit: pass level limit from pass level bisect result - Return: Total number of transformations if limit set to -1, else return 0. + limit: transformation level limit for bad item. + pass_name: name of bad pass debugcounter from pass level bisect result. + pass_limit: pass level limit from pass level bisect result. + generate_ir: Whether to generate IR comparison. + + Returns: + Total number of transformations if limit set to -1, else return 0. """ counter_name = pass_name @@ -513,7 +517,7 @@ class BinarySearchState(object): 'Total %s number: %d' % (self.mode, self.binary_search.total)) trans_index, _ = self.DoBinarySearchBadPass(pass_index, pass_name) - if (trans_index == 0): + if trans_index == 0: raise ValueError('Bisecting %s cannot reproduce good result.' % pass_name) if self.ir_diff: @@ -530,13 +534,15 @@ class BinarySearchState(object): Args: pass_index: Works for transformation level bisection, indicates the limit - number of pass from pass level bisecting result. + number of pass from pass level bisecting result. pass_name: Works for transformation level bisection, indicates - DebugCounter name of the bad pass from pass level bisecting result. - Return: + DebugCounter name of the bad pass from pass level bisecting + result. + + Returns: index: Index of problematic pass/transformation. pass_name: Works for pass level bisection, returns DebugCounter name for - bad pass. + bad pass. """ # If in resume mode don't reset search_cycles if not self.resumed: @@ -642,26 +648,27 @@ class BinarySearchState(object): if not os.path.isfile(STATE_FILE): return None try: - bss = pickle.load(file(STATE_FILE)) - bss.l = logger.GetLogger() - bss.ce = command_executer.GetCommandExecuter() - bss.binary_search.logger = bss.l - bss.start_time = time.time() - - # Set resumed to be True so we can enter DoBinarySearch without the method - # resetting our current search_cycles to 0. - bss.resumed = True - - # Set currently_good_items and currently_bad_items to empty so that the - # first iteration after resuming will always be non-incremental. This is - # just in case the environment changes, the user makes manual changes, or - # a previous switch_script corrupted the environment. - bss.currently_good_items = set([]) - bss.currently_bad_items = set([]) - - binary_search_perforce.verbose = bss.verbose - return bss - except StandardError: + with open(STATE_FILE, 'rb') as f: + bss = pickle.load(f) + bss.l = logger.GetLogger() + bss.ce = command_executer.GetCommandExecuter() + bss.binary_search.logger = bss.l + bss.start_time = time.time() + + # Set resumed to be True so we can enter DoBinarySearch without the + # method resetting our current search_cycles to 0. + bss.resumed = True + + # Set currently_good_items and currently_bad_items to empty so that the + # first iteration after resuming will always be non-incremental. This + # is just in case the environment changes, the user makes manual + # changes, or a previous switch_script corrupted the environment. + bss.currently_good_items = set() + bss.currently_bad_items = set() + + binary_search_perforce.verbose = bss.verbose + return bss + except Exception: return None def RemoveState(self): diff --git a/binary_search_tool/bisect.py b/binary_search_tool/bisect.py index c7dd5238..6e19dd69 100755 --- a/binary_search_tool/bisect.py +++ b/binary_search_tool/bisect.py @@ -1,28 +1,32 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """The unified package/object bisecting tool.""" from __future__ import print_function import abc import argparse +from argparse import RawTextHelpFormatter import os import sys -from argparse import RawTextHelpFormatter +import six + +import binary_search_state import common from cros_utils import command_executer from cros_utils import logger -import binary_search_state - +@six.add_metaclass(abc.ABCMeta) class Bisector(object): """The abstract base class for Bisectors.""" - # Make Bisector an abstract class - __metaclass__ = abc.ABCMeta - def __init__(self, options, overrides=None): """Constructor for Bisector abstract base class @@ -84,9 +88,7 @@ class Bisector(object): max_key_len = max([len(str(x)) for x in args.keys()]) # Print args in common._ArgsDict order args_order = [x['dest'] for x in common.GetArgsDict().itervalues()] - compare = lambda x, y: cmp(args_order.index(x), args_order.index(y)) - - for key in sorted(args, cmp=compare): + for key in sorted(args, key=args_order.index): val = args[key] key_str = str(key).rjust(max_key_len) val_str = str(val) @@ -193,9 +195,9 @@ class BisectObject(Bisector): if options.dir: os.environ['BISECT_DIR'] = options.dir self.options.dir = os.environ.get('BISECT_DIR', '/tmp/sysroot_bisect') - self.setup_cmd = ('%s %s %s %s' % - (self.sysroot_wrapper_setup, self.options.board, - self.options.remote, self.options.package)) + self.setup_cmd = ( + '%s %s %s %s' % (self.sysroot_wrapper_setup, self.options.board, + self.options.remote, self.options.package)) self.ArgOverride(self.default_kwargs, overrides) diff --git a/binary_search_tool/bisect_driver.py b/binary_search_tool/bisect_driver.py index 82df15d6..e890e5ec 100644 --- a/binary_search_tool/bisect_driver.py +++ b/binary_search_tool/bisect_driver.py @@ -1,10 +1,10 @@ -# Copyright 2016 Googie Inc. All rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. # # This script is used to help the compiler wrapper in the ChromeOS and # Android build systems bisect for bad object files. -# -# pylint: disable=not-callable -# pylint: disable=indentation """Utilities for bisection of ChromeOS and Android object files. @@ -278,7 +278,8 @@ def cache_file(execargs, bisect_dir, cache, abs_file_path): os.chmod(bisect_path, 0o444) return True else: - # File not found (happens when compilation fails but error code is still 0) + # File not found (happens when compilation fails but error code is still + # 0) return False except Exception: print('Could not cache file %s' % abs_file_path, file=sys.stderr) diff --git a/binary_search_tool/common.py b/binary_search_tool/common.py index 40660b52..1d033a44 100644 --- a/binary_search_tool/common.py +++ b/binary_search_tool/common.py @@ -1,4 +1,5 @@ -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. @@ -32,8 +33,8 @@ if os.path.isabs(sys.argv[0]): os.path.dirname(sys.argv[0]))) else: wdir = os.getcwd() - utils_pythonpath = os.path.abspath('{0}/{1}/..'.format(wdir, os.path.dirname( - sys.argv[0]))) + utils_pythonpath = os.path.abspath('{0}/{1}/..'.format( + wdir, os.path.dirname(sys.argv[0]))) sys.path.append(utils_pythonpath) @@ -55,8 +56,10 @@ class ArgumentDict(collections.OrderedDict): ... } """ - _POSSIBLE_OPTIONS = ['action', 'nargs', 'const', 'default', 'type', 'choices', - 'required', 'help', 'metavar', 'dest'] + _POSSIBLE_OPTIONS = [ + 'action', 'nargs', 'const', 'default', 'type', 'choices', 'required', + 'help', 'metavar', 'dest' + ] def AddArgument(self, *args, **kwargs): """Add argument to ArgsDict, has same signature as argparse.add_argument @@ -77,7 +80,7 @@ class ArgumentDict(collections.OrderedDict): TypeError: if args is empty or if option in kwargs is not a valid option for argparse.add_argument. """ - if len(args) == 0: + if not args: raise TypeError('Argument needs at least one name') for key in kwargs: @@ -147,34 +150,34 @@ def _BuildArgsDict(args): '--get_initial_items', dest='get_initial_items', help='Script to run to get the initial objects. ' - 'If your script requires user input ' - 'the --verbose option must be used') + 'If your script requires user input ' + 'the --verbose option must be used') args.AddArgument( '-g', '--switch_to_good', dest='switch_to_good', help='Script to run to switch to good. ' - 'If your switch script requires user input ' - 'the --verbose option must be used') + 'If your switch script requires user input ' + 'the --verbose option must be used') args.AddArgument( '-b', '--switch_to_bad', dest='switch_to_bad', help='Script to run to switch to bad. ' - 'If your switch script requires user input ' - 'the --verbose option must be used') + 'If your switch script requires user input ' + 'the --verbose option must be used') args.AddArgument( '-I', '--test_setup_script', dest='test_setup_script', help='Optional script to perform building, flashing, ' - 'and other setup before the test script runs.') + 'and other setup before the test script runs.') args.AddArgument( '-t', '--test_script', dest='test_script', help='Script to run to test the ' - 'output after packages are built.') + 'output after packages are built.') # No input (evals to False), # --prune (evals to True), # --prune=False, @@ -189,19 +192,19 @@ def _BuildArgsDict(args): type=StrToBool, metavar='bool', help='If True, continue until all bad items are found. ' - 'Defaults to False.') + 'Defaults to False.') args.AddArgument( '-P', '--pass_bisect', dest='pass_bisect', default=None, help='Script to generate another script for pass level bisect, ' - 'which contains command line options to build bad item. ' - 'This will also turn on pass/transformation level bisection. ' - 'Needs support of `-opt-bisect-limit`(pass) and ' - '`-print-debug-counter`(transformation) from LLVM. ' - 'For now it only supports one single bad item, so to use it, ' - 'prune must be set to False.') + 'which contains command line options to build bad item. ' + 'This will also turn on pass/transformation level bisection. ' + 'Needs support of `-opt-bisect-limit`(pass) and ' + '`-print-debug-counter`(transformation) from LLVM. ' + 'For now it only supports one single bad item, so to use it, ' + 'prune must be set to False.') # No input (evals to False), # --ir_diff (evals to True), # --ir_diff=False, @@ -216,8 +219,8 @@ def _BuildArgsDict(args): type=StrToBool, metavar='bool', help='Whether to print IR differences before and after bad ' - 'pass/transformation to verbose output. Defaults to False, ' - 'only works when pass_bisect is enabled.') + 'pass/transformation to verbose output. Defaults to False, ' + 'only works when pass_bisect is enabled.') # No input (evals to False), # --noincremental (evals to True), # --noincremental=False, @@ -231,8 +234,8 @@ def _BuildArgsDict(args): default=False, type=StrToBool, metavar='bool', - help='If True, don\'t propagate good/bad changes ' - 'incrementally. Defaults to False.') + help="If True, don't propagate good/bad changes " + 'incrementally. Defaults to False.') # No input (evals to False), # --file_args (evals to True), # --file_args=False, @@ -247,7 +250,7 @@ def _BuildArgsDict(args): type=StrToBool, metavar='bool', help='Whether to use a file to pass arguments to scripts. ' - 'Defaults to False.') + 'Defaults to False.') # No input (evals to True), # --verify (evals to True), # --verify=False, @@ -261,7 +264,7 @@ def _BuildArgsDict(args): type=StrToBool, metavar='bool', help='Whether to run verify iterations before searching. ' - 'Defaults to True.') + 'Defaults to True.') args.AddArgument( '-N', '--prune_iterations', @@ -289,5 +292,5 @@ def _BuildArgsDict(args): dest='resume', action='store_true', help='Resume bisection tool execution from state file.' - 'Useful if the last bisection was terminated ' - 'before it could properly finish.') + 'Useful if the last bisection was terminated ' + 'before it could properly finish.') diff --git a/binary_search_tool/compiler_wrapper.py b/binary_search_tool/compiler_wrapper.py index a6d189b5..32f0f9e2 100755 --- a/binary_search_tool/compiler_wrapper.py +++ b/binary_search_tool/compiler_wrapper.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Prototype compiler wrapper. Only tested with: gcc, g++, clang, clang++ diff --git a/binary_search_tool/cros_pkg/create_cleanup_script.py b/binary_search_tool/cros_pkg/create_cleanup_script.py index ed4eab61..1a7d97b8 100755 --- a/binary_search_tool/cros_pkg/create_cleanup_script.py +++ b/binary_search_tool/cros_pkg/create_cleanup_script.py @@ -1,6 +1,9 @@ #!/usr/bin/env python2 -# -# Copyright 2015 Google Inc. All Rights Reserved +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """The script to generate a cleanup script after setup.sh. This script takes a set of flags, telling it what setup.sh changed @@ -69,16 +72,18 @@ def Main(argv): if options.old_link or options.renamed_tree: if not options.tree_existed: - Usage(parser, 'If --tree_existed is False, cannot have ' - '--renamed_tree or --old_link') + Usage( + parser, 'If --tree_existed is False, cannot have ' + '--renamed_tree or --old_link') if options.old_link and options.renamed_tree: Usage(parser, '--old_link and --renamed_tree are incompatible options.') if options.tree_existed: if not options.old_link and not options.renamed_tree: - Usage(parser, 'If --tree_existed is True, then must have either ' - '--old_link or --renamed_tree') + Usage( + parser, 'If --tree_existed is True, then must have either ' + '--old_link or --renamed_tree') out_filename = 'cros_pkg/' + options.board + '_cleanup.sh' @@ -100,8 +105,8 @@ def Main(argv): original_link = original_link[1:] if original_link[-1] == "'": original_link = original_link[:-1] - out_file.write('sudo ln -s %s /build/%s\n' % (original_link, - options.board)) + out_file.write( + 'sudo ln -s %s /build/%s\n' % (original_link, options.board)) out_file.write('\n') # Remove common.sh file out_file.write('rm common/common.sh\n') diff --git a/binary_search_tool/pass_mapping.py b/binary_search_tool/pass_mapping.py index cb80910c..2678fd6d 100644 --- a/binary_search_tool/pass_mapping.py +++ b/binary_search_tool/pass_mapping.py @@ -1,6 +1,8 @@ -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Config file for pass level bisection Provides a mapping from pass info from -opt-bisect result to DebugCounter name. diff --git a/binary_search_tool/run_bisect_test.py b/binary_search_tool/run_bisect_tests.py index d4ff4f73..2de58ac1 100755 --- a/binary_search_tool/run_bisect_test.py +++ b/binary_search_tool/run_bisect_tests.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Run full bisection test.""" from __future__ import print_function @@ -81,7 +86,7 @@ def verify_compiler_and_wrapper(): # We don't need to do any special setup if running inside a ChromeOS # chroot. if os.path.exists('/usr/bin/x86_64-cros-linux-gnu-gcc'): - return + return True message = """ *** IMPORTANT --- READ THIS CAREFULLY!! *** diff --git a/binary_search_tool/sysroot_wrapper/testing_test.py b/binary_search_tool/sysroot_wrapper/testing_test.py index a0d6ca10..e860c000 100755 --- a/binary_search_tool/sysroot_wrapper/testing_test.py +++ b/binary_search_tool/sysroot_wrapper/testing_test.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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 sysroot_wrapper bisector. All files in bad_files will be determined to be bad. This test was made for @@ -15,9 +20,9 @@ import os base_path = ('/var/cache/chromeos-chrome/chrome-src-internal/src/out_daisy/' 'Release/obj/') bad_files = [ - os.path.join(base_path, 'base/base.cpu.o'), os.path.join( - base_path, 'base/base.version.o'), os.path.join(base_path, - 'apps/apps.launcher.o') + os.path.join(base_path, 'base/base.cpu.o'), + os.path.join(base_path, 'base/base.version.o'), + os.path.join(base_path, 'apps/apps.launcher.o') ] bisect_dir = os.environ.get('BISECT_DIR', '/tmp/sysroot_bisect') diff --git a/binary_search_tool/test/__init__.py b/binary_search_tool/test/__init__.py index 8b137891..76500def 100644 --- a/binary_search_tool/test/__init__.py +++ b/binary_search_tool/test/__init__.py @@ -1 +1,4 @@ - +# -*- coding: utf-8 -*- +# Copyright 2020 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. diff --git a/binary_search_tool/test/binary_search_tool_tester.py b/binary_search_tool/test/binary_search_tool_test.py index aff45a86..43437c91 100755 --- a/binary_search_tool/test/binary_search_tool_tester.py +++ b/binary_search_tool/test/binary_search_tool_test.py @@ -1,10 +1,12 @@ #!/usr/bin/env python2 - -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Tests for bisecting tool.""" +from __future__ import division from __future__ import print_function __author__ = 'shenhan@google.com (Han Shen)' @@ -24,7 +26,7 @@ import gen_obj def GenObj(): obj_num = random.randint(100, 1000) - bad_obj_num = random.randint(obj_num / 100, obj_num / 20) + bad_obj_num = random.randint(obj_num // 100, obj_num // 20) if bad_obj_num == 0: bad_obj_num = 1 gen_obj.Main(['--obj_num', str(obj_num), '--bad_obj_num', str(bad_obj_num)]) @@ -82,7 +84,7 @@ class BisectTest(unittest.TestCase): def test_full_bisector(self): ret = bisect.Run(self.FullBisector({}, {})) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.assertFalse(os.path.exists(common.OBJECTS_FILE)) self.assertFalse(os.path.exists(common.WORKING_SET_FILE)) @@ -146,7 +148,7 @@ class BisectingUtilsTest(unittest.TestCase): test_script='./is_good.py', prune=True, file_args=True) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def test_arg_parse(self): @@ -156,7 +158,7 @@ class BisectingUtilsTest(unittest.TestCase): '--test_script', './is_good.py', '--prune', '--file_args' ] ret = binary_search_state.Main(args) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def test_test_setup_script(self): @@ -178,7 +180,7 @@ class BisectingUtilsTest(unittest.TestCase): test_setup_script='./test_setup.py', prune=True, file_args=True) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def test_bad_test_setup_script(self): @@ -204,7 +206,7 @@ class BisectingUtilsTest(unittest.TestCase): bss.SaveState() with open(state_file, 'r') as f: - self.assertEquals(f.read(), 'test123') + self.assertEqual(f.read(), 'test123') os.remove(state_file) @@ -243,9 +245,9 @@ class BisectingUtilsTest(unittest.TestCase): bss = None bss2 = binary_search_state.MockBinarySearchState.LoadState() - self.assertEquals(bss2.all_items, test_items) - self.assertEquals(bss2.currently_good_items, set([])) - self.assertEquals(bss2.currently_bad_items, set([])) + self.assertEqual(bss2.all_items, test_items) + self.assertEqual(bss2.currently_good_items, set([])) + self.assertEqual(bss2.currently_bad_items, set([])) def test_tmp_cleanup(self): bss = binary_search_state.MockBinarySearchState( @@ -262,7 +264,7 @@ class BisectingUtilsTest(unittest.TestCase): self.assertFalse(os.path.exists(tmp_file)) ws = common.ReadWorkingSet() for i in range(3): - self.assertEquals(ws[i], 42) + self.assertEqual(ws[i], 42) def test_verify_fail(self): bss = binary_search_state.MockBinarySearchState( @@ -298,11 +300,11 @@ class BisectingUtilsTest(unittest.TestCase): prune=False, file_args=True) bss.DoSearchBadItems() - self.assertEquals(len(bss.found_items), 1) + self.assertEqual(len(bss.found_items), 1) bad_objs = common.ReadObjectsFile() found_obj = int(bss.found_items.pop()) - self.assertEquals(bad_objs[found_obj], 1) + self.assertEqual(bad_objs[found_obj], 1) def test_set_file(self): binary_search_state.Run( @@ -326,7 +328,7 @@ class BisectingUtilsTest(unittest.TestCase): noincremental=True, file_args=True, verify=False) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def check_output(self): @@ -383,7 +385,7 @@ class BisectingUtilsPassTest(BisectingUtilsTest): pass_bisect='./generate_cmd.py', prune=True, file_args=True) - self.assertEquals(ret, 1) + self.assertEqual(ret, 1) def test_gen_cmd_script(self): bss = binary_search_state.MockBinarySearchState( @@ -488,7 +490,7 @@ class BisectStressTest(unittest.TestCase): prune=True, file_args=True, verify=False) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def test_every_index_is_bad(self): @@ -506,7 +508,7 @@ class BisectStressTest(unittest.TestCase): test_script='./is_good.py', prune=True, file_args=True) - self.assertEquals(ret, 0) + self.assertEqual(ret, 0) self.check_output() def check_output(self): diff --git a/binary_search_tool/test/cmd_script.py b/binary_search_tool/test/cmd_script.py index eb91fe9b..5be3f959 100755 --- a/binary_search_tool/test/cmd_script.py +++ b/binary_search_tool/test/cmd_script.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Command script without compiler support for pass level bisection. This script generates a pseudo log which a workable compiler should print out. diff --git a/binary_search_tool/test/cmd_script_no_support.py b/binary_search_tool/test/cmd_script_no_support.py index a817f300..badbedc8 100644 --- a/binary_search_tool/test/cmd_script_no_support.py +++ b/binary_search_tool/test/cmd_script_no_support.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Command script without compiler support for pass level bisection. This script generates a pseudo log when certain bisecting flags are not @@ -13,8 +18,9 @@ import sys def Main(): if not os.path.exists('./is_setup'): return 1 - print('No support for -opt-bisect-limit or -print-debug-counter.', - file=sys.stderr) + print( + 'No support for -opt-bisect-limit or -print-debug-counter.', + file=sys.stderr) return 0 diff --git a/binary_search_tool/test/common.py b/binary_search_tool/test/common.py index 5c3ff538..ae2c843f 100755 --- a/binary_search_tool/test/common.py +++ b/binary_search_tool/test/common.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Common utility functions.""" DEFAULT_OBJECT_NUMBER = 1238 diff --git a/binary_search_tool/test/gen_init_list.py b/binary_search_tool/test/gen_init_list.py index 002fc352..5c83206a 100755 --- a/binary_search_tool/test/gen_init_list.py +++ b/binary_search_tool/test/gen_init_list.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Prints out index for every object file, starting from 0.""" from __future__ import print_function diff --git a/binary_search_tool/test/gen_obj.py b/binary_search_tool/test/gen_obj.py index a2bc7d93..dc7aeefa 100755 --- a/binary_search_tool/test/gen_obj.py +++ b/binary_search_tool/test/gen_obj.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Script to generate a list of object files. 0 represents a good object file. diff --git a/binary_search_tool/test/generate_cmd.py b/binary_search_tool/test/generate_cmd.py index f6876eda..51e352e0 100755 --- a/binary_search_tool/test/generate_cmd.py +++ b/binary_search_tool/test/generate_cmd.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Generate a virtual cmd script for pass level bisection. This is a required argument for pass level bisecting. For unit test, we use diff --git a/binary_search_tool/test/is_good.py b/binary_search_tool/test/is_good.py index a0be4a08..55298da8 100755 --- a/binary_search_tool/test/is_good.py +++ b/binary_search_tool/test/is_good.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Check to see if the working set produces a good executable.""" from __future__ import print_function diff --git a/binary_search_tool/test/is_good_noinc_prune.py b/binary_search_tool/test/is_good_noinc_prune.py index a900bd32..aa0c5884 100755 --- a/binary_search_tool/test/is_good_noinc_prune.py +++ b/binary_search_tool/test/is_good_noinc_prune.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Check to see if the working set produces a good executable. This test script is made for the noincremental-prune test. This makes sure diff --git a/binary_search_tool/test/switch_tmp.py b/binary_search_tool/test/switch_tmp.py index 51b7110e..28b0ac2f 100755 --- a/binary_search_tool/test/switch_tmp.py +++ b/binary_search_tool/test/switch_tmp.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Change portions of the object files to good. This file is a test switch script. Used only for the test test_tmp_cleanup. diff --git a/binary_search_tool/test/switch_to_bad.py b/binary_search_tool/test/switch_to_bad.py index a1b6bd59..91b7e7a8 100755 --- a/binary_search_tool/test/switch_to_bad.py +++ b/binary_search_tool/test/switch_to_bad.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Switch part of the objects file in working set to (possible) bad ones.""" from __future__ import print_function diff --git a/binary_search_tool/test/switch_to_bad_noinc_prune.py b/binary_search_tool/test/switch_to_bad_noinc_prune.py index db76acad..0deaf1ff 100755 --- a/binary_search_tool/test/switch_to_bad_noinc_prune.py +++ b/binary_search_tool/test/switch_to_bad_noinc_prune.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Switch part of the objects file in working set to (possible) bad ones. The "portion" is defined by the file (which is passed as the only argument to diff --git a/binary_search_tool/test/switch_to_bad_set_file.py b/binary_search_tool/test/switch_to_bad_set_file.py index edf226d3..829e25c5 100755 --- a/binary_search_tool/test/switch_to_bad_set_file.py +++ b/binary_search_tool/test/switch_to_bad_set_file.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Switch part of the objects file in working set to (possible) bad ones. This script is meant to be specifically used with the set_file test. This uses diff --git a/binary_search_tool/test/switch_to_good.py b/binary_search_tool/test/switch_to_good.py index 59a118c1..43ec8714 100755 --- a/binary_search_tool/test/switch_to_good.py +++ b/binary_search_tool/test/switch_to_good.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Change portions of the object files to good. The "portion" is defined by the file (which is passed as the only argument to diff --git a/binary_search_tool/test/switch_to_good_noinc_prune.py b/binary_search_tool/test/switch_to_good_noinc_prune.py index 00488a74..6d054f8f 100755 --- a/binary_search_tool/test/switch_to_good_noinc_prune.py +++ b/binary_search_tool/test/switch_to_good_noinc_prune.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Change portions of the object files to good. The "portion" is defined by the file (which is passed as the only argument to diff --git a/binary_search_tool/test/switch_to_good_set_file.py b/binary_search_tool/test/switch_to_good_set_file.py index b5e521f9..b27cf0f6 100755 --- a/binary_search_tool/test/switch_to_good_set_file.py +++ b/binary_search_tool/test/switch_to_good_set_file.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Change portions of the object files to good. The "portion" is defined by the file (which is passed as the only argument to diff --git a/binary_search_tool/test/test_setup.py b/binary_search_tool/test/test_setup.py index 0d6a410e..da531429 100755 --- a/binary_search_tool/test/test_setup.py +++ b/binary_search_tool/test/test_setup.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Emulate running of test setup script, is_good.py should fail without this.""" from __future__ import print_function diff --git a/binary_search_tool/test/test_setup_bad.py b/binary_search_tool/test/test_setup_bad.py index d715f57a..abd9a83c 100755 --- a/binary_search_tool/test/test_setup_bad.py +++ b/binary_search_tool/test/test_setup_bad.py @@ -1,4 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Emulate test setup that fails (i.e. failed flash to device)""" from __future__ import print_function |