blob: 26c64da57280c48b6aaaa6099549fe8bdf8535c7 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001import os
2
Jared Smolens2a76ad22021-03-04 11:18:54 -08003# Copyright (c) 2020-2021, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07004#
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
Kevin Cheng550ccc52021-03-03 11:21:43 -080022
Eric Kunzee5e26762020-10-13 16:11:07 -070023class TosaRefRunner(TosaTestRunner):
24 def __init__(self, args, runnerArgs, testDir):
25 super().__init__(args, runnerArgs, testDir)
26
27 def runModel(self):
28 # Build up the TOSA reference command line
29 # Uses arguments from the argParser args, not the runnerArgs
30 args = self.args
31
Kevin Cheng550ccc52021-03-03 11:21:43 -080032 ref_cmd = [
33 args.ref_model_path,
34 "-Csubgraph_file={}".format(self.testDesc["tosa_file"]),
35 "-Csubgraph_dir={}".format(self.testDir),
36 "-Cinput_dir={}".format(self.testDir),
37 "-Coutput_dir={}".format(self.testDir),
38 "-Coutput_tensor_prefix=ref-", # Naming agreement with TosaSerializer
39 ]
Eric Kunzee5e26762020-10-13 16:11:07 -070040
41 # Build up input tensor_name/filename list
42 inputTensors = []
Kevin Cheng550ccc52021-03-03 11:21:43 -080043 for i in range(len(self.testDesc["ifm_placeholder"])):
44 inputTensors.append(
45 "{}:{}".format(
46 self.testDesc["ifm_placeholder"][i], self.testDesc["ifm_file"][i]
47 )
48 )
Eric Kunzee5e26762020-10-13 16:11:07 -070049
Kevin Cheng550ccc52021-03-03 11:21:43 -080050 ref_cmd.append("-Cinput_tensor={}".format(",".join(inputTensors)))
Eric Kunzee5e26762020-10-13 16:11:07 -070051
52 if args.ref_debug:
Kevin Cheng550ccc52021-03-03 11:21:43 -080053 ref_cmd.extend(["-dALL", "-l{}".format(args.ref_debug)])
Eric Kunzee5e26762020-10-13 16:11:07 -070054
55 if args.ref_intermediates:
Kevin Cheng550ccc52021-03-03 11:21:43 -080056 ref_cmd.extend(["-Ddump_intermediates=1"])
Eric Kunzee5e26762020-10-13 16:11:07 -070057
Kevin Cheng550ccc52021-03-03 11:21:43 -080058 expectedFailure = self.testDesc["expected_failure"]
Eric Kunzee5e26762020-10-13 16:11:07 -070059
60 try:
61 run_sh_command(self.args, ref_cmd)
62 if expectedFailure:
63 result = TosaTestRunner.Result.UNEXPECTED_PASS
64 else:
65 result = TosaTestRunner.Result.EXPECTED_PASS
66 except Exception as e:
67 if expectedFailure:
68 result = TosaTestRunner.Result.EXPECTED_FAILURE
69 else:
Jared Smolens2a76ad22021-03-04 11:18:54 -080070 result = TosaTestRunner.Result.UNEXPECTED_FAILURE
Eric Kunzee5e26762020-10-13 16:11:07 -070071
72 return result