blob: 499513b7494de234b8ed404cce7e0ab7eff90cb5 [file] [log] [blame]
Jared Smolens2a76ad22021-03-04 11:18:54 -08001# Copyright (c) 2020-2021, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07002#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Kevin Chengcd79f0e2021-06-03 15:00:34 -070015import os
Eric Kunzee5e26762020-10-13 16:11:07 -070016import json
17import shlex
18import subprocess
Kevin Chengacb550f2021-06-29 15:32:19 -070019from enum import Enum, IntEnum, unique
Eric Kunzee5e26762020-10-13 16:11:07 -070020from tosa_test_runner import TosaTestRunner, run_sh_command
21
Kevin Cheng550ccc52021-03-03 11:21:43 -080022
Kevin Chengacb550f2021-06-29 15:32:19 -070023@unique
24class TosaReturnCode(IntEnum):
25 VALID = 0
26 UNPREDICTABLE = 1
27 ERROR = 2
28
29
Eric Kunzee5e26762020-10-13 16:11:07 -070030class TosaRefRunner(TosaTestRunner):
31 def __init__(self, args, runnerArgs, testDir):
32 super().__init__(args, runnerArgs, testDir)
33
34 def runModel(self):
35 # Build up the TOSA reference command line
36 # Uses arguments from the argParser args, not the runnerArgs
37 args = self.args
38
Kevin Cheng550ccc52021-03-03 11:21:43 -080039 ref_cmd = [
40 args.ref_model_path,
Kevin Chengcd79f0e2021-06-03 15:00:34 -070041 "-Ctest_desc={}".format(os.path.join(self.testDir, "desc.json")),
Kevin Cheng550ccc52021-03-03 11:21:43 -080042 ]
Eric Kunzee5e26762020-10-13 16:11:07 -070043
Eric Kunzee5e26762020-10-13 16:11:07 -070044 if args.ref_debug:
Kevin Cheng550ccc52021-03-03 11:21:43 -080045 ref_cmd.extend(["-dALL", "-l{}".format(args.ref_debug)])
Eric Kunzee5e26762020-10-13 16:11:07 -070046
47 if args.ref_intermediates:
Kevin Cheng550ccc52021-03-03 11:21:43 -080048 ref_cmd.extend(["-Ddump_intermediates=1"])
Eric Kunzee5e26762020-10-13 16:11:07 -070049
Kevin Chengacb550f2021-06-29 15:32:19 -070050 expectedReturnCode = self.testDesc["expected_return_code"]
Eric Kunzee5e26762020-10-13 16:11:07 -070051
52 try:
Kevin Chengacb550f2021-06-29 15:32:19 -070053 rc = run_sh_command(self.args, ref_cmd)
54 if rc == TosaReturnCode.VALID:
55 if expectedReturnCode == TosaReturnCode.VALID:
56 result = TosaTestRunner.Result.EXPECTED_PASS
57 else:
58 result = TosaTestRunner.Result.UNEXPECTED_PASS
59 elif rc == TosaReturnCode.ERROR:
60 if expectedReturnCode == TosaReturnCode.ERROR:
61 result = TosaTestRunner.Result.EXPECTED_FAILURE
62 else:
63 result = TosaTestRunner.Result.UNEXPECTED_FAILURE
64 elif rc == TosaReturnCode.UNPREDICTABLE:
65 if expectedReturnCode == TosaReturnCode.UNPREDICTABLE:
66 result = TosaTestRunner.Result.EXPECTED_FAILURE
67 else:
68 result = TosaTestRunner.Result.UNEXPECTED_FAILURE
Eric Kunzee5e26762020-10-13 16:11:07 -070069 else:
Kevin Chengacb550f2021-06-29 15:32:19 -070070 raise Exception("Return code unknown.")
71
Eric Kunzee5e26762020-10-13 16:11:07 -070072 except Exception as e:
Kevin Chengacb550f2021-06-29 15:32:19 -070073 raise Exception("Runtime Error when running: {}".format(" ".join(ref_cmd)))
Eric Kunzee5e26762020-10-13 16:11:07 -070074
75 return result