Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2676)

Side by Side Diff: Lib/test/regrtest.py

Issue 12073: regrtest: use faulthandler to dump the tracebacks on SIGUSR1
Patch Set: Created 1 year, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 """ 3 """
4 Usage: 4 Usage:
5 5
6 python -m test [options] [test_name1 [test_name2 ...]] 6 python -m test [options] [test_name1 [test_name2 ...]]
7 python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]] 7 python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]]
8 8
9 9
10 If no arguments or options are provided, finds all files matching 10 If no arguments or options are provided, finds all files matching
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 subprocess Run all tests for the subprocess module. 153 subprocess Run all tests for the subprocess module.
154 154
155 urlfetch - It is okay to download files required on testing. 155 urlfetch - It is okay to download files required on testing.
156 156
157 gui - Run tests that require a running GUI. 157 gui - Run tests that require a running GUI.
158 158
159 To enable all resources except one, use '-uall,-<resource>'. For 159 To enable all resources except one, use '-uall,-<resource>'. For
160 example, to run all the tests except for the gui tests, give the 160 example, to run all the tests except for the gui tests, give the
161 option '-uall,-gui'. 161 option '-uall,-gui'.
162 """ 162 """
163 USAGE_SIGUSR1 = """
164 You can send a SIGUSR1 signal to display the tracebacks of the current threads.
165 Note that sending a signal may interrupt a system call in progress and thus
166 interfere with the tests, so only do it if a test hangs and you want to know
167 where.
168 """
163 169
164 import builtins 170 import builtins
171 import errno
165 import faulthandler 172 import faulthandler
166 import getopt 173 import getopt
174 import io
167 import json 175 import json
168 import os 176 import os
169 import random 177 import random
170 import re 178 import re
171 import io 179 import signal
172 import sys 180 import sys
173 import time 181 import time
174 import errno
175 import traceback 182 import traceback
183 import unittest
176 import warnings 184 import warnings
177 import unittest
178 from inspect import isabstract 185 from inspect import isabstract
179 import tempfile 186 import tempfile
180 import platform 187 import platform
181 import sysconfig 188 import sysconfig
182 import logging 189 import logging
183 190
184 191
185 # Some times __path__ and __file__ are not absolute (e.g. while running from 192 # Some times __path__ and __file__ are not absolute (e.g. while running from
186 # Lib/) and, if we change the CWD to run the tests in a temporary dir, some 193 # Lib/) and, if we change the CWD to run the tests in a temporary dir, some
187 # imports might fail. This affects only the modules imported before os.chdir(). 194 # imports might fail. This affects only the modules imported before os.chdir().
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 268
262 The other default arguments (verbose, quiet, exclude, 269 The other default arguments (verbose, quiet, exclude,
263 single, randomize, findleaks, use_resources, trace, coverdir, 270 single, randomize, findleaks, use_resources, trace, coverdir,
264 print_slow, and random_seed) allow programmers calling main() 271 print_slow, and random_seed) allow programmers calling main()
265 directly to set the values that would normally be set by flags 272 directly to set the values that would normally be set by flags
266 on the command line. 273 on the command line.
267 """ 274 """
268 275
269 # Display the Python traceback fatal errors (e.g. segfault) 276 # Display the Python traceback fatal errors (e.g. segfault)
270 faulthandler.enable(all_threads=True) 277 faulthandler.enable(all_threads=True)
278 if hasattr(signal, 'SIGUSR1'):
279 faulthandler.register(signal.SIGUSR1)
271 280
272 if hasattr(faulthandler, 'dump_tracebacks_later'): 281 if hasattr(faulthandler, 'dump_tracebacks_later'):
273 timeout = 60*60 282 timeout = 60*60
274 else: 283 else:
275 timeout = None 284 timeout = None
276 285
277 replace_stdout() 286 replace_stdout()
278 287
279 support.record_original_stdout(sys.stdout) 288 support.record_original_stdout(sys.stdout)
280 try: 289 try:
281 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:' , 290 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:' ,
282 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', 291 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
283 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', 292 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
284 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 293 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
285 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 294 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
286 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 295 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
287 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait']) 296 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait'])
288 except getopt.error as msg: 297 except getopt.error as msg:
289 usage(msg) 298 usage(msg)
290 299
291 # Defaults 300 # Defaults
292 if random_seed is None: 301 if random_seed is None:
293 random_seed = random.randrange(10000000) 302 random_seed = random.randrange(10000000)
294 if use_resources is None: 303 if use_resources is None:
295 use_resources = [] 304 use_resources = []
296 debug = False 305 debug = False
297 start = None 306 start = None
298 for o, a in opts: 307 for o, a in opts:
299 if o in ('-h', '--help'): 308 if o in ('-h', '--help'):
300 print(__doc__) 309 usage = __doc__
310 if hasattr(signal, 'SIGUSR1'):
311 usage += USAGE_SIGUSR1
312 print(usage)
301 return 313 return
302 elif o in ('-v', '--verbose'): 314 elif o in ('-v', '--verbose'):
303 verbose += 1 315 verbose += 1
304 elif o in ('-w', '--verbose2'): 316 elif o in ('-w', '--verbose2'):
305 verbose2 = True 317 verbose2 = True
306 elif o in ('-d', '--debug'): 318 elif o in ('-d', '--debug'):
307 debug = True 319 debug = True
308 elif o in ('-W', '--verbose3'): 320 elif o in ('-W', '--verbose3'):
309 verbose3 = True 321 verbose3 = True
310 elif o in ('-q', '--quiet'): 322 elif o in ('-q', '--quiet'):
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 assert __file__ == os.path.abspath(sys.argv[0]) 1626 assert __file__ == os.path.abspath(sys.argv[0])
1615 1627
1616 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR) 1628 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR)
1617 1629
1618 # Run the tests in a context manager that temporary changes the CWD to a 1630 # Run the tests in a context manager that temporary changes the CWD to a
1619 # temporary and writable directory. If it's not possible to create or 1631 # temporary and writable directory. If it's not possible to create or
1620 # change the CWD, the original CWD will be used. The original CWD is 1632 # change the CWD, the original CWD will be used. The original CWD is
1621 # available from support.SAVEDCWD. 1633 # available from support.SAVEDCWD.
1622 with support.temp_cwd(TESTCWD, quiet=True): 1634 with support.temp_cwd(TESTCWD, quiet=True):
1623 main() 1635 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7