blob: aa6292f675b2b534ac67579c8076f02a202fa1ac [file] [log] [blame]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +01001#!/usr/bin/env python3
2
3#
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +01004# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
Kristofer Jonsson715c07b2021-02-25 09:49:34 +01005#
6# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the License); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an AS IS BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20
21import argparse
22import subprocess
23import sys
Per Åstrand9de1b742022-02-03 19:35:35 +010024import os
25from pathlib import Path
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010026
27def __print_arguments(args):
28 if isinstance(args, list):
29 print("$ " + " ".join(args))
30 else:
31 print(args)
32
33def Popen(args, **kwargs):
34 __print_arguments(args)
35 return subprocess.Popen(args, **kwargs)
36
37def call(args, **kwargs):
38 __print_arguments(args)
39 return subprocess.call(args, **kwargs)
40
41def check_call(args, **kwargs):
42 __print_arguments(args)
43 return subprocess.check_call(args, **kwargs)
44
45def check_output(args, **kwargs):
46 __print_arguments(args)
47 return subprocess.check_output(args, **kwargs)
48
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +010049def run_fvp(cmd):
50 # Run FVP and tee output to console while scanning for exit tag
51 ret = 1
52 proc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
53 while True:
54 line = proc.stdout.readline().decode()
55 if not line:
56 break
57
58 if 'Application exit code: 0.' in line:
59 ret = 0
60
61 sys.stdout.write(line)
62 sys.stdout.flush()
63
64 return ret
65
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010066def run_corstone_300(args):
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010067 if not args.arch or args.arch == 'ethos-u55':
68 fvp = 'FVP_Corstone_SSE-300_Ethos-U55'
69 elif args.arch == 'ethos-u65':
70 fvp = 'FVP_Corstone_SSE-300_Ethos-U65'
71 else:
72 raise 'Unsupported NPU arch'
73
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010074 # Verify supported FVP version
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010075 version = subprocess.check_output([fvp, '--version']).decode()
Rickard Bolin54350d62021-10-18 15:33:18 +000076 supported_version = ['11.13', '11.14', '11.15', '11.16']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010077
78 if not [s for s in supported_version if s in version]:
79 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
80
81 # FVP executable
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010082 cmd = [fvp]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010083
84 # NPU configuration
85 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
86
87 # Output parameters
88 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
89 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
90 '-C', 'mps3_board.uart0.out_file="-"',
91 '-C', 'mps3_board.uart0.unbuffered_output=1',
Jonny Svärd2faaf402021-04-20 10:49:57 +020092 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010093
Per Åstrand9de1b742022-02-03 19:35:35 +010094 if args.tarmac:
95 try:
96 pvlib_home = Path(os.getenv('PVLIB_HOME'))
97 except:
98 raise Exception("Environment variable PVLIB_HOME not found. Needed to produce tarmac trace.")
99
100 if sys.platform == 'linux':
101 tarmac_trace_plugin = pvlib_home / Path('plugins/Linux64_GCC-7.3/TarmacTrace.so')
102 else:
103 raise Exception("tarmac trace: This feature is not currently supported on" + sys.platform)
104
105 if tarmac_trace_plugin.exists():
106 print("Tarmac trace will be created");
107 basename = [ e for e in args.args if e.endswith('.elf')][0][:-4]
108 cmd += ['--plugin', str(tarmac_trace_plugin)]
109 cmd += ['-C', f'TRACE.TarmacTrace.trace-file={basename}.trace']
110 else:
111 raise Exception("tarmac trace: Can't find TarmacTrace plugin in " + pvlib_home)
112
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100113 cmd += args.args
114
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100115 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100116
Kristofer Jonsson93175812022-04-21 19:27:11 +0200117def run_corstone_310(args):
118 # Verify supported FVP version
Kristofer Jonssonde1a9f62022-08-03 15:51:08 +0200119 version = subprocess.check_output(['FVP_Corstone_SSE-310_Ethos-U65', '--version']).decode()
120 supported_version = ['11.18']
Kristofer Jonsson93175812022-04-21 19:27:11 +0200121
122 if not [s for s in supported_version if s in version]:
123 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
124
125 # FVP executable
Kristofer Jonssonde1a9f62022-08-03 15:51:08 +0200126 cmd = ['FVP_Corstone_SSE-310_Ethos-U65']
Kristofer Jonsson93175812022-04-21 19:27:11 +0200127
128 # NPU configuration
129 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
130
131 # Output parameters
132 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
133 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
134 '-C', 'mps3_board.uart0.out_file="-"',
135 '-C', 'mps3_board.uart0.unbuffered_output=1',
136 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
137
138 cmd += args.args
139
140 return run_fvp(cmd)
141
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100142def run_corstone_polaris(args):
143 # Verify supported FVP version
144 version = subprocess.check_output(['FVP_Corstone-Polaris', '--version']).decode()
145 supported_version = ['11.16']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100146
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100147 if not [s for s in supported_version if s in version]:
148 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100149
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100150 # FVP executable
151 cmd = ['FVP_Corstone-Polaris']
152
153 # NPU configuration
154 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
155
156 # 32kB ITCM, 32kB DTCM, 2MB SRAM
157 cmd += ['-C', 'cpu0.CFGITCMSZ=6',
158 '-C', 'cpu0.CFGDTCMSZ=6',
159 '-C', 'mps3_board.sse300.NUMVMBANK=1',
160 '-C', 'mps3_board.sse300.VM_BANK_SIZE=2048']
161
162 # Output parameters
163 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
164 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
165 '-C', 'mps3_board.uart0.out_file="-"',
166 '-C', 'mps3_board.uart0.unbuffered_output=1',
167 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
168
169 cmd += args.args
170
171 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100172
173if __name__ == '__main__':
174 parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.')
Kristofer Jonsson93175812022-04-21 19:27:11 +0200175 parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-310', 'corstone-polaris'], required=True, help='FVP target.')
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +0100176 parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.')
Kristofer Jonsson3eaabb42022-02-07 16:39:11 +0100177 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 +0100178 parser.add_argument('-c', '--tarmac', dest='tarmac', action='store_true', help='Collect tarmac traces when running FVP.')
179
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100180 parser.add_argument('args', nargs='+', help='Arguments.')
181 args = parser.parse_args()
182
183 if args.target == 'corstone-300':
184 sys.exit(run_corstone_300(args))
Kristofer Jonsson93175812022-04-21 19:27:11 +0200185 elif args.target == 'corstone-310':
186 sys.exit(run_corstone_310(args))
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100187 elif args.target == 'corstone-polaris':
188 sys.exit(run_corstone_polaris(args))