##// END OF EJS Templates
run-tests: add --time option to log times for each test...
Siddharth Agarwal -
r17921:4ac9cf3d default
parent child Browse files
Show More
@@ -176,6 +176,8 b' def parseargs():'
176 176 parser.add_option("-t", "--timeout", type="int",
177 177 help="kill errant tests after TIMEOUT seconds"
178 178 " (default: $%s or %d)" % defaults['timeout'])
179 parser.add_option("--time", action="store_true",
180 help="time how long each test takes")
179 181 parser.add_option("--tmpdir", type="string",
180 182 help="run tests in the given temporary directory"
181 183 " (implies --keep-tmpdir)")
@@ -264,6 +266,10 b' def parseargs():'
264 266 sys.stderr.write(
265 267 'warning: --timeout option ignored with --debug\n')
266 268 options.timeout = 0
269 if options.time:
270 sys.stderr.write(
271 'warning: --time option ignored with --debug\n')
272 options.time = False
267 273 if options.py3k_warnings:
268 274 if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0):
269 275 parser.error('--py3k-warnings can only be used on Python 2.6+')
@@ -448,6 +454,14 b' def installhg(options):'
448 454 fn = os.path.join(INST, '..', '.coverage')
449 455 os.environ['COVERAGE_FILE'] = fn
450 456
457 def outputtimes(options):
458 vlog('# Producing time report')
459 times.sort(key=lambda t: (t[1], t[0]), reverse=True)
460 cols = '%7.3f %s'
461 print '\n%-7s %s' % ('Time', 'Test')
462 for test, timetaken in times:
463 print cols % (timetaken, test)
464
451 465 def outputcoverage(options):
452 466
453 467 vlog('# Producing coverage report')
@@ -887,7 +901,12 b' def runone(options, test):'
887 901 replacements.append((re.escape(testtmp), '$TESTTMP'))
888 902
889 903 os.mkdir(testtmp)
904 if options.time:
905 starttime = time.time()
890 906 ret, out = runner(testpath, testtmp, options, replacements)
907 if options.time:
908 endtime = time.time()
909 times.append((test, endtime - starttime))
891 910 vlog("# Ret was:", ret)
892 911
893 912 mark = '.'
@@ -1072,6 +1091,9 b' def runchildren(options, tests):'
1072 1091 failed += len(childresults['f'])
1073 1092 skips.extend(childresults['s'])
1074 1093 fails.extend(childresults['f'])
1094 if options.time:
1095 childtimes = pickle.load(fp)
1096 times.extend(childtimes)
1075 1097
1076 1098 vlog('pid %d exited, status %d' % (pid, status))
1077 1099 failures |= status
@@ -1089,11 +1111,14 b' def runchildren(options, tests):'
1089 1111 print "# Ran %d tests, %d skipped, %d failed." % (
1090 1112 passed + failed, skipped, failed)
1091 1113
1114 if options.time:
1115 outputtimes(options)
1092 1116 if options.anycoverage:
1093 1117 outputcoverage(options)
1094 1118 sys.exit(failures != 0)
1095 1119
1096 1120 results = dict(p=[], f=[], s=[], i=[])
1121 times = []
1097 1122 iolock = threading.Lock()
1098 1123
1099 1124 def runqueue(options, tests, results):
@@ -1132,6 +1157,8 b' def runtests(options, tests):'
1132 1157 if options.child:
1133 1158 fp = os.fdopen(options.child, 'w')
1134 1159 pickle.dump(results, fp, pickle.HIGHEST_PROTOCOL)
1160 if options.time:
1161 pickle.dump(times, fp, pickle.HIGHEST_PROTOCOL)
1135 1162 fp.close()
1136 1163 else:
1137 1164 print
@@ -1142,6 +1169,8 b' def runtests(options, tests):'
1142 1169 _checkhglib("Tested")
1143 1170 print "# Ran %d tests, %d skipped, %d failed." % (
1144 1171 tested, skipped + ignored, failed)
1172 if options.time:
1173 outputtimes(options)
1145 1174
1146 1175 if options.anycoverage:
1147 1176 outputcoverage(options)
General Comments 0
You need to be logged in to leave comments. Login now