aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/test
diff options
context:
space:
mode:
Diffstat (limited to 'binary_search_tool/test')
-rw-r--r--binary_search_tool/test/__init__.py2
-rwxr-xr-xbinary_search_tool/test/binary_search_tool_test.py1106
-rwxr-xr-xbinary_search_tool/test/cmd_script.py116
-rw-r--r--binary_search_tool/test/cmd_script_no_support.py26
-rwxr-xr-xbinary_search_tool/test/common.py42
-rwxr-xr-xbinary_search_tool/test/gen_init_list.py20
-rwxr-xr-xbinary_search_tool/test/gen_obj.py169
-rwxr-xr-xbinary_search_tool/test/generate_cmd.py21
-rwxr-xr-xbinary_search_tool/test/is_good.py27
-rwxr-xr-xbinary_search_tool/test/is_good_noinc_prune.py45
-rwxr-xr-xbinary_search_tool/test/switch_tmp.py27
-rwxr-xr-xbinary_search_tool/test/switch_to_bad.py25
-rwxr-xr-xbinary_search_tool/test/switch_to_bad_noinc_prune.py27
-rwxr-xr-xbinary_search_tool/test/switch_to_bad_set_file.py31
-rwxr-xr-xbinary_search_tool/test/switch_to_good.py21
-rwxr-xr-xbinary_search_tool/test/switch_to_good_noinc_prune.py23
-rwxr-xr-xbinary_search_tool/test/switch_to_good_set_file.py27
-rwxr-xr-xbinary_search_tool/test/test_setup.py17
-rwxr-xr-xbinary_search_tool/test/test_setup_bad.py11
19 files changed, 917 insertions, 866 deletions
diff --git a/binary_search_tool/test/__init__.py b/binary_search_tool/test/__init__.py
index 76500def..6e3ade4a 100644
--- a/binary_search_tool/test/__init__.py
+++ b/binary_search_tool/test/__init__.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
diff --git a/binary_search_tool/test/binary_search_tool_test.py b/binary_search_tool/test/binary_search_tool_test.py
index 6f5b514e..a79c9a1d 100755
--- a/binary_search_tool/test/binary_search_tool_test.py
+++ b/binary_search_tool/test/binary_search_tool_test.py
@@ -1,15 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for bisecting tool."""
-from __future__ import division
-from __future__ import print_function
-__author__ = 'shenhan@google.com (Han Shen)'
+__author__ = "shenhan@google.com (Han Shen)"
import os
import random
@@ -25,545 +23,597 @@ from binary_search_tool.test import gen_obj
def GenObj():
- obj_num = random.randint(100, 1000)
- bad_obj_num = random.randint(obj_num // 100, obj_num // 20)
- if bad_obj_num == 0:
- bad_obj_num = 1
- gen_obj.Main(['--obj_num', str(obj_num), '--bad_obj_num', str(bad_obj_num)])
+ obj_num = random.randint(100, 1000)
+ bad_obj_num = random.randint(obj_num // 100, obj_num // 20)
+ if bad_obj_num == 0:
+ bad_obj_num = 1
+ gen_obj.Main(["--obj_num", str(obj_num), "--bad_obj_num", str(bad_obj_num)])
def CleanObj():
- os.remove(common.OBJECTS_FILE)
- os.remove(common.WORKING_SET_FILE)
- print('Deleted "{0}" and "{1}"'.format(common.OBJECTS_FILE,
- common.WORKING_SET_FILE))
+ os.remove(common.OBJECTS_FILE)
+ os.remove(common.WORKING_SET_FILE)
+ print(
+ 'Deleted "{0}" and "{1}"'.format(
+ common.OBJECTS_FILE, common.WORKING_SET_FILE
+ )
+ )
class BisectTest(unittest.TestCase):
- """Tests for run_bisect.py"""
-
- def setUp(self):
- with open('./is_setup', 'w', encoding='utf-8'):
- pass
-
- try:
- os.remove(binary_search_state.STATE_FILE)
- except OSError:
- pass
-
- def tearDown(self):
- try:
- os.remove('./is_setup')
- os.remove(os.readlink(binary_search_state.STATE_FILE))
- os.remove(binary_search_state.STATE_FILE)
- except OSError:
- pass
-
- class FullBisector(run_bisect.Bisector):
- """Test bisector to test run_bisect.py with"""
-
- def __init__(self, options, overrides):
- super(BisectTest.FullBisector, self).__init__(options, overrides)
-
- def PreRun(self):
- GenObj()
- return 0
-
- def Run(self):
- return binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True)
-
- def PostRun(self):
- CleanObj()
- return 0
-
- def test_full_bisector(self):
- ret = run_bisect.Run(self.FullBisector({}, {}))
- self.assertEqual(ret, 0)
- self.assertFalse(os.path.exists(common.OBJECTS_FILE))
- self.assertFalse(os.path.exists(common.WORKING_SET_FILE))
-
- def check_output(self):
- _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
- ('grep "Bad items are: " logs/binary_search_tool_test.py.out | '
- 'tail -n1'))
- ls = out.splitlines()
- self.assertEqual(len(ls), 1)
- line = ls[0]
-
- _, _, bad_ones = line.partition('Bad items are: ')
- bad_ones = bad_ones.split()
- expected_result = common.ReadObjectsFile()
-
- # Reconstruct objects file from bad_ones and compare
- actual_result = [0] * len(expected_result)
- for bad_obj in bad_ones:
- actual_result[int(bad_obj)] = 1
-
- self.assertEqual(actual_result, expected_result)
+ """Tests for run_bisect.py"""
+
+ def setUp(self):
+ with open("./is_setup", "w", encoding="utf-8"):
+ pass
+
+ try:
+ os.remove(binary_search_state.STATE_FILE)
+ except OSError:
+ pass
+
+ def tearDown(self):
+ try:
+ os.remove("./is_setup")
+ os.remove(os.readlink(binary_search_state.STATE_FILE))
+ os.remove(binary_search_state.STATE_FILE)
+ except OSError:
+ pass
+
+ class FullBisector(run_bisect.Bisector):
+ """Test bisector to test run_bisect.py with"""
+
+ def __init__(self, options, overrides):
+ super(BisectTest.FullBisector, self).__init__(options, overrides)
+
+ def PreRun(self):
+ GenObj()
+ return 0
+
+ def Run(self):
+ return binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ )
+
+ def PostRun(self):
+ CleanObj()
+ return 0
+
+ def test_full_bisector(self):
+ ret = run_bisect.Run(self.FullBisector({}, {}))
+ self.assertEqual(ret, 0)
+ self.assertFalse(os.path.exists(common.OBJECTS_FILE))
+ self.assertFalse(os.path.exists(common.WORKING_SET_FILE))
+
+ def check_output(self):
+ _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
+ (
+ 'grep "Bad items are: " logs/binary_search_tool_test.py.out | '
+ "tail -n1"
+ )
+ )
+ ls = out.splitlines()
+ self.assertEqual(len(ls), 1)
+ line = ls[0]
+
+ _, _, bad_ones = line.partition("Bad items are: ")
+ bad_ones = bad_ones.split()
+ expected_result = common.ReadObjectsFile()
+
+ # Reconstruct objects file from bad_ones and compare
+ actual_result = [0] * len(expected_result)
+ for bad_obj in bad_ones:
+ actual_result[int(bad_obj)] = 1
+
+ self.assertEqual(actual_result, expected_result)
class BisectingUtilsTest(unittest.TestCase):
- """Tests for bisecting tool."""
-
- def setUp(self):
- """Generate [100-1000] object files, and 1-5% of which are bad ones."""
- GenObj()
-
- with open('./is_setup', 'w', encoding='utf-8'):
- pass
-
- try:
- os.remove(binary_search_state.STATE_FILE)
- except OSError:
- pass
-
- def tearDown(self):
- """Cleanup temp files."""
- CleanObj()
-
- try:
- os.remove(os.readlink(binary_search_state.STATE_FILE))
- except OSError:
- pass
-
- cleanup_list = [
- './is_setup', binary_search_state.STATE_FILE, 'noinc_prune_bad',
- 'noinc_prune_good', './cmd_script.sh'
- ]
- for f in cleanup_list:
- if os.path.exists(f):
- os.remove(f)
-
- def runTest(self):
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def test_arg_parse(self):
- args = [
- '--get_initial_items', './gen_init_list.py', '--switch_to_good',
- './switch_to_good.py', '--switch_to_bad', './switch_to_bad.py',
- '--test_script', './is_good.py', '--prune', '--file_args'
- ]
- ret = binary_search_state.Main(args)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def test_test_setup_script(self):
- os.remove('./is_setup')
- with self.assertRaises(AssertionError):
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True)
-
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- test_setup_script='./test_setup.py',
- prune=True,
- file_args=True)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def test_bad_test_setup_script(self):
- with self.assertRaises(AssertionError):
- binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- test_setup_script='./test_setup_bad.py',
- prune=True,
- file_args=True)
-
- def test_bad_save_state(self):
- state_file = binary_search_state.STATE_FILE
- hidden_state_file = os.path.basename(binary_search_state.HIDDEN_STATE_FILE)
-
- with open(state_file, 'w', encoding='utf-8') as f:
- f.write('test123')
-
- bss = binary_search_state.MockBinarySearchState()
- with self.assertRaises(OSError):
- bss.SaveState()
-
- with open(state_file, 'r', encoding='utf-8') as f:
- self.assertEqual(f.read(), 'test123')
-
- os.remove(state_file)
-
- # Cleanup generated save state that has no symlink
- files = os.listdir(os.getcwd())
- save_states = [x for x in files if x.startswith(hidden_state_file)]
- _ = [os.remove(x) for x in save_states]
-
- def test_save_state(self):
- state_file = binary_search_state.STATE_FILE
-
- bss = binary_search_state.MockBinarySearchState()
- bss.SaveState()
- self.assertTrue(os.path.exists(state_file))
- first_state = os.readlink(state_file)
-
- bss.SaveState()
- second_state = os.readlink(state_file)
- self.assertTrue(os.path.exists(state_file))
- self.assertTrue(second_state != first_state)
- self.assertFalse(os.path.exists(first_state))
-
- bss.RemoveState()
- self.assertFalse(os.path.islink(state_file))
- self.assertFalse(os.path.exists(second_state))
-
- def test_load_state(self):
- test_items = [1, 2, 3, 4, 5]
-
- bss = binary_search_state.MockBinarySearchState()
- bss.all_items = test_items
- bss.currently_good_items = set([1, 2, 3])
- bss.currently_bad_items = set([4, 5])
- bss.SaveState()
-
- bss = None
-
- bss2 = binary_search_state.MockBinarySearchState.LoadState()
- self.assertEqual(bss2.all_items, test_items)
- self.assertEqual(bss2.currently_good_items, set([]))
- self.assertEqual(bss2.currently_bad_items, set([]))
-
- def test_tmp_cleanup(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='echo "0\n1\n2\n3"',
- switch_to_good='./switch_tmp.py',
- file_args=True)
- bss.SwitchToGood(['0', '1', '2', '3'])
-
- tmp_file = None
- with open('tmp_file', 'r', encoding='utf-8') as f:
- tmp_file = f.read()
- os.remove('tmp_file')
-
- self.assertFalse(os.path.exists(tmp_file))
- ws = common.ReadWorkingSet()
- for i in range(3):
- self.assertEqual(ws[i], 42)
-
- def test_verify_fail(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_bad.py',
- switch_to_bad='./switch_to_good.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True,
- verify=True)
- with self.assertRaises(AssertionError):
- bss.DoVerify()
-
- def test_early_terminate(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True,
- iterations=1)
- bss.DoSearchBadItems()
- self.assertFalse(bss.found_items)
-
- def test_no_prune(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- test_setup_script='./test_setup.py',
- prune=False,
- file_args=True)
- bss.DoSearchBadItems()
- self.assertEqual(len(bss.found_items), 1)
-
- bad_objs = common.ReadObjectsFile()
- found_obj = int(bss.found_items.pop())
- self.assertEqual(bad_objs[found_obj], 1)
-
- def test_set_file(self):
- binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good_set_file.py',
- switch_to_bad='./switch_to_bad_set_file.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True,
- verify=True)
- self.check_output()
-
- def test_noincremental_prune(self):
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good_noinc_prune.py',
- switch_to_bad='./switch_to_bad_noinc_prune.py',
- test_script='./is_good_noinc_prune.py',
- test_setup_script='./test_setup.py',
- prune=True,
- noincremental=True,
- file_args=True,
- verify=False)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def check_output(self):
- _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
- ('grep "Bad items are: " logs/binary_search_tool_test.py.out | '
- 'tail -n1'))
- ls = out.splitlines()
- self.assertEqual(len(ls), 1)
- line = ls[0]
-
- _, _, bad_ones = line.partition('Bad items are: ')
- bad_ones = bad_ones.split()
- expected_result = common.ReadObjectsFile()
-
- # Reconstruct objects file from bad_ones and compare
- actual_result = [0] * len(expected_result)
- for bad_obj in bad_ones:
- actual_result[int(bad_obj)] = 1
-
- self.assertEqual(actual_result, expected_result)
+ """Tests for bisecting tool."""
+
+ def setUp(self):
+ """Generate [100-1000] object files, and 1-5% of which are bad ones."""
+ GenObj()
+
+ with open("./is_setup", "w", encoding="utf-8"):
+ pass
+
+ try:
+ os.remove(binary_search_state.STATE_FILE)
+ except OSError:
+ pass
+
+ def tearDown(self):
+ """Cleanup temp files."""
+ CleanObj()
+
+ try:
+ os.remove(os.readlink(binary_search_state.STATE_FILE))
+ except OSError:
+ pass
+
+ cleanup_list = [
+ "./is_setup",
+ binary_search_state.STATE_FILE,
+ "noinc_prune_bad",
+ "noinc_prune_good",
+ "./cmd_script.sh",
+ ]
+ for f in cleanup_list:
+ if os.path.exists(f):
+ os.remove(f)
+
+ def runTest(self):
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ )
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def test_arg_parse(self):
+ args = [
+ "--get_initial_items",
+ "./gen_init_list.py",
+ "--switch_to_good",
+ "./switch_to_good.py",
+ "--switch_to_bad",
+ "./switch_to_bad.py",
+ "--test_script",
+ "./is_good.py",
+ "--prune",
+ "--file_args",
+ ]
+ ret = binary_search_state.Main(args)
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def test_test_setup_script(self):
+ os.remove("./is_setup")
+ with self.assertRaises(AssertionError):
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ )
+
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ test_setup_script="./test_setup.py",
+ prune=True,
+ file_args=True,
+ )
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def test_bad_test_setup_script(self):
+ with self.assertRaises(AssertionError):
+ binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ test_setup_script="./test_setup_bad.py",
+ prune=True,
+ file_args=True,
+ )
+
+ def test_bad_save_state(self):
+ state_file = binary_search_state.STATE_FILE
+ hidden_state_file = os.path.basename(
+ binary_search_state.HIDDEN_STATE_FILE
+ )
+
+ with open(state_file, "w", encoding="utf-8") as f:
+ f.write("test123")
+
+ bss = binary_search_state.MockBinarySearchState()
+ with self.assertRaises(OSError):
+ bss.SaveState()
+
+ with open(state_file, "r", encoding="utf-8") as f:
+ self.assertEqual(f.read(), "test123")
+
+ os.remove(state_file)
+
+ # Cleanup generated save state that has no symlink
+ files = os.listdir(os.getcwd())
+ save_states = [x for x in files if x.startswith(hidden_state_file)]
+ _ = [os.remove(x) for x in save_states]
+
+ def test_save_state(self):
+ state_file = binary_search_state.STATE_FILE
+
+ bss = binary_search_state.MockBinarySearchState()
+ bss.SaveState()
+ self.assertTrue(os.path.exists(state_file))
+ first_state = os.readlink(state_file)
+
+ bss.SaveState()
+ second_state = os.readlink(state_file)
+ self.assertTrue(os.path.exists(state_file))
+ self.assertTrue(second_state != first_state)
+ self.assertFalse(os.path.exists(first_state))
+
+ bss.RemoveState()
+ self.assertFalse(os.path.islink(state_file))
+ self.assertFalse(os.path.exists(second_state))
+
+ def test_load_state(self):
+ test_items = [1, 2, 3, 4, 5]
+
+ bss = binary_search_state.MockBinarySearchState()
+ bss.all_items = test_items
+ bss.currently_good_items = set([1, 2, 3])
+ bss.currently_bad_items = set([4, 5])
+ bss.SaveState()
+
+ bss = None
+
+ bss2 = binary_search_state.MockBinarySearchState.LoadState()
+ self.assertEqual(bss2.all_items, test_items)
+ self.assertEqual(bss2.currently_good_items, set([]))
+ self.assertEqual(bss2.currently_bad_items, set([]))
+
+ def test_tmp_cleanup(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items='echo "0\n1\n2\n3"',
+ switch_to_good="./switch_tmp.py",
+ file_args=True,
+ )
+ bss.SwitchToGood(["0", "1", "2", "3"])
+
+ tmp_file = None
+ with open("tmp_file", "r", encoding="utf-8") as f:
+ tmp_file = f.read()
+ os.remove("tmp_file")
+
+ self.assertFalse(os.path.exists(tmp_file))
+ ws = common.ReadWorkingSet()
+ for i in range(3):
+ self.assertEqual(ws[i], 42)
+
+ def test_verify_fail(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_bad.py",
+ switch_to_bad="./switch_to_good.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ verify=True,
+ )
+ with self.assertRaises(AssertionError):
+ bss.DoVerify()
+
+ def test_early_terminate(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ iterations=1,
+ )
+ bss.DoSearchBadItems()
+ self.assertFalse(bss.found_items)
+
+ def test_no_prune(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ test_setup_script="./test_setup.py",
+ prune=False,
+ file_args=True,
+ )
+ bss.DoSearchBadItems()
+ self.assertEqual(len(bss.found_items), 1)
+
+ bad_objs = common.ReadObjectsFile()
+ found_obj = int(bss.found_items.pop())
+ self.assertEqual(bad_objs[found_obj], 1)
+
+ def test_set_file(self):
+ binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good_set_file.py",
+ switch_to_bad="./switch_to_bad_set_file.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ verify=True,
+ )
+ self.check_output()
+
+ def test_noincremental_prune(self):
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good_noinc_prune.py",
+ switch_to_bad="./switch_to_bad_noinc_prune.py",
+ test_script="./is_good_noinc_prune.py",
+ test_setup_script="./test_setup.py",
+ prune=True,
+ noincremental=True,
+ file_args=True,
+ verify=False,
+ )
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def check_output(self):
+ _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
+ (
+ 'grep "Bad items are: " logs/binary_search_tool_test.py.out | '
+ "tail -n1"
+ )
+ )
+ ls = out.splitlines()
+ self.assertEqual(len(ls), 1)
+ line = ls[0]
+
+ _, _, bad_ones = line.partition("Bad items are: ")
+ bad_ones = bad_ones.split()
+ expected_result = common.ReadObjectsFile()
+
+ # Reconstruct objects file from bad_ones and compare
+ actual_result = [0] * len(expected_result)
+ for bad_obj in bad_ones:
+ actual_result[int(bad_obj)] = 1
+
+ self.assertEqual(actual_result, expected_result)
class BisectingUtilsPassTest(BisectingUtilsTest):
- """Tests for bisecting tool at pass/transformation level."""
-
- def check_pass_output(self, pass_name, pass_num, trans_num):
- _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
- ('grep "Bad pass: " logs/binary_search_tool_test.py.out | '
- 'tail -n1'))
- ls = out.splitlines()
- self.assertEqual(len(ls), 1)
- line = ls[0]
- _, _, bad_info = line.partition('Bad pass: ')
- actual_info = pass_name + ' at number ' + str(pass_num)
- self.assertEqual(actual_info, bad_info)
-
- _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
- ('grep "Bad transformation number: '
- '" logs/binary_search_tool_test.py.out | '
- 'tail -n1'))
- ls = out.splitlines()
- self.assertEqual(len(ls), 1)
- line = ls[0]
- _, _, bad_info = line.partition('Bad transformation number: ')
- actual_info = str(trans_num)
- self.assertEqual(actual_info, bad_info)
-
- def test_with_prune(self):
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=True,
- file_args=True)
- self.assertEqual(ret, 1)
-
- def test_gen_cmd_script(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- bss.DoSearchBadItems()
- cmd_script_path = bss.cmd_script
- self.assertTrue(os.path.exists(cmd_script_path))
-
- def test_no_pass_support(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- bss.cmd_script = './cmd_script_no_support.py'
- # No support for -opt-bisect-limit
- with self.assertRaises(RuntimeError):
- bss.BuildWithPassLimit(-1)
-
- def test_no_transform_support(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- bss.cmd_script = './cmd_script_no_support.py'
- # No support for -print-debug-counter
- with self.assertRaises(RuntimeError):
- bss.BuildWithTransformLimit(-1, 'counter_name')
-
- def test_pass_transform_bisect(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- pass_num = 4
- trans_num = 19
- bss.cmd_script = './cmd_script.py %d %d' % (pass_num, trans_num)
- bss.DoSearchBadPass()
- self.check_pass_output('instcombine-visit', pass_num, trans_num)
-
- def test_result_not_reproduced_pass(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- # Fails reproducing at pass level.
- pass_num = 0
- trans_num = 19
- bss.cmd_script = './cmd_script.py %d %d' % (pass_num, trans_num)
- with self.assertRaises(ValueError):
- bss.DoSearchBadPass()
-
- def test_result_not_reproduced_transform(self):
- bss = binary_search_state.MockBinarySearchState(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- pass_bisect='./generate_cmd.py',
- prune=False,
- file_args=True)
- # Fails reproducing at transformation level.
- pass_num = 4
- trans_num = 0
- bss.cmd_script = './cmd_script.py %d %d' % (pass_num, trans_num)
- with self.assertRaises(ValueError):
- bss.DoSearchBadPass()
+ """Tests for bisecting tool at pass/transformation level."""
+
+ def check_pass_output(self, pass_name, pass_num, trans_num):
+ _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
+ (
+ 'grep "Bad pass: " logs/binary_search_tool_test.py.out | '
+ "tail -n1"
+ )
+ )
+ ls = out.splitlines()
+ self.assertEqual(len(ls), 1)
+ line = ls[0]
+ _, _, bad_info = line.partition("Bad pass: ")
+ actual_info = pass_name + " at number " + str(pass_num)
+ self.assertEqual(actual_info, bad_info)
+
+ _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
+ (
+ 'grep "Bad transformation number: '
+ '" logs/binary_search_tool_test.py.out | '
+ "tail -n1"
+ )
+ )
+ ls = out.splitlines()
+ self.assertEqual(len(ls), 1)
+ line = ls[0]
+ _, _, bad_info = line.partition("Bad transformation number: ")
+ actual_info = str(trans_num)
+ self.assertEqual(actual_info, bad_info)
+
+ def test_with_prune(self):
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=True,
+ file_args=True,
+ )
+ self.assertEqual(ret, 1)
+
+ def test_gen_cmd_script(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ bss.DoSearchBadItems()
+ cmd_script_path = bss.cmd_script
+ self.assertTrue(os.path.exists(cmd_script_path))
+
+ def test_no_pass_support(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ bss.cmd_script = "./cmd_script_no_support.py"
+ # No support for -opt-bisect-limit
+ with self.assertRaises(RuntimeError):
+ bss.BuildWithPassLimit(-1)
+
+ def test_no_transform_support(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ bss.cmd_script = "./cmd_script_no_support.py"
+ # No support for -print-debug-counter
+ with self.assertRaises(RuntimeError):
+ bss.BuildWithTransformLimit(-1, "counter_name")
+
+ def test_pass_transform_bisect(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ pass_num = 4
+ trans_num = 19
+ bss.cmd_script = "./cmd_script.py %d %d" % (pass_num, trans_num)
+ bss.DoSearchBadPass()
+ self.check_pass_output("instcombine-visit", pass_num, trans_num)
+
+ def test_result_not_reproduced_pass(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ # Fails reproducing at pass level.
+ pass_num = 0
+ trans_num = 19
+ bss.cmd_script = "./cmd_script.py %d %d" % (pass_num, trans_num)
+ with self.assertRaises(ValueError):
+ bss.DoSearchBadPass()
+
+ def test_result_not_reproduced_transform(self):
+ bss = binary_search_state.MockBinarySearchState(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ pass_bisect="./generate_cmd.py",
+ prune=False,
+ file_args=True,
+ )
+ # Fails reproducing at transformation level.
+ pass_num = 4
+ trans_num = 0
+ bss.cmd_script = "./cmd_script.py %d %d" % (pass_num, trans_num)
+ with self.assertRaises(ValueError):
+ bss.DoSearchBadPass()
class BisectStressTest(unittest.TestCase):
- """Stress tests for bisecting tool."""
-
- def test_every_obj_bad(self):
- amt = 25
- gen_obj.Main(['--obj_num', str(amt), '--bad_obj_num', str(amt)])
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True,
- verify=False)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def test_every_index_is_bad(self):
- amt = 25
- for i in range(amt):
- obj_list = ['0'] * amt
- obj_list[i] = '1'
- obj_list = ','.join(obj_list)
- gen_obj.Main(['--obj_list', obj_list])
- ret = binary_search_state.Run(
- get_initial_items='./gen_init_list.py',
- switch_to_good='./switch_to_good.py',
- switch_to_bad='./switch_to_bad.py',
- test_setup_script='./test_setup.py',
- test_script='./is_good.py',
- prune=True,
- file_args=True)
- self.assertEqual(ret, 0)
- self.check_output()
-
- def check_output(self):
- _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
- ('grep "Bad items are: " logs/binary_search_tool_test.py.out | '
- 'tail -n1'))
- ls = out.splitlines()
- self.assertEqual(len(ls), 1)
- line = ls[0]
-
- _, _, bad_ones = line.partition('Bad items are: ')
- bad_ones = bad_ones.split()
- expected_result = common.ReadObjectsFile()
-
- # Reconstruct objects file from bad_ones and compare
- actual_result = [0] * len(expected_result)
- for bad_obj in bad_ones:
- actual_result[int(bad_obj)] = 1
-
- self.assertEqual(actual_result, expected_result)
+ """Stress tests for bisecting tool."""
+
+ def test_every_obj_bad(self):
+ amt = 25
+ gen_obj.Main(["--obj_num", str(amt), "--bad_obj_num", str(amt)])
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ verify=False,
+ )
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def test_every_index_is_bad(self):
+ amt = 25
+ for i in range(amt):
+ obj_list = ["0"] * amt
+ obj_list[i] = "1"
+ obj_list = ",".join(obj_list)
+ gen_obj.Main(["--obj_list", obj_list])
+ ret = binary_search_state.Run(
+ get_initial_items="./gen_init_list.py",
+ switch_to_good="./switch_to_good.py",
+ switch_to_bad="./switch_to_bad.py",
+ test_setup_script="./test_setup.py",
+ test_script="./is_good.py",
+ prune=True,
+ file_args=True,
+ )
+ self.assertEqual(ret, 0)
+ self.check_output()
+
+ def check_output(self):
+ _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput(
+ (
+ 'grep "Bad items are: " logs/binary_search_tool_test.py.out | '
+ "tail -n1"
+ )
+ )
+ ls = out.splitlines()
+ self.assertEqual(len(ls), 1)
+ line = ls[0]
+
+ _, _, bad_ones = line.partition("Bad items are: ")
+ bad_ones = bad_ones.split()
+ expected_result = common.ReadObjectsFile()
+
+ # Reconstruct objects file from bad_ones and compare
+ actual_result = [0] * len(expected_result)
+ for bad_obj in bad_ones:
+ actual_result[int(bad_obj)] = 1
+
+ self.assertEqual(actual_result, expected_result)
def Main(argv):
- num_tests = 2
- if len(argv) > 1:
- num_tests = int(argv[1])
-
- suite = unittest.TestSuite()
- for _ in range(0, num_tests):
- suite.addTest(BisectingUtilsTest())
- suite.addTest(BisectingUtilsTest('test_arg_parse'))
- suite.addTest(BisectingUtilsTest('test_test_setup_script'))
- suite.addTest(BisectingUtilsTest('test_bad_test_setup_script'))
- suite.addTest(BisectingUtilsTest('test_bad_save_state'))
- suite.addTest(BisectingUtilsTest('test_save_state'))
- suite.addTest(BisectingUtilsTest('test_load_state'))
- suite.addTest(BisectingUtilsTest('test_tmp_cleanup'))
- suite.addTest(BisectingUtilsTest('test_verify_fail'))
- suite.addTest(BisectingUtilsTest('test_early_terminate'))
- suite.addTest(BisectingUtilsTest('test_no_prune'))
- suite.addTest(BisectingUtilsTest('test_set_file'))
- suite.addTest(BisectingUtilsTest('test_noincremental_prune'))
- suite.addTest(BisectingUtilsPassTest('test_with_prune'))
- suite.addTest(BisectingUtilsPassTest('test_gen_cmd_script'))
- suite.addTest(BisectingUtilsPassTest('test_no_pass_support'))
- suite.addTest(BisectingUtilsPassTest('test_no_transform_support'))
- suite.addTest(BisectingUtilsPassTest('test_pass_transform_bisect'))
- suite.addTest(BisectingUtilsPassTest('test_result_not_reproduced_pass'))
- suite.addTest(BisectingUtilsPassTest('test_result_not_reproduced_transform'))
- suite.addTest(BisectTest('test_full_bisector'))
- suite.addTest(BisectStressTest('test_every_obj_bad'))
- suite.addTest(BisectStressTest('test_every_index_is_bad'))
- runner = unittest.TextTestRunner()
- runner.run(suite)
-
-
-if __name__ == '__main__':
- Main(sys.argv)
+ num_tests = 2
+ if len(argv) > 1:
+ num_tests = int(argv[1])
+
+ suite = unittest.TestSuite()
+ for _ in range(0, num_tests):
+ suite.addTest(BisectingUtilsTest())
+ suite.addTest(BisectingUtilsTest("test_arg_parse"))
+ suite.addTest(BisectingUtilsTest("test_test_setup_script"))
+ suite.addTest(BisectingUtilsTest("test_bad_test_setup_script"))
+ suite.addTest(BisectingUtilsTest("test_bad_save_state"))
+ suite.addTest(BisectingUtilsTest("test_save_state"))
+ suite.addTest(BisectingUtilsTest("test_load_state"))
+ suite.addTest(BisectingUtilsTest("test_tmp_cleanup"))
+ suite.addTest(BisectingUtilsTest("test_verify_fail"))
+ suite.addTest(BisectingUtilsTest("test_early_terminate"))
+ suite.addTest(BisectingUtilsTest("test_no_prune"))
+ suite.addTest(BisectingUtilsTest("test_set_file"))
+ suite.addTest(BisectingUtilsTest("test_noincremental_prune"))
+ suite.addTest(BisectingUtilsPassTest("test_with_prune"))
+ suite.addTest(BisectingUtilsPassTest("test_gen_cmd_script"))
+ suite.addTest(BisectingUtilsPassTest("test_no_pass_support"))
+ suite.addTest(BisectingUtilsPassTest("test_no_transform_support"))
+ suite.addTest(BisectingUtilsPassTest("test_pass_transform_bisect"))
+ suite.addTest(BisectingUtilsPassTest("test_result_not_reproduced_pass"))
+ suite.addTest(
+ BisectingUtilsPassTest("test_result_not_reproduced_transform")
+ )
+ suite.addTest(BisectTest("test_full_bisector"))
+ suite.addTest(BisectStressTest("test_every_obj_bad"))
+ suite.addTest(BisectStressTest("test_every_index_is_bad"))
+ runner = unittest.TextTestRunner()
+ runner.run(suite)
+
+
+if __name__ == "__main__":
+ Main(sys.argv)
diff --git a/binary_search_tool/test/cmd_script.py b/binary_search_tool/test/cmd_script.py
index bfd56052..b0475c70 100755
--- a/binary_search_tool/test/cmd_script.py
+++ b/binary_search_tool/test/cmd_script.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -11,7 +11,6 @@ It assumes that -opt-bisect-limit and -print-debug-counter are supported by the
compiler.
"""
-from __future__ import print_function
import os
import sys
@@ -20,57 +19,62 @@ from binary_search_tool.test import common
def Main(argv):
- if not os.path.exists('./is_setup'):
- return 1
-
- if len(argv) != 3:
- return 1
-
- limit_flags = os.environ['LIMIT_FLAGS']
- opt_bisect_exist = False
- debug_counter_exist = False
-
- for option in limit_flags.split():
- if '-opt-bisect-limit' in option:
- opt_bisect_limit = int(option.split('=')[-1])
- opt_bisect_exist = True
- if '-debug-counter=' in option:
- debug_counter = int(option.split('=')[-1])
- debug_counter_exist = True
-
- if not opt_bisect_exist:
- return 1
-
- # Manually set total number and bad number
- total_pass = 10
- total_transform = 20
- bad_pass = int(argv[1])
- bad_transform = int(argv[2])
-
- if opt_bisect_limit == -1:
- opt_bisect_limit = total_pass
-
- for i in range(1, total_pass + 1):
- bisect_str = 'BISECT: %srunning pass (%d) Combine redundant ' \
- 'instructions on function (f1)' \
- % ('NOT ' if i > opt_bisect_limit else '', i)
- print(bisect_str, file=sys.stderr)
-
- if debug_counter_exist:
- print('Counters and values:', file=sys.stderr)
- print(
- 'instcombine-visit : {%d, 0, %d}' % (total_transform, debug_counter),
- file=sys.stderr)
-
- if opt_bisect_limit > bad_pass or \
- (debug_counter_exist and debug_counter > bad_transform):
- common.WriteWorkingSet([1])
- else:
- common.WriteWorkingSet([0])
-
- return 0
-
-
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+ if not os.path.exists("./is_setup"):
+ return 1
+
+ if len(argv) != 3:
+ return 1
+
+ limit_flags = os.environ["LIMIT_FLAGS"]
+ opt_bisect_exist = False
+ debug_counter_exist = False
+
+ for option in limit_flags.split():
+ if "-opt-bisect-limit" in option:
+ opt_bisect_limit = int(option.split("=")[-1])
+ opt_bisect_exist = True
+ if "-debug-counter=" in option:
+ debug_counter = int(option.split("=")[-1])
+ debug_counter_exist = True
+
+ if not opt_bisect_exist:
+ return 1
+
+ # Manually set total number and bad number
+ total_pass = 10
+ total_transform = 20
+ bad_pass = int(argv[1])
+ bad_transform = int(argv[2])
+
+ if opt_bisect_limit == -1:
+ opt_bisect_limit = total_pass
+
+ for i in range(1, total_pass + 1):
+ bisect_str = (
+ "BISECT: %srunning pass (%d) Combine redundant "
+ "instructions on function (f1)"
+ % ("NOT " if i > opt_bisect_limit else "", i)
+ )
+ print(bisect_str, file=sys.stderr)
+
+ if debug_counter_exist:
+ print("Counters and values:", file=sys.stderr)
+ print(
+ "instcombine-visit : {%d, 0, %d}"
+ % (total_transform, debug_counter),
+ file=sys.stderr,
+ )
+
+ if opt_bisect_limit > bad_pass or (
+ debug_counter_exist and debug_counter > bad_transform
+ ):
+ common.WriteWorkingSet([1])
+ else:
+ common.WriteWorkingSet([0])
+
+ return 0
+
+
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/cmd_script_no_support.py b/binary_search_tool/test/cmd_script_no_support.py
index badbedc8..f1c2bcbe 100644
--- a/binary_search_tool/test/cmd_script_no_support.py
+++ b/binary_search_tool/test/cmd_script_no_support.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -9,21 +9,21 @@ This script generates a pseudo log when certain bisecting flags are not
supported by compiler.
"""
-from __future__ import print_function
import os
import sys
def Main():
- if not os.path.exists('./is_setup'):
- return 1
- print(
- 'No support for -opt-bisect-limit or -print-debug-counter.',
- file=sys.stderr)
- return 0
-
-
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+ if not os.path.exists("./is_setup"):
+ return 1
+ print(
+ "No support for -opt-bisect-limit or -print-debug-counter.",
+ file=sys.stderr,
+ )
+ return 0
+
+
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)
diff --git a/binary_search_tool/test/common.py b/binary_search_tool/test/common.py
index cf5300f5..6632a4c7 100755
--- a/binary_search_tool/test/common.py
+++ b/binary_search_tool/test/common.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -8,35 +8,35 @@
DEFAULT_OBJECT_NUMBER = 1238
DEFAULT_BAD_OBJECT_NUMBER = 23
-OBJECTS_FILE = 'objects.txt'
-WORKING_SET_FILE = 'working_set.txt'
+OBJECTS_FILE = "objects.txt"
+WORKING_SET_FILE = "working_set.txt"
def ReadWorkingSet():
- working_set = []
- with open(WORKING_SET_FILE, 'r', encoding='utf-8') as f:
- for l in f:
- working_set.append(int(l))
- return working_set
+ working_set = []
+ with open(WORKING_SET_FILE, "r", encoding="utf-8") as f:
+ for l in f:
+ working_set.append(int(l))
+ return working_set
def WriteWorkingSet(working_set):
- with open(WORKING_SET_FILE, 'w', encoding='utf-8') as f:
- for o in working_set:
- f.write('{0}\n'.format(o))
+ with open(WORKING_SET_FILE, "w", encoding="utf-8") as f:
+ for o in working_set:
+ f.write("{0}\n".format(o))
def ReadObjectsFile():
- objects_file = []
- with open(OBJECTS_FILE, 'r', encoding='utf-8') as f:
- for l in f:
- objects_file.append(int(l))
- return objects_file
+ objects_file = []
+ with open(OBJECTS_FILE, "r", encoding="utf-8") as f:
+ for l in f:
+ objects_file.append(int(l))
+ return objects_file
def ReadObjectIndex(filename):
- object_index = []
- with open(filename, 'r', encoding='utf-8') as f:
- for o in f:
- object_index.append(int(o))
- return object_index
+ object_index = []
+ with open(filename, "r", encoding="utf-8") as f:
+ for o in f:
+ object_index.append(int(o))
+ return object_index
diff --git a/binary_search_tool/test/gen_init_list.py b/binary_search_tool/test/gen_init_list.py
index bc5dd8fe..138e949c 100755
--- a/binary_search_tool/test/gen_init_list.py
+++ b/binary_search_tool/test/gen_init_list.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Prints out index for every object file, starting from 0."""
-from __future__ import print_function
import sys
@@ -15,13 +14,14 @@ from binary_search_tool.test import common
def Main():
- ce = command_executer.GetCommandExecuter()
- _, l, _ = ce.RunCommandWOutput(
- 'cat {0} | wc -l'.format(common.OBJECTS_FILE), print_to_console=False)
- for i in range(0, int(l)):
- print(i)
+ ce = command_executer.GetCommandExecuter()
+ _, l, _ = ce.RunCommandWOutput(
+ "cat {0} | wc -l".format(common.OBJECTS_FILE), print_to_console=False
+ )
+ for i in range(0, int(l)):
+ print(i)
-if __name__ == '__main__':
- Main()
- sys.exit(0)
+if __name__ == "__main__":
+ Main()
+ sys.exit(0)
diff --git a/binary_search_tool/test/gen_obj.py b/binary_search_tool/test/gen_obj.py
index 4f65c71b..394445f0 100755
--- a/binary_search_tool/test/gen_obj.py
+++ b/binary_search_tool/test/gen_obj.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -10,7 +10,6 @@
1 represents a bad object file.
"""
-from __future__ import print_function
import argparse
import os
@@ -21,81 +20,91 @@ from binary_search_tool.test import common
def Main(argv):
- """Generates a list, the value of each element is 0 or 1.
-
- The number of 1s in the list is specified by bad_obj_num.
- The others are all 0s. The total number of 0s and 1s is specified by obj_num.
-
- Args:
- argv: argument from command line
-
- Returns:
- 0 always.
- """
- parser = argparse.ArgumentParser()
- parser.add_argument(
- '-n',
- '--obj_num',
- dest='obj_num',
- default=common.DEFAULT_OBJECT_NUMBER,
- help=('Number of total objects.'))
- parser.add_argument(
- '-b',
- '--bad_obj_num',
- dest='bad_obj_num',
- default=common.DEFAULT_BAD_OBJECT_NUMBER,
- help=('Number of bad objects. Must be great than or '
- 'equal to zero and less than total object '
- 'number.'))
- parser.add_argument(
- '-o',
- '--obj_list',
- dest='obj_list',
- default='',
- help=('List of comma seperated objects to generate. '
- 'A 0 means the object is good, a 1 means the '
- 'object is bad.'))
- options = parser.parse_args(argv)
-
- obj_num = int(options.obj_num)
- bad_obj_num = int(options.bad_obj_num)
- bad_to_gen = int(options.bad_obj_num)
- obj_list = options.obj_list
- if not obj_list:
- obj_list = []
- for i in range(obj_num):
- if bad_to_gen > 0 and random.randint(1, obj_num) <= bad_obj_num:
- obj_list.append(1)
- bad_to_gen -= 1
- else:
- obj_list.append(0)
- while bad_to_gen > 0:
- t = random.randint(0, obj_num - 1)
- if obj_list[t] == 0:
- obj_list[t] = 1
- bad_to_gen -= 1
- else:
- obj_list = obj_list.split(',')
-
- if os.path.isfile(common.OBJECTS_FILE):
- os.remove(common.OBJECTS_FILE)
- if os.path.isfile(common.WORKING_SET_FILE):
- os.remove(common.WORKING_SET_FILE)
-
- with open(common.OBJECTS_FILE, 'w', encoding='utf-8') as f:
- with open(common.WORKING_SET_FILE, 'w', encoding='utf-8') as w:
- for i in obj_list:
- f.write('{0}\n'.format(i))
- w.write('{0}\n'.format(i))
-
- obj_num = len(obj_list)
- bad_obj_num = obj_list.count(1)
- print('Generated {0} object files, with {1} bad ones.'.format(
- obj_num, bad_obj_num))
-
- return 0
-
-
-if __name__ == '__main__':
- retval = Main(sys.argv[1:])
- sys.exit(retval)
+ """Generates a list, the value of each element is 0 or 1.
+
+ The number of 1s in the list is specified by bad_obj_num.
+ The others are all 0s. The total number of 0s and 1s is specified by obj_num.
+
+ Args:
+ argv: argument from command line
+
+ Returns:
+ 0 always.
+ """
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "-n",
+ "--obj_num",
+ dest="obj_num",
+ default=common.DEFAULT_OBJECT_NUMBER,
+ help=("Number of total objects."),
+ )
+ parser.add_argument(
+ "-b",
+ "--bad_obj_num",
+ dest="bad_obj_num",
+ default=common.DEFAULT_BAD_OBJECT_NUMBER,
+ help=(
+ "Number of bad objects. Must be great than or "
+ "equal to zero and less than total object "
+ "number."
+ ),
+ )
+ parser.add_argument(
+ "-o",
+ "--obj_list",
+ dest="obj_list",
+ default="",
+ help=(
+ "List of comma seperated objects to generate. "
+ "A 0 means the object is good, a 1 means the "
+ "object is bad."
+ ),
+ )
+ options = parser.parse_args(argv)
+
+ obj_num = int(options.obj_num)
+ bad_obj_num = int(options.bad_obj_num)
+ bad_to_gen = int(options.bad_obj_num)
+ obj_list = options.obj_list
+ if not obj_list:
+ obj_list = []
+ for i in range(obj_num):
+ if bad_to_gen > 0 and random.randint(1, obj_num) <= bad_obj_num:
+ obj_list.append(1)
+ bad_to_gen -= 1
+ else:
+ obj_list.append(0)
+ while bad_to_gen > 0:
+ t = random.randint(0, obj_num - 1)
+ if obj_list[t] == 0:
+ obj_list[t] = 1
+ bad_to_gen -= 1
+ else:
+ obj_list = obj_list.split(",")
+
+ if os.path.isfile(common.OBJECTS_FILE):
+ os.remove(common.OBJECTS_FILE)
+ if os.path.isfile(common.WORKING_SET_FILE):
+ os.remove(common.WORKING_SET_FILE)
+
+ with open(common.OBJECTS_FILE, "w", encoding="utf-8") as f:
+ with open(common.WORKING_SET_FILE, "w", encoding="utf-8") as w:
+ for i in obj_list:
+ f.write("{0}\n".format(i))
+ w.write("{0}\n".format(i))
+
+ obj_num = len(obj_list)
+ bad_obj_num = obj_list.count(1)
+ print(
+ "Generated {0} object files, with {1} bad ones.".format(
+ obj_num, bad_obj_num
+ )
+ )
+
+ return 0
+
+
+if __name__ == "__main__":
+ retval = Main(sys.argv[1:])
+ sys.exit(retval)
diff --git a/binary_search_tool/test/generate_cmd.py b/binary_search_tool/test/generate_cmd.py
index 51b36b0a..96fa720c 100755
--- a/binary_search_tool/test/generate_cmd.py
+++ b/binary_search_tool/test/generate_cmd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -10,21 +10,20 @@ This is a required argument for pass level bisecting. For unit test, we use
this script to verify if cmd_script.sh is generated correctly.
"""
-from __future__ import print_function
import os
import sys
def Main():
- if not os.path.exists('./is_setup'):
- return 1
- file_name = 'cmd_script.sh'
- with open(file_name, 'w', encoding='utf-8') as f:
- f.write('Generated by generate_cmd.py')
- return 0
+ if not os.path.exists("./is_setup"):
+ return 1
+ file_name = "cmd_script.sh"
+ with open(file_name, "w", encoding="utf-8") as f:
+ f.write("Generated by generate_cmd.py")
+ return 0
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)
diff --git a/binary_search_tool/test/is_good.py b/binary_search_tool/test/is_good.py
index 662921e8..fd3f908f 100755
--- a/binary_search_tool/test/is_good.py
+++ b/binary_search_tool/test/is_good.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Check to see if the working set produces a good executable."""
-from __future__ import print_function
import os
import sys
@@ -15,15 +14,15 @@ from binary_search_tool.test import common
def Main():
- if not os.path.exists('./is_setup'):
- return 1
- working_set = common.ReadWorkingSet()
- for w in working_set:
- if w == 1:
- return 1 ## False, linking failure
- return 0
-
-
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+ if not os.path.exists("./is_setup"):
+ return 1
+ working_set = common.ReadWorkingSet()
+ for w in working_set:
+ if w == 1:
+ return 1 ## False, linking failure
+ return 0
+
+
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)
diff --git a/binary_search_tool/test/is_good_noinc_prune.py b/binary_search_tool/test/is_good_noinc_prune.py
index c0e42bb1..654fcd25 100755
--- a/binary_search_tool/test/is_good_noinc_prune.py
+++ b/binary_search_tool/test/is_good_noinc_prune.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -12,7 +12,6 @@ to the switch scripts is equals to the actual number of items (i.e. checking
that noincremental always holds).
"""
-from __future__ import print_function
import os
import sys
@@ -21,31 +20,31 @@ from binary_search_tool.test import common
def Main():
- working_set = common.ReadWorkingSet()
+ working_set = common.ReadWorkingSet()
- with open('noinc_prune_good', 'r', encoding='utf-8') as good_args:
- num_good_args = len(good_args.readlines())
+ with open("noinc_prune_good", "r", encoding="utf-8") as good_args:
+ num_good_args = len(good_args.readlines())
- with open('noinc_prune_bad', 'r', encoding='utf-8') as bad_args:
- num_bad_args = len(bad_args.readlines())
+ with open("noinc_prune_bad", "r", encoding="utf-8") as bad_args:
+ num_bad_args = len(bad_args.readlines())
- num_args = num_good_args + num_bad_args
- if num_args != len(working_set):
- print('Only %d args, expected %d' % (num_args, len(working_set)))
- print('%d good args, %d bad args' % (num_good_args, num_bad_args))
- return 3
+ num_args = num_good_args + num_bad_args
+ if num_args != len(working_set):
+ print("Only %d args, expected %d" % (num_args, len(working_set)))
+ print("%d good args, %d bad args" % (num_good_args, num_bad_args))
+ return 3
- os.remove('noinc_prune_bad')
- os.remove('noinc_prune_good')
+ os.remove("noinc_prune_bad")
+ os.remove("noinc_prune_good")
- if not os.path.exists('./is_setup'):
- return 1
- for w in working_set:
- if w == 1:
- return 1 ## False, linking failure
- return 0
+ if not os.path.exists("./is_setup"):
+ return 1
+ for w in working_set:
+ if w == 1:
+ return 1 ## False, linking failure
+ return 0
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_tmp.py b/binary_search_tool/test/switch_tmp.py
index 0f3c4234..acc0393d 100755
--- a/binary_search_tool/test/switch_tmp.py
+++ b/binary_search_tool/test/switch_tmp.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -12,7 +12,6 @@ this script) content. Every line in the file is an object index, which will be
set to good (mark as 42).
"""
-from __future__ import print_function
import sys
@@ -20,20 +19,20 @@ from binary_search_tool.test import common
def Main(argv):
- working_set = common.ReadWorkingSet()
- object_index = common.ReadObjectIndex(argv[1])
+ working_set = common.ReadWorkingSet()
+ object_index = common.ReadObjectIndex(argv[1])
- # Random number so the results can be checked
- for oi in object_index:
- working_set[int(oi)] = 42
+ # Random number so the results can be checked
+ for oi in object_index:
+ working_set[int(oi)] = 42
- common.WriteWorkingSet(working_set)
- with open('tmp_file', 'w', encoding='utf-8') as f:
- f.write(argv[1])
+ common.WriteWorkingSet(working_set)
+ with open("tmp_file", "w", encoding="utf-8") as f:
+ f.write(argv[1])
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_bad.py b/binary_search_tool/test/switch_to_bad.py
index e3553eb6..bc32f3cc 100755
--- a/binary_search_tool/test/switch_to_bad.py
+++ b/binary_search_tool/test/switch_to_bad.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Switch part of the objects file in working set to (possible) bad ones."""
-from __future__ import print_function
import sys
@@ -14,19 +13,19 @@ from binary_search_tool.test import common
def Main(argv):
- """Switch part of the objects file in working set to (possible) bad ones."""
- working_set = common.ReadWorkingSet()
- objects_file = common.ReadObjectsFile()
- object_index = common.ReadObjectIndex(argv[1])
+ """Switch part of the objects file in working set to (possible) bad ones."""
+ working_set = common.ReadWorkingSet()
+ objects_file = common.ReadObjectsFile()
+ object_index = common.ReadObjectIndex(argv[1])
- for oi in object_index:
- working_set[oi] = objects_file[oi]
+ for oi in object_index:
+ working_set[oi] = objects_file[oi]
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_bad_noinc_prune.py b/binary_search_tool/test/switch_to_bad_noinc_prune.py
index 81b558e1..e5574f95 100755
--- a/binary_search_tool/test/switch_to_bad_noinc_prune.py
+++ b/binary_search_tool/test/switch_to_bad_noinc_prune.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -18,7 +18,6 @@ that noincremental always holds).
Warning: This switch script assumes the --file_args option
"""
-from __future__ import print_function
import shutil
import sys
@@ -27,21 +26,21 @@ from binary_search_tool.test import common
def Main(argv):
- """Switch part of the objects file in working set to (possible) bad ones."""
- working_set = common.ReadWorkingSet()
- objects_file = common.ReadObjectsFile()
- object_index = common.ReadObjectIndex(argv[1])
+ """Switch part of the objects file in working set to (possible) bad ones."""
+ working_set = common.ReadWorkingSet()
+ objects_file = common.ReadObjectsFile()
+ object_index = common.ReadObjectIndex(argv[1])
- for oi in object_index:
- working_set[oi] = objects_file[oi]
+ for oi in object_index:
+ working_set[oi] = objects_file[oi]
- shutil.copy(argv[1], './noinc_prune_bad')
+ shutil.copy(argv[1], "./noinc_prune_bad")
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_bad_set_file.py b/binary_search_tool/test/switch_to_bad_set_file.py
index 5b941c62..9d4bee6f 100755
--- a/binary_search_tool/test/switch_to_bad_set_file.py
+++ b/binary_search_tool/test/switch_to_bad_set_file.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -10,7 +10,6 @@ This script is meant to be specifically used with the set_file test. This uses
the set files generated by binary_search_state to do the switching.
"""
-from __future__ import print_function
import os
import sys
@@ -19,24 +18,24 @@ from binary_search_tool.test import common
def Main(_):
- """Switch part of the objects file in working set to (possible) bad ones."""
- working_set = common.ReadWorkingSet()
- objects_file = common.ReadObjectsFile()
+ """Switch part of the objects file in working set to (possible) bad ones."""
+ working_set = common.ReadWorkingSet()
+ objects_file = common.ReadObjectsFile()
- if not os.path.exists(os.environ['BISECT_BAD_SET']):
- print('Bad set file does not exist!')
- return 1
+ if not os.path.exists(os.environ["BISECT_BAD_SET"]):
+ print("Bad set file does not exist!")
+ return 1
- object_index = common.ReadObjectIndex(os.environ['BISECT_BAD_SET'])
+ object_index = common.ReadObjectIndex(os.environ["BISECT_BAD_SET"])
- for oi in object_index:
- working_set[int(oi)] = objects_file[oi]
+ for oi in object_index:
+ working_set[int(oi)] = objects_file[oi]
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_good.py b/binary_search_tool/test/switch_to_good.py
index 97479329..61a59a2a 100755
--- a/binary_search_tool/test/switch_to_good.py
+++ b/binary_search_tool/test/switch_to_good.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -11,7 +11,6 @@ this script) content. Every line in the file is an object index, which will be
set to good (mark as 0).
"""
-from __future__ import print_function
import sys
@@ -19,17 +18,17 @@ from binary_search_tool.test import common
def Main(argv):
- working_set = common.ReadWorkingSet()
- object_index = common.ReadObjectIndex(argv[1])
+ working_set = common.ReadWorkingSet()
+ object_index = common.ReadObjectIndex(argv[1])
- for oi in object_index:
- working_set[int(oi)] = 0
+ for oi in object_index:
+ working_set[int(oi)] = 0
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_good_noinc_prune.py b/binary_search_tool/test/switch_to_good_noinc_prune.py
index 0b91a0d8..3bda1d78 100755
--- a/binary_search_tool/test/switch_to_good_noinc_prune.py
+++ b/binary_search_tool/test/switch_to_good_noinc_prune.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -18,7 +18,6 @@ that noincremental always holds).
Warning: This switch script assumes the --file_args option
"""
-from __future__ import print_function
import shutil
import sys
@@ -27,19 +26,19 @@ from binary_search_tool.test import common
def Main(argv):
- working_set = common.ReadWorkingSet()
- object_index = common.ReadObjectIndex(argv[1])
+ working_set = common.ReadWorkingSet()
+ object_index = common.ReadObjectIndex(argv[1])
- for oi in object_index:
- working_set[int(oi)] = 0
+ for oi in object_index:
+ working_set[int(oi)] = 0
- shutil.copy(argv[1], './noinc_prune_good')
+ shutil.copy(argv[1], "./noinc_prune_good")
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/switch_to_good_set_file.py b/binary_search_tool/test/switch_to_good_set_file.py
index 1cb05e0c..b83cbe3f 100755
--- a/binary_search_tool/test/switch_to_good_set_file.py
+++ b/binary_search_tool/test/switch_to_good_set_file.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -14,7 +14,6 @@ This script is meant to be specifically used with the set_file test. This uses
the set files generated by binary_search_state to do the switching.
"""
-from __future__ import print_function
import os
import sys
@@ -23,22 +22,22 @@ from binary_search_tool.test import common
def Main(_):
- working_set = common.ReadWorkingSet()
+ working_set = common.ReadWorkingSet()
- if not os.path.exists(os.environ['BISECT_GOOD_SET']):
- print('Good set file does not exist!')
- return 1
+ if not os.path.exists(os.environ["BISECT_GOOD_SET"]):
+ print("Good set file does not exist!")
+ return 1
- object_index = common.ReadObjectIndex(os.environ['BISECT_GOOD_SET'])
+ object_index = common.ReadObjectIndex(os.environ["BISECT_GOOD_SET"])
- for oi in object_index:
- working_set[int(oi)] = 0
+ for oi in object_index:
+ working_set[int(oi)] = 0
- common.WriteWorkingSet(working_set)
+ common.WriteWorkingSet(working_set)
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main(sys.argv)
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main(sys.argv)
+ sys.exit(retval)
diff --git a/binary_search_tool/test/test_setup.py b/binary_search_tool/test/test_setup.py
index ecc8eb97..52486a28 100755
--- a/binary_search_tool/test/test_setup.py
+++ b/binary_search_tool/test/test_setup.py
@@ -1,24 +1,23 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Emulate running of test setup script, is_good.py should fail without this."""
-from __future__ import print_function
import sys
def Main():
- # create ./is_setup
- with open('./is_setup', 'w', encoding='utf-8'):
- pass
+ # create ./is_setup
+ with open("./is_setup", "w", encoding="utf-8"):
+ pass
- return 0
+ return 0
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)
diff --git a/binary_search_tool/test/test_setup_bad.py b/binary_search_tool/test/test_setup_bad.py
index cbca3c21..518a69fd 100755
--- a/binary_search_tool/test/test_setup_bad.py
+++ b/binary_search_tool/test/test_setup_bad.py
@@ -1,20 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Emulate test setup that fails (i.e. failed flash to device)"""
-from __future__ import print_function
import sys
def Main():
- return 1 ## False, flashing failure
+ return 1 ## False, flashing failure
-if __name__ == '__main__':
- retval = Main()
- sys.exit(retval)
+if __name__ == "__main__":
+ retval = Main()
+ sys.exit(retval)