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 |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 18 | from abc import ABC, abstractmethod |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 19 | import collections |
Andrew Scull | 04502e4 | 2018-09-03 14:54:52 +0100 | [diff] [blame] | 20 | import datetime |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 21 | import importlib |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 22 | import json |
| 23 | import os |
| 24 | import re |
| 25 | import subprocess |
| 26 | import sys |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 27 | import time |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 28 | import fdt |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 29 | |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 30 | HFTEST_LOG_PREFIX = "[hftest] " |
| 31 | HFTEST_LOG_FAILURE_PREFIX = "Failure:" |
| 32 | HFTEST_LOG_FINISHED = "FINISHED" |
| 33 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 34 | HFTEST_CTRL_GET_COMMAND_LINE = "[hftest_ctrl:get_command_line]" |
| 35 | HFTEST_CTRL_FINISHED = "[hftest_ctrl:finished]" |
| 36 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 37 | HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname( |
| 38 | os.path.abspath(__file__)))) |
David Brazdil | 5715f04 | 2019-08-27 11:11:51 +0100 | [diff] [blame] | 39 | DTC_SCRIPT = os.path.join(HF_ROOT, "build", "image", "dtc.py") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 40 | FVP_BINARY = os.path.join( |
| 41 | os.path.dirname(HF_ROOT), "fvp", "Base_RevC_AEMv8A_pkg", "models", |
Olivier Deprez | e415304 | 2020-10-02 15:24:59 +0200 | [diff] [blame] | 42 | "Linux64_GCC-6.4", "FVP_Base_RevC-2xAEMv8A") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 43 | HF_PREBUILTS = os.path.join(HF_ROOT, "prebuilts") |
| 44 | FVP_PREBUILTS_TFA_TRUSTY_ROOT = os.path.join( |
| 45 | HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-trusty", "fvp") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 46 | FVP_PREBUILT_DTS = os.path.join( |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 47 | FVP_PREBUILTS_TFA_TRUSTY_ROOT, "fvp-base-gicv3-psci-1t.dts") |
| 48 | |
| 49 | FVP_PREBUILT_TFA_ROOT = os.path.join( |
| 50 | HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a", "fvp") |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 51 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 52 | def read_file(path): |
| 53 | with open(path, "r") as f: |
| 54 | return f.read() |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 55 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 56 | def write_file(path, to_write, append=False): |
| 57 | with open(path, "a" if append else "w") as f: |
| 58 | f.write(to_write) |
| 59 | |
| 60 | def append_file(path, to_write): |
| 61 | write_file(path, to_write, append=True) |
| 62 | |
| 63 | def join_if_not_None(*args): |
| 64 | return " ".join(filter(lambda x: x, args)) |
| 65 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 66 | DT = collections.namedtuple("DT", ["dts", "dtb"]) |
| 67 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 68 | class ArtifactsManager: |
| 69 | """Class which manages folder with test artifacts.""" |
| 70 | |
| 71 | def __init__(self, log_dir): |
| 72 | self.created_files = [] |
| 73 | self.log_dir = log_dir |
| 74 | |
| 75 | # Create directory. |
Andrew Scull | 845fc9b | 2019-04-03 12:44:26 +0100 | [diff] [blame] | 76 | try: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 77 | os.makedirs(self.log_dir) |
| 78 | except OSError: |
| 79 | if not os.path.isdir(self.log_dir): |
| 80 | raise |
| 81 | print("Logs saved under", log_dir) |
| 82 | |
| 83 | # Create files expected by the Sponge test result parser. |
| 84 | self.sponge_log_path = self.create_file("sponge_log", ".log") |
| 85 | self.sponge_xml_path = self.create_file("sponge_log", ".xml") |
| 86 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 87 | def gen_file_path(self, basename, extension): |
| 88 | """Generate path to a file in the log directory.""" |
| 89 | return os.path.join(self.log_dir, basename + extension) |
| 90 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 91 | def create_file(self, basename, extension): |
| 92 | """Create and touch a new file in the log folder. Ensure that no other |
| 93 | file of the same name was created by this instance of ArtifactsManager. |
| 94 | """ |
| 95 | # Determine the path of the file. |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 96 | path = self.gen_file_path(basename, extension) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 97 | |
| 98 | # Check that the path is unique. |
| 99 | assert(path not in self.created_files) |
| 100 | self.created_files += [ path ] |
| 101 | |
| 102 | # Touch file. |
| 103 | with open(path, "w") as f: |
| 104 | pass |
| 105 | |
| 106 | return path |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 107 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 108 | def get_file(self, basename, extension): |
| 109 | """Return path to a file in the log folder. Assert that it was created |
| 110 | by this instance of ArtifactsManager.""" |
| 111 | path = self.gen_file_path(basename, extension) |
| 112 | assert(path in self.created_files) |
| 113 | return path |
| 114 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 115 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 116 | # Tuple holding the arguments common to all driver constructors. |
| 117 | # This is to avoid having to pass arguments from subclasses to superclasses. |
| 118 | DriverArgs = collections.namedtuple("DriverArgs", [ |
| 119 | "artifacts", |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 120 | "hypervisor", |
| 121 | "spmc", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 122 | "initrd", |
| 123 | "vm_args", |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 124 | "cpu", |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 125 | "partitions" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 126 | ]) |
Marc Bonnici | 0a12563 | 2019-04-01 13:46:52 +0100 | [diff] [blame] | 127 | |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 128 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 129 | # State shared between the common Driver class and its subclasses during |
| 130 | # a single invocation of the target platform. |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 131 | class DriverRunState: |
| 132 | def __init__(self, log_path): |
| 133 | self.log_path = log_path |
| 134 | self.ret_code = 0 |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 135 | |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 136 | def set_ret_code(self, ret_code): |
| 137 | self.ret_code = ret_code |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 138 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 139 | class DriverRunException(Exception): |
| 140 | """Exception thrown if subprocess invoked by a driver returned non-zero |
| 141 | status code. Used to fast-exit from a driver command sequence.""" |
| 142 | pass |
| 143 | |
| 144 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 145 | class Driver: |
| 146 | """Parent class of drivers for all testable platforms.""" |
| 147 | |
| 148 | def __init__(self, args): |
| 149 | self.args = args |
| 150 | |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 151 | def get_run_log(self, run_name): |
| 152 | """Return path to the main log of a given test run.""" |
| 153 | return self.args.artifacts.get_file(run_name, ".log") |
| 154 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 155 | def start_run(self, run_name): |
| 156 | """Hook called by Driver subclasses before they invoke the target |
| 157 | platform.""" |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 158 | return DriverRunState(self.args.artifacts.create_file(run_name, ".log")) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 159 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 160 | def exec_logged(self, run_state, exec_args, cwd=None): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 161 | """Run a subprocess on behalf of a Driver subclass and append its |
| 162 | stdout and stderr to the main log.""" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 163 | assert(run_state.ret_code == 0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 164 | with open(run_state.log_path, "a") as f: |
| 165 | f.write("$ {}\r\n".format(" ".join(exec_args))) |
| 166 | f.flush() |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 167 | ret_code = subprocess.call(exec_args, stdout=f, stderr=f, cwd=cwd) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 168 | if ret_code != 0: |
David Brazdil | 7325eaf | 2019-09-27 13:04:51 +0100 | [diff] [blame] | 169 | run_state.set_ret_code(ret_code) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 170 | raise DriverRunException() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 171 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 172 | def finish_run(self, run_state): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 173 | """Hook called by Driver subclasses after they finished running the |
| 174 | target platform. `ret_code` argument is the return code of the main |
| 175 | command run by the driver. A corresponding log message is printed.""" |
| 176 | # Decode return code and add a message to the log. |
| 177 | with open(run_state.log_path, "a") as f: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 178 | if run_state.ret_code == 124: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 179 | f.write("\r\n{}{} timed out\r\n".format( |
| 180 | HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX)) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 181 | elif run_state.ret_code != 0: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 182 | f.write("\r\n{}{} process return code {}\r\n".format( |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 183 | HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX, |
| 184 | run_state.ret_code)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 185 | |
| 186 | # Append log of this run to full test log. |
| 187 | log_content = read_file(run_state.log_path) |
| 188 | append_file( |
| 189 | self.args.artifacts.sponge_log_path, |
| 190 | log_content + "\r\n\r\n") |
| 191 | return log_content |
Andrew Walbran | 9865625 | 2019-03-14 14:52:29 +0000 | [diff] [blame] | 192 | |
| 193 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 194 | class QemuDriver(Driver): |
| 195 | """Driver which runs tests in QEMU.""" |
| 196 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 197 | def __init__(self, args, qemu_wd, tfa): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 198 | Driver.__init__(self, args) |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 199 | self.qemu_wd = qemu_wd |
| 200 | self.tfa = tfa |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 201 | |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 202 | def gen_exec_args(self, test_args, is_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 203 | """Generate command line arguments for QEMU.""" |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 204 | time_limit = "120s" if is_long_running else "10s" |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 205 | # If no CPU configuration is selected, then test against the maximum |
| 206 | # configuration, "max", supported by QEMU. |
| 207 | cpu = self.args.cpu or "max" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 208 | exec_args = [ |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 209 | "timeout", "--foreground", time_limit, |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 210 | os.path.abspath("prebuilts/linux-x64/qemu/qemu-system-aarch64"), |
Andrew Walbran | a081a29 | 2020-01-23 10:08:42 +0000 | [diff] [blame] | 211 | "-machine", "virt,virtualization=on,gic-version=3", |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 212 | "-cpu", cpu, "-smp", "4", "-m", "1G", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 213 | "-nographic", "-nodefaults", "-serial", "stdio", |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 214 | "-d", "unimp", "-kernel", os.path.abspath(self.args.hypervisor), |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 215 | ] |
| 216 | |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 217 | if self.tfa: |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 218 | bl1_path = os.path.join( |
| 219 | HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-trusty", |
| 220 | "qemu", "bl1.bin") |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 221 | exec_args += ["-bios", |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 222 | os.path.abspath(bl1_path), |
| 223 | "-machine", "secure=on", "-semihosting-config", |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 224 | "enable,target=native"] |
| 225 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 226 | if self.args.initrd: |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 227 | exec_args += ["-initrd", os.path.abspath(self.args.initrd)] |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 228 | |
| 229 | vm_args = join_if_not_None(self.args.vm_args, test_args) |
| 230 | if vm_args: |
| 231 | exec_args += ["-append", vm_args] |
| 232 | |
| 233 | return exec_args |
| 234 | |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 235 | def run(self, run_name, test_args, is_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 236 | """Run test given by `test_args` in QEMU.""" |
| 237 | run_state = self.start_run(run_name) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 238 | |
| 239 | try: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 240 | # Execute test in QEMU.. |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 241 | exec_args = self.gen_exec_args(test_args, is_long_running) |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 242 | self.exec_logged(run_state, exec_args, |
| 243 | cwd=self.qemu_wd) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 244 | except DriverRunException: |
| 245 | pass |
| 246 | |
| 247 | return self.finish_run(run_state) |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 248 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 249 | def finish(self): |
| 250 | """Clean up after running tests.""" |
| 251 | pass |
| 252 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 253 | class FvpDriver(Driver, ABC): |
| 254 | """Base class for driver which runs tests in Arm FVP emulator.""" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 255 | |
| 256 | def __init__(self, args): |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 257 | if args.cpu: |
| 258 | raise ValueError("FVP emulator does not support the --cpu option.") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 259 | super().__init__(args) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 260 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 261 | @property |
| 262 | @abstractmethod |
| 263 | def CPU_START_ADDRESS(self): |
| 264 | pass |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 265 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 266 | @property |
| 267 | @abstractmethod |
| 268 | def DTB_ADDRESS(self): |
| 269 | pass |
| 270 | |
| 271 | @property |
| 272 | @abstractmethod |
| 273 | def FVP_PREBUILT_BL31(self): |
| 274 | pass |
| 275 | |
| 276 | @property |
| 277 | @abstractmethod |
| 278 | def KERNEL_ADDRESS(self): |
| 279 | pass |
| 280 | |
| 281 | def create_dt(self, run_name : str): |
| 282 | """Create DT related files, and return respective paths in a tuple |
| 283 | (dts,dtb)""" |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 284 | return DT(self.args.artifacts.create_file(run_name, ".dts"), |
| 285 | self.args.artifacts.create_file(run_name, ".dtb")) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 286 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 287 | def compile_dt(self, run_state, dt : DT): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 288 | """Compile DT calling dtc.""" |
| 289 | dtc_args = [ |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 290 | DTC_SCRIPT, "compile", "-i", dt.dts, "-o", dt.dtb, |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 291 | ] |
| 292 | self.exec_logged(run_state, dtc_args) |
| 293 | |
| 294 | def create_uart_log(self, run_name : str, file_name : str): |
| 295 | """Create uart log file, and return path""" |
| 296 | return self.args.artifacts.create_file(run_name, file_name) |
| 297 | |
| 298 | def get_img_and_ldadd(self, partitions : dict): |
| 299 | ret = [] |
| 300 | for i, p in enumerate(partitions): |
| 301 | with open(p["dts"], "r") as dts: |
| 302 | manifest = fdt.parse_dts(dts.read()) |
| 303 | load_address = manifest.get_property("load_address", |
| 304 | f"/hypervisor/vm{str(i+1)}").value |
| 305 | ret.append((p["img"], load_address)) |
| 306 | return ret |
| 307 | |
| 308 | def get_manifests_from_json(self, partitions : list): |
| 309 | manifests = "" |
| 310 | if partitions is not None: |
| 311 | for p in partitions: |
| 312 | manifests += read_file(p["dts"]) |
| 313 | return manifests |
| 314 | |
| 315 | @abstractmethod |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 316 | def gen_dts(self, dt, test_args): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 317 | """Abstract method to generate dts file. This specific to the use case |
| 318 | so should be implemented within derived driver""" |
| 319 | pass |
| 320 | |
| 321 | @abstractmethod |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 322 | def gen_fvp_args( |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 323 | self, is_long_running, uart0_log_path, uart1_log_path, dt): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 324 | """Generate command line arguments for FVP.""" |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 325 | time_limit = "80s" if is_long_running else "40s" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 326 | fvp_args = [ |
Andrew Walbran | ee5418e | 2019-11-27 17:43:05 +0000 | [diff] [blame] | 327 | "timeout", "--foreground", time_limit, |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 328 | FVP_BINARY, |
J-Alves | 10446d8 | 2021-04-26 11:52:57 +0100 | [diff] [blame] | 329 | "-C", "pci.pci_smmuv3.mmu.SMMU_AIDR=2", |
| 330 | "-C", "pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B", |
| 331 | "-C", "pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002", |
| 332 | "-C", "pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714", |
| 333 | "-C", "pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472", |
| 334 | "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002", |
| 335 | "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR2=0", |
| 336 | "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR3=0", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 337 | "-C", "pctl.startup=0.0.0.0", |
| 338 | "-C", "bp.secure_memory=0", |
| 339 | "-C", "cluster0.NUM_CORES=4", |
| 340 | "-C", "cluster1.NUM_CORES=4", |
| 341 | "-C", "cache_state_modelled=0", |
| 342 | "-C", "bp.vis.disable_visualisation=true", |
| 343 | "-C", "bp.vis.rate_limit-enable=false", |
| 344 | "-C", "bp.terminal_0.start_telnet=false", |
| 345 | "-C", "bp.terminal_1.start_telnet=false", |
| 346 | "-C", "bp.terminal_2.start_telnet=false", |
| 347 | "-C", "bp.terminal_3.start_telnet=false", |
| 348 | "-C", "bp.pl011_uart0.untimed_fifos=1", |
| 349 | "-C", "bp.pl011_uart0.unbuffered_output=1", |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 350 | "-C", f"bp.pl011_uart0.out_file={uart0_log_path}", |
| 351 | "-C", f"bp.pl011_uart1.out_file={uart1_log_path}", |
| 352 | "-C", f"cluster0.cpu0.RVBAR={self.CPU_START_ADDRESS}", |
| 353 | "-C", f"cluster0.cpu1.RVBAR={self.CPU_START_ADDRESS}", |
| 354 | "-C", f"cluster0.cpu2.RVBAR={self.CPU_START_ADDRESS}", |
| 355 | "-C", f"cluster0.cpu3.RVBAR={self.CPU_START_ADDRESS}", |
| 356 | "-C", f"cluster1.cpu0.RVBAR={self.CPU_START_ADDRESS}", |
| 357 | "-C", f"cluster1.cpu1.RVBAR={self.CPU_START_ADDRESS}", |
| 358 | "-C", f"cluster1.cpu2.RVBAR={self.CPU_START_ADDRESS}", |
| 359 | "-C", f"cluster1.cpu3.RVBAR={self.CPU_START_ADDRESS}", |
| 360 | "--data", |
| 361 | f"cluster0.cpu0={self.FVP_PREBUILT_BL31}@{self.CPU_START_ADDRESS}", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 362 | "-C", "bp.ve_sysregs.mmbSiteDefault=0", |
| 363 | "-C", "bp.ve_sysregs.exit_on_shutdown=1", |
| 364 | ] |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 365 | return fvp_args |
| 366 | |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 367 | def run(self, run_name, test_args, is_long_running): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 368 | """ Run test """ |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 369 | run_state = self.start_run(run_name) |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 370 | dt = self.create_dt(run_name) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 371 | uart0_log_path = self.create_uart_log(run_name, ".uart0.log") |
| 372 | uart1_log_path = self.create_uart_log(run_name, ".uart1.log") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 373 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 374 | try: |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 375 | self.gen_dts(dt, test_args) |
| 376 | self.compile_dt(run_state, dt) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 377 | fvp_args = self.gen_fvp_args(is_long_running, uart0_log_path, |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 378 | uart1_log_path, dt) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 379 | self.exec_logged(run_state, fvp_args) |
| 380 | except DriverRunException: |
| 381 | pass |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 382 | |
| 383 | # Append UART0 output to main log. |
| 384 | append_file(run_state.log_path, read_file(uart0_log_path)) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 385 | return self.finish_run(run_state) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 386 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 387 | def finish(self): |
| 388 | """Clean up after running tests.""" |
| 389 | pass |
| 390 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 391 | class FvpDriverHypervisor(FvpDriver): |
| 392 | """ |
| 393 | Driver which runs tests in Arm FVP emulator, with hafnium as hypervisor |
| 394 | """ |
| 395 | INITRD_START= 0x84000000 |
Olivier Deprez | a516f48 | 2021-04-30 18:47:59 +0200 | [diff] [blame] | 396 | INITRD_END = 0x86000000 #Default value, however may change if initrd in args |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 397 | |
| 398 | def __init__(self, args): |
| 399 | self.vms_in_partitions_json = args.partitions and args.partitions["VMs"] |
| 400 | super().__init__(args) |
| 401 | |
| 402 | @property |
| 403 | def CPU_START_ADDRESS(self): |
| 404 | return "0x04020000" |
| 405 | |
| 406 | @property |
| 407 | def DTB_ADDRESS(self): |
| 408 | return "0x82000000" |
| 409 | |
| 410 | @property |
| 411 | def FVP_PREBUILT_BL31(self): |
| 412 | return os.path.join(FVP_PREBUILTS_TFA_TRUSTY_ROOT, "bl31.bin") |
| 413 | |
| 414 | @property |
| 415 | def KERNEL_ADDRESS(self): |
| 416 | return "0x80000000" |
| 417 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 418 | def gen_dts(self, dt, test_args): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 419 | """Create a DeviceTree source which will be compiled into a DTB and |
| 420 | passed to FVP for a test run.""" |
| 421 | |
| 422 | vm_args = join_if_not_None(self.args.vm_args, test_args) |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 423 | write_file(dt.dts, read_file(FVP_PREBUILT_DTS)) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 424 | |
| 425 | # Write the vm arguments to the partition manifest |
| 426 | to_append = f""" |
| 427 | / {{ |
| 428 | chosen {{ |
| 429 | bootargs = "{vm_args}"; |
| 430 | stdout-path = "serial0:115200n8"; |
| 431 | linux,initrd-start = <{self.INITRD_START if self.args.initrd else 0}>; |
| 432 | linux,initrd-end = <{self.INITRD_END if self.args.initrd else 0}>; |
| 433 | }}; |
| 434 | }};""" |
| 435 | if self.vms_in_partitions_json: |
| 436 | to_append += self.get_manifests_from_json(self.args.partitions["VMs"]) |
| 437 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 438 | append_file(dt.dts, to_append) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 439 | |
| 440 | def gen_fvp_args( |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 441 | self, is_long_running, uart0_log_path, uart1_log_path, dt, call_super = True): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 442 | """Generate command line arguments for FVP.""" |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 443 | common_args = (is_long_running, uart0_log_path, uart1_log_path, dt) |
| 444 | fvp_args = super().gen_fvp_args(*common_args) if call_super else [] |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 445 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 446 | fvp_args += [ |
| 447 | "--data", f"cluster0.cpu0={dt.dtb}@{self.DTB_ADDRESS}", |
| 448 | "--data", f"cluster0.cpu0={self.args.hypervisor}@{self.KERNEL_ADDRESS}", |
| 449 | ] |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 450 | |
| 451 | if self.vms_in_partitions_json: |
| 452 | img_ldadd = self.get_img_and_ldadd(self.args.partitions["VMs"]) |
| 453 | for img, ldadd in img_ldadd: |
| 454 | fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"] |
| 455 | |
| 456 | if self.args.initrd: |
| 457 | fvp_args += [ |
| 458 | "--data", |
| 459 | f"cluster0.cpu0={self.args.initrd}@{self.INITRD_START}" |
| 460 | ] |
| 461 | return fvp_args |
| 462 | |
| 463 | class FvpDriverSPMC(FvpDriver): |
| 464 | """ |
| 465 | Driver which runs tests in Arm FVP emulator, with hafnium as SPMC |
| 466 | """ |
| 467 | FVP_PREBUILT_SECURE_DTS = os.path.join( |
| 468 | HF_ROOT, "test", "vmapi", "fvp-base-spmc.dts") |
| 469 | HFTEST_CMD_FILE = os.path.join("/tmp/", "hftest_cmds") |
| 470 | |
| 471 | def __init__(self, args): |
| 472 | if args.partitions is None or args.partitions["SPs"] is None: |
J-Alves | 10446d8 | 2021-04-26 11:52:57 +0100 | [diff] [blame] | 473 | raise Exception("Need to provide SPs in partitions_json") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 474 | super().__init__(args) |
| 475 | |
| 476 | @property |
| 477 | def CPU_START_ADDRESS(self): |
| 478 | return "0x04010000" |
| 479 | |
| 480 | @property |
| 481 | def DTB_ADDRESS(self): |
| 482 | return "0x0403f000" |
| 483 | |
| 484 | @property |
| 485 | def FVP_PREBUILT_BL31(self): |
| 486 | return os.path.join(FVP_PREBUILT_TFA_ROOT, "bl31_spmd.bin") |
| 487 | |
| 488 | @property |
| 489 | def KERNEL_ADDRESS(self): |
| 490 | return "0x6000000" |
| 491 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 492 | def gen_dts(self, dt, test_args): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 493 | """Create a DeviceTree source which will be compiled into a DTB and |
| 494 | passed to FVP for a test run.""" |
| 495 | to_append = self.get_manifests_from_json(self.args.partitions["SPs"]) |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 496 | write_file(dt.dts, read_file(FvpDriverSPMC.FVP_PREBUILT_SECURE_DTS)) |
| 497 | append_file(dt.dts, to_append) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 498 | |
| 499 | def gen_fvp_args( |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 500 | self, is_long_running, uart0_log_path, uart1_log_path, dt, |
| 501 | call_super = True, secure_hfctrl = True): |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 502 | """Generate command line arguments for FVP.""" |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 503 | common_args = (is_long_running, uart0_log_path, uart1_log_path, dt.dtb) |
| 504 | fvp_args = super().gen_fvp_args(*common_args) if call_super else [] |
| 505 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 506 | fvp_args += [ |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 507 | "--data", f"cluster0.cpu0={dt.dtb}@{self.DTB_ADDRESS}", |
| 508 | "--data", f"cluster0.cpu0={self.args.spmc}@{self.KERNEL_ADDRESS}", |
| 509 | ] |
| 510 | |
| 511 | if secure_hfctrl: |
| 512 | fvp_args += [ |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 513 | "-C", f"bp.pl011_uart0.in_file={FvpDriverSPMC.HFTEST_CMD_FILE}", |
| 514 | "-C", f"bp.pl011_uart0.shutdown_tag=\"{HFTEST_CTRL_FINISHED}\"", |
J-Alves | b5a6399 | 2021-04-30 10:23:19 +0100 | [diff] [blame] | 515 | "-C", "cluster0.has_arm_v8-5=1", |
| 516 | "-C", "cluster1.has_arm_v8-5=1", |
| 517 | "-C", "cluster0.has_branch_target_exception=1", |
| 518 | "-C", "cluster1.has_branch_target_exception=1", |
| 519 | "-C", "cluster0.restriction_on_speculative_execution=2", |
| 520 | "-C", "cluster1.restriction_on_speculative_execution=2", |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 521 | ] |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 522 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 523 | img_ldadd = self.get_img_and_ldadd(self.args.partitions["SPs"]) |
| 524 | for img, ldadd in img_ldadd: |
| 525 | fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"] |
| 526 | |
| 527 | return fvp_args |
| 528 | |
| 529 | def run(self, run_name, test_args, is_long_running): |
| 530 | with open(FvpDriverSPMC.HFTEST_CMD_FILE, "w+") as f: |
| 531 | vm_args = join_if_not_None(self.args.vm_args, test_args) |
| 532 | f.write(f"{vm_args}\n") |
| 533 | return super().run(run_name, test_args, is_long_running) |
| 534 | |
| 535 | def finish(self): |
| 536 | """Clean up after running tests.""" |
| 537 | os.remove(FvpDriverSPMC.HFTEST_CMD_FILE) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 538 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 539 | class SerialDriver(Driver): |
| 540 | """Driver which communicates with a device over the serial port.""" |
| 541 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 542 | def __init__(self, args, tty_file, baudrate, init_wait): |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 543 | Driver.__init__(self, args) |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 544 | self.tty_file = tty_file |
| 545 | self.baudrate = baudrate |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 546 | self.pyserial = importlib.import_module("serial") |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 547 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 548 | if init_wait: |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 549 | input("Press ENTER and then reset the device...") |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 550 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 551 | def connect(self): |
David Brazdil | 4f9cf9a | 2020-02-06 17:34:44 +0000 | [diff] [blame] | 552 | return self.pyserial.Serial(self.tty_file, self.baudrate, timeout=10) |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 553 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 554 | def run(self, run_name, test_args, is_long_running): |
| 555 | """Communicate `test_args` to the device over the serial port.""" |
| 556 | run_state = self.start_run(run_name) |
| 557 | |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 558 | with self.connect() as ser: |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 559 | with open(run_state.log_path, "a") as f: |
| 560 | while True: |
| 561 | # Read one line from the serial port. |
| 562 | line = ser.readline().decode('utf-8') |
| 563 | if len(line) == 0: |
| 564 | # Timeout |
| 565 | run_state.set_ret_code(124) |
| 566 | input("Timeout. " + |
| 567 | "Press ENTER and then reset the device...") |
| 568 | break |
| 569 | # Write the line to the log file. |
| 570 | f.write(line) |
| 571 | if HFTEST_CTRL_GET_COMMAND_LINE in line: |
| 572 | # Device is waiting for `test_args`. |
| 573 | ser.write(test_args.encode('ascii')) |
| 574 | ser.write(b'\r') |
| 575 | elif HFTEST_CTRL_FINISHED in line: |
| 576 | # Device has finished running this test and will reboot. |
| 577 | break |
| 578 | return self.finish_run(run_state) |
| 579 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 580 | def finish(self): |
| 581 | """Clean up after running tests.""" |
David Brazdil | 9d4ed96 | 2020-02-06 17:23:48 +0000 | [diff] [blame] | 582 | with self.connect() as ser: |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 583 | while True: |
| 584 | line = ser.readline().decode('utf-8') |
| 585 | if len(line) == 0: |
| 586 | input("Timeout. Press ENTER and then reset the device...") |
| 587 | elif HFTEST_CTRL_GET_COMMAND_LINE in line: |
| 588 | # Device is waiting for a command. Instruct it to exit |
| 589 | # the test environment. |
| 590 | ser.write("exit".encode('ascii')) |
| 591 | ser.write(b'\r') |
| 592 | break |
| 593 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 594 | # Tuple used to return information about the results of running a set of tests. |
| 595 | TestRunnerResult = collections.namedtuple("TestRunnerResult", [ |
| 596 | "tests_run", |
| 597 | "tests_failed", |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 598 | "tests_skipped", |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 599 | ]) |
| 600 | |
| 601 | |
| 602 | class TestRunner: |
| 603 | """Class which communicates with a test platform to obtain a list of |
| 604 | available tests and driving their execution.""" |
| 605 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 606 | def __init__(self, artifacts, driver, test_set_up, suite_regex, test_regex, |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 607 | skip_long_running_tests, force_long_running): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 608 | self.artifacts = artifacts |
| 609 | self.driver = driver |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 610 | self.test_set_up = test_set_up |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 611 | self.skip_long_running_tests = skip_long_running_tests |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 612 | self.force_long_running = force_long_running |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 613 | |
| 614 | self.suite_re = re.compile(suite_regex or ".*") |
| 615 | self.test_re = re.compile(test_regex or ".*") |
| 616 | |
| 617 | def extract_hftest_lines(self, raw): |
| 618 | """Extract hftest-specific lines from a raw output from an invocation |
| 619 | of the test platform.""" |
| 620 | lines = [] |
J-Alves | 07be7bb | 2021-04-13 11:09:12 +0100 | [diff] [blame] | 621 | lines_to_process = raw.splitlines() |
| 622 | |
| 623 | try: |
| 624 | # If logs have logs of more than one VM, the loop below to extract |
| 625 | # lines won't work. Thus, extracting between starting and ending |
| 626 | # logs: HFTEST_CTRL_GET_COMMAND_LINE and HFTEST_CTRL_FINISHED. |
| 627 | hftest_start = lines_to_process.index(HFTEST_CTRL_GET_COMMAND_LINE) + 1 |
| 628 | hftest_end = lines_to_process.index(HFTEST_CTRL_FINISHED) |
| 629 | except ValueError: |
| 630 | hftest_start = 0 |
| 631 | hftest_end = len(lines_to_process) |
| 632 | |
| 633 | lines_to_process = lines_to_process[hftest_start : hftest_end] |
| 634 | |
| 635 | for line in lines_to_process: |
J-Alves | 3dbb856 | 2020-12-01 10:45:37 +0000 | [diff] [blame] | 636 | match = re.search(f"^VM \d+: ", line) |
| 637 | if match is not None: |
| 638 | line = line[match.end():] |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 639 | if line.startswith(HFTEST_LOG_PREFIX): |
| 640 | lines.append(line[len(HFTEST_LOG_PREFIX):]) |
| 641 | return lines |
| 642 | |
| 643 | def get_test_json(self): |
| 644 | """Invoke the test platform and request a JSON of available test and |
| 645 | test suites.""" |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 646 | out = self.driver.run("json", "json", self.force_long_running) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 647 | hf_out = "\n".join(self.extract_hftest_lines(out)) |
| 648 | try: |
| 649 | return json.loads(hf_out) |
| 650 | except ValueError as e: |
| 651 | print(out) |
| 652 | raise e |
| 653 | |
| 654 | def collect_results(self, fn, it, xml_node): |
| 655 | """Run `fn` on every entry in `it` and collect their TestRunnerResults. |
| 656 | Insert "tests" and "failures" nodes to `xml_node`.""" |
| 657 | tests_run = 0 |
| 658 | tests_failed = 0 |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 659 | tests_skipped = 0 |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 660 | start_time = time.perf_counter() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 661 | for i in it: |
| 662 | sub_result = fn(i) |
| 663 | assert(sub_result.tests_run >= sub_result.tests_failed) |
| 664 | tests_run += sub_result.tests_run |
| 665 | tests_failed += sub_result.tests_failed |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 666 | tests_skipped += sub_result.tests_skipped |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 667 | elapsed_time = time.perf_counter() - start_time |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 668 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 669 | xml_node.set("tests", str(tests_run + tests_skipped)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 670 | xml_node.set("failures", str(tests_failed)) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 671 | xml_node.set("skipped", str(tests_skipped)) |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 672 | xml_node.set("time", str(elapsed_time)) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 673 | return TestRunnerResult(tests_run, tests_failed, tests_skipped) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 674 | |
| 675 | def is_passed_test(self, test_out): |
| 676 | """Parse the output of a test and return True if it passed.""" |
| 677 | return \ |
| 678 | len(test_out) > 0 and \ |
| 679 | test_out[-1] == HFTEST_LOG_FINISHED and \ |
| 680 | not any(l.startswith(HFTEST_LOG_FAILURE_PREFIX) for l in test_out) |
| 681 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 682 | def get_failure_message(self, test_out): |
| 683 | """Parse the output of a test and return the message of the first |
| 684 | assertion failure.""" |
| 685 | for i, line in enumerate(test_out): |
| 686 | if line.startswith(HFTEST_LOG_FAILURE_PREFIX) and i + 1 < len(test_out): |
| 687 | # The assertion message is on the line after the 'Failure:' |
| 688 | return test_out[i + 1].strip() |
| 689 | |
| 690 | return None |
| 691 | |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 692 | def get_log_name(self, suite, test): |
| 693 | """Returns a string with a generated log name for the test.""" |
| 694 | log_name = "" |
| 695 | |
| 696 | cpu = self.driver.args.cpu |
| 697 | if cpu: |
| 698 | log_name += cpu + "." |
| 699 | |
| 700 | log_name += suite["name"] + "." + test["name"] |
| 701 | |
| 702 | return log_name |
| 703 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 704 | def run_test(self, suite, test, suite_xml): |
| 705 | """Invoke the test platform and request to run a given `test` in given |
| 706 | `suite`. Create a new XML node with results under `suite_xml`. |
| 707 | Test only invoked if it matches the regex given to constructor.""" |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 708 | if not self.test_re.match(test["name"]): |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 709 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 710 | |
| 711 | test_xml = ET.SubElement(suite_xml, "testcase") |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 712 | test_xml.set("name", test["name"]) |
| 713 | test_xml.set("classname", suite["name"]) |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 714 | |
| 715 | if self.skip_long_running_tests and test["is_long_running"]: |
| 716 | print(" SKIP", test["name"]) |
| 717 | test_xml.set("status", "notrun") |
| 718 | skipped_xml = ET.SubElement(test_xml, "skipped") |
| 719 | skipped_xml.set("message", "Long running") |
| 720 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=1) |
| 721 | |
| 722 | print(" RUN", test["name"]) |
| 723 | log_name = self.get_log_name(suite, test) |
| 724 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 725 | test_xml.set("status", "run") |
| 726 | |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 727 | start_time = time.perf_counter() |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 728 | out = self.driver.run( |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 729 | log_name, "run {} {}".format(suite["name"], test["name"]), |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 730 | test["is_long_running"] or self.force_long_running) |
| 731 | hftest_out = self.extract_hftest_lines(out) |
Andrew Walbran | 42bf284 | 2020-06-05 18:50:19 +0100 | [diff] [blame] | 732 | elapsed_time = time.perf_counter() - start_time |
| 733 | |
| 734 | test_xml.set("time", str(elapsed_time)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 735 | |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 736 | system_out_xml = ET.SubElement(test_xml, "system-out") |
| 737 | system_out_xml.text = out |
| 738 | |
| 739 | if self.is_passed_test(hftest_out): |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 740 | print(" PASS") |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 741 | return TestRunnerResult(tests_run=1, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 742 | else: |
David Brazdil | 623b681 | 2019-09-09 11:41:08 +0100 | [diff] [blame] | 743 | print("[x] FAIL --", self.driver.get_run_log(log_name)) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 744 | failure_xml = ET.SubElement(test_xml, "failure") |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 745 | failure_message = self.get_failure_message(hftest_out) or "Test failed" |
| 746 | failure_xml.set("message", failure_message) |
| 747 | failure_xml.text = '\n'.join(hftest_out) |
| 748 | return TestRunnerResult(tests_run=1, tests_failed=1, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 749 | |
| 750 | def run_suite(self, suite, xml): |
| 751 | """Invoke the test platform and request to run all matching tests in |
| 752 | `suite`. Create new XML nodes with results under `xml`. |
| 753 | Suite skipped if it does not match the regex given to constructor.""" |
| 754 | if not self.suite_re.match(suite["name"]): |
Andrew Walbran | f946392 | 2020-06-05 16:44:42 +0100 | [diff] [blame] | 755 | return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 756 | |
| 757 | print(" SUITE", suite["name"]) |
| 758 | suite_xml = ET.SubElement(xml, "testsuite") |
| 759 | suite_xml.set("name", suite["name"]) |
Andrew Walbran | 16ae62e | 2020-06-05 18:27:46 +0100 | [diff] [blame] | 760 | properties_xml = ET.SubElement(suite_xml, "properties") |
| 761 | |
| 762 | property_xml = ET.SubElement(properties_xml, "property") |
| 763 | property_xml.set("name", "driver") |
| 764 | property_xml.set("value", type(self.driver).__name__) |
| 765 | |
| 766 | if self.driver.args.cpu: |
| 767 | property_xml = ET.SubElement(properties_xml, "property") |
| 768 | property_xml.set("name", "cpu") |
| 769 | property_xml.set("value", self.driver.args.cpu) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 770 | |
| 771 | return self.collect_results( |
| 772 | lambda test: self.run_test(suite, test, suite_xml), |
| 773 | suite["tests"], |
| 774 | suite_xml) |
| 775 | |
| 776 | def run_tests(self): |
| 777 | """Run all suites and tests matching regexes given to constructor. |
| 778 | Write results to sponge log XML. Return the number of run and failed |
| 779 | tests.""" |
| 780 | |
| 781 | test_spec = self.get_test_json() |
| 782 | timestamp = datetime.datetime.now().replace(microsecond=0).isoformat() |
| 783 | |
| 784 | xml = ET.Element("testsuites") |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 785 | xml.set("name", self.test_set_up) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 786 | xml.set("timestamp", timestamp) |
| 787 | |
| 788 | result = self.collect_results( |
| 789 | lambda suite: self.run_suite(suite, xml), |
| 790 | test_spec["suites"], |
| 791 | xml) |
| 792 | |
| 793 | # Write XML to file. |
David Brazdil | ee5e25d | 2020-01-24 14:17:45 +0000 | [diff] [blame] | 794 | ET.ElementTree(xml).write(self.artifacts.sponge_xml_path, |
| 795 | encoding='utf-8', xml_declaration=True) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 796 | |
| 797 | if result.tests_failed > 0: |
| 798 | print("[x] FAIL:", result.tests_failed, "of", result.tests_run, |
| 799 | "tests failed") |
| 800 | elif result.tests_run > 0: |
| 801 | print(" PASS: all", result.tests_run, "tests passed") |
| 802 | |
David Brazdil | 94fd1e9 | 2020-02-03 16:45:20 +0000 | [diff] [blame] | 803 | # Let the driver clean up. |
| 804 | self.driver.finish() |
| 805 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 806 | return result |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 807 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 808 | def Main(): |
| 809 | parser = argparse.ArgumentParser() |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 810 | parser.add_argument("--hypervisor") |
| 811 | parser.add_argument("--spmc") |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 812 | parser.add_argument("--log", required=True) |
Andrew Walbran | 7559fcf | 2019-05-09 17:11:20 +0100 | [diff] [blame] | 813 | parser.add_argument("--out_initrd") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 814 | parser.add_argument("--out_partitions") |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 815 | parser.add_argument("--initrd") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 816 | parser.add_argument("--partitions_json") |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 817 | parser.add_argument("--suite") |
| 818 | parser.add_argument("--test") |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 819 | parser.add_argument("--vm_args") |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 820 | parser.add_argument("--driver", default="qemu") |
| 821 | parser.add_argument("--serial-dev", default="/dev/ttyUSB0") |
| 822 | parser.add_argument("--serial-baudrate", type=int, default=115200) |
David Brazdil | d8013f9 | 2020-02-03 16:40:25 +0000 | [diff] [blame] | 823 | parser.add_argument("--serial-no-init-wait", action="store_true") |
David Brazdil | 3cc24aa | 2019-09-27 10:24:41 +0100 | [diff] [blame] | 824 | parser.add_argument("--skip-long-running-tests", action="store_true") |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 825 | parser.add_argument("--force-long-running", action="store_true") |
Fuad Tabba | 36c8c2b | 2019-11-04 16:55:32 +0000 | [diff] [blame] | 826 | parser.add_argument("--cpu", |
| 827 | help="Selects the CPU configuration for the run environment.") |
Andrew Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 828 | parser.add_argument("--tfa", action="store_true") |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 829 | args = parser.parse_args() |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 830 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 831 | # Create class which will manage all test artifacts. |
| 832 | if args.hypervisor and args.spmc: |
| 833 | test_set_up = "hypervisor_and_spmc" |
| 834 | elif args.hypervisor: |
| 835 | test_set_up = "hypervisor" |
| 836 | elif args.spmc: |
| 837 | test_set_up = "spmc" |
| 838 | else: |
| 839 | raise Exception("No Hafnium image provided!\n") |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 840 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 841 | initrd = None |
| 842 | if args.hypervisor and args.initrd: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 843 | initrd_dir = os.path.join(args.out_initrd, "obj", args.initrd) |
| 844 | initrd = os.path.join(initrd_dir, "initrd.img") |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 845 | test_set_up += "_" + args.initrd |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 846 | vm_args = args.vm_args or "" |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 847 | |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 848 | partitions = None |
| 849 | if args.driver == "fvp" and args.partitions_json is not None: |
| 850 | partitions_dir = os.path.join(args.out_partitions, "obj", args.partitions_json) |
| 851 | partitions = json.load(open(partitions_dir, "r")) |
| 852 | |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 853 | # Create class which will manage all test artifacts. |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 854 | log_dir = os.path.join(args.log, test_set_up) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 855 | artifacts = ArtifactsManager(log_dir) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 856 | |
| 857 | # Create a driver for the platform we want to test on. |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 858 | driver_args = DriverArgs(artifacts, args.hypervisor, args.spmc, initrd, |
| 859 | vm_args, args.cpu, partitions) |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 860 | |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 861 | if args.spmc: |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 862 | if args.driver != "fvp": |
| 863 | raise Exception("Secure tests can only run with fvp driver") |
| 864 | driver = FvpDriverSPMC(driver_args) |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 865 | elif args.hypervisor: |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 866 | if args.driver == "qemu": |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 867 | out = os.path.dirname(args.hypervisor) |
| 868 | driver = QemuDriver(driver_args, out, args.tfa) |
Olivier Deprez | a6d2e6d | 2020-11-06 18:09:50 +0100 | [diff] [blame] | 869 | elif args.driver == "fvp": |
| 870 | driver = FvpDriverHypervisor(driver_args) |
| 871 | elif args.driver == "serial": |
| 872 | driver = SerialDriver(driver_args, args.serial_dev, |
| 873 | args.serial_baudrate, not args.serial_no_init_wait) |
| 874 | else: |
| 875 | raise Exception("Unknown driver name: {}".format(args.driver)) |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 876 | else: |
| 877 | raise Exception("No Hafnium image provided!\n") |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 878 | |
| 879 | # Create class which will drive test execution. |
J-Alves | 8cc7dbb | 2021-04-16 10:38:48 +0100 | [diff] [blame^] | 880 | runner = TestRunner(artifacts, driver, test_set_up, args.suite, args.test, |
Andrew Walbran | e1fa70b | 2020-05-28 11:30:11 +0100 | [diff] [blame] | 881 | args.skip_long_running_tests, args.force_long_running) |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 882 | |
| 883 | # Run tests. |
| 884 | runner_result = runner.run_tests() |
| 885 | |
| 886 | # Print error message if no tests were run as this is probably unexpected. |
| 887 | # Return suitable error code. |
| 888 | if runner_result.tests_run == 0: |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 889 | print("Error: no tests match") |
| 890 | return 10 |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 891 | elif runner_result.tests_failed > 0: |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 892 | return 1 |
| 893 | else: |
David Brazdil | 2df2408 | 2019-09-05 11:55:08 +0100 | [diff] [blame] | 894 | return 0 |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 895 | |
| 896 | if __name__ == "__main__": |
| 897 | sys.exit(Main()) |