Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 4 | # Copyright (c) 2021-2022 Arm Limited. All rights reserved. |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 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 | |
| 21 | import argparse |
| 22 | import subprocess |
| 23 | import sys |
Per Åstrand | 9de1b74 | 2022-02-03 19:35:35 +0100 | [diff] [blame] | 24 | import os |
| 25 | from pathlib import Path |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 26 | |
| 27 | def __print_arguments(args): |
| 28 | if isinstance(args, list): |
| 29 | print("$ " + " ".join(args)) |
| 30 | else: |
| 31 | print(args) |
| 32 | |
| 33 | def Popen(args, **kwargs): |
| 34 | __print_arguments(args) |
| 35 | return subprocess.Popen(args, **kwargs) |
| 36 | |
| 37 | def call(args, **kwargs): |
| 38 | __print_arguments(args) |
| 39 | return subprocess.call(args, **kwargs) |
| 40 | |
| 41 | def check_call(args, **kwargs): |
| 42 | __print_arguments(args) |
| 43 | return subprocess.check_call(args, **kwargs) |
| 44 | |
| 45 | def check_output(args, **kwargs): |
| 46 | __print_arguments(args) |
| 47 | return subprocess.check_output(args, **kwargs) |
| 48 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 49 | def 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 66 | def run_corstone_300(args): |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 67 | 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 74 | # Verify supported FVP version |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 75 | version = subprocess.check_output([fvp, '--version']).decode() |
Rickard Bolin | 54350d6 | 2021-10-18 15:33:18 +0000 | [diff] [blame] | 76 | supported_version = ['11.13', '11.14', '11.15', '11.16'] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 77 | |
| 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 Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 82 | cmd = [fvp] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 83 | |
| 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ärd | 2faaf40 | 2021-04-20 10:49:57 +0200 | [diff] [blame] | 92 | '-C', 'mps3_board.uart0.shutdown_on_eot=1'] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 93 | |
Per Åstrand | 9de1b74 | 2022-02-03 19:35:35 +0100 | [diff] [blame] | 94 | 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 113 | cmd += args.args |
| 114 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 115 | return run_fvp(cmd) |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 116 | |
Kristofer Jonsson | 9317581 | 2022-04-21 19:27:11 +0200 | [diff] [blame] | 117 | def run_corstone_310(args): |
| 118 | # Verify supported FVP version |
Davide Grohmann | 7275f50 | 2022-08-09 14:32:52 +0200 | [diff] [blame] | 119 | version = subprocess.check_output(['FVP_Corstone_SSE-310', '--version']).decode() |
| 120 | supported_version = ['11.17'] |
Kristofer Jonsson | 9317581 | 2022-04-21 19:27:11 +0200 | [diff] [blame] | 121 | |
| 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 |
Davide Grohmann | 7275f50 | 2022-08-09 14:32:52 +0200 | [diff] [blame] | 126 | cmd = ['FVP_Corstone_SSE-310'] |
Kristofer Jonsson | 9317581 | 2022-04-21 19:27:11 +0200 | [diff] [blame] | 127 | |
| 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 Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 142 | def 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 146 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 147 | 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 149 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 150 | # 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 172 | |
| 173 | if __name__ == '__main__': |
| 174 | parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.') |
Kristofer Jonsson | 9317581 | 2022-04-21 19:27:11 +0200 | [diff] [blame] | 175 | parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-310', 'corstone-polaris'], required=True, help='FVP target.') |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 176 | parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.') |
Kristofer Jonsson | 3eaabb4 | 2022-02-07 16:39:11 +0100 | [diff] [blame] | 177 | parser.add_argument('-m', '--macs', type=int, choices=[32, 64, 128, 256, 512], default=128, help='NPU number of MACs.') |
Per Åstrand | 9de1b74 | 2022-02-03 19:35:35 +0100 | [diff] [blame] | 178 | parser.add_argument('-c', '--tarmac', dest='tarmac', action='store_true', help='Collect tarmac traces when running FVP.') |
| 179 | |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 180 | 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 Jonsson | 9317581 | 2022-04-21 19:27:11 +0200 | [diff] [blame] | 185 | elif args.target == 'corstone-310': |
| 186 | sys.exit(run_corstone_310(args)) |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame] | 187 | elif args.target == 'corstone-polaris': |
| 188 | sys.exit(run_corstone_polaris(args)) |