David Brazdil | ee5e25d | 2020-01-24 14:17:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 2 | # |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 3 | # Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 4 | # |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 5 | # Use of this source code is governed by a BSD-style |
| 6 | # license that can be found in the LICENSE file or at |
| 7 | # https://opensource.org/licenses/BSD-3-Clause. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 8 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 9 | """Script which drives invocation of tests and parsing their output to produce |
| 10 | a results report. |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 11 | """ |
| 12 | |
| 13 | from __future__ import print_function |
| 14 | |
Andrew Scull | 3b62f2b | 2018-08-21 14:26:12 +0100 | [diff] [blame] | 15 | import xml.etree.ElementTree as ET |
| 16 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 17 | import argparse |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 18 | import collections |
Andrew Scull | 04502e4 | 2018-09-03 14:54:52 +0100 | [diff] [blame] | 19 | import datetime |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 20 | import importlib |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 21 | import json |
| 22 | import os |
| 23 | import re |
| 24 | import subprocess |
| 25 | import sys |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 26 | import time |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 27 | |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 28 | HFTEST_LOG_PREFIX = "[hftest] " |
| 29 | HFTEST_LOG_FAILURE_PREFIX = "Failure:" |
| 30 | HFTEST_LOG_FINISHED = "FINISHED" |
| 31 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 32 | HFTEST_CTRL_GET_COMMAND_LINE = "[hftest_ctrl:get_command_line]" |
| 33 | HFTEST_CTRL_FINISHED = "[hftest_ctrl:finished]" |
| 34 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 35 | HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname( |
| 36 | os.path.abspath(__file__)))) |
David Brazdil | 5715f04 | 2019-08-27 11:11:51 +0100 | [diff] [blame] | 37 | DTC_SCRIPT = os.path.join(HF_ROOT, "build", "image", "dtc.py") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 38 | FVP_BINARY = os.path.join( |
| 39 | os.path.dirname(HF_ROOT), "fvp", "Base_RevC_AEMv8A_pkg", "models", |
Olivier Deprez | e415304 | 2020-10-02 15:24:59 +0200 | [diff] [blame^] | 40 | "Linux64_GCC-6.4", "FVP_Base_RevC-2xAEMv8A") |
David Brazdil | 21204ae | 2019-10-30 19:22:38 +0000 | [diff] [blame] | 41 | FVP_PREBUILTS_ROOT = os.path.join( |
J-Alves | eabd899 | 2020-12-08 14:08:43 +0000 | [diff] [blame] | 42 | HF_ROOT, "prebuilts", "linux-aarch64", "trusted-firmware-a-trusty", "fvp") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 43 | FVP_PREBUILT_DTS = os.path.join( |
David Brazdil | 21204ae | 2019-10-30 19:22:38 +0000 | [diff] [blame] | 44 | FVP_PREBUILTS_ROOT, "fvp-base-gicv3-psci-1t.dts") |
| 45 | FVP_PREBUILT_BL31 = os.path.join(FVP_PREBUILTS_ROOT, "bl31.bin") |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 46 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 47 | def read_file(path): |
| 48 | with open(path, "r") as f: |
| 49 | return f.read() |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 50 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 51 | def write_file(path, to_write, append=False): |
| 52 | with open(path, "a" if append else "w") as f: |
| 53 | f.write(to_write) |
| 54 | |
| 55 | def append_file(path, to_write): |
| 56 | write_file(path, to_write, append=True) |
| 57 | |
| 58 | def join_if_not_None(*args): |
| 59 | return " ".join(filter(lambda x: x, args)) |
| 60 | |
| 61 | class ArtifactsManager: |
| 62 | """Class which manages folder with test artifacts.""" |
| 63 | |
| 64 | def __init__(self, log_dir): |
| 65 | self.created_files = [] |
| 66 | self.log_dir = log_dir |
| 67 | |
| 68 | # Create directory. |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 69 | try: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 70 | os.makedirs(self.log_dir) |
| 71 | except OSError: |
| 72 | if not os.path.isdir(self.log_dir): |
| 73 | raise |
| 74 | print("Logs saved under", log_dir) |
| 75 | |
| 76 | # Create files expected by the Sponge test result parser. |
| 77 | self.sponge_log_path = self.create_file("sponge_log", ".log") |
| 78 | self.sponge_xml_path = self.create_file("sponge_log", ".xml") |
| 79 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 80 | def gen_file_path(self, basename, extension): |
| 81 | """Generate path to a file in the log directory.""" |
| 82 | return os.path.join(self.log_dir, basename + extension) |
| 83 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 84 | def create_file(self, basename, extension): |
| 85 | """Create and touch a new file in the log folder. Ensure that no other |
| 86 | file of the same name was created by this instance of ArtifactsManager. |
| 87 | """ |
| 88 | # Determine the path of the file. |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 89 | path = self.gen_file_path(basename, extension) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 90 | |
| 91 | # Check that the path is unique. |
| 92 | assert(path not in self.created_files) |
| 93 | self.created_files += [ path ] |
| 94 | |
| 95 | # Touch file. |
| 96 | with open(path, "w") as f: |
| 97 | pass |
| 98 | |
| 99 | return path |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 100 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 101 | def get_file(self, basename, extension): |
| 102 | """Return path to a file in the log folder. Assert that it was created |
| 103 | by this instance of ArtifactsManager.""" |
| 104 | path = self.gen_file_path(basename, extension) |
| 105 | assert(path in self.created_files) |
| 106 | return path |
| 107 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 108 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 109 | # Tuple holding the arguments common to all driver constructors. |
| 110 | # This is to avoid having to pass arguments from subclasses to superclasses. |
| 111 | DriverArgs = collections.namedtuple("DriverArgs", [ |
| 112 | "artifacts", |
| 113 | "kernel", |
| 114 | "initrd", |
| 115 | "vm_args", |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 116 | "cpu", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 117 | ]) |
Marc Bonnici | 0a12563 | 2019-04-01 13:46:52 +0100 | [diff] [blame] | 118 | |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 119 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 120 | # State shared between the common Driver class and its subclasses during |
| 121 | # a single invocation of the target platform. |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 122 | class DriverRunState: |
| 123 | def __init__(self, log_path): |
| 124 | self.log_path = log_path |
| 125 | self.ret_code = 0 |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 126 | |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 127 | def set_ret_code(self, ret_code): |
| 128 | self.ret_code = ret_code |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 129 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 130 | class DriverRunException(Exception): |
| 131 | """Exception thrown if subprocess invoked by a driver returned non-zero |
| 132 | status code. Used to fast-exit from a driver command sequence.""" |
| 133 | pass |
| 134 | |
| 135 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 136 | class Driver: |
| 137 | """Parent class of drivers for all testable platforms.""" |
| 138 | |
| 139 | def __init__(self, args): |
| 140 | self.args = args |
| 141 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 142 | def get_run_log(self, run_name): |
| 143 | """Return path to the main log of a given test run.""" |
| 144 | return self.args.artifacts.get_file(run_name, ".log") |
| 145 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 146 | def start_run(self, run_name): |
| 147 | """Hook called by Driver subclasses before they invoke the target |
| 148 | platform.""" |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 149 | return DriverRunState(self.args.artifacts.create_file(run_name, ".log")) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 150 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 151 | def exec_logged(self, run_state, exec_args, cwd=None): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 152 | """Run a subprocess on behalf of a Driver subclass and append its |
| 153 | stdout and stderr to the main log.""" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 154 | assert(run_state.ret_code == 0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 155 | with open(run_state.log_path, "a") as f: |
| 156 | f.write("$ {}\r\n".format(" ".join(exec_args))) |
| 157 | f.flush() |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 158 | ret_code = subprocess.call(exec_args, stdout=f, stderr=f, cwd=cwd) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 159 | if ret_code != 0: |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 160 | run_state.set_ret_code(ret_code) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 161 | raise DriverRunException() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 162 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 163 | def finish_run(self, run_state): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 164 | """Hook called by Driver subclasses after they finished running the |
| 165 | target platform. `ret_code` argument is the return code of the main |
| 166 | command run by the driver. A corresponding log message is printed.""" |
| 167 | # Decode return code and add a message to the log. |
| 168 | with open(run_state.log_path, "a") as f: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 169 | if run_state.ret_code == 124: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 170 | f.write("\r\n{}{} timed out\r\n".format( |
| 171 | HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX)) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 172 | elif run_state.ret_code != 0: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 173 | f.write("\r\n{}{} process return code {}\r\n".format( |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 174 | HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX, |
| 175 | run_state.ret_code)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 176 | |
| 177 | # Append log of this run to full test log. |
| 178 | log_content = read_file(run_state.log_path) |
| 179 | append_file( |
| 180 | self.args.artifacts.sponge_log_path, |
| 181 | log_content + "\r\n\r\n") |
| 182 | return log_content |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 183 | |
| 184 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 185 | class QemuDriver(Driver): |
| 186 | """Driver which runs tests in QEMU.""" |
| 187 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 188 | def __init__(self, args, qemu_wd, tfa): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 189 | Driver.__init__(self, args) |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 190 | self.qemu_wd = qemu_wd |
| 191 | self.tfa = tfa |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 192 | |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 193 | def gen_exec_args(self, test_args, is_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 194 | """Generate command line arguments for QEMU.""" |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 195 | time_limit = "120s" if is_long_running else "10s" |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 196 | # If no CPU configuration is selected, then test against the maximum |
| 197 | # configuration, "max", supported by QEMU. |
| 198 | cpu = self.args.cpu or "max" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 199 | exec_args = [ |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 200 | "timeout", "--foreground", time_limit, |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 201 | os.path.abspath("prebuilts/linux-x64/qemu/qemu-system-aarch64"), |
Andrew Walbran | a081a29 | 2020-01-23 10:08:42 +0000 | [diff] [blame] | 202 | "-machine", "virt,virtualization=on,gic-version=3", |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 203 | "-cpu", cpu, "-smp", "4", "-m", "1G", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 204 | "-nographic", "-nodefaults", "-serial", "stdio", |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 205 | "-d", "unimp", "-kernel", os.path.abspath(self.args.kernel), |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 206 | ] |
| 207 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 208 | if self.tfa: |
| 209 | exec_args += ["-bios", |
| 210 | os.path.abspath( |
J-Alves | eabd899 | 2020-12-08 14:08:43 +0000 | [diff] [blame] | 211 | "prebuilts/linux-aarch64/trusted-firmware-a-trusty/qemu/bl1.bin" |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 212 | ), "-machine", "secure=on", "-semihosting-config", |
| 213 | "enable,target=native"] |
| 214 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 215 | if self.args.initrd: |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 216 | exec_args += ["-initrd", os.path.abspath(self.args.initrd)] |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 217 | |
| 218 | vm_args = join_if_not_None(self.args.vm_args, test_args) |
| 219 | if vm_args: |
| 220 | exec_args += ["-append", vm_args] |
| 221 | |
| 222 | return exec_args |
| 223 | |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 224 | def run(self, run_name, test_args, is_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 225 | """Run test given by `test_args` in QEMU.""" |
| 226 | run_state = self.start_run(run_name) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 227 | |
| 228 | try: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 229 | # Execute test in QEMU.. |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 230 | exec_args = self.gen_exec_args(test_args, is_long_running) |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 231 | self.exec_logged(run_state, exec_args, |
| 232 | cwd=self.qemu_wd) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 233 | except DriverRunException: |
| 234 | pass |
| 235 | |
| 236 | return self.finish_run(run_state) |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 237 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 238 | def finish(self): |
| 239 | """Clean up after running tests.""" |
| 240 | pass |
| 241 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 242 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 243 | class FvpDriver(Driver): |
Andrew Walbran | 2021574 | 2019-11-18 11:35:05 +0000 | [diff] [blame] | 244 | """Driver which runs tests in Arm FVP emulator.""" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 245 | |
| 246 | def __init__(self, args): |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 247 | if args.cpu: |
| 248 | raise ValueError("FVP emulator does not support the --cpu option.") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 249 | Driver.__init__(self, args) |
| 250 | |
| 251 | def gen_dts(self, dts_path, test_args, initrd_start, initrd_end): |
| 252 | """Create a DeviceTree source which will be compiled into a DTB and |
| 253 | passed to FVP for a test run.""" |
| 254 | vm_args = join_if_not_None(self.args.vm_args, test_args) |
| 255 | write_file(dts_path, read_file(FVP_PREBUILT_DTS)) |
| 256 | append_file(dts_path, """ |
| 257 | / {{ |
| 258 | chosen {{ |
| 259 | bootargs = "{}"; |
| 260 | stdout-path = "serial0:115200n8"; |
| 261 | linux,initrd-start = <{}>; |
| 262 | linux,initrd-end = <{}>; |
| 263 | }}; |
| 264 | }}; |
| 265 | """.format(vm_args, initrd_start, initrd_end)) |
| 266 | |
| 267 | def gen_fvp_args( |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 268 | self, is_long_running, initrd_start, uart0_log_path, uart1_log_path, |
| 269 | dtb_path): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 270 | """Generate command line arguments for FVP.""" |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 271 | time_limit = "80s" if is_long_running else "40s" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 272 | fvp_args = [ |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 273 | "timeout", "--foreground", time_limit, |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 274 | FVP_BINARY, |
| 275 | "-C", "pctl.startup=0.0.0.0", |
| 276 | "-C", "bp.secure_memory=0", |
| 277 | "-C", "cluster0.NUM_CORES=4", |
| 278 | "-C", "cluster1.NUM_CORES=4", |
| 279 | "-C", "cache_state_modelled=0", |
| 280 | "-C", "bp.vis.disable_visualisation=true", |
| 281 | "-C", "bp.vis.rate_limit-enable=false", |
| 282 | "-C", "bp.terminal_0.start_telnet=false", |
| 283 | "-C", "bp.terminal_1.start_telnet=false", |
| 284 | "-C", "bp.terminal_2.start_telnet=false", |
| 285 | "-C", "bp.terminal_3.start_telnet=false", |
| 286 | "-C", "bp.pl011_uart0.untimed_fifos=1", |
| 287 | "-C", "bp.pl011_uart0.unbuffered_output=1", |
| 288 | "-C", "bp.pl011_uart0.out_file=" + uart0_log_path, |
| 289 | "-C", "bp.pl011_uart1.out_file=" + uart1_log_path, |
| 290 | "-C", "cluster0.cpu0.RVBAR=0x04020000", |
| 291 | "-C", "cluster0.cpu1.RVBAR=0x04020000", |
| 292 | "-C", "cluster0.cpu2.RVBAR=0x04020000", |
| 293 | "-C", "cluster0.cpu3.RVBAR=0x04020000", |
| 294 | "-C", "cluster1.cpu0.RVBAR=0x04020000", |
| 295 | "-C", "cluster1.cpu1.RVBAR=0x04020000", |
| 296 | "-C", "cluster1.cpu2.RVBAR=0x04020000", |
| 297 | "-C", "cluster1.cpu3.RVBAR=0x04020000", |
David Brazdil | 21204ae | 2019-10-30 19:22:38 +0000 | [diff] [blame] | 298 | "--data", "cluster0.cpu0=" + FVP_PREBUILT_BL31 + "@0x04020000", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 299 | "--data", "cluster0.cpu0=" + dtb_path + "@0x82000000", |
| 300 | "--data", "cluster0.cpu0=" + self.args.kernel + "@0x80000000", |
| 301 | "-C", "bp.ve_sysregs.mmbSiteDefault=0", |
| 302 | "-C", "bp.ve_sysregs.exit_on_shutdown=1", |
| 303 | ] |
| 304 | |
| 305 | if self.args.initrd: |
| 306 | fvp_args += [ |
| 307 | "--data", |
| 308 | "cluster0.cpu0={}@{}".format( |
| 309 | self.args.initrd, hex(initrd_start)) |
| 310 | ] |
| 311 | |
| 312 | return fvp_args |
| 313 | |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 314 | def run(self, run_name, test_args, is_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 315 | run_state = self.start_run(run_name) |
| 316 | |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 317 | dts_path = self.args.artifacts.create_file(run_name, ".dts") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 318 | dtb_path = self.args.artifacts.create_file(run_name, ".dtb") |
| 319 | uart0_log_path = self.args.artifacts.create_file(run_name, ".uart0.log") |
| 320 | uart1_log_path = self.args.artifacts.create_file(run_name, ".uart1.log") |
| 321 | |
| 322 | initrd_start = 0x84000000 |
| 323 | if self.args.initrd: |
| 324 | initrd_end = initrd_start + os.path.getsize(self.args.initrd) |
| 325 | else: |
| 326 | initrd_end = 0x85000000 # Default value |
| 327 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 328 | try: |
| 329 | # Create a DT to pass to FVP. |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 330 | self.gen_dts(dts_path, test_args, initrd_start, initrd_end) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 331 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 332 | # Compile DTS to DTB. |
| 333 | dtc_args = [ |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 334 | DTC_SCRIPT, "compile", "-i", dts_path, "-o", dtb_path, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 335 | ] |
| 336 | self.exec_logged(run_state, dtc_args) |
| 337 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 338 | # Run FVP. |
| 339 | fvp_args = self.gen_fvp_args( |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 340 | is_long_running, initrd_start, uart0_log_path, uart1_log_path, |
| 341 | dtb_path) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 342 | self.exec_logged(run_state, fvp_args) |
| 343 | except DriverRunException: |
| 344 | pass |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 345 | |
| 346 | # Append UART0 output to main log. |
| 347 | append_file(run_state.log_path, read_file(uart0_log_path)) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 348 | return self.finish_run(run_state) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 349 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 350 | def finish(self): |
| 351 | """Clean up after running tests.""" |
| 352 | pass |
| 353 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 354 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 355 | class SerialDriver(Driver): |
| 356 | """Driver which communicates with a device over the serial port.""" |
| 357 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 358 | def __init__(self, args, tty_file, baudrate, init_wait): |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 359 | Driver.__init__(self, args) |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 360 | self.tty_file = tty_file |
| 361 | self.baudrate = baudrate |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 362 | self.pyserial = importlib.import_module("serial") |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 363 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 364 | if init_wait: |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 365 | input("Press ENTER and then reset the device...") |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 366 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 367 | def connect(self): |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 368 | return self.pyserial.Serial(self.tty_file, self.baudrate, timeout=10) |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 369 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 370 | def run(self, run_name, test_args, is_long_running): |
| 371 | """Communicate `test_args` to the device over the serial port.""" |
| 372 | run_state = self.start_run(run_name) |
| 373 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 374 | with self.connect() as ser: |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 375 | with open(run_state.log_path, "a") as f: |
| 376 | while True: |
| 377 | # Read one line from the serial port. |
| 378 | line = ser.readline().decode('utf-8') |
| 379 | if len(line) == 0: |
| 380 | # Timeout |
| 381 | run_state.set_ret_code(124) |
| 382 | input("Timeout. " + |
| 383 | "Press ENTER and then reset the device...") |
| 384 | break |
| 385 | # Write the line to the log file. |
| 386 | f.write(line) |
| 387 | if HFTEST_CTRL_GET_COMMAND_LINE in line: |
| 388 | # Device is waiting for `test_args`. |
| 389 | ser.write(test_args.encode('ascii')) |
| 390 | ser.write(b'\r') |
| 391 | elif HFTEST_CTRL_FINISHED in line: |
| 392 | # Device has finished running this test and will reboot. |
| 393 | break |
| 394 | return self.finish_run(run_state) |
| 395 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 396 | def finish(self): |
| 397 | """Clean up after running tests.""" |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 398 | with self.connect() as ser: |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 399 | while True: |
| 400 | line = ser.readline().decode('utf-8') |
| 401 | if len(line) == 0: |
| 402 | input("Timeout. Press ENTER and then reset the device...") |
| 403 | elif HFTEST_CTRL_GET_COMMAND_LINE in line: |
| 404 | # Device is waiting for a command. Instruct it to exit |
| 405 | # the test environment. |
| 406 | ser.write("exit".encode('ascii')) |
| 407 | ser.write(b'\r') |
| 408 | break |
| 409 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 410 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 411 | # Tuple used to return information about the results of running a set of tests. |
| 412 | TestRunnerResult = collections.namedtuple("TestRunnerResult", [ |
| 413 | "tests_run", |
| 414 | "tests_failed", |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 415 | "tests_skipped", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 416 | ]) |
| 417 | |
| 418 | |
| 419 | class TestRunner: |
| 420 | """Class which communicates with a test platform to obtain a list of |
| 421 | available tests and driving their execution.""" |
| 422 | |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 423 | def __init__(self, artifacts, driver, image_name, suite_regex, test_regex, |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 424 | skip_long_running_tests, force_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 425 | self.artifacts = artifacts |
| 426 | self.driver = driver |
| 427 | self.image_name = image_name |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 428 | self.skip_long_running_tests = skip_long_running_tests |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 429 | self.force_long_running = force_long_running |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 430 | |
| 431 | self.suite_re = re.compile(suite_regex or ".*") |
| 432 | self.test_re = re.compile(test_regex or ".*") |
| 433 | |
| 434 | def extract_hftest_lines(self, raw): |
| 435 | """Extract hftest-specific lines from a raw output from an invocation |
| 436 | of the test platform.""" |
| 437 | lines = [] |
| 438 | for line in raw.splitlines(): |
| 439 | if line.startswith("VM "): |
| 440 | line = line[len("VM 0: "):] |
| 441 | if line.startswith(HFTEST_LOG_PREFIX): |
| 442 | lines.append(line[len(HFTEST_LOG_PREFIX):]) |
| 443 | return lines |
| 444 | |
| 445 | def get_test_json(self): |
| 446 | """Invoke the test platform and request a JSON of available test and |
| 447 | test suites.""" |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 448 | out = self.driver.run("json", "json", self.force_long_running) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 449 | hf_out = "\n".join(self.extract_hftest_lines(out)) |
| 450 | try: |
| 451 | return json.loads(hf_out) |
| 452 | except ValueError as e: |
| 453 | print(out) |
| 454 | raise e |
| 455 | |
| 456 | def collect_results(self, fn, it, xml_node): |
| 457 | """Run `fn` on every entry in `it` and collect their TestRunnerResults. |
| 458 | Insert "tests" and "failures" nodes to `xml_node`.""" |
| 459 | tests_run = 0 |
| 460 | tests_failed = 0 |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 461 | tests_skipped = 0 |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 462 | start_time = time.perf_counter() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 463 | for i in it: |
| 464 | sub_result = fn(i) |
| 465 | assert(sub_result.tests_run >= sub_result.tests_failed) |
| 466 | tests_run += sub_result.tests_run |
| 467 | tests_failed += sub_result.tests_failed |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 468 | tests_skipped += sub_result.tests_skipped |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 469 | elapsed_time = time.perf_counter() - start_time |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 470 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 471 | xml_node.set("tests", str(tests_run + tests_skipped)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 472 | xml_node.set("failures", str(tests_failed)) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 473 | xml_node.set("skipped", str(tests_skipped)) |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 474 | xml_node.set("time", str(elapsed_time)) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 475 | return TestRunnerResult(tests_run, tests_failed, tests_skipped) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 476 | |
| 477 | def is_passed_test(self, test_out): |
| 478 | """Parse the output of a test and return True if it passed.""" |
| 479 | return \ |
| 480 | len(test_out) > 0 and \ |
| 481 | test_out[-1] == HFTEST_LOG_FINISHED and \ |
| 482 | not any(l.startswith(HFTEST_LOG_FAILURE_PREFIX) for l in test_out) |
| 483 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 484 | def get_failure_message(self, test_out): |
| 485 | """Parse the output of a test and return the message of the first |
| 486 | assertion failure.""" |
| 487 | for i, line in enumerate(test_out): |
| 488 | if line.startswith(HFTEST_LOG_FAILURE_PREFIX) and i + 1 < len(test_out): |
| 489 | # The assertion message is on the line after the 'Failure:' |
| 490 | return test_out[i + 1].strip() |
| 491 | |
| 492 | return None |
| 493 | |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 494 | def get_log_name(self, suite, test): |
| 495 | """Returns a string with a generated log name for the test.""" |
| 496 | log_name = "" |
| 497 | |
| 498 | cpu = self.driver.args.cpu |
| 499 | if cpu: |
| 500 | log_name += cpu + "." |
| 501 | |
| 502 | log_name += suite["name"] + "." + test["name"] |
| 503 | |
| 504 | return log_name |
| 505 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 506 | def run_test(self, suite, test, suite_xml): |
| 507 | """Invoke the test platform and request to run a given `test` in given |
| 508 | `suite`. Create a new XML node with results under `suite_xml`. |
| 509 | Test only invoked if it matches the regex given to constructor.""" |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 510 | if not self.test_re.match(test["name"]): |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 511 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 512 | |
| 513 | test_xml = ET.SubElement(suite_xml, "testcase") |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 514 | test_xml.set("name", test["name"]) |
| 515 | test_xml.set("classname", suite["name"]) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 516 | |
| 517 | if self.skip_long_running_tests and test["is_long_running"]: |
| 518 | print(" SKIP", test["name"]) |
| 519 | test_xml.set("status", "notrun") |
| 520 | skipped_xml = ET.SubElement(test_xml, "skipped") |
| 521 | skipped_xml.set("message", "Long running") |
| 522 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=1) |
| 523 | |
| 524 | print(" RUN", test["name"]) |
| 525 | log_name = self.get_log_name(suite, test) |
| 526 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 527 | test_xml.set("status", "run") |
| 528 | |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 529 | start_time = time.perf_counter() |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 530 | out = self.driver.run( |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 531 | log_name, "run {} {}".format(suite["name"], test["name"]), |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 532 | test["is_long_running"] or self.force_long_running) |
| 533 | hftest_out = self.extract_hftest_lines(out) |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 534 | elapsed_time = time.perf_counter() - start_time |
| 535 | |
| 536 | test_xml.set("time", str(elapsed_time)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 537 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 538 | system_out_xml = ET.SubElement(test_xml, "system-out") |
| 539 | system_out_xml.text = out |
| 540 | |
| 541 | if self.is_passed_test(hftest_out): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 542 | print(" PASS") |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 543 | return TestRunnerResult(tests_run=1, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 544 | else: |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 545 | print("[x] FAIL --", self.driver.get_run_log(log_name)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 546 | failure_xml = ET.SubElement(test_xml, "failure") |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 547 | failure_message = self.get_failure_message(hftest_out) or "Test failed" |
| 548 | failure_xml.set("message", failure_message) |
| 549 | failure_xml.text = '\n'.join(hftest_out) |
| 550 | return TestRunnerResult(tests_run=1, tests_failed=1, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 551 | |
| 552 | def run_suite(self, suite, xml): |
| 553 | """Invoke the test platform and request to run all matching tests in |
| 554 | `suite`. Create new XML nodes with results under `xml`. |
| 555 | Suite skipped if it does not match the regex given to constructor.""" |
| 556 | if not self.suite_re.match(suite["name"]): |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 557 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 558 | |
| 559 | print(" SUITE", suite["name"]) |
| 560 | suite_xml = ET.SubElement(xml, "testsuite") |
| 561 | suite_xml.set("name", suite["name"]) |
Andrew Walbran | 16ae62e | 2020-06-05 18:27:46 +0100 | [diff] [blame] | 562 | properties_xml = ET.SubElement(suite_xml, "properties") |
| 563 | |
| 564 | property_xml = ET.SubElement(properties_xml, "property") |
| 565 | property_xml.set("name", "driver") |
| 566 | property_xml.set("value", type(self.driver).__name__) |
| 567 | |
| 568 | if self.driver.args.cpu: |
| 569 | property_xml = ET.SubElement(properties_xml, "property") |
| 570 | property_xml.set("name", "cpu") |
| 571 | property_xml.set("value", self.driver.args.cpu) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 572 | |
| 573 | return self.collect_results( |
| 574 | lambda test: self.run_test(suite, test, suite_xml), |
| 575 | suite["tests"], |
| 576 | suite_xml) |
| 577 | |
| 578 | def run_tests(self): |
| 579 | """Run all suites and tests matching regexes given to constructor. |
| 580 | Write results to sponge log XML. Return the number of run and failed |
| 581 | tests.""" |
| 582 | |
| 583 | test_spec = self.get_test_json() |
| 584 | timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() |
| 585 | |
| 586 | xml = ET.Element("testsuites") |
| 587 | xml.set("name", self.image_name) |
| 588 | xml.set("timestamp", timestamp) |
| 589 | |
| 590 | result = self.collect_results( |
| 591 | lambda suite: self.run_suite(suite, xml), |
| 592 | test_spec["suites"], |
| 593 | xml) |
| 594 | |
| 595 | # Write XML to file. |
David Brazdil | ee5e25d | 2020-01-24 14:17:45 +0000 | [diff] [blame] | 596 | ET.ElementTree(xml).write(self.artifacts.sponge_xml_path, |
| 597 | encoding='utf-8', xml_declaration=True) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 598 | |
| 599 | if result.tests_failed > 0: |
| 600 | print("[x] FAIL:", result.tests_failed, "of", result.tests_run, |
| 601 | "tests failed") |
| 602 | elif result.tests_run > 0: |
| 603 | print(" PASS: all", result.tests_run, "tests passed") |
| 604 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 605 | # Let the driver clean up. |
| 606 | self.driver.finish() |
| 607 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 608 | return result |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 609 | |
| 610 | |
| 611 | def Main(): |
| 612 | parser = argparse.ArgumentParser() |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 613 | parser.add_argument("image") |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 614 | parser.add_argument("--out", required=True) |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 615 | parser.add_argument("--log", required=True) |
Andrew Walbran | 7559fcf | 2019-05-09 17:11:20 +0100 | [diff] [blame] | 616 | parser.add_argument("--out_initrd") |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 617 | parser.add_argument("--initrd") |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 618 | parser.add_argument("--suite") |
| 619 | parser.add_argument("--test") |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 620 | parser.add_argument("--vm_args") |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 621 | parser.add_argument("--driver", default="qemu") |
| 622 | parser.add_argument("--serial-dev", default="/dev/ttyUSB0") |
| 623 | parser.add_argument("--serial-baudrate", type=int, default=115200) |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 624 | parser.add_argument("--serial-no-init-wait", action="store_true") |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 625 | parser.add_argument("--skip-long-running-tests", action="store_true") |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 626 | parser.add_argument("--force-long-running", action="store_true") |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 627 | parser.add_argument("--cpu", |
| 628 | help="Selects the CPU configuration for the run environment.") |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 629 | parser.add_argument("--tfa", action="store_true") |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 630 | args = parser.parse_args() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 631 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 632 | # Resolve some paths. |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 633 | image = os.path.join(args.out, args.image + ".bin") |
| 634 | initrd = None |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 635 | image_name = args.image |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 636 | if args.initrd: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 637 | initrd_dir = os.path.join(args.out_initrd, "obj", args.initrd) |
| 638 | initrd = os.path.join(initrd_dir, "initrd.img") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 639 | image_name += "_" + args.initrd |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 640 | vm_args = args.vm_args or "" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 641 | |
| 642 | # Create class which will manage all test artifacts. |
| 643 | artifacts = ArtifactsManager(os.path.join(args.log, image_name)) |
| 644 | |
| 645 | # Create a driver for the platform we want to test on. |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 646 | driver_args = DriverArgs(artifacts, image, initrd, vm_args, args.cpu) |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 647 | |
| 648 | if args.driver == "qemu": |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 649 | driver = QemuDriver(driver_args, args.out, args.tfa) |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 650 | elif args.driver == "fvp": |
| 651 | driver = FvpDriver(driver_args) |
| 652 | elif args.driver == "serial": |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 653 | driver = SerialDriver(driver_args, args.serial_dev, |
| 654 | args.serial_baudrate, not args.serial_no_init_wait) |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 655 | else: |
| 656 | raise Exception("Unknown driver name: {}".format(args.driver)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 657 | |
| 658 | # Create class which will drive test execution. |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 659 | runner = TestRunner(artifacts, driver, image_name, args.suite, args.test, |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 660 | args.skip_long_running_tests, args.force_long_running) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 661 | |
| 662 | # Run tests. |
| 663 | runner_result = runner.run_tests() |
| 664 | |
| 665 | # Print error message if no tests were run as this is probably unexpected. |
| 666 | # Return suitable error code. |
| 667 | if runner_result.tests_run == 0: |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 668 | print("Error: no tests match") |
| 669 | return 10 |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 670 | elif runner_result.tests_failed > 0: |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 671 | return 1 |
| 672 | else: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 673 | return 0 |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 674 | |
| 675 | if __name__ == "__main__": |
| 676 | sys.exit(Main()) |