Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame^] | 1 | import os |
| 2 | |
| 3 | # Copyright (c) 2020, ARM Limited. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import json |
| 18 | import shlex |
| 19 | import subprocess |
| 20 | from enum import IntEnum, unique |
| 21 | |
| 22 | def run_sh_command(args, full_cmd, capture_output=False): |
| 23 | '''Utility function to run an external command. Optionally return captured stdout/stderr''' |
| 24 | |
| 25 | # Quote the command line for printing |
| 26 | full_cmd_esc = [ shlex.quote(x) for x in full_cmd ] |
| 27 | |
| 28 | if args.verbose: |
| 29 | print('### Running {}'.format(' '.join(full_cmd_esc))) |
| 30 | |
| 31 | if capture_output: |
| 32 | rc = subprocess.run(full_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 33 | if rc.returncode != 0: |
| 34 | print(rc.stdout.decode('utf-8')) |
| 35 | print(rc.stderr.decode('utf-8')) |
| 36 | raise Exception('Error running command: {}.\n{}'.format(' '.join(full_cmd_esc), rc.stderr.decode('utf-8'))) |
| 37 | return (rc.stdout, rc.stderr) |
| 38 | else: |
| 39 | rc = subprocess.run(full_cmd) |
| 40 | if rc.returncode != 0: |
| 41 | raise Exception('Error running command: {}'.format(' '.join(full_cmd_esc))) |
| 42 | |
| 43 | class TosaTestRunner: |
| 44 | |
| 45 | def __init__(self, args, runnerArgs, testDir): |
| 46 | |
| 47 | self.args = args |
| 48 | self.runnerArgs = runnerArgs |
| 49 | self.testDir = testDir |
| 50 | |
| 51 | # Load the json test file |
| 52 | with open(os.path.join(testDir, 'desc.json'), 'r') as fd: |
| 53 | self.testDesc = json.load(fd) |
| 54 | |
| 55 | def runModel(self): |
| 56 | pass |
| 57 | |
| 58 | class Result(IntEnum): |
| 59 | EXPECTED_PASS = 0 |
| 60 | EXPECTED_FAILURE = 1 |
| 61 | UNEXPECTED_PASS = 2 |
| 62 | UNEXPECTED_FAILURE = 3 |
| 63 | INTERNAL_ERROR = 4 |