2 # This script is used to bisect skip and count arguments for --debug-counter.
3 # It is similar to bisect, except it understands how to increase skip and decrease count
7 # This is for timeout support. Use the recommended way of import.
8 # We do timeouts because when doing, execution testing, we have a habit
9 # of finding variants that infinite loop
10 if os
.name
== 'posix' and sys
.version_info
[0] < 3:
11 import subprocess32
as subprocess
14 parser
= argparse
.ArgumentParser()
16 parser
.add_argument('--skipstart', type=int, default
=0)
17 parser
.add_argument('--skipend', type=int, default
=(1 << 32))
18 parser
.add_argument('--countstart', type=int, default
=0)
19 parser
.add_argument('--countend', type=int, default
=(1 << 32))
20 parser
.add_argument('--timeout', type=int, default
=None)
21 # Use shell support if you need to use complex shell expressions in your command
22 parser
.add_argument('--shell', type=bool, default
=False)
23 parser
.add_argument('command', nargs
='+')
25 args
= parser
.parse_args()
27 start
= args
.skipstart
30 print("Bisect of Skip starting!")
31 print("Start: %d" % start
)
32 print("End: %d" % end
)
35 while start
!= end
and start
!= end
-1:
36 count
= start
+ (end
- start
)/2
37 print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count
, start
, end
))
38 cmd
= [x
% {'skip':count
, 'count':-1} for x
in args
.command
]
41 result
= subprocess
.call(cmd
, shell
=args
.shell
, timeout
=args
.timeout
)
43 print(" PASSES! Setting end to count")
46 print(" FAILS! Setting start to count")
49 print(" TIMEOUT, setting end to count")
52 print("Last good skip: %d" % start
)
53 start
= args
.countstart
55 print("Bisect of Count starting!")
56 print("Start: %d" % start
)
57 print("End: %d" % end
)
58 while start
!= end
and start
!= end
-1:
59 count
= start
+ (end
- start
)/2
60 print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count
, start
, end
))
61 cmd
= [x
% {'count':count
, 'skip':firstcount
} for x
in args
.command
]
64 result
= subprocess
.call(cmd
, shell
=args
.shell
, timeout
=args
.timeout
)
66 print(" PASSES! Setting start to count")
69 print(" FAILS! Setting end to count")
72 print(" TIMEOUT, setting start to count")
75 print("Last good count: %d" % start
)