1#!/usr/bin/env python3 2from junit_common import * 3 4 5def create_argparser() -> argparse.ArgumentParser: 6 """Creates argument parser to read command line arguments 7 8 Returns: 9 argparse.ArgumentParser: Created `ArgumentParser` 10 """ 11 parser = argparse.ArgumentParser('Test runner with JUnit and TAP output') 12 parser.add_argument( 13 '-c', 14 '--ceed-backends', 15 type=str, 16 nargs='*', 17 default=['/cpu/self'], 18 help='libCEED backend to use with convergence tests') 19 parser.add_argument( 20 '-m', 21 '--mode', 22 type=RunMode, 23 action=CaseInsensitiveEnumAction, 24 help='Output mode, junit or tap', 25 default=RunMode.JUNIT) 26 parser.add_argument('-n', '--nproc', type=int, default=1, help='number of MPI processes') 27 parser.add_argument('-b', '--junit-batch', type=str, default='', help='Name of JUnit batch for output file') 28 parser.add_argument('-np', '--pool-size', type=int, default=1, help='Number of test cases to run in parallel') 29 parser.add_argument('-s', '--search', type=str, default='.*', 30 help='Search string to filter tests, using `re` package format') 31 parser.add_argument('-v', '--verbose', action='store_true', default=False, 32 help='print details for all runs, not just failures') 33 parser.add_argument('test', help='Test executable', nargs='?') 34 35 return parser 36 37 38# Necessary functions for running tests 39class CeedSuiteSpec(SuiteSpec): 40 def __init__(self): 41 pass 42 43 def get_source_path(self, test: str) -> Path: 44 """Compute path to test source file 45 46 Args: 47 test (str): Name of test 48 49 Returns: 50 Path: Path to source file 51 """ 52 prefix, rest = test.split('-', 1) 53 if prefix == 'rustqfunctions': 54 return (Path('examples') / 'rust-qfunctions' / rest).with_suffix('.c') 55 if prefix == 'petsc': 56 return (Path('examples') / 'petsc' / rest).with_suffix('.c') 57 elif prefix == 'mfem': 58 return (Path('examples') / 'mfem' / rest).with_suffix('.cpp') 59 elif prefix == 'nek': 60 return (Path('examples') / 'nek' / 'bps' / rest).with_suffix('.usr') 61 elif prefix == 'dealii': 62 return (Path('examples') / 'deal.II' / rest).with_suffix('.cc') 63 elif prefix == 'fluids': 64 return (Path('examples') / 'fluids' / rest).with_suffix('.c') 65 elif prefix == 'solids': 66 return (Path('examples') / 'solids' / rest).with_suffix('.c') 67 elif test.startswith('ex'): 68 return (Path('examples') / 'ceed' / test).with_suffix('.c') 69 elif test.endswith('-f'): 70 return (Path('tests') / test).with_suffix('.f90') 71 else: 72 return (Path('tests') / test).with_suffix('.c') 73 74 # get path to executable 75 def get_run_path(self, test: str) -> Path: 76 """Compute path to built test executable file 77 78 Args: 79 test (str): Name of test 80 81 Returns: 82 Path: Path to test executable 83 """ 84 return Path('build') / test 85 86 def get_output_path(self, test: str, output_file: str) -> Path: 87 """Compute path to expected output file 88 89 Args: 90 test (str): Name of test 91 output_file (str): File name of output file 92 93 Returns: 94 Path: Path to expected output file 95 """ 96 return Path('tests') / 'output' / output_file 97 98 def check_pre_skip(self, test: str, spec: TestSpec, resource: str, nproc: int) -> Optional[str]: 99 """Check if a test case should be skipped prior to running, returning the reason for skipping 100 101 Args: 102 test (str): Name of test 103 spec (TestSpec): Test case specification 104 resource (str): libCEED backend 105 nproc (int): Number of MPI processes to use when running test case 106 107 Returns: 108 Optional[str]: Skip reason, or `None` if test case should not be skipped 109 """ 110 if contains_any(resource, ['occa']) and startswith_any( 111 test, ['t4', 't5', 'ex', 'mfem', 'nek', 'petsc', 'fluids', 'solids']): 112 return 'OCCA mode not supported' 113 if test.startswith('t318') and contains_any(resource, ['/gpu/cuda/ref']): 114 return 'CUDA ref backend not supported' 115 if test.startswith('t506') and contains_any(resource, ['/gpu/cuda/shared']): 116 return 'CUDA shared backend not supported' 117 for condition in spec.only: 118 if (condition == 'cpu') and ('gpu' in resource): 119 return 'CPU only test with GPU backend' 120 121 def check_post_skip(self, test: str, spec: TestSpec, resource: str, stderr: str) -> Optional[str]: 122 """Check if a test case should be allowed to fail, based on its stderr output 123 124 Args: 125 test (str): Name of test 126 spec (TestSpec): Test case specification 127 resource (str): libCEED backend 128 stderr (str): Standard error output from test case execution 129 130 Returns: 131 Optional[str]: Skip reason, or `None` if unexpeced error 132 """ 133 if 'OCCA backend failed to use' in stderr: 134 return f'OCCA mode not supported' 135 elif 'Backend does not implement' in stderr: 136 return f'Backend does not implement' 137 elif 'Can only provide HOST memory for this backend' in stderr: 138 return f'Device memory not supported' 139 elif 'Can only set HOST memory for this backend' in stderr: 140 return f'Device memory not supported' 141 elif 'Test not implemented in single precision' in stderr: 142 return f'Test not implemented in single precision' 143 elif 'No SYCL devices of the requested type are available' in stderr: 144 return f'SYCL device type not available' 145 elif 'You may need to add --download-ctetgen or --download-tetgen' in stderr: 146 return f'Tet mesh generator not installed for {test}, {spec.name}' 147 return None 148 149 def check_required_failure(self, test: str, spec: TestSpec, resource: str, stderr: str) -> Tuple[str, bool]: 150 """Check whether a test case is expected to fail and if it failed expectedly 151 152 Args: 153 test (str): Name of test 154 spec (TestSpec): Test case specification 155 resource (str): libCEED backend 156 stderr (str): Standard error output from test case execution 157 158 Returns: 159 tuple[str, bool]: Tuple of the expected failure string and whether it was present in `stderr` 160 """ 161 test_id: str = test[:4] 162 fail_str: str = '' 163 if test_id in ['t006', 't007']: 164 fail_str = 'No suitable backend:' 165 elif test_id in ['t008']: 166 fail_str = 'Available backend resources:' 167 elif test_id in ['t110', 't111', 't112', 't113', 't114']: 168 fail_str = 'Cannot grant CeedVector array access' 169 elif test_id in ['t115']: 170 fail_str = 'Cannot grant CeedVector read-only array access, the access lock is already in use' 171 elif test_id in ['t116']: 172 fail_str = 'Cannot destroy CeedVector, the writable access lock is in use' 173 elif test_id in ['t117']: 174 fail_str = 'Cannot restore CeedVector array access, access was not granted' 175 elif test_id in ['t118']: 176 fail_str = 'Cannot sync CeedVector, the access lock is already in use' 177 elif test_id in ['t215']: 178 fail_str = 'Cannot destroy CeedElemRestriction, a process has read access to the offset data' 179 elif test_id in ['t303']: 180 fail_str = 'Input/output vectors too short for basis and evaluation mode' 181 elif test_id in ['t408']: 182 fail_str = 'CeedQFunctionContextGetData(): Cannot grant CeedQFunctionContext data access, a process has read access' 183 elif test_id in ['t409'] and contains_any(resource, ['memcheck']): 184 fail_str = 'Context data changed while accessed in read-only mode' 185 186 return fail_str, fail_str in stderr 187 188 def check_allowed_stdout(self, test: str) -> bool: 189 """Check whether a test is allowed to print console output 190 191 Args: 192 test (str): Name of test 193 194 Returns: 195 bool: True if the test is allowed to print console output 196 """ 197 return test[:4] in ['t003'] 198 199 200if __name__ == '__main__': 201 args = create_argparser().parse_args() 202 203 result: TestSuite = run_tests( 204 args.test, 205 args.ceed_backends, 206 args.mode, 207 args.nproc, 208 CeedSuiteSpec(), 209 args.pool_size, 210 search=args.search, 211 verbose=args.verbose) 212 213 # write output and check for failures 214 if args.mode is RunMode.JUNIT: 215 write_junit_xml(result, args.junit_batch) 216 if has_failures(result): 217 sys.exit(1) 218