Home | History | Annotate | Download | only in utils
      1 #!/usr/bin/env python
      2 
      3 import os
      4 import sys
      5 import argparse
      6 import subprocess
      7 
      8 parser = argparse.ArgumentParser()
      9 
     10 parser.add_argument('--start', type=int, default=0)
     11 parser.add_argument('--end', type=int, default=(1 << 32))
     12 parser.add_argument('command', nargs='+')
     13 
     14 args = parser.parse_args()
     15 
     16 start = args.start
     17 end = args.end
     18 
     19 print("Bisect Starting!")
     20 print("Start: %d" % start)
     21 print("End: %d" % end)
     22 
     23 last = None
     24 while start != end and start != end-1:
     25     count = start + (end - start)/2
     26     print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
     27     cmd = [x % {'count':count} for x in args.command]
     28     print cmd
     29     result = subprocess.call(cmd)
     30     if result == 0:
     31         print("    PASSES! Setting start to count")
     32         start = count
     33     else:
     34         print("    FAILS! Setting end to count")
     35         end = count
     36 
     37 print("Last good count: %d" % start)
     38