blob: cc02226e9a1192c8e2f5e6a5d4deed213b736e41 [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
24
25def __print_arguments(args):
26 if isinstance(args, list):
27 print("$ " + " ".join(args))
28 else:
29 print(args)
30
31def Popen(args, **kwargs):
32 __print_arguments(args)
33 return subprocess.Popen(args, **kwargs)
34
35def call(args, **kwargs):
36 __print_arguments(args)
37 return subprocess.call(args, **kwargs)
38
39def check_call(args, **kwargs):
40 __print_arguments(args)
41 return subprocess.check_call(args, **kwargs)
42
43def check_output(args, **kwargs):
44 __print_arguments(args)
45 return subprocess.check_output(args, **kwargs)
46
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +010047def run_fvp(cmd):
48 # Run FVP and tee output to console while scanning for exit tag
49 ret = 1
50 proc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
51 while True:
52 line = proc.stdout.readline().decode()
53 if not line:
54 break
55
56 if 'Application exit code: 0.' in line:
57 ret = 0
58
59 sys.stdout.write(line)
60 sys.stdout.flush()
61
62 return ret
63
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010064def run_corstone_300(args):
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010065 if not args.arch or args.arch == 'ethos-u55':
66 fvp = 'FVP_Corstone_SSE-300_Ethos-U55'
67 elif args.arch == 'ethos-u65':
68 fvp = 'FVP_Corstone_SSE-300_Ethos-U65'
69 else:
70 raise 'Unsupported NPU arch'
71
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010072 # Verify supported FVP version
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010073 version = subprocess.check_output([fvp, '--version']).decode()
Rickard Bolin54350d62021-10-18 15:33:18 +000074 supported_version = ['11.13', '11.14', '11.15', '11.16']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010075
76 if not [s for s in supported_version if s in version]:
77 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
78
79 # FVP executable
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +010080 cmd = [fvp]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010081
82 # NPU configuration
83 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
84
85 # Output parameters
86 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
87 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
88 '-C', 'mps3_board.uart0.out_file="-"',
89 '-C', 'mps3_board.uart0.unbuffered_output=1',
Jonny Svärd2faaf402021-04-20 10:49:57 +020090 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010091
92 cmd += args.args
93
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +010094 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010095
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +010096def run_corstone_polaris(args):
97 # Verify supported FVP version
98 version = subprocess.check_output(['FVP_Corstone-Polaris', '--version']).decode()
99 supported_version = ['11.16']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100100
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100101 if not [s for s in supported_version if s in version]:
102 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100103
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100104 # FVP executable
105 cmd = ['FVP_Corstone-Polaris']
106
107 # NPU configuration
108 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
109
110 # 32kB ITCM, 32kB DTCM, 2MB SRAM
111 cmd += ['-C', 'cpu0.CFGITCMSZ=6',
112 '-C', 'cpu0.CFGDTCMSZ=6',
113 '-C', 'mps3_board.sse300.NUMVMBANK=1',
114 '-C', 'mps3_board.sse300.VM_BANK_SIZE=2048']
115
116 # Output parameters
117 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
118 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
119 '-C', 'mps3_board.uart0.out_file="-"',
120 '-C', 'mps3_board.uart0.unbuffered_output=1',
121 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
122
123 cmd += args.args
124
125 return run_fvp(cmd)
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100126
127if __name__ == '__main__':
128 parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.')
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100129 parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-polaris'], required=True, help='FVP target.')
Kristofer Jonssonf7edeb72022-01-17 09:40:09 +0100130 parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.')
Kristofer Jonsson715c07b2021-02-25 09:49:34 +0100131 parser.add_argument('-m', '--macs', type=int, choices=[32, 64, 128, 256], default=128, help='NPU number of MACs.')
132 parser.add_argument('args', nargs='+', help='Arguments.')
133 args = parser.parse_args()
134
135 if args.target == 'corstone-300':
136 sys.exit(run_corstone_300(args))
Kristofer Jonsson6e9fdc02022-01-14 16:38:17 +0100137 elif args.target == 'corstone-polaris':
138 sys.exit(run_corstone_polaris(args))