diff options
author | George Burgess IV <gbiv@google.com> | 2019-10-03 22:58:05 -0700 |
---|---|---|
committer | George Burgess <gbiv@chromium.org> | 2019-10-17 18:35:32 +0000 |
commit | 90d3658f7f8170c66f67f021df64bd421cdb7f11 (patch) | |
tree | 859c13d9fb9209eb5f8c382ce9050b5cd16742e3 /afdo_tools/bisection/afdo_prof_analysis_e2e_test.py | |
parent | bce57b75d6b4109e0a18974261f8c2820eb3ce44 (diff) | |
download | toolchain-utils-90d3658f7f8170c66f67f021df64bd421cdb7f11.tar.gz |
afdo_bisection: remove absl dependency
absl isn't available outside of the chroot, which makes using this
script pretty difficult in some cases. The dependency isn't necessary
(we only care for flags), and it's probably better if we parameterize
functions/objects on the things they depend on, rather than having them
reach into FLAGS.
BUG=None
TEST=Ran the tests
Change-Id: Ic535b92ce580071ab5a346cde76f201941a748ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1839618
Reviewed-by: Caroline Tice <cmtice@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'afdo_tools/bisection/afdo_prof_analysis_e2e_test.py')
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis_e2e_test.py | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py index 24f9e4d0..85c1c175 100755 --- a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py +++ b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py @@ -6,18 +6,30 @@ """End-to-end test for afdo_prof_analysis.""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from datetime import date - -import afdo_prof_analysis as analysis +from __future__ import absolute_import, division, print_function import json +import os import shutil import tempfile -import os import unittest +from datetime import date + +import afdo_prof_analysis as analysis + + +class ObjectWithFields(object): + """Turns kwargs given to the constructor into fields on an object. + + Example usage: + x = ObjectWithFields(a=1, b=2) + assert x.a == 1 + assert x.b == 2 + """ + + def __init__(self, **kwargs): + for key, val in kwargs.items(): + setattr(self, key, val) class AfdoProfAnalysisE2ETest(unittest.TestCase): @@ -233,27 +245,33 @@ class AfdoProfAnalysisE2ETest(unittest.TestCase): with open(bad_prof_file, 'w') as f: f.write(bad_prof_text) - analysis.FLAGS.good_prof = good_prof_file - analysis.FLAGS.bad_prof = bad_prof_file - if state_file: - actual_state_file = analysis.FLAGS.state_file - - def cleanup(): - analysis.FLAGS.state_file = actual_state_file - - self.addCleanup(cleanup) - - analysis.FLAGS.state_file = state_file - - analysis.FLAGS.seed = seed - analysis.FLAGS.no_resume = no_resume - 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/%s' % (dir_path, extern_decider or 'e2e_external.sh') - analysis.FLAGS.external_decider = external_script - actual = analysis.main(None) + # FIXME: This test ideally shouldn't be writing to $PWD + if state_file is None: + state_file = '%s/afdo_analysis_state.json' % os.getcwd() + + def rm_state(): + try: + os.unlink(state_file) + except OSError: + # Probably because the file DNE. That's fine. + pass + + self.addCleanup(rm_state) + + actual = analysis.main( + ObjectWithFields( + good_prof=good_prof_file, + bad_prof=bad_prof_file, + external_decider=external_script, + analysis_output_file=out_file or '/dev/null', + state_file=state_file, + no_resume=no_resume, + remove_state_on_completion=False, + seed=seed, + )) actual_seed = actual.pop('seed') # nothing to check self.assertEqual(actual, expected) return actual_seed |