1
- import faulthandler
2
1
import locale
3
2
import os
4
3
import platform
5
4
import random
6
5
import re
7
6
import sys
8
- import sysconfig
9
- import tempfile
10
7
import time
11
8
import unittest
9
+
10
+ from test import support
11
+ from test .support import os_helper
12
+
12
13
from test .libregrtest .cmdline import _parse_args , Namespace
13
14
from test .libregrtest .logger import Logger
14
15
from test .libregrtest .runtest import (
15
16
findtests , split_test_packages , run_single_test , abs_module_name ,
16
17
PROGRESS_MIN_TIME , State , RunTests , HuntRefleak ,
17
- FilterTuple , TestList , StrPath , StrJSON , TestName )
18
+ FilterTuple , TestList , StrJSON , TestName )
18
19
from test .libregrtest .setup import setup_tests , setup_test_dir
19
20
from test .libregrtest .pgo import setup_pgo_tests
20
21
from test .libregrtest .results import TestResults
21
- from test .libregrtest .utils import (strip_py_suffix , count , format_duration ,
22
- printlist , get_build_info )
23
- from test import support
24
- from test .support import os_helper
25
- from test .support import threading_helper
26
-
27
-
28
- # bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()).
29
- # Used to protect against threading._shutdown() hang.
30
- # Must be smaller than buildbot "1200 seconds without output" limit.
31
- EXIT_TIMEOUT = 120.0
22
+ from test .libregrtest .utils import (
23
+ strip_py_suffix , count , format_duration , StrPath ,
24
+ printlist , get_build_info , get_temp_dir , get_work_dir , exit_timeout )
32
25
33
26
34
27
class Regrtest :
@@ -104,7 +97,9 @@ def __init__(self, ns: Namespace):
104
97
self .verbose : bool = ns .verbose
105
98
self .quiet : bool = ns .quiet
106
99
if ns .huntrleaks :
107
- self .hunt_refleak : HuntRefleak = HuntRefleak (* ns .huntrleaks )
100
+ warmups , runs , filename = ns .huntrleaks
101
+ filename = os .path .abspath (filename )
102
+ self .hunt_refleak : HuntRefleak = HuntRefleak (warmups , runs , filename )
108
103
else :
109
104
self .hunt_refleak = None
110
105
self .test_dir : StrPath | None = ns .testdir
@@ -454,64 +449,6 @@ def display_summary(self):
454
449
state = self .get_state ()
455
450
print (f"Result: { state } " )
456
451
457
- @staticmethod
458
- def fix_umask ():
459
- if support .is_emscripten :
460
- # Emscripten has default umask 0o777, which breaks some tests.
461
- # see https://github.com/emscripten-core/emscripten/issues/17269
462
- old_mask = os .umask (0 )
463
- if old_mask == 0o777 :
464
- os .umask (0o027 )
465
- else :
466
- os .umask (old_mask )
467
-
468
- @staticmethod
469
- def select_temp_dir (tmp_dir ):
470
- if tmp_dir :
471
- tmp_dir = os .path .expanduser (tmp_dir )
472
- else :
473
- # When tests are run from the Python build directory, it is best practice
474
- # to keep the test files in a subfolder. This eases the cleanup of leftover
475
- # files using the "make distclean" command.
476
- if sysconfig .is_python_build ():
477
- tmp_dir = sysconfig .get_config_var ('abs_builddir' )
478
- if tmp_dir is None :
479
- # bpo-30284: On Windows, only srcdir is available. Using
480
- # abs_builddir mostly matters on UNIX when building Python
481
- # out of the source tree, especially when the source tree
482
- # is read only.
483
- tmp_dir = sysconfig .get_config_var ('srcdir' )
484
- tmp_dir = os .path .join (tmp_dir , 'build' )
485
- else :
486
- tmp_dir = tempfile .gettempdir ()
487
-
488
- return os .path .abspath (tmp_dir )
489
-
490
- def is_worker (self ):
491
- return (self .worker_json is not None )
492
-
493
- @staticmethod
494
- def make_temp_dir (tmp_dir : StrPath , is_worker : bool ):
495
- os .makedirs (tmp_dir , exist_ok = True )
496
-
497
- # Define a writable temp dir that will be used as cwd while running
498
- # the tests. The name of the dir includes the pid to allow parallel
499
- # testing (see the -j option).
500
- # Emscripten and WASI have stubbed getpid(), Emscripten has only
501
- # milisecond clock resolution. Use randint() instead.
502
- if sys .platform in {"emscripten" , "wasi" }:
503
- nounce = random .randint (0 , 1_000_000 )
504
- else :
505
- nounce = os .getpid ()
506
-
507
- if is_worker :
508
- work_dir = 'test_python_worker_{}' .format (nounce )
509
- else :
510
- work_dir = 'test_python_{}' .format (nounce )
511
- work_dir += os_helper .FS_NONASCII
512
- work_dir = os .path .join (tmp_dir , work_dir )
513
- return work_dir
514
-
515
452
@staticmethod
516
453
def cleanup_temp_dir (tmp_dir : StrPath ):
517
454
import glob
@@ -534,17 +471,16 @@ def main(self, tests: TestList | None = None):
534
471
535
472
strip_py_suffix (self .cmdline_args )
536
473
537
- self .tmp_dir = self .select_temp_dir (self .tmp_dir )
538
-
539
- self .fix_umask ()
474
+ self .tmp_dir = get_temp_dir (self .tmp_dir )
540
475
541
476
if self .want_cleanup :
542
477
self .cleanup_temp_dir (self .tmp_dir )
543
478
sys .exit (0 )
544
479
545
- work_dir = self .make_temp_dir (self .tmp_dir , self .is_worker ())
480
+ os .makedirs (self .tmp_dir , exist_ok = True )
481
+ work_dir = get_work_dir (parent_dir = self .tmp_dir )
546
482
547
- try :
483
+ with exit_timeout () :
548
484
# Run the tests in a context manager that temporarily changes the
549
485
# CWD to a temporary and writable directory. If it's not possible
550
486
# to create or change the CWD, the original CWD will be used.
@@ -556,13 +492,6 @@ def main(self, tests: TestList | None = None):
556
492
# processes.
557
493
558
494
self ._main ()
559
- except SystemExit as exc :
560
- # bpo-38203: Python can hang at exit in Py_Finalize(), especially
561
- # on threading._shutdown() call: put a timeout
562
- if threading_helper .can_start_thread :
563
- faulthandler .dump_traceback_later (EXIT_TIMEOUT , exit = True )
564
-
565
- sys .exit (exc .code )
566
495
567
496
def create_run_tests (self ):
568
497
return RunTests (
@@ -579,7 +508,7 @@ def create_run_tests(self):
579
508
quiet = self .quiet ,
580
509
hunt_refleak = self .hunt_refleak ,
581
510
test_dir = self .test_dir ,
582
- junit_filename = self .junit_filename ,
511
+ use_junit = ( self .junit_filename is not None ) ,
583
512
memory_limit = self .memory_limit ,
584
513
gc_threshold = self .gc_threshold ,
585
514
use_resources = self .use_resources ,
@@ -634,11 +563,6 @@ def run_tests(self) -> int:
634
563
self .fail_rerun )
635
564
636
565
def _main (self ):
637
- if self .is_worker ():
638
- from test .libregrtest .runtest_mp import worker_process
639
- worker_process (self .worker_json )
640
- return
641
-
642
566
if self .want_wait :
643
567
input ("Press any key to continue..." )
644
568
0 commit comments