aboutsummaryrefslogtreecommitdiff
path: root/scripts/run_ctest.py
blob: 1faf0e2d7d83280f5874fae11680e9001d0bc678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3

#
# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import argparse
import subprocess
import sys

def __print_arguments(args):
    if isinstance(args, list):
        print("$ " + " ".join(args))
    else:
        print(args)

def Popen(args, **kwargs):
    __print_arguments(args)
    return subprocess.Popen(args, **kwargs)

def call(args, **kwargs):
    __print_arguments(args)
    return subprocess.call(args, **kwargs)

def check_call(args, **kwargs):
    __print_arguments(args)
    return subprocess.check_call(args, **kwargs)

def check_output(args, **kwargs):
    __print_arguments(args)
    return subprocess.check_output(args, **kwargs)

def run_fvp(cmd):
    # Run FVP and tee output to console while scanning for exit tag
    ret = 1
    proc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    while True:
        line = proc.stdout.readline().decode()
        if not line:
                break

        if 'Application exit code: 0.' in line:
            ret = 0

        sys.stdout.write(line)
        sys.stdout.flush()

    return ret

def run_corstone_300(args):
    if not args.arch or args.arch == 'ethos-u55':
        fvp = 'FVP_Corstone_SSE-300_Ethos-U55'
    elif args.arch == 'ethos-u65':
        fvp = 'FVP_Corstone_SSE-300_Ethos-U65'
    else:
        raise 'Unsupported NPU arch'

    # Verify supported FVP version
    version = subprocess.check_output([fvp, '--version']).decode()
    supported_version = ['11.13', '11.14', '11.15', '11.16']

    if not [s for s in supported_version if s in version]:
        raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))

    # FVP executable
    cmd = [fvp]

    # NPU configuration
    cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]

    # Output parameters
    cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
            '-C', 'mps3_board.telnetterminal0.start_telnet=0',
            '-C', 'mps3_board.uart0.out_file="-"',
            '-C', 'mps3_board.uart0.unbuffered_output=1',
            '-C', 'mps3_board.uart0.shutdown_on_eot=1']

    cmd += args.args

    return run_fvp(cmd)

def run_corstone_polaris(args):
    # Verify supported FVP version
    version = subprocess.check_output(['FVP_Corstone-Polaris', '--version']).decode()
    supported_version = ['11.16']

    if not [s for s in supported_version if s in version]:
        raise Exception("Incorrect FVP version. Supported versions are '{}'.".format(supported_version))

    # FVP executable
    cmd = ['FVP_Corstone-Polaris']

    # NPU configuration
    cmd += ['-C', 'ethosu.num_macs=' + str(args.macs)]

    # 32kB ITCM, 32kB DTCM, 2MB SRAM
    cmd += ['-C', 'cpu0.CFGITCMSZ=6',
            '-C', 'cpu0.CFGDTCMSZ=6',
            '-C', 'mps3_board.sse300.NUMVMBANK=1',
            '-C', 'mps3_board.sse300.VM_BANK_SIZE=2048']

    # Output parameters
    cmd += ['-C', 'mps3_board.visualisation.disable-visualisation=1',
            '-C', 'mps3_board.telnetterminal0.start_telnet=0',
            '-C', 'mps3_board.uart0.out_file="-"',
            '-C', 'mps3_board.uart0.unbuffered_output=1',
            '-C', 'mps3_board.uart0.shutdown_on_eot=1']

    cmd += args.args

    return run_fvp(cmd)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Run a test with given test command and test binary.')
    parser.add_argument('-t', '--target', choices=['corstone-300', 'corstone-polaris'], required=True, help='FVP target.')
    parser.add_argument('-a', '--arch', choices=['ethos-u55', 'ethos-u65'], help='NPU architecture.')
    parser.add_argument('-m', '--macs', type=int, choices=[32, 64, 128, 256, 512], default=128, help='NPU number of MACs.')
    parser.add_argument('args', nargs='+', help='Arguments.')
    args = parser.parse_args()

    if args.target == 'corstone-300':
        sys.exit(run_corstone_300(args))
    elif args.target == 'corstone-polaris':
        sys.exit(run_corstone_polaris(args))