LLVM tools: Added unittest for llvm_bisection.py
BUG=None
TEST='./llvm_bisection_unittest.py' passes
Change-Id: I2689deff7ede41bcfcf5707d4419bd3c816bba39
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1798739
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Salud Lemus <saludlemus@google.com>
diff --git a/llvm_tools/llvm_bisection.py b/llvm_tools/llvm_bisection.py
index 04fbdd5..b45be0a 100755
--- a/llvm_tools/llvm_bisection.py
+++ b/llvm_tools/llvm_bisection.py
@@ -371,6 +371,19 @@
'The bad revision is %d and its commit hash is %s' % (end, bad_llvm_hash))
+def LoadStatusFile(last_tested, start, end):
+ """Loads the status file for bisection."""
+
+ try:
+ with open(last_tested) as f:
+ return json.load(f)
+ except IOError as err:
+ if err.errno != errno.ENOENT:
+ raise
+
+ return {'start': start, 'end': end, 'jobs': []}
+
+
def main(args_output):
"""Bisects LLVM based off of a .JSON file.
@@ -390,13 +403,7 @@
start = args_output.start_rev
end = args_output.end_rev
- try:
- with open(args_output.last_tested) as f:
- bisect_contents = json.load(f)
- except IOError as err:
- if err.errno != errno.ENOENT:
- raise
- bisect_contents = {'start': start, 'end': end, 'jobs': []}
+ bisect_contents = LoadStatusFile(args_output.last_tested, start, end)
_ValidateStartAndEndAgainstJSONStartAndEnd(
start, end, bisect_contents['start'], bisect_contents['end'])