blob: 7b129da3eb9e217614a8daf5cee3e9b8f72b9392 [file] [log] [blame]
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +00001"""TOSA test runner module for the Reference Model."""
2# Copyright (c) 2020-2022, ARM Limited.
3# 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
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,
Jerry Ge0bd4ec82023-05-01 18:36:43 +000037 "--tosa_level={}".format(args.tosa_level),
Eric Kunze286f8342022-06-22 11:30:23 -070038 "--operator_fbs={}".format(args.operator_fbs),
39 "--test_desc={}".format(self.descFile),
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000040 ]
41
42 # Specific debug options for reference model
43 if args.ref_debug:
Jeremy Johnson93d43902022-09-27 12:26:14 +010044 cmd.extend(["-d", "ALL", "-l", args.ref_debug])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000045
46 if args.ref_intermediates:
Jeremy Johnson93d43902022-09-27 12:26:14 +010047 cmd.extend(["--dump_intermediates", str(args.ref_intermediates)])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000048
Tai Lya4d748b2023-03-28 22:06:56 +000049 if args.precise_mode:
50 cmd.extend(["--precise_mode=1"])
51
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000052 # Run command and interpret tosa graph result via process return codes
53 graphMessage = None
54 try:
55 run_sh_command(cmd, self.args.verbose, capture_output=True)
56 graphResult = TosaTestRunner.TosaGraphResult.TOSA_VALID
57 except RunShCommandError as e:
58 graphMessage = e.stderr
59 if e.return_code == TosaRefReturnCode.ERROR:
60 graphResult = TosaTestRunner.TosaGraphResult.TOSA_ERROR
61 elif e.return_code == TosaRefReturnCode.UNPREDICTABLE:
62 graphResult = TosaTestRunner.TosaGraphResult.TOSA_UNPREDICTABLE
63 else:
64 graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR
Jeremy Johnson015c3552022-02-23 12:15:03 +000065 if not self.args.verbose:
66 print(e)
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000067 except Exception as e:
68 print(e)
69 graphMessage = str(e)
70 graphResult = TosaTestRunner.TosaGraphResult.OTHER_ERROR
71
72 # Return graph result and message
73 return graphResult, graphMessage