18ec9d54bSJed Brown#!/usr/bin/env python3 21b16049aSZach Atkinsfrom junit_common import * 38ec9d54bSJed Brown 43d94f746Srezgarshakeri 51b16049aSZach Atkinsdef create_argparser() -> argparse.ArgumentParser: 61b16049aSZach Atkins """Creates argument parser to read command line arguments 71b16049aSZach Atkins 81b16049aSZach Atkins Returns: 91b16049aSZach Atkins argparse.ArgumentParser: Created `ArgumentParser` 101b16049aSZach Atkins """ 111b16049aSZach Atkins parser = argparse.ArgumentParser('Test runner with JUnit and TAP output') 12*2fee3251SSebastian Grimberg parser.add_argument( 13*2fee3251SSebastian Grimberg '-c', 14*2fee3251SSebastian Grimberg '--ceed-backends', 15*2fee3251SSebastian Grimberg type=str, 16*2fee3251SSebastian Grimberg nargs='*', 17*2fee3251SSebastian Grimberg default=['/cpu/self'], 18*2fee3251SSebastian Grimberg help='libCEED backend to use with convergence tests') 19*2fee3251SSebastian Grimberg parser.add_argument( 20*2fee3251SSebastian Grimberg '-m', 21*2fee3251SSebastian Grimberg '--mode', 22*2fee3251SSebastian Grimberg type=RunMode, 23*2fee3251SSebastian Grimberg action=CaseInsensitiveEnumAction, 24*2fee3251SSebastian Grimberg help='Output mode, junit or tap', 25*2fee3251SSebastian Grimberg default=RunMode.JUNIT) 261b16049aSZach Atkins parser.add_argument('-n', '--nproc', type=int, default=1, help='number of MPI processes') 271b16049aSZach Atkins parser.add_argument('-o', '--output', type=Optional[Path], default=None, help='Output file to write test') 281b16049aSZach Atkins parser.add_argument('-b', '--junit-batch', type=str, default='', help='Name of JUnit batch for output file') 291b16049aSZach Atkins parser.add_argument('test', help='Test executable', nargs='?') 301b16049aSZach Atkins 311b16049aSZach Atkins return parser 328ec9d54bSJed Brown 333d94f746Srezgarshakeri 341b16049aSZach Atkins# Necessary functions for running tests 351b16049aSZach Atkinsclass CeedSuiteSpec(SuiteSpec): 361b16049aSZach Atkins def get_source_path(self, test: str) -> Path: 371b16049aSZach Atkins """Compute path to test source file 388ec9d54bSJed Brown 391b16049aSZach Atkins Args: 401b16049aSZach Atkins test (str): Name of test 413d94f746Srezgarshakeri 421b16049aSZach Atkins Returns: 431b16049aSZach Atkins Path: Path to source file 441b16049aSZach Atkins """ 45372821a4SZach Atkins prefix, rest = test.split('-', 1) 46372821a4SZach Atkins if prefix == 'petsc': 47372821a4SZach Atkins return (Path('examples') / 'petsc' / rest).with_suffix('.c') 48372821a4SZach Atkins elif prefix == 'mfem': 49372821a4SZach Atkins return (Path('examples') / 'mfem' / rest).with_suffix('.cpp') 50372821a4SZach Atkins elif prefix == 'nek': 51372821a4SZach Atkins return (Path('examples') / 'nek' / 'bps' / rest).with_suffix('.usr') 52372821a4SZach Atkins elif prefix == 'fluids': 53372821a4SZach Atkins return (Path('examples') / 'fluids' / rest).with_suffix('.c') 54372821a4SZach Atkins elif prefix == 'solids': 55372821a4SZach Atkins return (Path('examples') / 'solids' / rest).with_suffix('.c') 56372821a4SZach Atkins elif test.startswith('ex'): 57372821a4SZach Atkins return (Path('examples') / 'ceed' / test).with_suffix('.c') 58372821a4SZach Atkins elif test.endswith('-f'): 59372821a4SZach Atkins return (Path('tests') / test).with_suffix('.f90') 60372821a4SZach Atkins else: 61372821a4SZach Atkins return (Path('tests') / test).with_suffix('.c') 62372821a4SZach Atkins 631b16049aSZach Atkins # get path to executable 641b16049aSZach Atkins def get_run_path(self, test: str) -> Path: 651b16049aSZach Atkins """Compute path to built test executable file 66372821a4SZach Atkins 671b16049aSZach Atkins Args: 681b16049aSZach Atkins test (str): Name of test 69bdb0bdbbSJed Brown 701b16049aSZach Atkins Returns: 711b16049aSZach Atkins Path: Path to test executable 721b16049aSZach Atkins """ 731b16049aSZach Atkins return Path('build') / test 743d94f746Srezgarshakeri 751b16049aSZach Atkins def get_output_path(self, test: str, output_file: str) -> Path: 761b16049aSZach Atkins """Compute path to expected output file 77b974e86eSJed Brown 781b16049aSZach Atkins Args: 791b16049aSZach Atkins test (str): Name of test 801b16049aSZach Atkins output_file (str): File name of output file 813d94f746Srezgarshakeri 821b16049aSZach Atkins Returns: 831b16049aSZach Atkins Path: Path to expected output file 841b16049aSZach Atkins """ 851b16049aSZach Atkins return Path('tests') / 'output' / output_file 86b974e86eSJed Brown 871b16049aSZach Atkins def check_pre_skip(self, test: str, spec: TestSpec, resource: str, nproc: int) -> Optional[str]: 881b16049aSZach Atkins """Check if a test case should be skipped prior to running, returning the reason for skipping 893d94f746Srezgarshakeri 901b16049aSZach Atkins Args: 911b16049aSZach Atkins test (str): Name of test 921b16049aSZach Atkins spec (TestSpec): Test case specification 931b16049aSZach Atkins resource (str): libCEED backend 941b16049aSZach Atkins nproc (int): Number of MPI processes to use when running test case 95288c0443SJeremy L Thompson 961b16049aSZach Atkins Returns: 971b16049aSZach Atkins Optional[str]: Skip reason, or `None` if test case should not be skipped 981b16049aSZach Atkins """ 99*2fee3251SSebastian Grimberg if contains_any(resource, ['occa']) and startswith_any( 100*2fee3251SSebastian Grimberg test, ['t4', 't5', 'ex', 'mfem', 'nek', 'petsc', 'fluids', 'solids']): 1011b16049aSZach Atkins return 'OCCA mode not supported' 1021b16049aSZach Atkins if test.startswith('t318') and contains_any(resource, ['/gpu/cuda/ref']): 1031b16049aSZach Atkins return 'CUDA ref backend not supported' 1041b16049aSZach Atkins if test.startswith('t506') and contains_any(resource, ['/gpu/cuda/shared']): 1051b16049aSZach Atkins return 'CUDA shared backend not supported' 106f85e4a7bSJeremy L Thompson for condition in spec.only: 107f85e4a7bSJeremy L Thompson if (condition == 'cpu') and ('gpu' in resource): 108f85e4a7bSJeremy L Thompson return 'CPU only test with GPU backend' 1094a2fcf2fSJeremy L Thompson 1101b16049aSZach Atkins def check_post_skip(self, test: str, spec: TestSpec, resource: str, stderr: str) -> Optional[str]: 1111b16049aSZach Atkins """Check if a test case should be allowed to fail, based on its stderr output 112b974e86eSJed Brown 1131b16049aSZach Atkins Args: 1141b16049aSZach Atkins test (str): Name of test 1151b16049aSZach Atkins spec (TestSpec): Test case specification 1161b16049aSZach Atkins resource (str): libCEED backend 1171b16049aSZach Atkins stderr (str): Standard error output from test case execution 1188ec9d54bSJed Brown 1191b16049aSZach Atkins Returns: 1201b16049aSZach Atkins Optional[str]: Skip reason, or `None` if unexpeced error 1211b16049aSZach Atkins """ 1221b16049aSZach Atkins if 'OCCA backend failed to use' in stderr: 1231b16049aSZach Atkins return f'OCCA mode not supported' 1241b16049aSZach Atkins elif 'Backend does not implement' in stderr: 1251b16049aSZach Atkins return f'Backend does not implement' 1261b16049aSZach Atkins elif 'Can only provide HOST memory for this backend' in stderr: 1271b16049aSZach Atkins return f'Device memory not supported' 128b0976d5aSZach Atkins elif 'Can only set HOST memory for this backend' in stderr: 129b0976d5aSZach Atkins return f'Device memory not supported' 1301b16049aSZach Atkins elif 'Test not implemented in single precision' in stderr: 1311b16049aSZach Atkins return f'Test not implemented in single precision' 1321b16049aSZach Atkins elif 'No SYCL devices of the requested type are available' in stderr: 1331b16049aSZach Atkins return f'SYCL device type not available' 1341b16049aSZach Atkins return None 135bdb0bdbbSJed Brown 1361b16049aSZach Atkins def check_required_failure(self, test: str, spec: TestSpec, resource: str, stderr: str) -> tuple[str, bool]: 1371b16049aSZach Atkins """Check whether a test case is expected to fail and if it failed expectedly 138bdb0bdbbSJed Brown 1391b16049aSZach Atkins Args: 1401b16049aSZach Atkins test (str): Name of test 1411b16049aSZach Atkins spec (TestSpec): Test case specification 1421b16049aSZach Atkins resource (str): libCEED backend 1431b16049aSZach Atkins stderr (str): Standard error output from test case execution 144bdb0bdbbSJed Brown 1451b16049aSZach Atkins Returns: 1461b16049aSZach Atkins tuple[str, bool]: Tuple of the expected failure string and whether it was present in `stderr` 1471b16049aSZach Atkins """ 1481b16049aSZach Atkins test_id: str = test[:4] 1491b16049aSZach Atkins fail_str: str = '' 1501b16049aSZach Atkins if test_id in ['t006', 't007']: 1511b16049aSZach Atkins fail_str = 'No suitable backend:' 1521b16049aSZach Atkins elif test_id in ['t008']: 1531b16049aSZach Atkins fail_str = 'Available backend resources:' 1541b16049aSZach Atkins elif test_id in ['t110', 't111', 't112', 't113', 't114']: 1551b16049aSZach Atkins fail_str = 'Cannot grant CeedVector array access' 1561b16049aSZach Atkins elif test_id in ['t115']: 1571b16049aSZach Atkins fail_str = 'Cannot grant CeedVector read-only array access, the access lock is already in use' 1581b16049aSZach Atkins elif test_id in ['t116']: 1591b16049aSZach Atkins fail_str = 'Cannot destroy CeedVector, the writable access lock is in use' 1601b16049aSZach Atkins elif test_id in ['t117']: 1611b16049aSZach Atkins fail_str = 'Cannot restore CeedVector array access, access was not granted' 1621b16049aSZach Atkins elif test_id in ['t118']: 1631b16049aSZach Atkins fail_str = 'Cannot sync CeedVector, the access lock is already in use' 1641b16049aSZach Atkins elif test_id in ['t215']: 1651b16049aSZach Atkins fail_str = 'Cannot destroy CeedElemRestriction, a process has read access to the offset data' 1661b16049aSZach Atkins elif test_id in ['t303']: 1671b16049aSZach Atkins fail_str = 'Length of input/output vectors incompatible with basis dimensions' 1681b16049aSZach Atkins elif test_id in ['t408']: 1691b16049aSZach Atkins fail_str = 'CeedQFunctionContextGetData(): Cannot grant CeedQFunctionContext data access, a process has read access' 1701b16049aSZach Atkins elif test_id in ['t409'] and contains_any(resource, ['memcheck']): 1711b16049aSZach Atkins fail_str = 'Context data changed while accessed in read-only mode' 1724a2fcf2fSJeremy L Thompson 1731b16049aSZach Atkins return fail_str, fail_str in stderr 1744a2fcf2fSJeremy L Thompson 1751b16049aSZach Atkins def check_allowed_stdout(self, test: str) -> bool: 1761b16049aSZach Atkins """Check whether a test is allowed to print console output 1774a2fcf2fSJeremy L Thompson 1781b16049aSZach Atkins Args: 1791b16049aSZach Atkins test (str): Name of test 1801b16049aSZach Atkins 1811b16049aSZach Atkins Returns: 1821b16049aSZach Atkins bool: True if the test is allowed to print console output 1831b16049aSZach Atkins """ 1841b16049aSZach Atkins return test[:4] in ['t003'] 1851b16049aSZach Atkins 1868ec9d54bSJed Brown 1878ec9d54bSJed Brownif __name__ == '__main__': 1881b16049aSZach Atkins args = create_argparser().parse_args() 1898ec9d54bSJed Brown 1904a2fcf2fSJeremy L Thompson # run tests 1911b16049aSZach Atkins result: TestSuite = run_tests(args.test, args.ceed_backends, args.mode, args.nproc, CeedSuiteSpec()) 192add335c8SJeremy L Thompson 1931b16049aSZach Atkins # write output and check for failures 1941b16049aSZach Atkins if args.mode is RunMode.JUNIT: 1951b16049aSZach Atkins write_junit_xml(result, args.output, args.junit_batch) 1961b16049aSZach Atkins if has_failures(result): 1974d57a9fcSJed Brown sys.exit(1) 198