| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from __future__ import print_function |
| 16 |
import os |
| 17 |
import sys |
| 18 |
import argparse |
| 19 |
import subprocess |
| 20 |
|
| 21 |
parser = argparse.ArgumentParser() |
| 22 |
|
| 23 |
parser.add_argument('--start', type=int, default=0) |
| 24 |
parser.add_argument('--end', type=int, default=(1 << 32)) |
| 25 |
parser.add_argument('command', nargs='+') |
| 26 |
|
| 27 |
args = parser.parse_args() |
| 28 |
|
| 29 |
start = args.start |
| 30 |
end = args.end |
| 31 |
|
| 32 |
print("Bisect Starting!") |
| 33 |
print("Start: %d" % start) |
| 34 |
print("End: %d" % end) |
| 35 |
|
| 36 |
last = None |
| 37 |
while start != end and start != end-1: |
| 38 |
count = start + (end - start)//2 |
| 39 |
print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end)) |
| 40 |
cmd = [x % {'count':count} for x in args.command] |
| 41 |
print(cmd) |
| 42 |
result = subprocess.call(cmd) |
| 43 |
if result == 0: |
| 44 |
print(" PASSES! Setting start to count") |
| 45 |
start = count |
| 46 |
else: |
| 47 |
print(" FAILS! Setting end to count") |
| 48 |
end = count |
| 49 |
|
| 50 |
print("Last good count: %d" % start) |