@@ -698,7 +698,7 @@ def is_included(path):
698698
699699
700700def run_python_unittests (python_binary , args = None , paths = None , aot_compatible = False , exclude = None , env = None ,
701- use_pytest = False , cwd = None , lock = None , out = None , err = None ):
701+ use_pytest = False , cwd = None , lock = None , out = None , err = None , nonZeroIsFatal = True ):
702702 if lock :
703703 lock .acquire ()
704704 # ensure that the test distribution is up-to-date
@@ -760,13 +760,13 @@ def graalvm_vm_arg(java_arg):
760760 # at once it generates so much data we run out of heap space
761761 for testfile in testfiles :
762762 mx .run ([python_binary , "--jvm" , agent_args ] + args + [testfile ],
763- nonZeroIsFatal = False , env = env , cwd = cwd , out = out , err = err )
763+ nonZeroIsFatal = nonZeroIsFatal , env = env , cwd = cwd , out = out , err = err )
764764 else :
765765 args += testfiles
766766 mx .logv (" " .join ([python_binary ] + args ))
767767 if lock :
768768 lock .release ()
769- return mx .run ([python_binary ] + args , nonZeroIsFatal = True , env = env , cwd = cwd , out = out , err = err )
769+ return mx .run ([python_binary ] + args , nonZeroIsFatal = nonZeroIsFatal , env = env , cwd = cwd , out = out , err = err )
770770
771771
772772def is_bash_launcher (launcher_path ):
@@ -800,20 +800,21 @@ def run_hpy_unittests(python_binary, args=None, include_native=True):
800800 threads = []
801801 lock = threading .RLock ()
802802
803- class RaisingThread (threading .Thread ):
803+ class HPyUnitTestsThread (threading .Thread ):
804804 def __init__ (self , ** tkwargs ):
805- capture = mx .LinesOutputCapture ()
806- tkwargs ["kwargs" ]["out" ] = capture
807- tkwargs ["kwargs" ]["err" ] = capture
808805 super ().__init__ (** tkwargs )
809- self .out = capture
810- self .exc = None
806+ self .out = mx . LinesOutputCapture ()
807+ self .result = None
811808
812809 def run (self ):
810+ # Note: for some reason catching BaseException is not enough to catch mx.abort,
811+ # so we use nonZeroIsFatal=False instead.
813812 try :
814- super ().run ()
815- except Exception as e : # pylint: disable=broad-except;
816- self .exc = e
813+ self .result = run_python_unittests (python_binary , args = args , paths = [_hpy_test_root ()],
814+ env = tenv , use_pytest = True , lock = lock , nonZeroIsFatal = False ,
815+ out = self .out , err = self .out )
816+ except BaseException as e : # pylint: disable=broad-except;
817+ self .result = e
817818
818819 abi_list = ['cpython' , 'universal' ]
819820 if include_native :
@@ -822,9 +823,7 @@ def run(self):
822823 for abi in abi_list :
823824 tenv = env .copy ()
824825 tenv ["TEST_HPY_ABI" ] = abi
825- thread = RaisingThread (name = abi , target = run_python_unittests , args = (python_binary , ), kwargs = {
826- "args" : args , "paths" : [_hpy_test_root ()], "env" : tenv , "use_pytest" : True , "lock" : lock ,
827- })
826+ thread = HPyUnitTestsThread (name = abi )
828827 threads .append (thread )
829828 thread .start ()
830829
@@ -835,8 +834,8 @@ def run(self):
835834 mx .logv ("## Progress (last 5 lines) of thread %r:\n %s\n " % (t .name , os .linesep .join (t .out .lines [- 5 :])))
836835 alive [i ] = t .is_alive ()
837836
838- thread_exceptions = [t .exc for t in threads ]
839- if any (thread_exceptions ):
837+ thread_errors = [t .result for t in threads if t . result != 0 ]
838+ if any (thread_errors ):
840839 for t in threads :
841840 mx .log_error ("\n \n ### Output of thread %r: \n \n %s" % (t .name , t .out ))
842841 mx .abort ("At least one HPy testing thread failed." )
0 commit comments