aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/test/gen_obj.py
diff options
context:
space:
mode:
authorCassidy Burden <cburden@google.com>2016-07-26 09:40:33 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-08-01 14:13:59 -0700
commit660e682dae1e34076cb758694be67edfc7bc6ed4 (patch)
tree893b0948941755c794efb1e78361a12167148c58 /binary_search_tool/test/gen_obj.py
parent25fcdc012532b8208cec9cf854de1d6df3cf0793 (diff)
downloadtoolchain-utils-660e682dae1e34076cb758694be67edfc7bc6ed4.tar.gz
binary search tool: Fix off by one bug, add stress tests
Revert change that introduced bug when bad item is very last item in list. Add tests that stress limits of binary search tool and try to look for these off-by-one errors. Specifically one test checks for the bad item being in every index of the binary search. Another tests checks for if every single item is bad. TEST=Add two new stress tests, run all unit tests Change-Id: I2d5a0bda035b2c2b4994b0378aa416da19db651d Reviewed-on: https://chrome-internal-review.googlesource.com/271916 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/test/gen_obj.py')
-rwxr-xr-xbinary_search_tool/test/gen_obj.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/binary_search_tool/test/gen_obj.py b/binary_search_tool/test/gen_obj.py
index 6fb9a908..1c060e01 100755
--- a/binary_search_tool/test/gen_obj.py
+++ b/binary_search_tool/test/gen_obj.py
@@ -40,23 +40,34 @@ def Main(argv):
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 = []
- 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
+ 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)
@@ -70,8 +81,11 @@ def Main(argv):
w.write('{0}\n'.format(i))
f.close()
+ obj_num = len(obj_list)
+ bad_obj_num = obj_list.count('1')
print('Generated {0} object files, with {1} bad ones.'.format(
- options.obj_num, options.bad_obj_num))
+ obj_num, bad_obj_num))
+
return 0