diff options
author | Emma Vukelj <emmavukelj@google.com> | 2019-07-19 13:50:41 -0700 |
---|---|---|
committer | Emma Vukelj <emmavukelj@google.com> | 2019-07-22 17:42:31 +0000 |
commit | d8ce1d6da9f3646c0a04c7b870d31c40bfb643e5 (patch) | |
tree | 27c3080f554683929cc5cafac96f36955f433847 | |
parent | 0e39ab73c1b0a944f08313c2c0667419843d5b7b (diff) | |
download | toolchain-utils-d8ce1d6da9f3646c0a04c7b870d31c40bfb643e5.tar.gz |
AFDO-Bisect: Exit analysis on problem_status exit code
This CL makes it such that if the user-provided external script returns
PROBLEM_STATUS indicating that something went wrong (e.g. user sent
SIGINT, or some part of script crashed), then the analysis raises an
error stating so and terminates analysis. Receipt of the problem status
code is not persisted in the state file.
BUG=None
TEST=Existing tests and added test confirming error raising all pass.
Change-Id: Ie2ca6c608ed01b3717d5f09495660f99c3a5e05a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1710021
Reviewed-by: Caroline Tice <cmtice@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Emma Vukelj <emmavukelj@google.com>
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis.py | 6 | ||||
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis_e2e_test.py | 19 | ||||
-rwxr-xr-x | afdo_tools/bisection/problemstatus_external.sh | 3 |
3 files changed, 26 insertions, 2 deletions
diff --git a/afdo_tools/bisection/afdo_prof_analysis.py b/afdo_tools/bisection/afdo_prof_analysis.py index 095adf0c..d974a7a8 100755 --- a/afdo_tools/bisection/afdo_prof_analysis.py +++ b/afdo_tools/bisection/afdo_prof_analysis.py @@ -142,6 +142,12 @@ class DeciderState(object): if return_code in statuses: status = StatusEnum(return_code) + if status == StatusEnum.PROBLEM_STATUS: + prof_file = prof_to_tmp(prof) + raise RuntimeError('Provided decider script returned PROBLEM_STATUS ' + 'when run on profile stored at %s. AFDO Profile ' + 'analysis aborting' % prof_file) + if save_run: self.accumulated_results.append(status.value) logging.info('Run %d of external script %s returned %s', diff --git a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py index 3f7c844a..f95d46e7 100755 --- a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py +++ b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py @@ -112,13 +112,28 @@ class AfdoProfAnalysisE2ETest(unittest.TestCase): loaded_run = json.load(f) self.assertEqual(initial_run, loaded_run) + def test_exit_on_problem_status(self): + temp_dir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True) + + fd_state, state_file = tempfile.mkstemp(dir=temp_dir) + os.close(fd_state) + with self.assertRaises(RuntimeError): + self.run_check( + self.good_prof, + self.bad_prof, + self.expected, + state_file=state_file, + extern_decider='problemstatus_external.sh') + def run_check(self, good_prof, bad_prof, expected, state_file=None, no_resume=True, - out_file=None): + out_file=None, + extern_decider=None): temp_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True) @@ -139,7 +154,7 @@ class AfdoProfAnalysisE2ETest(unittest.TestCase): analysis.FLAGS.analysis_output_file = out_file or '/dev/null' dir_path = os.path.dirname(os.path.realpath(__file__)) # dir of this file - external_script = '%s/e2e_external.sh' % (dir_path) + external_script = '%s/%s' % (dir_path, extern_decider or 'e2e_external.sh') analysis.FLAGS.external_decider = external_script actual = analysis.main(None) diff --git a/afdo_tools/bisection/problemstatus_external.sh b/afdo_tools/bisection/problemstatus_external.sh new file mode 100755 index 00000000..3b53875b --- /dev/null +++ b/afdo_tools/bisection/problemstatus_external.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eu + +exit 127 |