Show More
@@ -345,6 +345,8 b' def getparser():' | |||
|
345 | 345 | help="loop tests repeatedly") |
|
346 | 346 | harness.add_argument('--random', action="store_true", |
|
347 | 347 | help='run tests in random order') |
|
348 | harness.add_argument('--order-by-runtime', action="store_true", | |
|
349 | help='run slowest tests first, according to .testtimes') | |
|
348 | 350 | harness.add_argument("-p", "--port", type=int, |
|
349 | 351 | help="port on which servers should listen" |
|
350 | 352 | " (default: $%s or %d)" % defaults['port']) |
@@ -2307,47 +2309,57 b' class TextTestRunner(unittest.TextTestRu' | |||
|
2307 | 2309 | separators=(',', ': ')) |
|
2308 | 2310 | outf.writelines(("testreport =", jsonout)) |
|
2309 | 2311 | |
|
2310 | def sorttests(testdescs, shuffle=False): | |
|
2312 | def sorttests(testdescs, previoustimes, shuffle=False): | |
|
2311 | 2313 | """Do an in-place sort of tests.""" |
|
2312 | 2314 | if shuffle: |
|
2313 | 2315 | random.shuffle(testdescs) |
|
2314 | 2316 | return |
|
2315 | 2317 | |
|
2316 | # keywords for slow tests | |
|
2317 | slow = {b'svn': 10, | |
|
2318 | b'cvs': 10, | |
|
2319 | b'hghave': 10, | |
|
2320 | b'largefiles-update': 10, | |
|
2321 | b'run-tests': 10, | |
|
2322 | b'corruption': 10, | |
|
2323 | b'race': 10, | |
|
2324 | b'i18n': 10, | |
|
2325 | b'check': 100, | |
|
2326 | b'gendoc': 100, | |
|
2327 |
|
|
|
2328 |
|
|
|
2329 | perf = {} | |
|
2330 | ||
|
2331 | def sortkey(f): | |
|
2332 | # run largest tests first, as they tend to take the longest | |
|
2333 | f = f['path'] | |
|
2334 | try: | |
|
2335 | return perf[f] | |
|
2336 | except KeyError: | |
|
2318 | if previoustimes: | |
|
2319 | def sortkey(f): | |
|
2320 | f = f['path'] | |
|
2321 | if f in previoustimes: | |
|
2322 | # Use most recent time as estimate | |
|
2323 | return -previoustimes[f][-1] | |
|
2324 | else: | |
|
2325 | # Default to a rather arbitrary value of 1 second for new tests | |
|
2326 | return -1.0 | |
|
2327 | else: | |
|
2328 | # keywords for slow tests | |
|
2329 | slow = {b'svn': 10, | |
|
2330 | b'cvs': 10, | |
|
2331 | b'hghave': 10, | |
|
2332 | b'largefiles-update': 10, | |
|
2333 | b'run-tests': 10, | |
|
2334 | b'corruption': 10, | |
|
2335 | b'race': 10, | |
|
2336 | b'i18n': 10, | |
|
2337 | b'check': 100, | |
|
2338 | b'gendoc': 100, | |
|
2339 | b'contrib-perf': 200, | |
|
2340 | } | |
|
2341 | perf = {} | |
|
2342 | ||
|
2343 | def sortkey(f): | |
|
2344 | # run largest tests first, as they tend to take the longest | |
|
2345 | f = f['path'] | |
|
2337 | 2346 | try: |
|
2338 | val = -os.stat(f).st_size | |
|
2339 |
except |
|
|
2340 | if e.errno != errno.ENOENT: | |
|
2341 |
|
|
|
2342 | perf[f] = -1e9 # file does not exist, tell early | |
|
2343 | return -1e9 | |
|
2344 | for kw, mul in slow.items(): | |
|
2345 | if kw in f: | |
|
2346 |
|
|
|
2347 | if f.endswith(b'.py'): | |
|
2348 |
|
|
|
2349 | perf[f] = val / 1000.0 | |
|
2350 | return perf[f] | |
|
2347 | return perf[f] | |
|
2348 | except KeyError: | |
|
2349 | try: | |
|
2350 | val = -os.stat(f).st_size | |
|
2351 | except OSError as e: | |
|
2352 | if e.errno != errno.ENOENT: | |
|
2353 | raise | |
|
2354 | perf[f] = -1e9 # file does not exist, tell early | |
|
2355 | return -1e9 | |
|
2356 | for kw, mul in slow.items(): | |
|
2357 | if kw in f: | |
|
2358 | val *= mul | |
|
2359 | if f.endswith(b'.py'): | |
|
2360 | val /= 10.0 | |
|
2361 | perf[f] = val / 1000.0 | |
|
2362 | return perf[f] | |
|
2351 | 2363 | |
|
2352 | 2364 | testdescs.sort(key=sortkey) |
|
2353 | 2365 | |
@@ -2418,8 +2430,6 b' class TestRunner(object):' | |||
|
2418 | 2430 | os.umask(oldmask) |
|
2419 | 2431 | |
|
2420 | 2432 | def _run(self, testdescs): |
|
2421 | sorttests(testdescs, shuffle=self.options.random) | |
|
2422 | ||
|
2423 | 2433 | self._testdir = osenvironb[b'TESTDIR'] = getattr( |
|
2424 | 2434 | os, 'getcwdb', os.getcwd)() |
|
2425 | 2435 | # assume all tests in same folder for now |
@@ -2434,6 +2444,10 b' class TestRunner(object):' | |||
|
2434 | 2444 | self._outputdir = self._testdir |
|
2435 | 2445 | if testdescs and pathname: |
|
2436 | 2446 | self._outputdir = os.path.join(self._outputdir, pathname) |
|
2447 | previoustimes = {} | |
|
2448 | if self.options.order_by_runtime: | |
|
2449 | previoustimes = dict(loadtimes(self._outputdir)) | |
|
2450 | sorttests(testdescs, previoustimes, shuffle=self.options.random) | |
|
2437 | 2451 | |
|
2438 | 2452 | if 'PYTHONHASHSEED' not in os.environ: |
|
2439 | 2453 | # use a random python hash seed all the time |
General Comments 0
You need to be logged in to leave comments.
Login now