blob: e8f921d286af868f10da93bcaa9c66fe485472d9 [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
Kevin Cheng550ccc52021-03-03 11:21:43 -080022
Eric Kunzee5e26762020-10-13 16:11:07 -070023def run_sh_command(args, full_cmd, capture_output=False):
Kevin Cheng550ccc52021-03-03 11:21:43 -080024 """Utility function to run an external command. Optionally return captured stdout/stderr"""
Eric Kunzee5e26762020-10-13 16:11:07 -070025
26 # Quote the command line for printing
Kevin Cheng550ccc52021-03-03 11:21:43 -080027 full_cmd_esc = [shlex.quote(x) for x in full_cmd]
Eric Kunzee5e26762020-10-13 16:11:07 -070028
29 if args.verbose:
Kevin Cheng550ccc52021-03-03 11:21:43 -080030 print("### Running {}".format(" ".join(full_cmd_esc)))
Eric Kunzee5e26762020-10-13 16:11:07 -070031
32 if capture_output:
33 rc = subprocess.run(full_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
34 if rc.returncode != 0:
Kevin Cheng550ccc52021-03-03 11:21:43 -080035 print(rc.stdout.decode("utf-8"))
36 print(rc.stderr.decode("utf-8"))
37 raise Exception(
38 "Error running command: {}.\n{}".format(
39 " ".join(full_cmd_esc), rc.stderr.decode("utf-8")
40 )
41 )
Eric Kunzee5e26762020-10-13 16:11:07 -070042 return (rc.stdout, rc.stderr)
43 else:
44 rc = subprocess.run(full_cmd)
Kevin Chengacb550f2021-06-29 15:32:19 -070045
46 return rc.returncode
Kevin Cheng550ccc52021-03-03 11:21:43 -080047
Eric Kunzee5e26762020-10-13 16:11:07 -070048
49class TosaTestRunner:
Eric Kunzee5e26762020-10-13 16:11:07 -070050 def __init__(self, args, runnerArgs, testDir):
51
52 self.args = args
53 self.runnerArgs = runnerArgs
54 self.testDir = testDir
55
56 # Load the json test file
Kevin Cheng550ccc52021-03-03 11:21:43 -080057 with open(os.path.join(testDir, "desc.json"), "r") as fd:
Eric Kunzee5e26762020-10-13 16:11:07 -070058 self.testDesc = json.load(fd)
59
60 def runModel(self):
61 pass
62
63 class Result(IntEnum):
64 EXPECTED_PASS = 0
65 EXPECTED_FAILURE = 1
66 UNEXPECTED_PASS = 2
67 UNEXPECTED_FAILURE = 3
68 INTERNAL_ERROR = 4