llvm-project
95 строк · 3.2 Кб
1#!/usr/bin/env python3
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
4#
5# Typical usage:
6#
7# bisect-skip-count bisect-command.sh "%(skip)d" "%(count)d" 2>&1 | tee bisect.out
8#
9# bisect-command.sh is something like this:
10# #! /bin/bash
11#
12# skip=$1
13# count=$2
14#
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
17#
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.
22#
23from __future__ import print_function24import os25import sys26import argparse27# This is for timeout support. Use the recommended way of import.
28# We do timeouts because when doing, execution testing, we have a habit
29# of finding variants that infinite loop
30if os.name == 'posix' and sys.version_info[0] < 3:31import subprocess32 as subprocess32else:33import subprocess34parser = argparse.ArgumentParser()35
36parser.add_argument('--skipstart', type=int, default=0)37parser.add_argument('--skipend', type=int, default=(1 << 32))38parser.add_argument('--countstart', type=int, default=0)39parser.add_argument('--countend', type=int, default=(1 << 32))40parser.add_argument('--timeout', type=int, default=None)41# Use shell support if you need to use complex shell expressions in your command
42parser.add_argument('--shell', type=bool, default=False)43parser.add_argument('command', nargs='+')44
45args = parser.parse_args()46
47start = args.skipstart48end = args.skipend49
50print("Bisect of Skip starting!")51print("Start: %d" % start)52print("End: %d" % end)53
54last = None55while start != end and start != end-1:56count = start + (end - start)//257print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count, start, end))58cmd = [x % {'skip':count, 'count':-1} for x in args.command]59print(cmd)60try:61result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)62if result == 0:63print(" PASSES! Setting end to count")64end = count65else:66print(" FAILS! Setting start to count")67start = count68except:69print(" TIMEOUT, setting end to count")70end = count71firstcount = start72print("Last good skip: %d" % start)73start = args.countstart74end = args.countend75print("Bisect of Count starting!")76print("Start: %d" % start)77print("End: %d" % end)78while start != end and start != end-1:79count = start + (end - start)//280print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))81cmd = [x % {'count':count, 'skip':firstcount } for x in args.command]82print(cmd)83try:84result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)85if result == 0:86print(" PASSES! Setting start to count")87start = count88else:89print(" FAILS! Setting end to count")90end = count91except:92print(" TIMEOUT, setting start to count")93start = count94
95print("Last good count: %d" % start)96