blob: d9eb1084d1388a5f2368cf26acd3fe02c6e851cd [file] [log] [blame]
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +00001"""TOSA test runner module for the Reference Model."""
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +01002# Copyright (c) 2020-2023, ARM Limited.
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +00003# SPDX-License-Identifier: Apache-2.0
4from enum import IntEnum
5from enum import unique
6
7from runner.run_command import run_sh_command
8from runner.run_command import RunShCommandError
9from runner.tosa_test_runner import TosaTestRunner
10
11
12@unique
13class TosaRefReturnCode(IntEnum):
14 """Return codes from the Tosa Reference Model."""
15
16 VALID = 0
17 UNPREDICTABLE = 1
18 ERROR = 2
19
20
21class TosaSUTRunner(TosaTestRunner):
22 """TOSA Reference Model runner."""
23
Jeremy Johnsone4b08ff2022-09-15 10:38:17 +010024 def __init__(self, args, runnerArgs, testDirPath):
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000025 """Initialize using the given test details."""
Jeremy Johnsone4b08ff2022-09-15 10:38:17 +010026 super().__init__(args, runnerArgs, testDirPath)
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000027
Jeremy Johnsone2b5e872023-09-14 17:02:09 +010028 # Don't do any compliance runs
29 self.compliance = False
30
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000031 def runTestGraph(self):
32 """Run the test on the reference model."""
33 # Build up the TOSA reference command line
34 # Uses arguments from the argParser args, not the runnerArgs
35 args = self.args
36
37 # Call Reference model with description file to provide all file details
38 cmd = [
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +010039 str(args.ref_model_path),
40 f"--tosa_level={args.tosa_level}",
41 f"--operator_fbs={str(args.schema_path)}",
42 f"--test_desc={self.descFile}",
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000043 ]
44
45 # Specific debug options for reference model
46 if args.ref_debug:
Jeremy Johnson93d43902022-09-27 12:26:14 +010047 cmd.extend(["-d", "ALL", "-l", args.ref_debug])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000048
49 if args.ref_intermediates:
Jeremy Johnson93d43902022-09-27 12:26:14 +010050 cmd.extend(["--dump_intermediates", str(args.ref_intermediates)])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000051
Jeremy Johnsone2b5e872023-09-14 17:02:09 +010052 if args.precise_mode or self.compliance:
Tai Lya4d748b2023-03-28 22:06:56 +000053 cmd.extend(["--precise_mode=1"])
54
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000055 # Run command and interpret tosa graph result via process return codes
56 graphMessage = None
57 try:
58 run_sh_command(cmd, self.args.verbose, capture_output=True)
59 graphResult = TosaTestRunner.TosaGraphResult.TOSA_VALID
60 except RunShCommandError as e:
61 graphMessage = e.stderr
62 if e.return_code == TosaRefReturnCode.ERROR:
63 graphResult = TosaTestRunner.TosaGraphResult.TOSA_ERROR
64 elif e.return_code == TosaRefReturnCode.UNPREDICTABLE:
65 graphResult = TosaTestRunner.TosaGraphResult.TOSA_UNPREDICTABLE
66 else:
67 graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR
Jeremy Johnson015c3552022-02-23 12:15:03 +000068 if not self.args.verbose:
69 print(e)
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000070 except Exception as e:
71 print(e)
72 graphMessage = str(e)
73 graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR
74
75 # Return graph result and message
76 return graphResult, graphMessage