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