blob: 10d389c33cfb45176edf6bbc647c8ec16def162a [file] [log] [blame]
Kristofer Jonsson715c07b2021-02-25 09:49:34 +01001#!/usr/bin/env python3
2
3#
4# Copyright (c) 2021 Arm Limited. All rights reserved.
5#
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
47def run_corstone_300(args):
48 # Verify supported FVP version
49 version = subprocess.check_output(['FVP_Corstone_SSE-300_Ethos-U55', '--version']).decode()
Jonny Svärd2faaf402021-04-20 10:49:57 +020050 supported_version = ['11.13', '11.14']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010051
52 if not [s for s in supported_version if s in version]:
53 raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))
54
55 # FVP executable
56 cmd = ['FVP_Corstone_SSE-300_Ethos-U55']
57
58 # NPU configuration
59 cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]
60
61 # Output parameters
62 cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
63 '-C', 'mps3_board.telnetterminal0.start_telnet=0',
64 '-C', 'mps3_board.uart0.out_file="-"',
65 '-C', 'mps3_board.uart0.unbuffered_output=1',
Jonny Svärd2faaf402021-04-20 10:49:57 +020066 '-C', 'mps3_board.uart0.shutdown_on_eot=1']
Kristofer Jonsson715c07b2021-02-25 09:49:34 +010067
68 cmd += args.args
69
70 # Run FVP and tee output to console while scanning for exit tag
71 ret = 1
72 proc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
73 while True:
74 line = proc.stdout.readline().decode()
75 if not line:
76 break
77
78 if 'Application exit code: 0.' in line:
79 ret = 0
80
81 sys.stdout.write(line)
82 sys.stdout.flush()
83
84 return ret
85
86if __name__ == '__main__':
87 parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.')
88 parser.add_argument('-t', '--target', choices=['corstone-300'], required=True, help='FVP target.')
89 parser.add_argument('-a', '--arch', choices=['ethos-u55'], default='ethos-u55', help='NPU architecture.')
90 parser.add_argument('-m', '--macs', type=int, choices=[32, 64, 128, 256], default=128, help='NPU number of MACs.')
91 parser.add_argument('args', nargs='+', help='Arguments.')
92 args = parser.parse_args()
93
94 if args.target == 'corstone-300':
95 sys.exit(run_corstone_300(args))