forked from tskit-dev/msprime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stress_lowlevel.py
81 lines (71 loc) · 2.53 KB
/
stress_lowlevel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Code to stress the low-level API as much as possible to expose
any memory leaks or error handling issues.
"""
from __future__ import print_function
from __future__ import division
import argparse
import unittest
import random
import resource
import os
import sys
import time
import logging
import tests.test_demography as test_demography
import tests.test_highlevel as test_highlevel
import tests.test_lowlevel as test_lowlevel
import tests.test_dict_encoding as test_dict_encoding
def main():
modules = {
"demography": test_demography,
"highlevel": test_highlevel,
"lowlevel": test_lowlevel,
"dict_encoding": test_dict_encoding,
}
parser = argparse.ArgumentParser(
description="Run tests in a loop to stress low-level interface")
parser.add_argument(
"-m", "--module", help="Run tests only on this module",
choices=list(modules.keys()))
args = parser.parse_args()
test_modules = list(modules.values())
if args.module is not None:
test_modules = [modules[args.module]]
# Need to do this to silence the errors from the file_format tests.
logging.basicConfig(level=logging.ERROR)
print("iter\ttests\terr\tfail\tskip\tRSS\tmin\tmax\tmax@iter")
max_rss = 0
max_rss_iter = 0
min_rss = 1e100
iteration = 0
last_print = time.time()
devnull = open(os.devnull, 'w')
while True:
# We don't want any random variation in the amount of memory
# used from test-to-test.
random.seed(1)
testloader = unittest.TestLoader()
suite = testloader.loadTestsFromModule(test_modules[0])
for mod in test_modules[1:]:
suite.addTests(testloader.loadTestsFromModule(mod))
runner = unittest.TextTestRunner(verbosity=0, stream=devnull)
result = runner.run(suite)
rusage = resource.getrusage(resource.RUSAGE_SELF)
if max_rss < rusage.ru_maxrss:
max_rss = rusage.ru_maxrss
max_rss_iter = iteration
if min_rss > rusage.ru_maxrss:
min_rss = rusage.ru_maxrss
# We don't want to flood stdout, so we rate-limit to 1 per second.
if time.time() - last_print > 1:
print(
iteration, result.testsRun, len(result.failures),
len(result.errors), len(result.skipped),
rusage.ru_maxrss, min_rss, max_rss, max_rss_iter,
sep="\t", end="\r")
last_print = time.time()
sys.stdout.flush()
iteration += 1
if __name__ == "__main__":
main()