blob: 19e1243ecffbcf64c7f757ebe627454a9a26b801 [file] [log] [blame]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +01001#!/usr/bin/env python3
2
3#
Ledion Dajaf5f70532024-01-11 12:09:20 +01004# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Kristofer Jonsson715c07b2021-02-25 09:49:34 +01005# SPDX-License-Identifier: Apache-2.0
6#
7# Licensed under the Apache License, Version 2.0 (the License); you may
8# not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an AS IS BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19
20import argparse
21import subprocess
22import sys
Per Åstrand9de1b742022-02-03 19:35:35 +010023import os
24from pathlib import Path
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010025
26def __print_arguments(args):
27 if isinstance(args, list):
28 print("$ " + " ".join(args))
29 else:
30 print(args)
31
32def Popen(args, **kwargs):
33 __print_arguments(args)
34 return subprocess.Popen(args, **kwargs)
35
36def call(args, **kwargs):
37 __print_arguments(args)
38 return subprocess.call(args, **kwargs)
39
40def check_call(args, **kwargs):
41 __print_arguments(args)
42 return subprocess.check_call(args, **kwargs)
43
44def check_output(args, **kwargs):
45 __print_arguments(args)
46 return subprocess.check_output(args, **kwargs)
47
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +010048def run_fvp(cmd):
49 # Run FVP and tee output to console while scanning for exit tag
50 ret = 1
51 proc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
52 while True:
53 line = proc.stdout.readline().decode()
54 if not line:
55 break
56
57 if 'Application exit code: 0.' in line:
58 ret = 0
59
60 sys.stdout.write(line)
61 sys.stdout.flush()
62
63 return ret
64
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010065def run_corstone_300(args):
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010066 if not args.arch or args.arch == 'ethos-u55':
67 fvp = 'FVP_Corstone_SSE-300_Ethos-U55'
68 elif args.arch == 'ethos-u65':
69 fvp = 'FVP_Corstone_SSE-300_Ethos-U65'
70 else:
71 raise 'Unsupported NPU arch'
72
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010073 # Verify supported FVP version
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010074 version = subprocess.check_output([fvp, '--version']).decode()
Ledion Dajaf5f70532024-01-11 12:09:20 +010075 supported_version = ['11.16', '11.22', '11.24']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010076
77 if not [s for s in supported_version if s in version]:
78 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
79
80 # FVP executable
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010081 cmd = [fvp]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010082
83 # NPU configuration
84 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
85
86 # Output parameters
87 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
88 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
89 '-C', 'mps3_board.uart0.out_file="-"',
90 '-C', 'mps3_board.uart0.unbuffered_output=1',
Jonny Svärd2faaf402021-04-20 10:49:57 +020091 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010092
Per Åstrand9de1b742022-02-03 19:35:35 +010093 if args.tarmac:
94 try:
95 pvlib_home = Path(os.getenv('PVLIB_HOME'))
96 except:
97 raise Exception("Environment variable PVLIB_HOME not found. Needed to produce tarmac trace.")
98
99 if sys.platform == 'linux':
100 tarmac_trace_plugin = pvlib_home / Path('plugins/Linux64_GCC-7.3/TarmacTrace.so')
101 else:
102 raise Exception("tarmac trace: This feature is not currently supported on" + sys.platform)
103
104 if tarmac_trace_plugin.exists():
105 print("Tarmac trace will be created");
106 basename = [ e for e in args.args if e.endswith('.elf')][0][:-4]
107 cmd += ['--plugin', str(tarmac_trace_plugin)]
108 cmd += ['-C', f'TRACE.TarmacTrace.trace-file={basename}.trace']
109 else:
110 raise Exception("tarmac trace: Can't find TarmacTrace plugin in " + pvlib_home)
111
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100112 cmd += args.args
113
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100114 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100115
Kristofer Jonsson93175812022-04-21 19:27:11 +0200116def run_corstone_310(args):
117 # Verify supported FVP version
Davide Grohmann7275f502022-08-09 14:32:52 +0200118 version = subprocess.check_output(['FVP_Corstone_SSE-310', '--version']).decode()
Ledion Dajaf5f70532024-01-11 12:09:20 +0100119 supported_version = ['11.17', '11.22', '11.24']
Kristofer Jonsson93175812022-04-21 19:27:11 +0200120
121 if not [s for s in supported_version if s in version]:
122 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
123
124 # FVP executable
Davide Grohmann7275f502022-08-09 14:32:52 +0200125 cmd = ['FVP_Corstone_SSE-310']
Kristofer Jonsson93175812022-04-21 19:27:11 +0200126
127 # NPU configuration
128 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
129
130 # Output parameters
131 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
132 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
133 '-C', 'mps3_board.uart0.out_file="-"',
134 '-C', 'mps3_board.uart0.unbuffered_output=1',
135 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
136
137 cmd += args.args
138
139 return run_fvp(cmd)
140
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100141def run_corstone_polaris(args):
142 # Verify supported FVP version
143 version = subprocess.check_output(['FVP_Corstone-Polaris', '--version']).decode()
144 supported_version = ['11.16']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100145
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100146 if not [s for s in supported_version if s in version]:
147 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100148
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100149 # FVP executable
150 cmd = ['FVP_Corstone-Polaris']
151
152 # NPU configuration
153 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
154
155 # 32kB ITCM, 32kB DTCM, 2MB SRAM
156 cmd += ['-C', 'cpu0.CFGITCMSZ=6',
157 '-C', 'cpu0.CFGDTCMSZ=6',
158 '-C', 'mps3_board.sse300.NUMVMBANK=1',
159 '-C', 'mps3_board.sse300.VM_BANK_SIZE=2048']
160
161 # Output parameters
162 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
163 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
164 '-C', 'mps3_board.uart0.out_file="-"',
165 '-C', 'mps3_board.uart0.unbuffered_output=1',
166 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
167
168 cmd += args.args
169
170 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100171
172if __name__ == '__main__':
173 parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.')
Kristofer Jonsson93175812022-04-21 19:27:11 +0200174 parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-310', 'corstone-polaris'], required=True, help='FVP target.')
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +0100175 parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.')
Kristofer Jonsson3eaabb42022-02-07 16:39:11 +0100176 parser.add_argument('-m', '--macs', type=int, choices=[32, 64, 128, 256, 512], default=128, help='NPU number of MACs.')
Per Åstrand9de1b742022-02-03 19:35:35 +0100177 parser.add_argument('-c', '--tarmac', dest='tarmac', action='store_true', help='Collect tarmac traces when running FVP.')
178
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100179 parser.add_argument('args', nargs='+', help='Arguments.')
180 args = parser.parse_args()
181
182 if args.target == 'corstone-300':
183 sys.exit(run_corstone_300(args))
Kristofer Jonsson93175812022-04-21 19:27:11 +0200184 elif args.target == 'corstone-310':
185 sys.exit(run_corstone_310(args))
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100186 elif args.target == 'corstone-polaris':
187 sys.exit(run_corstone_polaris(args))