diff options
author | Cassidy Burden <cburden@google.com> | 2016-06-07 13:44:35 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-06-08 16:19:44 -0700 |
commit | bccc576843ee27fefda5094afc88489f4cbff3ff (patch) | |
tree | 8039f8c8150cc16e3af3ad5fa74402343f562919 /binary_search_tool/binary_search_state.py | |
parent | 42c64464b643df152c0f761fff4e7f6e257c27d5 (diff) | |
download | toolchain-utils-bccc576843ee27fefda5094afc88489f4cbff3ff.tar.gz |
Add install_script argument to binary search tool.
Add optional install_script argument that will run before test_script
use this install_script to perform building/flashing/other misc. setup.
If your build or flash succeeds then return 0, otherwise return 1 and
this build will be "skipped" (equivalent to the test script returning
a 2 exit code).
Test=Update unit tests to test for successful and failed install
Change-Id: Ic492f08230796f50b7bb93aebe078960419a3c99
Reviewed-on: https://chrome-internal-review.googlesource.com/262988
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/binary_search_state.py')
-rwxr-xr-x | binary_search_tool/binary_search_state.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/binary_search_tool/binary_search_state.py b/binary_search_tool/binary_search_state.py index b8898c23..56eaee10 100755 --- a/binary_search_tool/binary_search_state.py +++ b/binary_search_tool/binary_search_state.py @@ -1,5 +1,4 @@ #!/usr/bin/python2 - """The binary search wrapper.""" from __future__ import print_function @@ -30,12 +29,14 @@ STATE_FILE = '%s.state' % sys.argv[0] class BinarySearchState(object): """The binary search state class.""" + def __init__(self, get_initial_items, switch_to_good, switch_to_bad, - test_script, incremental, prune, iterations, prune_iterations, - verify_level, file_args): + install_script, test_script, incremental, prune, iterations, + prune_iterations, verify_level, file_args): self.get_initial_items = get_initial_items self.switch_to_good = switch_to_good self.switch_to_bad = switch_to_bad + self.install_script = install_script self.test_script = test_script self.incremental = incremental self.prune = prune @@ -107,15 +108,26 @@ class BinarySearchState(object): command = self.test_script return self.ce.RunCommand(command) + def InstallScript(self): + if not self.install_script: + return 0 + + command = self.install_script + return self.ce.RunCommand(command) + def DoVerify(self): for _ in range(int(self.verify_level)): self.l.LogOutput('Resetting all items to good to verify.') self.SwitchToGood(self.all_items) + status = self.InstallScript() + assert status == 0, 'When reset_to_good, install should succeed.' status = self.TestScript() assert status == 0, 'When reset_to_good, status should be 0.' self.l.LogOutput('Resetting all items to bad to verify.') self.SwitchToBad(self.all_items) + status = self.InstallScript() + assert status == 0, 'When reset_to_bad, install should succeed.' status = self.TestScript() assert status == 1, 'When reset_to_bad, status should be 1.' @@ -173,7 +185,12 @@ class BinarySearchState(object): # TODO: bad_items should come first. self.SwitchToGood(good_items) self.SwitchToBad(bad_items) - status = self.TestScript() + status = self.InstallScript() + if status == 0: + status = self.TestScript() + else: + # Install script failed, treat as skipped item + status = 2 terminated = self.bs.SetStatus(status) if terminated: @@ -255,6 +272,12 @@ def Main(argv): '--switch_to_bad', dest='switch_to_bad', help='Script to run to switch to bad.') + parser.add_argument('-I', + '--install_script', + dest='install_script', + default=None, + help=('Optional script to perform building, flashing, ' + 'and other setup before the test script runs.')) parser.add_argument('-t', '--test_script', dest='test_script', @@ -302,6 +325,9 @@ def Main(argv): iterations = int(options.iterations) switch_to_good = _CanonicalizeScript(options.switch_to_good) switch_to_bad = _CanonicalizeScript(options.switch_to_bad) + install_script = options.install_script + if install_script: + install_script = _CanonicalizeScript(options.install_script) test_script = _CanonicalizeScript(options.test_script) get_initial_items = _CanonicalizeScript(options.get_initial_items) prune = options.prune @@ -316,8 +342,9 @@ def Main(argv): try: bss = BinarySearchState(get_initial_items, switch_to_good, switch_to_bad, - test_script, incremental, prune, iterations, - prune_iterations, verify_level, file_args) + install_script, test_script, incremental, prune, + iterations, prune_iterations, verify_level, + file_args) bss.DoVerify() bss.DoSearch() |