Jared Smolens | 2a76ad2 | 2021-03-04 11:18:54 -0800 | [diff] [blame] | 1 | # Copyright (c) 2020-2021, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 2 | # |
| 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 Cheng | cd79f0e | 2021-06-03 15:00:34 -0700 | [diff] [blame] | 15 | import os |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 16 | import json |
| 17 | import shlex |
| 18 | import subprocess |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 19 | from enum import Enum, IntEnum, unique |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 20 | from tosa_test_runner import TosaTestRunner, run_sh_command |
| 21 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 22 | |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 23 | @unique |
| 24 | class TosaReturnCode(IntEnum): |
| 25 | VALID = 0 |
| 26 | UNPREDICTABLE = 1 |
| 27 | ERROR = 2 |
| 28 | |
| 29 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 30 | class 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 Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 39 | ref_cmd = [ |
| 40 | args.ref_model_path, |
Kevin Cheng | cd79f0e | 2021-06-03 15:00:34 -0700 | [diff] [blame] | 41 | "-Ctest_desc={}".format(os.path.join(self.testDir, "desc.json")), |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 42 | ] |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 43 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 44 | if args.ref_debug: |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 45 | ref_cmd.extend(["-dALL", "-l{}".format(args.ref_debug)]) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 46 | |
| 47 | if args.ref_intermediates: |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 48 | ref_cmd.extend(["-Ddump_intermediates=1"]) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 49 | |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 50 | expectedReturnCode = self.testDesc["expected_return_code"] |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 51 | |
| 52 | try: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 53 | 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 |
Jared Smolens | 7e7fccd | 2021-09-21 11:36:18 -0700 | [diff] [blame] | 69 | elif rc < 0: |
| 70 | # Unix signal caught (e.g., SIGABRT, SIGSEGV, SIGFPE, etc) |
| 71 | result = TosaTestRunner.Result.INTERNAL_ERROR |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 72 | else: |
Les Bell | f414b3c | 2021-09-06 11:29:46 +0100 | [diff] [blame] | 73 | raise Exception(f"Return code ({rc}) unknown.") |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 74 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 75 | except Exception as e: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 76 | raise Exception("Runtime Error when running: {}".format(" ".join(ref_cmd))) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 77 | |
| 78 | return result |