annotate utils/bisect-skip-count @ 140:276c179585fe

Added tag LLVM5.0.1 for changeset 3a76565eade5
author mir3636
date Tue, 03 Apr 2018 19:09:39 +0900
parents 803732b1fca8
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 #!/usr/bin/env python
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 # This script is used to bisect skip and count arguments for --debug-counter.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 # It is similar to bisect, except it understands how to increase skip and decrease count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 import os
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 import sys
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 import argparse
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 # This is for timeout support. Use the recommended way of import.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 # We do timeouts because when doing, execution testing, we have a habit
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 # of finding variants that infinite loop
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 if os.name == 'posix' and sys.version_info[0] < 3:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 import subprocess32 as subprocess
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 else:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 import subprocess
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 parser = argparse.ArgumentParser()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 parser.add_argument('--skipstart', type=int, default=0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 parser.add_argument('--skipend', type=int, default=(1 << 32))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 parser.add_argument('--countstart', type=int, default=0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 parser.add_argument('--countend', type=int, default=(1 << 32))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 parser.add_argument('--timeout', type=int, default=None)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 # Use shell support if you need to use complex shell expressions in your command
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 parser.add_argument('--shell', type=bool, default=False)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 parser.add_argument('command', nargs='+')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 args = parser.parse_args()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 start = args.skipstart
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 end = args.skipend
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 print("Bisect of Skip starting!")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 print("Start: %d" % start)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 print("End: %d" % end)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 last = None
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 while start != end and start != end-1:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 count = start + (end - start)/2
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count, start, end))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 cmd = [x % {'skip':count, 'count':-1} for x in args.command]
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 print cmd
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 try:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 if result == 0:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 print(" PASSES! Setting end to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 end = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 else:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 print(" FAILS! Setting start to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 start = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 except:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 print(" TIMEOUT, setting end to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 end = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 firstcount = start
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 print("Last good skip: %d" % start)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 start = args.countstart
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 end = args.countend
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 print("Bisect of Count starting!")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 print("Start: %d" % start)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 print("End: %d" % end)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 while start != end and start != end-1:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 count = start + (end - start)/2
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 cmd = [x % {'count':count, 'skip':firstcount } for x in args.command]
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 print cmd
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 try:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 if result == 0:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 print(" PASSES! Setting start to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 start = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 else:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 print(" FAILS! Setting end to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 end = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 except:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 print(" TIMEOUT, setting start to count")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 start = count
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 print("Last good count: %d" % start)