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