|
174 | 174 | import StringIO
|
175 | 175 | import datetime
|
176 | 176 | import getopt
|
| 177 | +import imp |
177 | 178 | import json
|
| 179 | +import math |
178 | 180 | import os
|
| 181 | +import platform |
179 | 182 | import random
|
180 | 183 | import re
|
181 | 184 | import shutil
|
182 | 185 | import sys
|
| 186 | +import sysconfig |
| 187 | +import tempfile |
183 | 188 | import time
|
184 | 189 | import traceback
|
185 |
| -import warnings |
186 | 190 | import unittest
|
187 |
| -import tempfile |
188 |
| -import imp |
189 |
| -import platform |
190 |
| -import sysconfig |
| 191 | +import warnings |
191 | 192 |
|
192 | 193 |
|
193 | 194 | # Some times __path__ and __file__ are not absolute (e.g. while running from
|
@@ -270,17 +271,25 @@ def usage(code, msg=''):
|
270 | 271 |
|
271 | 272 |
|
272 | 273 | def format_duration(seconds):
|
273 |
| - if seconds < 1.0: |
274 |
| - return '%.0f ms' % (seconds * 1e3) |
275 |
| - if seconds < 60.0: |
276 |
| - return '%.0f sec' % seconds |
| 274 | + ms = int(math.ceil(seconds * 1e3)) |
| 275 | + seconds, ms = divmod(ms, 1000) |
| 276 | + minutes, seconds = divmod(seconds, 60) |
| 277 | + hours, minutes = divmod(minutes, 60) |
277 | 278 |
|
278 |
| - minutes, seconds = divmod(seconds, 60.0) |
279 |
| - hours, minutes = divmod(minutes, 60.0) |
| 279 | + parts = [] |
280 | 280 | if hours:
|
281 |
| - return '%.0f hour %.0f min' % (hours, minutes) |
282 |
| - else: |
283 |
| - return '%.0f min %.0f sec' % (minutes, seconds) |
| 281 | + parts.append('%s hour' % hours) |
| 282 | + if minutes: |
| 283 | + parts.append('%s min' % minutes) |
| 284 | + if seconds: |
| 285 | + parts.append('%s sec' % seconds) |
| 286 | + if ms: |
| 287 | + parts.append('%s ms' % ms) |
| 288 | + if not parts: |
| 289 | + return '0 ms' |
| 290 | + |
| 291 | + parts = parts[:2] |
| 292 | + return ' '.join(parts) |
284 | 293 |
|
285 | 294 |
|
286 | 295 | _FORMAT_TEST_RESULT = {
|
@@ -507,6 +516,15 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
|
507 | 516 | except ValueError:
|
508 | 517 | pass
|
509 | 518 |
|
| 519 | + if huntrleaks: |
| 520 | + warmup, repetitions, _ = huntrleaks |
| 521 | + if warmup < 1 or repetitions < 1: |
| 522 | + msg = ("Invalid values for the --huntrleaks/-R parameters. The " |
| 523 | + "number of warmups and repetitions must be at least 1 " |
| 524 | + "each (1:1).") |
| 525 | + print >>sys.stderr, msg |
| 526 | + sys.exit(2) |
| 527 | + |
510 | 528 | if slaveargs is not None:
|
511 | 529 | args, kwargs = json.loads(slaveargs)
|
512 | 530 | if kwargs['huntrleaks']:
|
@@ -682,6 +700,12 @@ def display_progress(test_index, test):
|
682 | 700 | if ncpu:
|
683 | 701 | print "== CPU count:", ncpu
|
684 | 702 |
|
| 703 | + if huntrleaks: |
| 704 | + warmup, repetitions, _ = huntrleaks |
| 705 | + if warmup < 3: |
| 706 | + print("WARNING: Running tests with --huntrleaks/-R and less than " |
| 707 | + "3 warmup repetitions can give false positives!") |
| 708 | + |
685 | 709 | if randomize:
|
686 | 710 | random.seed(random_seed)
|
687 | 711 | print "Using random seed", random_seed
|
@@ -809,7 +833,7 @@ def get_running(workers):
|
809 | 833 | if (ok not in (CHILD_ERROR, INTERRUPTED)
|
810 | 834 | and test_time >= PROGRESS_MIN_TIME
|
811 | 835 | and not pgo):
|
812 |
| - text += ' (%.0f sec)' % test_time |
| 836 | + text += ' (%s)' % format_duration(test_time) |
813 | 837 | running = get_running(workers)
|
814 | 838 | if running and not pgo:
|
815 | 839 | text += ' -- running: %s' % ', '.join(running)
|
@@ -1293,11 +1317,12 @@ def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False, testdir=Non
|
1293 | 1317 | # being imported. For tests based on unittest or doctest,
|
1294 | 1318 | # explicitly invoke their test_main() function (if it exists).
|
1295 | 1319 | indirect_test = getattr(the_module, "test_main", None)
|
1296 |
| - if indirect_test is not None: |
1297 |
| - indirect_test() |
1298 | 1320 | if huntrleaks:
|
1299 | 1321 | refleak = dash_R(the_module, test, indirect_test,
|
1300 | 1322 | huntrleaks)
|
| 1323 | + else: |
| 1324 | + if indirect_test is not None: |
| 1325 | + indirect_test() |
1301 | 1326 | test_time = time.time() - start_time
|
1302 | 1327 | post_test_cleanup()
|
1303 | 1328 | finally:
|
|
0 commit comments