@@ -478,33 +478,46 @@ def _graalpytest_driver():
478
478
479
479
480
480
def _graalpytest_root ():
481
- return os .path .join (SUITE . dir , "graalpython" , " com.oracle.graal.python.test" , "src " , "tests" )
481
+ return os .path .join (mx . dependency ( " com.oracle.graal.python.test"). get_output_root () , "bin " , "tests" )
482
482
483
483
484
484
def _hpy_test_root ():
485
485
return os .path .join (_get_core_home (), "modules" , "hpy" , "test" )
486
486
487
487
488
- def run_python_unittests (python_binary , args = None , paths = None , aot_compatible = True , exclude = None , env = None ):
489
- args = args or []
490
- args = ["--experimental-options=true" ,
491
- "--python.CatchAllExceptions=true" ] + args
492
- exclude = exclude or []
493
- paths = paths or [_graalpytest_root ()]
494
- if env is None :
495
- env = os .environ .copy ()
488
+ def graalpytest (args ):
489
+ parser = ArgumentParser (prog = 'mx graalpytest' )
490
+ parser .add_argument ('--python' , type = str , action = 'store' , default = "" , help = 'Run tests with custom Python binary.' )
491
+ parser .add_argument ('-v' , "--verbose" , action = "store_true" , help = 'Verbose output.' )
492
+ parser .add_argument ('-k' , dest = "filter" , default = [], help = 'Test pattern.' )
493
+ parser .add_argument ('test' , nargs = "*" , default = [], help = 'Test file to run (specify absolute or relative; e.g. "/path/to/test_file.py" or "cpyext/test_object.py") ' )
494
+ args , unknown_args = parser .parse_known_args (args )
495
+
496
+ # ensure that the test distribution is up-to-date
497
+ mx .command_function ("build" )(["--dep" , "com.oracle.graal.python.test" ])
498
+
499
+ testfiles = _list_graalpython_unittests (args .test )
500
+ # we assume that unknown args are polyglot arguments and just prepend them to the test driver
501
+ cmd_args = unknown_args + [_graalpytest_driver ()]
502
+ if args .verbose :
503
+ cmd_args += ["-v" ]
504
+ cmd_args += testfiles
505
+ if args .filter :
506
+ cmd_args += ["-k" , args .filter ]
507
+ if args .python :
508
+ return mx .run ([args .python ] + cmd_args , nonZeroIsFatal = True )
509
+ else :
510
+ return do_run_python (cmd_args )
496
511
497
- # list of excluded tests
498
- if aot_compatible :
499
- exclude += AOT_INCOMPATIBLE_TESTS
500
512
513
+ def _list_graalpython_unittests (paths = None , exclude = []):
514
+ paths = paths or [_graalpytest_root ()]
501
515
def is_included (path ):
502
516
if path .endswith (".py" ):
503
517
basename = os .path .basename (path )
504
518
return basename .startswith ("test_" ) and basename not in exclude
505
519
return False
506
520
507
- # list all 1st-level tests and exclude the SVM-incompatible ones
508
521
testfiles = []
509
522
for path in paths :
510
523
if not os .path .exists (path ):
@@ -519,6 +532,26 @@ def is_included(path):
519
532
for testfile in glob .glob (os .path .join (path , "test_*.py" )):
520
533
if is_included (testfile ):
521
534
testfiles .append (testfile )
535
+ return testfiles
536
+
537
+
538
+ def run_python_unittests (python_binary , args = None , paths = None , aot_compatible = True , exclude = None , env = None ):
539
+ # ensure that the test distribution is up-to-date
540
+ mx .command_function ("build" )(["--dep" , "com.oracle.graal.python.test" ])
541
+
542
+ args = args or []
543
+ args = ["--experimental-options=true" ,
544
+ "--python.CatchAllExceptions=true" ] + args
545
+ exclude = exclude or []
546
+ if env is None :
547
+ env = os .environ .copy ()
548
+
549
+ # list of excluded tests
550
+ if aot_compatible :
551
+ exclude += AOT_INCOMPATIBLE_TESTS
552
+
553
+ # list all 1st-level tests and exclude the SVM-incompatible ones
554
+ testfiles = _list_graalpython_unittests (paths , exclude )
522
555
523
556
args += [_graalpytest_driver (), "-v" ]
524
557
@@ -1903,6 +1936,7 @@ def import_files(from_dir, to_dir):
1903
1936
'python-src-import' : [import_python_sources , '' ],
1904
1937
'python-coverage' : [python_coverage , '' ],
1905
1938
'punittest' : [punittest , '' ],
1939
+ 'graalpytest' : [graalpytest , '[-h] [-v] [--python PYTHON] [-k TEST_PATTERN] [TESTS]' ],
1906
1940
'clean' : [python_clean , '' ],
1907
1941
'python-update-hpy-import' : [update_hpy_import_cmd , '[--no-pull] PATH_TO_HPY' ],
1908
1942
})
0 commit comments