blob: b9a95754e42b6a4bf9012805bf32ef547d96a8e4 [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
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,
37 "-Coperator_fbs={}".format(args.operator_fbs),
38 "-Ctest_desc={}".format(self.descFile),
39 ]
40
41 # Specific debug options for reference model
42 if args.ref_debug:
43 cmd.extend(["-dALL", "-l{}".format(args.ref_debug)])
44
45 if args.ref_intermediates:
46 cmd.extend(["-Ddump_intermediates=1"])
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
61 if (
62 self.args.verbose
63 or graphResult == TosaTestRunner.TosaGraphResult.OTHER_ERROR
64 ):
65 print(e)
66
67 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