aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool
diff options
context:
space:
mode:
authorCassidy Burden <cburden@google.com>2016-06-29 10:28:15 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-06-29 17:27:32 -0700
commitbfe9c5300fca09e8790ed25b41028cba8cb0a78f (patch)
tree2efbc1041302d1a422f548acb37c8f78d3fe268d /binary_search_tool
parent2e9f8a097c095ca93052b368ffab4c850d4d3d0f (diff)
downloadtoolchain-utils-bfe9c5300fca09e8790ed25b41028cba8cb0a78f.tar.gz
Add argument overriding to bisect.py
Add the ability to override the default arguments given to the package and object bisecting tools. This allows users to specify their own test/install/etc. script but keep the others the same. Example 1 (do boot test instead of interactive test): ./bisect.py package daisy 172.17.211.182 --test_script=cros_pkg/boot_test.sh Example 2 (do package bisector system test instead of interactive test): ./bisect.py package daisy 172.17.211.182 \ --test_script=cros_pkg/testing_test.sh --install_script="" TEST=Run unit tests and ran above examples among others (such as overriding verbose, prune, etc. options) CQ-DEPEND=CL:*266996 Change-Id: I5ee24826d4d7e22e7328ce98c6b8cda9917df533 Reviewed-on: https://chrome-internal-review.googlesource.com/266305 Commit-Ready: Cassidy Burden <cburden@google.com> Tested-by: Cassidy Burden <cburden@google.com> Reviewed-by: Caroline Tice <cmtice@google.com>
Diffstat (limited to 'binary_search_tool')
-rwxr-xr-xbinary_search_tool/bisect.py83
-rwxr-xr-xbinary_search_tool/test/binary_search_tool_tester.py6
2 files changed, 63 insertions, 26 deletions
diff --git a/binary_search_tool/bisect.py b/binary_search_tool/bisect.py
index be6db75e..09a1bc4a 100755
--- a/binary_search_tool/bisect.py
+++ b/binary_search_tool/bisect.py
@@ -6,6 +6,8 @@ from __future__ import print_function
import abc
import argparse
import sys
+from argparse import RawTextHelpFormatter
+
import common
from utils import command_executer
@@ -20,8 +22,17 @@ class Bisector(object):
# Make Bisector an abstract class
__metaclass__ = abc.ABCMeta
- def __init__(self, options):
+ def __init__(self, options, overrides=None):
+ """Constructor for Bisector abstract base class
+
+ Args:
+ options: positional arguments for specific mode (board, remote, etc.)
+ overrides: optional dict of overrides for argument defaults
+ """
self.options = options
+ self.overrides = overrides
+ if not overrides:
+ self.overrides = {}
self.logger = logger.GetLogger()
self.ce = command_executer.GetCommandExecuter()
@@ -43,19 +54,19 @@ class BisectPackage(Bisector):
cros_pkg_setup = 'cros_pkg/setup.sh'
cros_pkg_cleanup = 'cros_pkg/%s_cleanup.sh'
- default_kwargs = {
- 'get_initial_items': 'cros_pkg/get_initial_items.sh',
- 'switch_to_good': 'cros_pkg/switch_to_good.sh',
- 'switch_to_bad': 'cros_pkg/switch_to_bad.sh',
- 'install_script': 'cros_pkg/install.sh',
- 'test_script': 'cros_pkg/interactive_test.sh',
- 'noincremental': False,
- 'prune': True,
- 'file_args': True
- }
-
- def __init__(self, options):
- super(BisectPackage, self).__init__(options)
+
+ def __init__(self, options, overrides):
+ super(BisectPackage, self).__init__(options, overrides)
+ self.default_kwargs = {
+ 'get_initial_items': 'cros_pkg/get_initial_items.sh',
+ 'switch_to_good': 'cros_pkg/switch_to_good.sh',
+ 'switch_to_bad': 'cros_pkg/switch_to_bad.sh',
+ 'install_script': 'cros_pkg/install.sh',
+ 'test_script': 'cros_pkg/interactive_test.sh',
+ 'noincremental': False,
+ 'prune': True,
+ 'file_args': True
+ }
def PreRun(self):
cmd = ('%s %s %s' %
@@ -67,6 +78,7 @@ class BisectPackage(Bisector):
return 0
def Run(self):
+ self.default_kwargs.update(self.overrides)
return binary_search_state.Run(**self.default_kwargs)
def PostRun(self):
@@ -81,8 +93,8 @@ class BisectPackage(Bisector):
class BisectObject(Bisector):
"""The class for object bisection steps."""
- def __init__(self, options):
- super(BisectObject, self).__init__(options)
+ def __init__(self, options, overrides):
+ super(BisectObject, self).__init__(options, overrides)
def PreRun(self):
raise NotImplementedError('Object bisecting still WIP')
@@ -110,13 +122,33 @@ def Run(bisector):
return 0
+_HELP_EPILOG = """
+Run ./bisect.py {method} --help for individual method help/args
+
+------------------
+
+See README.bisect for examples on argument overriding
+
+See below for full override argument reference:
+"""
+
+
def Main(argv):
- parser = argparse.ArgumentParser(epilog=('Run ./bisect.py {command} --help '
- 'for individual subcommand '
- 'help/args.'))
+ override_parser = argparse.ArgumentParser(add_help=False,
+ argument_default=argparse.SUPPRESS,
+ usage='bisect.py {mode} [options]')
+ common.BuildArgParser(override_parser, override=True)
+
+ epilog = _HELP_EPILOG + override_parser.format_help()
+ parser = argparse.ArgumentParser(epilog=epilog,
+ formatter_class=RawTextHelpFormatter)
subparsers = parser.add_subparsers(title='Bisect mode',
- description=('Whether to package or object'
- 'bisect'))
+ description=('Which bisection method to '
+ 'use. Each method has '
+ 'specific setup and '
+ 'arguments. Please consult '
+ 'the README for more '
+ 'information.'))
parser_package = subparsers.add_parser('package')
parser_package.add_argument('board', help='Board to target')
@@ -126,12 +158,17 @@ def Main(argv):
parser_object = subparsers.add_parser('object')
parser_object.set_defaults(handler=BisectObject)
- options = parser.parse_args(argv)
+ options, remaining = parser.parse_known_args(argv)
+ if remaining:
+ overrides = override_parser.parse_args(remaining)
+ overrides = vars(overrides)
+ else:
+ overrides = {}
subcmd = options.handler
del options.handler
- bisector = subcmd(options)
+ bisector = subcmd(options, overrides)
return Run(bisector)
diff --git a/binary_search_tool/test/binary_search_tool_tester.py b/binary_search_tool/test/binary_search_tool_tester.py
index 96f3e2b4..1be4481a 100755
--- a/binary_search_tool/test/binary_search_tool_tester.py
+++ b/binary_search_tool/test/binary_search_tool_tester.py
@@ -58,8 +58,8 @@ class BisectTest(unittest.TestCase):
class FullBisector(bisect.Bisector):
"""Test bisector to test bisect.py with"""
- def __init__(self, options):
- super(BisectTest.FullBisector, self).__init__(options)
+ def __init__(self, options, overrides):
+ super(BisectTest.FullBisector, self).__init__(options, overrides)
def PreRun(self):
GenObj()
@@ -78,7 +78,7 @@ class BisectTest(unittest.TestCase):
return 0
def test_full_bisector(self):
- ret = bisect.Run(self.FullBisector({}))
+ ret = bisect.Run(self.FullBisector({}, {}))
self.assertEquals(ret, 0)
self.assertFalse(os.path.exists(common.OBJECTS_FILE))
self.assertFalse(os.path.exists(common.WORKING_SET_FILE))