@@ -478,33 +478,46 @@ def _graalpytest_driver():
478478
479479
480480def _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" )
482482
483483
484484def _hpy_test_root ():
485485 return os .path .join (_get_core_home (), "modules" , "hpy" , "test" )
486486
487487
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 )
496511
497- # list of excluded tests
498- if aot_compatible :
499- exclude += AOT_INCOMPATIBLE_TESTS
500512
513+ def _list_graalpython_unittests (paths = None , exclude = []):
514+ paths = paths or [_graalpytest_root ()]
501515 def is_included (path ):
502516 if path .endswith (".py" ):
503517 basename = os .path .basename (path )
504518 return basename .startswith ("test_" ) and basename not in exclude
505519 return False
506520
507- # list all 1st-level tests and exclude the SVM-incompatible ones
508521 testfiles = []
509522 for path in paths :
510523 if not os .path .exists (path ):
@@ -519,6 +532,26 @@ def is_included(path):
519532 for testfile in glob .glob (os .path .join (path , "test_*.py" )):
520533 if is_included (testfile ):
521534 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 )
522555
523556 args += [_graalpytest_driver (), "-v" ]
524557
@@ -1903,6 +1936,7 @@ def import_files(from_dir, to_dir):
19031936 'python-src-import' : [import_python_sources , '' ],
19041937 'python-coverage' : [python_coverage , '' ],
19051938 'punittest' : [punittest , '' ],
1939+ 'graalpytest' : [graalpytest , '[-h] [-v] [--python PYTHON] [-k TEST_PATTERN] [TESTS]' ],
19061940 'clean' : [python_clean , '' ],
19071941 'python-update-hpy-import' : [update_hpy_import_cmd , '[--no-pull] PATH_TO_HPY' ],
19081942})
0 commit comments