blob: 65491923f47407bb73b0d3c5c963316e745848e7 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001import 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
17import json
18import shlex
19import subprocess
20from enum import IntEnum, unique
21
22def 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
43class 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