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 |
| 24 | |
| 25 | def __print_arguments(args): |
| 26 | if isinstance(args, list): |
| 27 | print("$ " + " ".join(args)) |
| 28 | else: |
| 29 | print(args) |
| 30 | |
| 31 | def Popen(args, **kwargs): |
| 32 | __print_arguments(args) |
| 33 | return subprocess.Popen(args, **kwargs) |
| 34 | |
| 35 | def call(args, **kwargs): |
| 36 | __print_arguments(args) |
| 37 | return subprocess.call(args, **kwargs) |
| 38 | |
| 39 | def check_call(args, **kwargs): |
| 40 | __print_arguments(args) |
| 41 | return subprocess.check_call(args, **kwargs) |
| 42 | |
| 43 | def check_output(args, **kwargs): |
| 44 | __print_arguments(args) |
| 45 | return subprocess.check_output(args, **kwargs) |
| 46 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 47 | def 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 64 | def run_corstone_300(args): |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 65 | 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 72 | # Verify supported FVP version |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 73 | version = subprocess.check_output([fvp, '--version']).decode() |
Rickard Bolin | 54350d6 | 2021-10-18 15:33:18 +0000 | [diff] [blame] | 74 | supported_version = ['11.13', '11.14', '11.15', '11.16'] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 75 | |
| 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 Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 80 | cmd = [fvp] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 81 | |
| 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ärd | 2faaf40 | 2021-04-20 10:49:57 +0200 | [diff] [blame] | 90 | '-C', 'mps3_board.uart0.shutdown_on_eot=1'] |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 91 | |
| 92 | cmd += args.args |
| 93 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 94 | return run_fvp(cmd) |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 95 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 96 | def 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 100 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 101 | 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 103 | |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 104 | # 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 Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 126 | |
| 127 | if __name__ == '__main__': |
| 128 | parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.') |
Kristofer Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 129 | parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-polaris'], required=True, help='FVP target.') |
Kristofer Jonsson | f7edeb7 | 2022-01-17 09:40:09 +0100 | [diff] [blame] | 130 | parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.') |
Kristofer Jonsson | 715c07b | 2021-02-25 09:49:34 +0100 | [diff] [blame] | 131 | 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 Jonsson | 6e9fdc0 | 2022-01-14 16:38:17 +0100 | [diff] [blame^] | 137 | elif args.target == 'corstone-polaris': |
| 138 | sys.exit(run_corstone_polaris(args)) |