blob: 6acaaf46ae0aee8a4ff5cc00f3003717c208b375 [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,
Eric Kunze286f8342022-06-22 11:30:23 -070037 "--operator_fbs={}".format(args.operator_fbs),
38 "--test_desc={}".format(self.descFile),
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000039 ]
40
41 # Specific debug options for reference model
42 if args.ref_debug:
Jeremy Johnson93d43902022-09-27 12:26:14 +010043 cmd.extend(["-d", "ALL", "-l", args.ref_debug])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000044
45 if args.ref_intermediates:
Jeremy Johnson93d43902022-09-27 12:26:14 +010046 cmd.extend(["--dump_intermediates", str(args.ref_intermediates)])
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000047
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 Johnson015c3552022-02-23 12:15:03 +000061 if not self.args.verbose:
62 print(e)
Jeremy Johnsonbe1a9402021-12-15 17:14:56 +000063 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