18ec9d54bSJed Brown#!/usr/bin/env python3 2*1b16049aSZach Atkinsfrom junit_common import * 38ec9d54bSJed Brown 43d94f746Srezgarshakeri 5*1b16049aSZach Atkinsdef create_argparser() -> argparse.ArgumentParser: 6*1b16049aSZach Atkins """Creates argument parser to read command line arguments 7*1b16049aSZach Atkins 8*1b16049aSZach Atkins Returns: 9*1b16049aSZach Atkins argparse.ArgumentParser: Created `ArgumentParser` 10*1b16049aSZach Atkins """ 11*1b16049aSZach Atkins parser = argparse.ArgumentParser('Test runner with JUnit and TAP output') 12*1b16049aSZach Atkins parser.add_argument('-c', '--ceed-backends', type=str, nargs='*', default=['/cpu/self'], help='libCEED backend to use with convergence tests') 13*1b16049aSZach Atkins parser.add_argument('-m', '--mode', type=RunMode, action=CaseInsensitiveEnumAction, help='Output mode, junit or tap', default=RunMode.JUNIT) 14*1b16049aSZach Atkins parser.add_argument('-n', '--nproc', type=int, default=1, help='number of MPI processes') 15*1b16049aSZach Atkins parser.add_argument('-o', '--output', type=Optional[Path], default=None, help='Output file to write test') 16*1b16049aSZach Atkins parser.add_argument('-b', '--junit-batch', type=str, default='', help='Name of JUnit batch for output file') 17*1b16049aSZach Atkins parser.add_argument('test', help='Test executable', nargs='?') 18*1b16049aSZach Atkins 19*1b16049aSZach Atkins return parser 208ec9d54bSJed Brown 213d94f746Srezgarshakeri 22*1b16049aSZach Atkins# Necessary functions for running tests 23*1b16049aSZach Atkinsclass CeedSuiteSpec(SuiteSpec): 24*1b16049aSZach Atkins def get_source_path(self, test: str) -> Path: 25*1b16049aSZach Atkins """Compute path to test source file 268ec9d54bSJed Brown 27*1b16049aSZach Atkins Args: 28*1b16049aSZach Atkins test (str): Name of test 293d94f746Srezgarshakeri 30*1b16049aSZach Atkins Returns: 31*1b16049aSZach Atkins Path: Path to source file 32*1b16049aSZach Atkins """ 33372821a4SZach Atkins prefix, rest = test.split('-', 1) 34372821a4SZach Atkins if prefix == 'petsc': 35372821a4SZach Atkins return (Path('examples') / 'petsc' / rest).with_suffix('.c') 36372821a4SZach Atkins elif prefix == 'mfem': 37372821a4SZach Atkins return (Path('examples') / 'mfem' / rest).with_suffix('.cpp') 38372821a4SZach Atkins elif prefix == 'nek': 39372821a4SZach Atkins return (Path('examples') / 'nek' / 'bps' / rest).with_suffix('.usr') 40372821a4SZach Atkins elif prefix == 'fluids': 41372821a4SZach Atkins return (Path('examples') / 'fluids' / rest).with_suffix('.c') 42372821a4SZach Atkins elif prefix == 'solids': 43372821a4SZach Atkins return (Path('examples') / 'solids' / rest).with_suffix('.c') 44372821a4SZach Atkins elif test.startswith('ex'): 45372821a4SZach Atkins return (Path('examples') / 'ceed' / test).with_suffix('.c') 46372821a4SZach Atkins elif test.endswith('-f'): 47372821a4SZach Atkins return (Path('tests') / test).with_suffix('.f90') 48372821a4SZach Atkins else: 49372821a4SZach Atkins return (Path('tests') / test).with_suffix('.c') 50372821a4SZach Atkins 51*1b16049aSZach Atkins # get path to executable 52*1b16049aSZach Atkins def get_run_path(self, test: str) -> Path: 53*1b16049aSZach Atkins """Compute path to built test executable file 54372821a4SZach Atkins 55*1b16049aSZach Atkins Args: 56*1b16049aSZach Atkins test (str): Name of test 57bdb0bdbbSJed Brown 58*1b16049aSZach Atkins Returns: 59*1b16049aSZach Atkins Path: Path to test executable 60*1b16049aSZach Atkins """ 61*1b16049aSZach Atkins return Path('build') / test 623d94f746Srezgarshakeri 63*1b16049aSZach Atkins def get_output_path(self, test: str, output_file: str) -> Path: 64*1b16049aSZach Atkins """Compute path to expected output file 65b974e86eSJed Brown 66*1b16049aSZach Atkins Args: 67*1b16049aSZach Atkins test (str): Name of test 68*1b16049aSZach Atkins output_file (str): File name of output file 693d94f746Srezgarshakeri 70*1b16049aSZach Atkins Returns: 71*1b16049aSZach Atkins Path: Path to expected output file 72*1b16049aSZach Atkins """ 73*1b16049aSZach Atkins return Path('tests') / 'output' / output_file 74b974e86eSJed Brown 75*1b16049aSZach Atkins def check_pre_skip(self, test: str, spec: TestSpec, resource: str, nproc: int) -> Optional[str]: 76*1b16049aSZach Atkins """Check if a test case should be skipped prior to running, returning the reason for skipping 773d94f746Srezgarshakeri 78*1b16049aSZach Atkins Args: 79*1b16049aSZach Atkins test (str): Name of test 80*1b16049aSZach Atkins spec (TestSpec): Test case specification 81*1b16049aSZach Atkins resource (str): libCEED backend 82*1b16049aSZach Atkins nproc (int): Number of MPI processes to use when running test case 83288c0443SJeremy L Thompson 84*1b16049aSZach Atkins Returns: 85*1b16049aSZach Atkins Optional[str]: Skip reason, or `None` if test case should not be skipped 86*1b16049aSZach Atkins """ 87*1b16049aSZach Atkins if contains_any(resource, ['occa']) and startswith_any(test, ['t4', 't5', 'ex', 'mfem', 'nek', 'petsc', 'fluids', 'solids']): 88*1b16049aSZach Atkins return 'OCCA mode not supported' 89*1b16049aSZach Atkins if test.startswith('t318') and contains_any(resource, ['/gpu/cuda/ref']): 90*1b16049aSZach Atkins return 'CUDA ref backend not supported' 91*1b16049aSZach Atkins if test.startswith('t506') and contains_any(resource, ['/gpu/cuda/shared']): 92*1b16049aSZach Atkins return 'CUDA shared backend not supported' 934a2fcf2fSJeremy L Thompson 94*1b16049aSZach Atkins def check_post_skip(self, test: str, spec: TestSpec, resource: str, stderr: str) -> Optional[str]: 95*1b16049aSZach Atkins """Check if a test case should be allowed to fail, based on its stderr output 96b974e86eSJed Brown 97*1b16049aSZach Atkins Args: 98*1b16049aSZach Atkins test (str): Name of test 99*1b16049aSZach Atkins spec (TestSpec): Test case specification 100*1b16049aSZach Atkins resource (str): libCEED backend 101*1b16049aSZach Atkins stderr (str): Standard error output from test case execution 1028ec9d54bSJed Brown 103*1b16049aSZach Atkins Returns: 104*1b16049aSZach Atkins Optional[str]: Skip reason, or `None` if unexpeced error 105*1b16049aSZach Atkins """ 106*1b16049aSZach Atkins if 'OCCA backend failed to use' in stderr: 107*1b16049aSZach Atkins return f'OCCA mode not supported' 108*1b16049aSZach Atkins elif 'Backend does not implement' in stderr: 109*1b16049aSZach Atkins return f'Backend does not implement' 110*1b16049aSZach Atkins elif 'Can only provide HOST memory for this backend' in stderr: 111*1b16049aSZach Atkins return f'Device memory not supported' 112*1b16049aSZach Atkins elif 'Test not implemented in single precision' in stderr: 113*1b16049aSZach Atkins return f'Test not implemented in single precision' 114*1b16049aSZach Atkins elif 'No SYCL devices of the requested type are available' in stderr: 115*1b16049aSZach Atkins return f'SYCL device type not available' 116*1b16049aSZach Atkins return None 117bdb0bdbbSJed Brown 118*1b16049aSZach Atkins def check_required_failure(self, test: str, spec: TestSpec, resource: str, stderr: str) -> tuple[str, bool]: 119*1b16049aSZach Atkins """Check whether a test case is expected to fail and if it failed expectedly 120bdb0bdbbSJed Brown 121*1b16049aSZach Atkins Args: 122*1b16049aSZach Atkins test (str): Name of test 123*1b16049aSZach Atkins spec (TestSpec): Test case specification 124*1b16049aSZach Atkins resource (str): libCEED backend 125*1b16049aSZach Atkins stderr (str): Standard error output from test case execution 126bdb0bdbbSJed Brown 127*1b16049aSZach Atkins Returns: 128*1b16049aSZach Atkins tuple[str, bool]: Tuple of the expected failure string and whether it was present in `stderr` 129*1b16049aSZach Atkins """ 130*1b16049aSZach Atkins test_id: str = test[:4] 131*1b16049aSZach Atkins fail_str: str = '' 132*1b16049aSZach Atkins if test_id in ['t006', 't007']: 133*1b16049aSZach Atkins fail_str = 'No suitable backend:' 134*1b16049aSZach Atkins elif test_id in ['t008']: 135*1b16049aSZach Atkins fail_str = 'Available backend resources:' 136*1b16049aSZach Atkins elif test_id in ['t110', 't111', 't112', 't113', 't114']: 137*1b16049aSZach Atkins fail_str = 'Cannot grant CeedVector array access' 138*1b16049aSZach Atkins elif test_id in ['t115']: 139*1b16049aSZach Atkins fail_str = 'Cannot grant CeedVector read-only array access, the access lock is already in use' 140*1b16049aSZach Atkins elif test_id in ['t116']: 141*1b16049aSZach Atkins fail_str = 'Cannot destroy CeedVector, the writable access lock is in use' 142*1b16049aSZach Atkins elif test_id in ['t117']: 143*1b16049aSZach Atkins fail_str = 'Cannot restore CeedVector array access, access was not granted' 144*1b16049aSZach Atkins elif test_id in ['t118']: 145*1b16049aSZach Atkins fail_str = 'Cannot sync CeedVector, the access lock is already in use' 146*1b16049aSZach Atkins elif test_id in ['t215']: 147*1b16049aSZach Atkins fail_str = 'Cannot destroy CeedElemRestriction, a process has read access to the offset data' 148*1b16049aSZach Atkins elif test_id in ['t303']: 149*1b16049aSZach Atkins fail_str = 'Length of input/output vectors incompatible with basis dimensions' 150*1b16049aSZach Atkins elif test_id in ['t408']: 151*1b16049aSZach Atkins fail_str = 'CeedQFunctionContextGetData(): Cannot grant CeedQFunctionContext data access, a process has read access' 152*1b16049aSZach Atkins elif test_id in ['t409'] and contains_any(resource, ['memcheck']): 153*1b16049aSZach Atkins fail_str = 'Context data changed while accessed in read-only mode' 1544a2fcf2fSJeremy L Thompson 155*1b16049aSZach Atkins return fail_str, fail_str in stderr 1564a2fcf2fSJeremy L Thompson 157*1b16049aSZach Atkins def check_allowed_stdout(self, test: str) -> bool: 158*1b16049aSZach Atkins """Check whether a test is allowed to print console output 1594a2fcf2fSJeremy L Thompson 160*1b16049aSZach Atkins Args: 161*1b16049aSZach Atkins test (str): Name of test 162*1b16049aSZach Atkins 163*1b16049aSZach Atkins Returns: 164*1b16049aSZach Atkins bool: True if the test is allowed to print console output 165*1b16049aSZach Atkins """ 166*1b16049aSZach Atkins return test[:4] in ['t003'] 167*1b16049aSZach Atkins 1688ec9d54bSJed Brown 1698ec9d54bSJed Brownif __name__ == '__main__': 170*1b16049aSZach Atkins args = create_argparser().parse_args() 1718ec9d54bSJed Brown 1724a2fcf2fSJeremy L Thompson # run tests 173*1b16049aSZach Atkins result: TestSuite = run_tests(args.test, args.ceed_backends, args.mode, args.nproc, CeedSuiteSpec()) 174add335c8SJeremy L Thompson 175*1b16049aSZach Atkins # write output and check for failures 176*1b16049aSZach Atkins if args.mode is RunMode.JUNIT: 177*1b16049aSZach Atkins write_junit_xml(result, args.output, args.junit_batch) 178*1b16049aSZach Atkins if has_failures(result): 1794d57a9fcSJed Brown sys.exit(1) 180