blob: 99f504b228d26303c1926c4fa41bc2beb8a71dc0 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001import os
2
3# Copyright (c) 2020, ARM Limited.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import json
18import shlex
19import subprocess
20from tosa_test_runner import TosaTestRunner, run_sh_command
21
22class TosaRefRunner(TosaTestRunner):
23 def __init__(self, args, runnerArgs, testDir):
24 super().__init__(args, runnerArgs, testDir)
25
26 def runModel(self):
27 # Build up the TOSA reference command line
28 # Uses arguments from the argParser args, not the runnerArgs
29 args = self.args
30
31 ref_cmd = [ args.ref_model_path,
32 '-Csubgraph_file={}'.format(self.testDesc['tosa_file']),
33 '-Csubgraph_dir={}'.format(self.testDir),
34 '-Cinput_dir={}'.format(self.testDir),
35 '-Coutput_dir={}'.format(self.testDir),
36 '-Coutput_tensor_prefix=ref-', # Naming agreement with TosaSerializer
37 ]
38
39 # Build up input tensor_name/filename list
40 inputTensors = []
41 for i in range(len(self.testDesc['ifm_placeholder'])):
42 inputTensors.append('{}:{}'.format(self.testDesc['ifm_placeholder'][i], self.testDesc['ifm_file'][i]))
43
44 ref_cmd.append('-Cinput_tensor={}'.format(','.join(inputTensors)))
45
46 if args.ref_debug:
47 ref_cmd.extend(['-dALL', '-l{}'.format(args.ref_debug)])
48
49 if args.ref_intermediates:
50 ref_cmd.extend(['-Ddump_intermediates=1'])
51
52 expectedFailure = self.testDesc['expected_failure']
53
54 try:
55 run_sh_command(self.args, ref_cmd)
56 if expectedFailure:
57 result = TosaTestRunner.Result.UNEXPECTED_PASS
58 else:
59 result = TosaTestRunner.Result.EXPECTED_PASS
60 except Exception as e:
61 if expectedFailure:
62 result = TosaTestRunner.Result.EXPECTED_FAILURE
63 else:
64 result = TosaTestRunner.Result.EXPECTED_PASS
65
66 return result