[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / utils / bisect-skip-count
blobf4f8ddcec797ad2ad5f109a8020c109bbaad4279
1 #!/usr/bin/env python
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
5 # Typical usage:
7 # bisect-skip-count bisect-command.sh "%(skip)d" "%(count)d" 2>&1 | tee bisect.out
9 # bisect-command.sh is something like this:
10 # #! /bin/bash
12 # skip=$1
13 # count=$2
15 # opt -debug-counter=my-counter-skip=${skip},my-counter-count=${count}
16 # ... Test output of opt and exit zero for pass, non-zero for fail
18 # Examine bisect.out to look for "Last good skip" and "Last good
19 # count" to find the values of the counter that produce a passing
20 # result. Incrementing the last good count by one or decrementing the
21 # last good skip by one should produce a failure.
23 import os
24 import sys
25 import argparse
26 # This is for timeout support. Use the recommended way of import.
27 # We do timeouts because when doing, execution testing, we have a habit
28 # of finding variants that infinite loop
29 if os.name == 'posix' and sys.version_info[0] < 3:
30 import subprocess32 as subprocess
31 else:
32 import subprocess
33 parser = argparse.ArgumentParser()
35 parser.add_argument('--skipstart', type=int, default=0)
36 parser.add_argument('--skipend', type=int, default=(1 << 32))
37 parser.add_argument('--countstart', type=int, default=0)
38 parser.add_argument('--countend', type=int, default=(1 << 32))
39 parser.add_argument('--timeout', type=int, default=None)
40 # Use shell support if you need to use complex shell expressions in your command
41 parser.add_argument('--shell', type=bool, default=False)
42 parser.add_argument('command', nargs='+')
44 args = parser.parse_args()
46 start = args.skipstart
47 end = args.skipend
49 print("Bisect of Skip starting!")
50 print("Start: %d" % start)
51 print("End: %d" % end)
53 last = None
54 while start != end and start != end-1:
55 count = start + (end - start)/2
56 print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count, start, end))
57 cmd = [x % {'skip':count, 'count':-1} for x in args.command]
58 print cmd
59 try:
60 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
61 if result == 0:
62 print(" PASSES! Setting end to count")
63 end = count
64 else:
65 print(" FAILS! Setting start to count")
66 start = count
67 except:
68 print(" TIMEOUT, setting end to count")
69 end = count
70 firstcount = start
71 print("Last good skip: %d" % start)
72 start = args.countstart
73 end = args.countend
74 print("Bisect of Count starting!")
75 print("Start: %d" % start)
76 print("End: %d" % end)
77 while start != end and start != end-1:
78 count = start + (end - start)/2
79 print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
80 cmd = [x % {'count':count, 'skip':firstcount } for x in args.command]
81 print cmd
82 try:
83 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
84 if result == 0:
85 print(" PASSES! Setting start to count")
86 start = count
87 else:
88 print(" FAILS! Setting end to count")
89 end = count
90 except:
91 print(" TIMEOUT, setting start to count")
92 start = count
94 print("Last good count: %d" % start)