Jeremy Johnson | be1a940 | 2021-12-15 17:14:56 +0000 | [diff] [blame] | 1 | """TOSA test runner module for the Reference Model.""" |
| 2 | # Copyright (c) 2020-2022, ARM Limited. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | from enum import IntEnum |
| 5 | from enum import unique |
| 6 | |
| 7 | from runner.run_command import run_sh_command |
| 8 | from runner.run_command import RunShCommandError |
| 9 | from runner.tosa_test_runner import TosaTestRunner |
| 10 | |
| 11 | |
| 12 | @unique |
| 13 | class TosaRefReturnCode(IntEnum): |
| 14 | """Return codes from the Tosa Reference Model.""" |
| 15 | |
| 16 | VALID = 0 |
| 17 | UNPREDICTABLE = 1 |
| 18 | ERROR = 2 |
| 19 | |
| 20 | |
| 21 | class TosaSUTRunner(TosaTestRunner): |
| 22 | """TOSA Reference Model runner.""" |
| 23 | |
| 24 | def __init__(self, args, runnerArgs, testDir): |
| 25 | """Initialize using the given test details.""" |
| 26 | super().__init__(args, runnerArgs, testDir) |
| 27 | |
| 28 | def runTestGraph(self): |
| 29 | """Run the test on the reference model.""" |
| 30 | # Build up the TOSA reference command line |
| 31 | # Uses arguments from the argParser args, not the runnerArgs |
| 32 | args = self.args |
| 33 | |
| 34 | # Call Reference model with description file to provide all file details |
| 35 | cmd = [ |
| 36 | args.ref_model_path, |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 37 | "--operator_fbs={}".format(args.operator_fbs), |
| 38 | "--test_desc={}".format(self.descFile), |
Jeremy Johnson | be1a940 | 2021-12-15 17:14:56 +0000 | [diff] [blame] | 39 | ] |
| 40 | |
| 41 | # Specific debug options for reference model |
| 42 | if args.ref_debug: |
Jeremy Johnson | 93d4390 | 2022-09-27 12:26:14 +0100 | [diff] [blame^] | 43 | cmd.extend(["-d", "ALL", "-l", args.ref_debug]) |
Jeremy Johnson | be1a940 | 2021-12-15 17:14:56 +0000 | [diff] [blame] | 44 | |
| 45 | if args.ref_intermediates: |
Jeremy Johnson | 93d4390 | 2022-09-27 12:26:14 +0100 | [diff] [blame^] | 46 | cmd.extend(["--dump_intermediates", str(args.ref_intermediates)]) |
Jeremy Johnson | be1a940 | 2021-12-15 17:14:56 +0000 | [diff] [blame] | 47 | |
| 48 | # Run command and interpret tosa graph result via process return codes |
| 49 | graphMessage = None |
| 50 | try: |
| 51 | run_sh_command(cmd, self.args.verbose, capture_output=True) |
| 52 | graphResult = TosaTestRunner.TosaGraphResult.TOSA_VALID |
| 53 | except RunShCommandError as e: |
| 54 | graphMessage = e.stderr |
| 55 | if e.return_code == TosaRefReturnCode.ERROR: |
| 56 | graphResult = TosaTestRunner.TosaGraphResult.TOSA_ERROR |
| 57 | elif e.return_code == TosaRefReturnCode.UNPREDICTABLE: |
| 58 | graphResult = TosaTestRunner.TosaGraphResult.TOSA_UNPREDICTABLE |
| 59 | else: |
| 60 | graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR |
Jeremy Johnson | 015c355 | 2022-02-23 12:15:03 +0000 | [diff] [blame] | 61 | if not self.args.verbose: |
| 62 | print(e) |
Jeremy Johnson | be1a940 | 2021-12-15 17:14:56 +0000 | [diff] [blame] | 63 | except Exception as e: |
| 64 | print(e) |
| 65 | graphMessage = str(e) |
| 66 | graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR |
| 67 | |
| 68 | # Return graph result and message |
| 69 | return graphResult, graphMessage |