aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/binary_search_state.py
diff options
context:
space:
mode:
Diffstat (limited to 'binary_search_tool/binary_search_state.py')
-rwxr-xr-xbinary_search_tool/binary_search_state.py89
1 files changed, 48 insertions, 41 deletions
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):