blob: 85ed9056e46e3def48349f5cb9fb7c8e75e9284a [file] [log] [blame]
David Brazdilee5e25d2020-01-24 14:17:45 +00001#!/usr/bin/env python3
Andrew Scull18834872018-10-12 11:48:09 +01002#
Andrew Walbran692b3252019-03-07 15:51:31 +00003# Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01004#
Andrew Walbrane959ec12020-06-17 15:01:09 +01005# 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 Scull18834872018-10-12 11:48:09 +01008
David Brazdil2df24082019-09-05 11:55:08 +01009"""Script which drives invocation of tests and parsing their output to produce
10a results report.
Andrew Scullbc7189d2018-08-14 09:35:13 +010011"""
12
13from __future__ import print_function
14
Andrew Scull3b62f2b2018-08-21 14:26:12 +010015import xml.etree.ElementTree as ET
16
Andrew Scullbc7189d2018-08-14 09:35:13 +010017import argparse
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010018from abc import ABC, abstractmethod
David Brazdil2df24082019-09-05 11:55:08 +010019import collections
Andrew Scull04502e42018-09-03 14:54:52 +010020import datetime
David Brazdil4f9cf9a2020-02-06 17:34:44 +000021import importlib
Andrew Scullbc7189d2018-08-14 09:35:13 +010022import json
23import os
24import re
25import subprocess
26import sys
Andrew Walbran42bf2842020-06-05 18:50:19 +010027import time
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010028import fdt
Olivier Depreze30c36f2022-11-22 11:26:47 +010029import platform
J-Alvesacdbb862023-01-31 17:14:55 +000030import tempfile
Andrew Scullbc7189d2018-08-14 09:35:13 +010031
Olivier Depreze30c36f2022-11-22 11:26:47 +010032MACHINE = platform.machine()
Olivier Depreze30c36f2022-11-22 11:26:47 +010033
Andrew Scull845fc9b2019-04-03 12:44:26 +010034HFTEST_LOG_PREFIX = "[hftest] "
35HFTEST_LOG_FAILURE_PREFIX = "Failure:"
36HFTEST_LOG_FINISHED = "FINISHED"
37
Daniel Boulby61049dc2023-06-16 14:15:21 +010038HFTEST_CTRL_JSON_START = "[hftest_ctrl:json_start]"
39HFTEST_CTRL_JSON_END = "[hftest_ctrl:json_end]"
40
David Brazdil17e76652020-01-29 14:44:19 +000041HFTEST_CTRL_GET_COMMAND_LINE = "[hftest_ctrl:get_command_line]"
42HFTEST_CTRL_FINISHED = "[hftest_ctrl:finished]"
43
Olivier Deprezbd432092024-07-26 14:01:12 +020044HFTEST_CTRL_JSON_REGEX = re.compile("^\\[[0-9a-fA-F]+ [0-9a-fA-F]+\\] ")
Karl Meakin6f1f1212024-07-16 10:18:16 +010045
David Brazdil2df24082019-09-05 11:55:08 +010046HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
47 os.path.abspath(__file__))))
David Brazdil5715f042019-08-27 11:11:51 +010048DTC_SCRIPT = os.path.join(HF_ROOT, "build", "image", "dtc.py")
David Brazdil2df24082019-09-05 11:55:08 +010049FVP_BINARY = os.path.join(
Olivier Deprez9f4bad42021-06-18 12:19:07 +020050 os.path.dirname(HF_ROOT), "fvp", "Base_RevC_AEMvA_pkg", "models",
Olivier Deprez78d94eb2023-01-31 09:02:32 +000051 "Linux64_armv8l_GCC-9.3" if MACHINE == "aarch64" else "Linux64_GCC-9.3",
52 "FVP_Base_RevC-2xAEMvA")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010053HF_PREBUILTS = os.path.join(HF_ROOT, "prebuilts")
Olivier Deprez78d94eb2023-01-31 09:02:32 +000054QEMU_PREBUILTS = os.path.join(HF_PREBUILTS,
55 "linux-" + ("x64" if MACHINE == "x86_64" else MACHINE),
56 "qemu", "qemu-system-aarch64")
Olivier Deprez0c5e7dc2023-01-17 10:29:04 +010057FVP_PREBUILTS_TFA_ROOT = os.path.join(
58 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a", "fvp")
David Brazdil2df24082019-09-05 11:55:08 +010059FVP_PREBUILT_DTS = os.path.join(
Olivier Deprez0c5e7dc2023-01-17 10:29:04 +010060 FVP_PREBUILTS_TFA_ROOT, "fvp-base-gicv3-psci-1t.dts")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010061
Olivier Deprez1b1c4b62023-01-17 09:56:32 +010062FVP_PREBUILT_TFA_SPMD_ROOT = os.path.join(
63 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-spmd", "fvp")
Andrew Scull845fc9b2019-04-03 12:44:26 +010064
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +000065FVP_PREBUILTS_TFA_EL3_SPMC_ROOT = os.path.join(
66 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-el3-spmc")
J-Alves852fe742021-04-22 11:59:55 +010067VM_NODE_REGEX = "vm[1-9]"
68
Olivier Deprez3917deb2023-01-19 11:08:43 +010069QEMU_CPU_MAX = "max,pauth-impdef=true"
70
David Brazdil2df24082019-09-05 11:55:08 +010071def read_file(path):
72 with open(path, "r") as f:
73 return f.read()
Andrew Scull845fc9b2019-04-03 12:44:26 +010074
David Brazdil2df24082019-09-05 11:55:08 +010075def write_file(path, to_write, append=False):
76 with open(path, "a" if append else "w") as f:
77 f.write(to_write)
78
79def append_file(path, to_write):
80 write_file(path, to_write, append=True)
81
82def join_if_not_None(*args):
83 return " ".join(filter(lambda x: x, args))
84
J-Alves852fe742021-04-22 11:59:55 +010085def get_vm_node_from_manifest(dts : str):
86 """ Get VM node string from Partition's extension to Partition Manager's
87 manifest."""
88 match = re.search(VM_NODE_REGEX, dts)
89 if not match:
90 raise Exception("Partition's node is not defined in its manifest.")
91 return match.group()
92
93def correct_vm_node(dts: str, node_index : int):
94 """ The vm node is being appended to the Partition Manager manifests.
95 Ideally, these files would be reused accross various test set-ups."""
96 return dts.replace(get_vm_node_from_manifest(dts), f"vm{node_index}")
97
J-Alves8cc7dbb2021-04-16 10:38:48 +010098DT = collections.namedtuple("DT", ["dts", "dtb"])
99
David Brazdil2df24082019-09-05 11:55:08 +0100100class ArtifactsManager:
101 """Class which manages folder with test artifacts."""
102
103 def __init__(self, log_dir):
104 self.created_files = []
105 self.log_dir = log_dir
106
107 # Create directory.
Andrew Scull845fc9b2019-04-03 12:44:26 +0100108 try:
David Brazdil2df24082019-09-05 11:55:08 +0100109 os.makedirs(self.log_dir)
110 except OSError:
111 if not os.path.isdir(self.log_dir):
112 raise
113 print("Logs saved under", log_dir)
114
115 # Create files expected by the Sponge test result parser.
116 self.sponge_log_path = self.create_file("sponge_log", ".log")
117 self.sponge_xml_path = self.create_file("sponge_log", ".xml")
118
David Brazdil623b6812019-09-09 11:41:08 +0100119 def gen_file_path(self, basename, extension):
120 """Generate path to a file in the log directory."""
121 return os.path.join(self.log_dir, basename + extension)
122
David Brazdil2df24082019-09-05 11:55:08 +0100123 def create_file(self, basename, extension):
124 """Create and touch a new file in the log folder. Ensure that no other
125 file of the same name was created by this instance of ArtifactsManager.
126 """
127 # Determine the path of the file.
David Brazdil623b6812019-09-09 11:41:08 +0100128 path = self.gen_file_path(basename, extension)
David Brazdil2df24082019-09-05 11:55:08 +0100129
130 # Check that the path is unique.
131 assert(path not in self.created_files)
132 self.created_files += [ path ]
133
134 # Touch file.
135 with open(path, "w") as f:
136 pass
137
138 return path
Andrew Scullbc7189d2018-08-14 09:35:13 +0100139
David Brazdil623b6812019-09-09 11:41:08 +0100140 def get_file(self, basename, extension):
141 """Return path to a file in the log folder. Assert that it was created
142 by this instance of ArtifactsManager."""
143 path = self.gen_file_path(basename, extension)
144 assert(path in self.created_files)
145 return path
146
Andrew Scullbc7189d2018-08-14 09:35:13 +0100147
David Brazdil2df24082019-09-05 11:55:08 +0100148# Tuple holding the arguments common to all driver constructors.
149# This is to avoid having to pass arguments from subclasses to superclasses.
150DriverArgs = collections.namedtuple("DriverArgs", [
151 "artifacts",
J-Alves8cc7dbb2021-04-16 10:38:48 +0100152 "hypervisor",
153 "spmc",
David Brazdil2df24082019-09-05 11:55:08 +0100154 "initrd",
155 "vm_args",
David Brazdil17e76652020-01-29 14:44:19 +0000156 "cpu",
J-Alves18a25f92021-05-04 17:47:41 +0100157 "partitions",
158 "global_run_name",
Saul Romero42a13632022-12-20 15:13:36 +0000159 "coverage_plugin",
J-Alvesff651e32024-07-23 13:34:56 +0100160 "disable_visualisation"
David Brazdil2df24082019-09-05 11:55:08 +0100161 ])
Marc Bonnici0a125632019-04-01 13:46:52 +0100162
David Brazdil2df24082019-09-05 11:55:08 +0100163# State shared between the common Driver class and its subclasses during
164# a single invocation of the target platform.
David Brazdil7325eaf2019-09-27 13:04:51 +0100165class DriverRunState:
166 def __init__(self, log_path):
167 self.log_path = log_path
168 self.ret_code = 0
Andrew Walbran98656252019-03-14 14:52:29 +0000169
David Brazdil7325eaf2019-09-27 13:04:51 +0100170 def set_ret_code(self, ret_code):
171 self.ret_code = ret_code
Andrew Walbran98656252019-03-14 14:52:29 +0000172
David Brazdil0dbb41f2019-09-09 18:03:35 +0100173class DriverRunException(Exception):
174 """Exception thrown if subprocess invoked by a driver returned non-zero
175 status code. Used to fast-exit from a driver command sequence."""
176 pass
177
178
David Brazdil2df24082019-09-05 11:55:08 +0100179class Driver:
180 """Parent class of drivers for all testable platforms."""
181
182 def __init__(self, args):
183 self.args = args
184
David Brazdil623b6812019-09-09 11:41:08 +0100185 def get_run_log(self, run_name):
186 """Return path to the main log of a given test run."""
187 return self.args.artifacts.get_file(run_name, ".log")
188
David Brazdil2df24082019-09-05 11:55:08 +0100189 def start_run(self, run_name):
190 """Hook called by Driver subclasses before they invoke the target
191 platform."""
David Brazdil7325eaf2019-09-27 13:04:51 +0100192 return DriverRunState(self.args.artifacts.create_file(run_name, ".log"))
David Brazdil2df24082019-09-05 11:55:08 +0100193
Andrew Walbranf636b842020-01-10 11:46:12 +0000194 def exec_logged(self, run_state, exec_args, cwd=None):
David Brazdil2df24082019-09-05 11:55:08 +0100195 """Run a subprocess on behalf of a Driver subclass and append its
196 stdout and stderr to the main log."""
David Brazdil0dbb41f2019-09-09 18:03:35 +0100197 assert(run_state.ret_code == 0)
David Brazdil2df24082019-09-05 11:55:08 +0100198 with open(run_state.log_path, "a") as f:
199 f.write("$ {}\r\n".format(" ".join(exec_args)))
200 f.flush()
Andrew Walbranf636b842020-01-10 11:46:12 +0000201 ret_code = subprocess.call(exec_args, stdout=f, stderr=f, cwd=cwd)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100202 if ret_code != 0:
David Brazdil7325eaf2019-09-27 13:04:51 +0100203 run_state.set_ret_code(ret_code)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100204 raise DriverRunException()
David Brazdil2df24082019-09-05 11:55:08 +0100205
David Brazdil0dbb41f2019-09-09 18:03:35 +0100206 def finish_run(self, run_state):
David Brazdil2df24082019-09-05 11:55:08 +0100207 """Hook called by Driver subclasses after they finished running the
208 target platform. `ret_code` argument is the return code of the main
209 command run by the driver. A corresponding log message is printed."""
210 # Decode return code and add a message to the log.
211 with open(run_state.log_path, "a") as f:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100212 if run_state.ret_code == 124:
David Brazdil2df24082019-09-05 11:55:08 +0100213 f.write("\r\n{}{} timed out\r\n".format(
214 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100215 elif run_state.ret_code != 0:
David Brazdil2df24082019-09-05 11:55:08 +0100216 f.write("\r\n{}{} process return code {}\r\n".format(
David Brazdil0dbb41f2019-09-09 18:03:35 +0100217 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX,
218 run_state.ret_code))
David Brazdil2df24082019-09-05 11:55:08 +0100219
220 # Append log of this run to full test log.
221 log_content = read_file(run_state.log_path)
222 append_file(
223 self.args.artifacts.sponge_log_path,
224 log_content + "\r\n\r\n")
225 return log_content
Andrew Walbran98656252019-03-14 14:52:29 +0000226
David Brazdil2df24082019-09-05 11:55:08 +0100227class QemuDriver(Driver):
228 """Driver which runs tests in QEMU."""
229
Andrew Walbranf636b842020-01-10 11:46:12 +0000230 def __init__(self, args, qemu_wd, tfa):
David Brazdil2df24082019-09-05 11:55:08 +0100231 Driver.__init__(self, args)
Andrew Walbranf636b842020-01-10 11:46:12 +0000232 self.qemu_wd = qemu_wd
233 self.tfa = tfa
David Brazdil2df24082019-09-05 11:55:08 +0100234
David Brazdila2358d42020-01-27 18:51:38 +0000235 def gen_exec_args(self, test_args, is_long_running):
David Brazdil2df24082019-09-05 11:55:08 +0100236 """Generate command line arguments for QEMU."""
J-Alvescc9d1132024-10-30 13:46:33 +0000237 time_limit = "120s" if is_long_running else "30s"
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000238 # If no CPU configuration is selected, then test against the maximum
239 # configuration, "max", supported by QEMU.
Olivier Deprez3917deb2023-01-19 11:08:43 +0100240 if not self.args.cpu or self.args.cpu == "max":
241 cpu = QEMU_CPU_MAX
242 else:
243 cpu = self.args.cpu
244
David Brazdil2df24082019-09-05 11:55:08 +0100245 exec_args = [
David Brazdil3cc24aa2019-09-27 10:24:41 +0100246 "timeout", "--foreground", time_limit,
Olivier Depreze30c36f2022-11-22 11:26:47 +0100247 QEMU_PREBUILTS,
Olivier Deprez5373f232022-11-23 09:57:19 +0100248 "-no-reboot", "-machine", "virt-6.2,virtualization=on,gic-version=3",
J-Alves871e3732022-05-31 17:10:50 +0100249 "-cpu", cpu, "-smp", "8", "-m", "1G",
David Brazdil2df24082019-09-05 11:55:08 +0100250 "-nographic", "-nodefaults", "-serial", "stdio",
J-Alves8cc7dbb2021-04-16 10:38:48 +0100251 "-d", "unimp", "-kernel", os.path.abspath(self.args.hypervisor),
David Brazdil2df24082019-09-05 11:55:08 +0100252 ]
253
Andrew Walbranf636b842020-01-10 11:46:12 +0000254 if self.tfa:
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100255 bl1_path = os.path.join(
Olivier Deprez0c5e7dc2023-01-17 10:29:04 +0100256 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100257 "qemu", "bl1.bin")
Andrew Walbranf636b842020-01-10 11:46:12 +0000258 exec_args += ["-bios",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100259 os.path.abspath(bl1_path),
260 "-machine", "secure=on", "-semihosting-config",
Andrew Walbranab4b2d52020-06-11 16:54:10 +0100261 "enable=on,target=native"]
Andrew Walbranf636b842020-01-10 11:46:12 +0000262
David Brazdil2df24082019-09-05 11:55:08 +0100263 if self.args.initrd:
Andrew Walbranf636b842020-01-10 11:46:12 +0000264 exec_args += ["-initrd", os.path.abspath(self.args.initrd)]
David Brazdil2df24082019-09-05 11:55:08 +0100265
266 vm_args = join_if_not_None(self.args.vm_args, test_args)
267 if vm_args:
268 exec_args += ["-append", vm_args]
269
270 return exec_args
271
J-Alves67c31912023-02-02 13:52:50 +0000272 def run(self, run_name, test_args, is_long_running, debug = False,
273 show_output = False):
David Brazdil2df24082019-09-05 11:55:08 +0100274 """Run test given by `test_args` in QEMU."""
J-Alves67c31912023-02-02 13:52:50 +0000275 # TODO: use 'debug' and 'show_output' flags.
David Brazdil2df24082019-09-05 11:55:08 +0100276 run_state = self.start_run(run_name)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100277
278 try:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100279 # Execute test in QEMU..
David Brazdila2358d42020-01-27 18:51:38 +0000280 exec_args = self.gen_exec_args(test_args, is_long_running)
Andrew Walbranf636b842020-01-10 11:46:12 +0000281 self.exec_logged(run_state, exec_args,
282 cwd=self.qemu_wd)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100283 except DriverRunException:
284 pass
285
286 return self.finish_run(run_state)
Andrew Scullbc7189d2018-08-14 09:35:13 +0100287
David Brazdil94fd1e92020-02-03 16:45:20 +0000288 def finish(self):
289 """Clean up after running tests."""
290 pass
291
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100292class FvpDriver(Driver, ABC):
293 """Base class for driver which runs tests in Arm FVP emulator."""
David Brazdil2df24082019-09-05 11:55:08 +0100294
J-Alves19216692023-05-12 15:01:31 +0100295 def __init__(self, args, cpu_start_address, fvp_prebuilt_bl31):
Saul Romero42a13632022-12-20 15:13:36 +0000296 self.cov_plugin = args.coverage_plugin or None
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000297 if args.cpu:
298 raise ValueError("FVP emulator does not support the --cpu option.")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100299 super().__init__(args)
J-Alves19216692023-05-12 15:01:31 +0100300 self._cpu_start_address = cpu_start_address
301 self._fvp_prebuilt_bl31 = fvp_prebuilt_bl31
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100302
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100303 def create_dt(self, run_name : str):
304 """Create DT related files, and return respective paths in a tuple
305 (dts,dtb)"""
J-Alves8cc7dbb2021-04-16 10:38:48 +0100306 return DT(self.args.artifacts.create_file(run_name, ".dts"),
307 self.args.artifacts.create_file(run_name, ".dtb"))
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100308
J-Alves8cc7dbb2021-04-16 10:38:48 +0100309 def compile_dt(self, run_state, dt : DT):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100310 """Compile DT calling dtc."""
311 dtc_args = [
J-Alves8cc7dbb2021-04-16 10:38:48 +0100312 DTC_SCRIPT, "compile", "-i", dt.dts, "-o", dt.dtb,
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100313 ]
314 self.exec_logged(run_state, dtc_args)
315
316 def create_uart_log(self, run_name : str, file_name : str):
317 """Create uart log file, and return path"""
318 return self.args.artifacts.create_file(run_name, file_name)
319
320 def get_img_and_ldadd(self, partitions : dict):
321 ret = []
322 for i, p in enumerate(partitions):
J-Alves852fe742021-04-22 11:59:55 +0100323 with open(p["dts"], "r") as dt:
324 dts = dt.read()
325 manifest = fdt.parse_dts(dts)
326 vm_node = get_vm_node_from_manifest(dts)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100327 load_address = manifest.get_property("load_address",
J-Alves852fe742021-04-22 11:59:55 +0100328 f"/hypervisor/{vm_node}").value
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100329 ret.append((p["img"], load_address))
330 return ret
331
332 def get_manifests_from_json(self, partitions : list):
333 manifests = ""
334 if partitions is not None:
J-Alves852fe742021-04-22 11:59:55 +0100335 for i, p in enumerate(partitions):
336 manifests += correct_vm_node(read_file(p["dts"]), i + 1)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100337 return manifests
338
339 @abstractmethod
J-Alves8cc7dbb2021-04-16 10:38:48 +0100340 def gen_dts(self, dt, test_args):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100341 """Abstract method to generate dts file. This specific to the use case
342 so should be implemented within derived driver"""
343 pass
344
345 @abstractmethod
David Brazdil2df24082019-09-05 11:55:08 +0100346 def gen_fvp_args(
J-Alves67c31912023-02-02 13:52:50 +0000347 self, is_long_running, uart0_log_path, uart1_log_path, dt,
348 debug = False, show_output = False):
David Brazdil2df24082019-09-05 11:55:08 +0100349 """Generate command line arguments for FVP."""
J-Alves67c31912023-02-02 13:52:50 +0000350 show_output = debug or show_output
J-Alvesff651e32024-07-23 13:34:56 +0100351 disable_visualisation = self.args.disable_visualisation is True
J-Alves21b03522025-01-07 16:38:39 +0000352
353 time_limit = "40s"
354 if self.cov_plugin is None:
355 time_limit = "150s" if is_long_running else time_limit
356 else:
357 time_limit = "300s" if is_long_running else "80s"
358
J-Alves67c31912023-02-02 13:52:50 +0000359 fvp_args = []
360
361 if not show_output:
362 fvp_args = [
363 "timeout", "--foreground", time_limit,
364 ]
365
366 fvp_args += [
David Brazdil2df24082019-09-05 11:55:08 +0100367 FVP_BINARY,
J-Alves10446d82021-04-26 11:52:57 +0100368 "-C", "pci.pci_smmuv3.mmu.SMMU_AIDR=2",
369 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B",
370 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002",
371 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714",
372 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472",
373 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002",
374 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR2=0",
375 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR3=0",
David Brazdil2df24082019-09-05 11:55:08 +0100376 "-C", "pctl.startup=0.0.0.0",
Olivier Deprezcd857002022-05-09 09:06:24 +0200377 "-C", "bp.secure_memory=1",
David Brazdil2df24082019-09-05 11:55:08 +0100378 "-C", "cluster0.NUM_CORES=4",
379 "-C", "cluster1.NUM_CORES=4",
380 "-C", "cache_state_modelled=0",
David Brazdil2df24082019-09-05 11:55:08 +0100381 "-C", "bp.vis.rate_limit-enable=false",
David Brazdil2df24082019-09-05 11:55:08 +0100382 "-C", "bp.pl011_uart0.untimed_fifos=1",
383 "-C", "bp.pl011_uart0.unbuffered_output=1",
J-Alves19216692023-05-12 15:01:31 +0100384 "-C", f"cluster0.cpu0.RVBAR={self._cpu_start_address}",
385 "-C", f"cluster0.cpu1.RVBAR={self._cpu_start_address}",
386 "-C", f"cluster0.cpu2.RVBAR={self._cpu_start_address}",
387 "-C", f"cluster0.cpu3.RVBAR={self._cpu_start_address}",
388 "-C", f"cluster1.cpu0.RVBAR={self._cpu_start_address}",
389 "-C", f"cluster1.cpu1.RVBAR={self._cpu_start_address}",
390 "-C", f"cluster1.cpu2.RVBAR={self._cpu_start_address}",
391 "-C", f"cluster1.cpu3.RVBAR={self._cpu_start_address}",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100392 "--data",
J-Alves19216692023-05-12 15:01:31 +0100393 f"cluster0.cpu0={self._fvp_prebuilt_bl31}@{self._cpu_start_address}",
David Brazdil2df24082019-09-05 11:55:08 +0100394 "-C", "bp.ve_sysregs.mmbSiteDefault=0",
Raghu Krishnamurthy75ebf8c2021-11-28 07:22:12 -0800395 "-C", "cluster0.has_arm_v8-5=1",
396 "-C", "cluster1.has_arm_v8-5=1",
397 "-C", "cluster0.has_branch_target_exception=1",
398 "-C", "cluster1.has_branch_target_exception=1",
Maksims Svecovsce1261f2022-03-04 15:22:58 +0000399 "-C", "cluster0.memory_tagging_support_level=2",
400 "-C", "cluster1.memory_tagging_support_level=2",
401 "-C", "bp.dram_metadata.is_enabled=1",
Raghu Krishnamurthye2eae292022-08-10 22:38:41 -0700402 "-C", "cluster0.gicv3.extended-interrupt-range-support=1",
403 "-C", "cluster1.gicv3.extended-interrupt-range-support=1",
404 "-C", "gic_distributor.extended-ppi-count=64",
405 "-C", "gic_distributor.extended-spi-count=1024",
406 "-C", "gic_distributor.ARE-fixed-to-one=1",
David Brazdil2df24082019-09-05 11:55:08 +0100407 ]
J-Alves18a25f92021-05-04 17:47:41 +0100408
409 if uart0_log_path and uart1_log_path:
410 fvp_args += [
411 "-C", f"bp.pl011_uart0.out_file={uart0_log_path}",
412 "-C", f"bp.pl011_uart1.out_file={uart1_log_path}",
413 ]
J-Alves67c31912023-02-02 13:52:50 +0000414
415 if not show_output:
416 fvp_args += [
J-Alves67c31912023-02-02 13:52:50 +0000417 "-C", "bp.terminal_0.start_telnet=false",
418 "-C", "bp.terminal_1.start_telnet=false",
419 "-C", "bp.terminal_2.start_telnet=false",
420 "-C", "bp.terminal_3.start_telnet=false",
421 "-C", "bp.ve_sysregs.exit_on_shutdown=1",
422 ]
J-Alvesff651e32024-07-23 13:34:56 +0100423 disable_visualisation = True
424
425 if disable_visualisation:
426 fvp_args += [
427 "-C", "bp.vis.disable_visualisation=true"
428 ]
J-Alves67c31912023-02-02 13:52:50 +0000429
430 if debug:
431 fvp_args += [
J-Alves9a444ad2024-02-19 10:56:09 +0000432 "--iris-connect", "tcpserver,allowRemote",
433 "-p",
Saul Romero42a13632022-12-20 15:13:36 +0000434 ]
435
436 if self.cov_plugin is not None:
437 fvp_args += [
438 "--plugin", self.cov_plugin
J-Alves67c31912023-02-02 13:52:50 +0000439 ]
David Brazdil2df24082019-09-05 11:55:08 +0100440 return fvp_args
441
J-Alves67c31912023-02-02 13:52:50 +0000442 def run(self, run_name, test_args, is_long_running, debug = False,
443 show_output = False):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100444 """ Run test """
David Brazdil2df24082019-09-05 11:55:08 +0100445 run_state = self.start_run(run_name)
J-Alves8cc7dbb2021-04-16 10:38:48 +0100446 dt = self.create_dt(run_name)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100447 uart0_log_path = self.create_uart_log(run_name, ".uart0.log")
448 uart1_log_path = self.create_uart_log(run_name, ".uart1.log")
David Brazdil2df24082019-09-05 11:55:08 +0100449
David Brazdil0dbb41f2019-09-09 18:03:35 +0100450 try:
J-Alves8cc7dbb2021-04-16 10:38:48 +0100451 self.gen_dts(dt, test_args)
452 self.compile_dt(run_state, dt)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100453 fvp_args = self.gen_fvp_args(is_long_running, uart0_log_path,
J-Alves67c31912023-02-02 13:52:50 +0000454 uart1_log_path, dt, debug=debug,
455 show_output=show_output)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100456 self.exec_logged(run_state, fvp_args)
457 except DriverRunException:
458 pass
David Brazdil2df24082019-09-05 11:55:08 +0100459
460 # Append UART0 output to main log.
461 append_file(run_state.log_path, read_file(uart0_log_path))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100462 return self.finish_run(run_state)
David Brazdil2df24082019-09-05 11:55:08 +0100463
David Brazdil94fd1e92020-02-03 16:45:20 +0000464 def finish(self):
465 """Clean up after running tests."""
466 pass
467
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100468class FvpDriverHypervisor(FvpDriver):
469 """
470 Driver which runs tests in Arm FVP emulator, with hafnium as hypervisor
471 """
472 INITRD_START= 0x84000000
Olivier Depreza516f482021-04-30 18:47:59 +0200473 INITRD_END = 0x86000000 #Default value, however may change if initrd in args
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100474
J-Alves19216692023-05-12 15:01:31 +0100475 def __init__(self, args, hypervisor_address=0x80000000, hypervisor_dtb_address=0x82000000):
476 fvp_prebuilt_bl31 = os.path.join(FVP_PREBUILTS_TFA_ROOT, "bl31.bin")
477 FvpDriver.__init__(self, args, 0x04020000, fvp_prebuilt_bl31)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100478 self.vms_in_partitions_json = args.partitions and args.partitions["VMs"]
J-Alves19216692023-05-12 15:01:31 +0100479 self._hypervisor_address = hypervisor_address
480 self._hypervisor_dtb_address = hypervisor_dtb_address
J-Alves38223dd2021-04-20 17:31:48 +0100481
J-Alves8cc7dbb2021-04-16 10:38:48 +0100482 def gen_dts(self, dt, test_args):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100483 """Create a DeviceTree source which will be compiled into a DTB and
484 passed to FVP for a test run."""
485
486 vm_args = join_if_not_None(self.args.vm_args, test_args)
J-Alves8cc7dbb2021-04-16 10:38:48 +0100487 write_file(dt.dts, read_file(FVP_PREBUILT_DTS))
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100488
489 # Write the vm arguments to the partition manifest
490 to_append = f"""
491/ {{
492 chosen {{
493 bootargs = "{vm_args}";
494 stdout-path = "serial0:115200n8";
495 linux,initrd-start = <{self.INITRD_START if self.args.initrd else 0}>;
496 linux,initrd-end = <{self.INITRD_END if self.args.initrd else 0}>;
497 }};
498}};"""
499 if self.vms_in_partitions_json:
500 to_append += self.get_manifests_from_json(self.args.partitions["VMs"])
501
J-Alves8cc7dbb2021-04-16 10:38:48 +0100502 append_file(dt.dts, to_append)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100503
504 def gen_fvp_args(
J-Alves67c31912023-02-02 13:52:50 +0000505 self, is_long_running, uart0_log_path, uart1_log_path, dt,
506 debug = False, show_output = False):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100507 """Generate command line arguments for FVP."""
J-Alves67c31912023-02-02 13:52:50 +0000508 common_args = (self, is_long_running, uart0_log_path, uart1_log_path, dt,
509 debug, show_output)
510 fvp_args = FvpDriver.gen_fvp_args(*common_args)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100511
J-Alves8cc7dbb2021-04-16 10:38:48 +0100512 fvp_args += [
J-Alves19216692023-05-12 15:01:31 +0100513 "--data", f"cluster0.cpu0={dt.dtb}@{self._hypervisor_dtb_address}",
514 "--data", f"cluster0.cpu0={self.args.hypervisor}@{self._hypervisor_address}",
J-Alves8cc7dbb2021-04-16 10:38:48 +0100515 ]
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100516
517 if self.vms_in_partitions_json:
518 img_ldadd = self.get_img_and_ldadd(self.args.partitions["VMs"])
519 for img, ldadd in img_ldadd:
520 fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"]
521
522 if self.args.initrd:
523 fvp_args += [
524 "--data",
525 f"cluster0.cpu0={self.args.initrd}@{self.INITRD_START}"
526 ]
527 return fvp_args
528
529class FvpDriverSPMC(FvpDriver):
530 """
531 Driver which runs tests in Arm FVP emulator, with hafnium as SPMC
532 """
533 FVP_PREBUILT_SECURE_DTS = os.path.join(
534 HF_ROOT, "test", "vmapi", "fvp-base-spmc.dts")
J-Alvesacdbb862023-01-31 17:14:55 +0000535 hftest_cmd_file = tempfile.NamedTemporaryFile(mode="w+")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100536
J-Alves19216692023-05-12 15:01:31 +0100537 def __init__(self, args, cpu_start_address=0x04010000, fvp_prebuilt_bl31=None):
538 fvp_prebuilt_bl31 = os.path.join(FVP_PREBUILT_TFA_SPMD_ROOT, "bl31.bin") if fvp_prebuilt_bl31 is None else fvp_prebuilt_bl31
539 super().__init__(args, cpu_start_address, fvp_prebuilt_bl31)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100540
J-Alves19216692023-05-12 15:01:31 +0100541 self._spmc_address = 0x6000000
542 self._spmc_dtb_address = 0x0403f000
J-Alves38223dd2021-04-20 17:31:48 +0100543
J-Alves8cc7dbb2021-04-16 10:38:48 +0100544 def gen_dts(self, dt, test_args):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100545 """Create a DeviceTree source which will be compiled into a DTB and
546 passed to FVP for a test run."""
547 to_append = self.get_manifests_from_json(self.args.partitions["SPs"])
J-Alves8cc7dbb2021-04-16 10:38:48 +0100548 write_file(dt.dts, read_file(FvpDriverSPMC.FVP_PREBUILT_SECURE_DTS))
549 append_file(dt.dts, to_append)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100550
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000551 def secure_ctrl_fvp_args(self, secure_ctrl):
552 fvp_args = ""
553 if secure_ctrl:
554 fvp_args = [
555 "-C", f"bp.pl011_uart0.in_file={FvpDriverSPMC.hftest_cmd_file.name}",
556 "-C", f"bp.pl011_uart0.shutdown_tag=\"{HFTEST_CTRL_FINISHED}\"",
557 ]
558 return fvp_args
559
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100560 def gen_fvp_args(
J-Alves8cc7dbb2021-04-16 10:38:48 +0100561 self, is_long_running, uart0_log_path, uart1_log_path, dt,
J-Alves67c31912023-02-02 13:52:50 +0000562 call_super = True, secure_ctrl = True, debug = False, show_output = False):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100563 """Generate command line arguments for FVP."""
J-Alves67c31912023-02-02 13:52:50 +0000564 common_args = (self, is_long_running, uart0_log_path, uart1_log_path, dt.dtb,
565 debug, show_output)
J-Alves38223dd2021-04-20 17:31:48 +0100566 fvp_args = FvpDriver.gen_fvp_args(*common_args) if call_super else []
J-Alves8cc7dbb2021-04-16 10:38:48 +0100567
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100568 fvp_args += [
J-Alves19216692023-05-12 15:01:31 +0100569 "--data", f"cluster0.cpu0={dt.dtb}@{self._spmc_dtb_address}",
570 "--data", f"cluster0.cpu0={self.args.spmc}@{self._spmc_address}",
J-Alves8cc7dbb2021-04-16 10:38:48 +0100571 ]
572
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000573 fvp_args += FvpDriverSPMC.secure_ctrl_fvp_args(self, secure_ctrl)
J-Alves18a25f92021-05-04 17:47:41 +0100574
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100575 img_ldadd = self.get_img_and_ldadd(self.args.partitions["SPs"])
576 for img, ldadd in img_ldadd:
577 fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"]
578
579 return fvp_args
580
J-Alves67c31912023-02-02 13:52:50 +0000581 def run(self, run_name, test_args, is_long_running, debug = False, show_output = False):
J-Alvesacdbb862023-01-31 17:14:55 +0000582 vm_args = join_if_not_None(self.args.vm_args, test_args)
583 FvpDriverSPMC.hftest_cmd_file.write(f"{vm_args}\n")
584 FvpDriverSPMC.hftest_cmd_file.seek(0)
J-Alves67c31912023-02-02 13:52:50 +0000585 return super().run(run_name, test_args, is_long_running, debug, show_output)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100586
587 def finish(self):
588 """Clean up after running tests."""
J-Alvesacdbb862023-01-31 17:14:55 +0000589 FvpDriverSPMC.hftest_cmd_file.close()
David Brazdil2df24082019-09-05 11:55:08 +0100590
J-Alves38223dd2021-04-20 17:31:48 +0100591class FvpDriverBothWorlds(FvpDriverHypervisor, FvpDriverSPMC):
592 def __init__(self, args):
J-Alves19216692023-05-12 15:01:31 +0100593 FvpDriverHypervisor.__init__(self, args, hypervisor_address=0x88000000)
J-Alves38223dd2021-04-20 17:31:48 +0100594 FvpDriverSPMC.__init__(self, args)
595
J-Alves38223dd2021-04-20 17:31:48 +0100596 def create_dt(self, run_name):
597 dt = dict()
598 dt["hypervisor"] = FvpDriver.create_dt(self, run_name + "_hypervisor")
599 dt["spmc"] = FvpDriver.create_dt(self, run_name + "_spmc")
600 return dt
601
J-Alves38223dd2021-04-20 17:31:48 +0100602 def compile_dt(self, run_state, dt):
603 FvpDriver.compile_dt(self, run_state, dt["hypervisor"])
604 FvpDriver.compile_dt(self, run_state, dt["spmc"])
605
606 def gen_dts(self, dt, test_args):
607 FvpDriverHypervisor.gen_dts(self, dt["hypervisor"], test_args)
608 FvpDriverSPMC.gen_dts(self, dt["spmc"], test_args)
609
J-Alves67c31912023-02-02 13:52:50 +0000610 def gen_fvp_args(self, is_long_running, uart0_log_path, uart1_log_path, dt,
611 debug = False, show_output = False):
J-Alves38223dd2021-04-20 17:31:48 +0100612 """Generate command line arguments for FVP."""
J-Alves8d9fbb92021-12-13 17:28:15 +0000613 common_args = (self, is_long_running, uart0_log_path, uart1_log_path)
J-Alves67c31912023-02-02 13:52:50 +0000614 fvp_args = FvpDriverHypervisor.gen_fvp_args(*common_args, dt["hypervisor"],
615 debug, show_output)
J-Alves18a25f92021-05-04 17:47:41 +0100616 fvp_args += FvpDriverSPMC.gen_fvp_args(*common_args, dt["spmc"], False,
617 False)
J-Alves8d9fbb92021-12-13 17:28:15 +0000618 return fvp_args
J-Alves18a25f92021-05-04 17:47:41 +0100619
J-Alves67c31912023-02-02 13:52:50 +0000620 def run(self, run_name, test_args, is_long_running, debug = False,
621 show_output = False):
622
623 return FvpDriver.run(self, run_name, test_args, is_long_running,
624 debug, show_output)
J-Alves38223dd2021-04-20 17:31:48 +0100625
626 def finish(self):
627 """Clean up after running tests."""
J-Alves8d9fbb92021-12-13 17:28:15 +0000628 FvpDriver.finish(self)
J-Alves38223dd2021-04-20 17:31:48 +0100629
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000630class FvpDriverEL3SPMC(FvpDriverSPMC):
631 """
632 Driver which runs tests in Arm FVP emulator, with EL3 as SPMC
633 """
634
635 def __init__(self, args):
J-Alves19216692023-05-12 15:01:31 +0100636 FvpDriverSPMC.__init__(
637 self, args, cpu_start_address=0x04003000,
638 fvp_prebuilt_bl31=os.path.join(FVP_PREBUILTS_TFA_EL3_SPMC_ROOT, "bl31.bin"))
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000639 self.vms_in_partitions_json = args.partitions and args.partitions["SPs"]
J-Alves19216692023-05-12 15:01:31 +0100640 self._sp_dtb_address = 0x0403f000
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000641
642 def sp_partition_manifest_fvp_args(self):
643 img_ldadd = self.get_img_and_ldadd(self.args.partitions["SPs"])
644
645 # Expect only one tuple with img and load address, as EL3 SPMC only supports
646 # one SP.
647 assert(len(img_ldadd) == 1)
648 img, ldadd = img_ldadd[0]
649 fvp_args = ["--data", f"cluster0.cpu0={img}@{ldadd}"]
650
651 # Even though FF-A manifest is part of the SP PKG we need to load at a specific
652 # location. Fetch the respective dtb file and load at the following address.
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000653 output_path = os.path.dirname(os.path.dirname(img))
654 partition_manifest = f"{output_path}/partition-manifest.dtb"
J-Alves19216692023-05-12 15:01:31 +0100655 fvp_args += ["--data", f"cluster0.cpu0={partition_manifest}@{self._sp_dtb_address}"]
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000656 return fvp_args
657
658 def gen_fvp_args(
659 self, is_long_running, uart0_log_path, uart1_log_path, dt,
660 call_super = True, secure_ctrl = True, debug = False, show_output = False):
661 """Generate command line arguments for FVP."""
662 common_args = (self, is_long_running, uart0_log_path, uart1_log_path, dt.dtb,
663 debug, show_output)
664 fvp_args = FvpDriver.gen_fvp_args(*common_args) if call_super else []
665
666 fvp_args += FvpDriverSPMC.secure_ctrl_fvp_args(self, secure_ctrl)
667
668 fvp_args += self.sp_partition_manifest_fvp_args()
669
670 return fvp_args
671
Shruti Gupta22dbef32023-04-03 10:26:31 +0100672class FvpDriverEL3SPMCBothWorlds(FvpDriverHypervisor, FvpDriverEL3SPMC):
673 """
674 Driver which runs tests in Arm FVP emulator, with EL3 as SPMC
675 """
676
J-Alves19216692023-05-12 15:01:31 +0100677 def __init__(self, args):
678 FvpDriverHypervisor.__init__(self, args)
679 FvpDriverEL3SPMC.__init__(self, args)
Shruti Gupta22dbef32023-04-03 10:26:31 +0100680
J-Alves19216692023-05-12 15:01:31 +0100681 self._fvp_prebuilt_bl32 = os.path.join(FVP_PREBUILTS_TFA_EL3_SPMC_ROOT, "bl32.bin")
682 self._fvp_prebuilt_dtb = os.path.join(FVP_PREBUILTS_TFA_EL3_SPMC_ROOT, "fdts/fvp_tsp_sp_manifest.dtb")
Shruti Gupta22dbef32023-04-03 10:26:31 +0100683
684 def gen_fvp_args(
685 self, is_long_running, uart0_log_path, uart1_log_path, dt,
686 call_super = True, secure_ctrl = True, debug = False, show_output = False):
687 """Generate command line arguments for FVP."""
688
689 fvp_args = FvpDriverHypervisor.gen_fvp_args(self, is_long_running, uart0_log_path, uart1_log_path, dt,
690 debug, show_output)
691
692 fvp_args += FvpDriverSPMC.secure_ctrl_fvp_args(self, secure_ctrl)
693
694 if self.args.partitions is not None and self.args.partitions["SPs"] is not None:
695 fvp_args += FvpDriverEL3SPMC.sp_partition_manifest_fvp_args(self)
696 else :
697 # Use prebuilt TSP and TSP manifest if build does not specify SP
698 # EL3 SPMC expects SP to be loaded at 0xFF200000 and SP manifest at 0x0403F000
J-Alves19216692023-05-12 15:01:31 +0100699 fvp_args += ["--data", f"cluster0.cpu0={self._fvp_prebuilt_bl32}@0xff200000"]
700 fvp_args += ["--data", f"cluster0.cpu0={self._fvp_prebuilt_dtb}@{self._sp_dtb_address}"]
Shruti Gupta22dbef32023-04-03 10:26:31 +0100701
702 return fvp_args
703
David Brazdil17e76652020-01-29 14:44:19 +0000704class SerialDriver(Driver):
705 """Driver which communicates with a device over the serial port."""
706
David Brazdil9d4ed962020-02-06 17:23:48 +0000707 def __init__(self, args, tty_file, baudrate, init_wait):
David Brazdil17e76652020-01-29 14:44:19 +0000708 Driver.__init__(self, args)
David Brazdil9d4ed962020-02-06 17:23:48 +0000709 self.tty_file = tty_file
710 self.baudrate = baudrate
David Brazdil4f9cf9a2020-02-06 17:34:44 +0000711 self.pyserial = importlib.import_module("serial")
David Brazdild8013f92020-02-03 16:40:25 +0000712
David Brazdil9d4ed962020-02-06 17:23:48 +0000713 if init_wait:
David Brazdild8013f92020-02-03 16:40:25 +0000714 input("Press ENTER and then reset the device...")
David Brazdil17e76652020-01-29 14:44:19 +0000715
David Brazdil9d4ed962020-02-06 17:23:48 +0000716 def connect(self):
David Brazdil4f9cf9a2020-02-06 17:34:44 +0000717 return self.pyserial.Serial(self.tty_file, self.baudrate, timeout=10)
David Brazdil9d4ed962020-02-06 17:23:48 +0000718
David Brazdil17e76652020-01-29 14:44:19 +0000719 def run(self, run_name, test_args, is_long_running):
720 """Communicate `test_args` to the device over the serial port."""
721 run_state = self.start_run(run_name)
722
David Brazdil9d4ed962020-02-06 17:23:48 +0000723 with self.connect() as ser:
David Brazdil17e76652020-01-29 14:44:19 +0000724 with open(run_state.log_path, "a") as f:
725 while True:
726 # Read one line from the serial port.
727 line = ser.readline().decode('utf-8')
728 if len(line) == 0:
729 # Timeout
730 run_state.set_ret_code(124)
731 input("Timeout. " +
732 "Press ENTER and then reset the device...")
733 break
734 # Write the line to the log file.
735 f.write(line)
736 if HFTEST_CTRL_GET_COMMAND_LINE in line:
737 # Device is waiting for `test_args`.
738 ser.write(test_args.encode('ascii'))
739 ser.write(b'\r')
740 elif HFTEST_CTRL_FINISHED in line:
741 # Device has finished running this test and will reboot.
742 break
J-Alves18a25f92021-05-04 17:47:41 +0100743
David Brazdil17e76652020-01-29 14:44:19 +0000744 return self.finish_run(run_state)
745
David Brazdil94fd1e92020-02-03 16:45:20 +0000746 def finish(self):
747 """Clean up after running tests."""
David Brazdil9d4ed962020-02-06 17:23:48 +0000748 with self.connect() as ser:
David Brazdil94fd1e92020-02-03 16:45:20 +0000749 while True:
750 line = ser.readline().decode('utf-8')
751 if len(line) == 0:
752 input("Timeout. Press ENTER and then reset the device...")
753 elif HFTEST_CTRL_GET_COMMAND_LINE in line:
754 # Device is waiting for a command. Instruct it to exit
755 # the test environment.
756 ser.write("exit".encode('ascii'))
757 ser.write(b'\r')
758 break
759
David Brazdil2df24082019-09-05 11:55:08 +0100760# Tuple used to return information about the results of running a set of tests.
761TestRunnerResult = collections.namedtuple("TestRunnerResult", [
762 "tests_run",
763 "tests_failed",
Andrew Walbranf9463922020-06-05 16:44:42 +0100764 "tests_skipped",
David Brazdil2df24082019-09-05 11:55:08 +0100765 ])
766
David Brazdil2df24082019-09-05 11:55:08 +0100767class TestRunner:
768 """Class which communicates with a test platform to obtain a list of
769 available tests and driving their execution."""
770
J-Alves8cc7dbb2021-04-16 10:38:48 +0100771 def __init__(self, artifacts, driver, test_set_up, suite_regex, test_regex,
J-Alves67c31912023-02-02 13:52:50 +0000772 skip_long_running_tests, force_long_running, debug, show_output):
David Brazdil2df24082019-09-05 11:55:08 +0100773 self.artifacts = artifacts
774 self.driver = driver
J-Alves8cc7dbb2021-04-16 10:38:48 +0100775 self.test_set_up = test_set_up
David Brazdil3cc24aa2019-09-27 10:24:41 +0100776 self.skip_long_running_tests = skip_long_running_tests
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100777 self.force_long_running = force_long_running
J-Alves67c31912023-02-02 13:52:50 +0000778 self.debug = debug
779 self.show_output = show_output
David Brazdil2df24082019-09-05 11:55:08 +0100780
781 self.suite_re = re.compile(suite_regex or ".*")
782 self.test_re = re.compile(test_regex or ".*")
783
784 def extract_hftest_lines(self, raw):
785 """Extract hftest-specific lines from a raw output from an invocation
786 of the test platform."""
787 lines = []
J-Alves07be7bb2021-04-13 11:09:12 +0100788 lines_to_process = raw.splitlines()
789
790 try:
791 # If logs have logs of more than one VM, the loop below to extract
792 # lines won't work. Thus, extracting between starting and ending
793 # logs: HFTEST_CTRL_GET_COMMAND_LINE and HFTEST_CTRL_FINISHED.
794 hftest_start = lines_to_process.index(HFTEST_CTRL_GET_COMMAND_LINE) + 1
795 hftest_end = lines_to_process.index(HFTEST_CTRL_FINISHED)
796 except ValueError:
797 hftest_start = 0
798 hftest_end = len(lines_to_process)
799
800 lines_to_process = lines_to_process[hftest_start : hftest_end]
801
802 for line in lines_to_process:
Karl Meakin6f1f1212024-07-16 10:18:16 +0100803 match = HFTEST_CTRL_JSON_REGEX.search(line)
J-Alves3dbb8562020-12-01 10:45:37 +0000804 if match is not None:
805 line = line[match.end():]
David Brazdil2df24082019-09-05 11:55:08 +0100806 if line.startswith(HFTEST_LOG_PREFIX):
807 lines.append(line[len(HFTEST_LOG_PREFIX):])
808 return lines
809
810 def get_test_json(self):
811 """Invoke the test platform and request a JSON of available test and
812 test suites."""
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100813 out = self.driver.run("json", "json", self.force_long_running)
Daniel Boulby61049dc2023-06-16 14:15:21 +0100814 hf_out = self.extract_hftest_lines(out)
Karl Meakinc7a38482024-07-15 10:29:11 +0100815 try:
816 hf_out = hf_out[hf_out.index(HFTEST_CTRL_JSON_START) + 1
Daniel Boulby61049dc2023-06-16 14:15:21 +0100817 :hf_out.index(HFTEST_CTRL_JSON_END)];
Karl Meakinc7a38482024-07-15 10:29:11 +0100818 except ValueError as e:
819 print("Unable to find JSON control string:")
820 print(f"out={out}")
821 print(f"hf_out={hf_out}")
822 raise e
823
Daniel Boulby61049dc2023-06-16 14:15:21 +0100824 hf_out = "\n".join(hf_out)
David Brazdil2df24082019-09-05 11:55:08 +0100825 try:
826 return json.loads(hf_out)
827 except ValueError as e:
Karl Meakinc7a38482024-07-15 10:29:11 +0100828 print("Unable to parse JSON:")
829 print(f"out={out}")
830 print(f"hf_out={hf_outout}")
David Brazdil2df24082019-09-05 11:55:08 +0100831 print(out)
832 raise e
833
834 def collect_results(self, fn, it, xml_node):
835 """Run `fn` on every entry in `it` and collect their TestRunnerResults.
836 Insert "tests" and "failures" nodes to `xml_node`."""
837 tests_run = 0
838 tests_failed = 0
Andrew Walbranf9463922020-06-05 16:44:42 +0100839 tests_skipped = 0
Andrew Walbran42bf2842020-06-05 18:50:19 +0100840 start_time = time.perf_counter()
David Brazdil2df24082019-09-05 11:55:08 +0100841 for i in it:
842 sub_result = fn(i)
843 assert(sub_result.tests_run >= sub_result.tests_failed)
844 tests_run += sub_result.tests_run
845 tests_failed += sub_result.tests_failed
Andrew Walbranf9463922020-06-05 16:44:42 +0100846 tests_skipped += sub_result.tests_skipped
Andrew Walbran42bf2842020-06-05 18:50:19 +0100847 elapsed_time = time.perf_counter() - start_time
David Brazdil2df24082019-09-05 11:55:08 +0100848
Andrew Walbranf9463922020-06-05 16:44:42 +0100849 xml_node.set("tests", str(tests_run + tests_skipped))
David Brazdil2df24082019-09-05 11:55:08 +0100850 xml_node.set("failures", str(tests_failed))
Andrew Walbranf9463922020-06-05 16:44:42 +0100851 xml_node.set("skipped", str(tests_skipped))
Andrew Walbran42bf2842020-06-05 18:50:19 +0100852 xml_node.set("time", str(elapsed_time))
Andrew Walbranf9463922020-06-05 16:44:42 +0100853 return TestRunnerResult(tests_run, tests_failed, tests_skipped)
David Brazdil2df24082019-09-05 11:55:08 +0100854
855 def is_passed_test(self, test_out):
856 """Parse the output of a test and return True if it passed."""
857 return \
858 len(test_out) > 0 and \
859 test_out[-1] == HFTEST_LOG_FINISHED and \
860 not any(l.startswith(HFTEST_LOG_FAILURE_PREFIX) for l in test_out)
861
Andrew Walbranf9463922020-06-05 16:44:42 +0100862 def get_failure_message(self, test_out):
863 """Parse the output of a test and return the message of the first
864 assertion failure."""
865 for i, line in enumerate(test_out):
866 if line.startswith(HFTEST_LOG_FAILURE_PREFIX) and i + 1 < len(test_out):
867 # The assertion message is on the line after the 'Failure:'
868 return test_out[i + 1].strip()
869
870 return None
871
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000872 def get_log_name(self, suite, test):
873 """Returns a string with a generated log name for the test."""
874 log_name = ""
875
876 cpu = self.driver.args.cpu
877 if cpu:
878 log_name += cpu + "."
879
880 log_name += suite["name"] + "." + test["name"]
881
882 return log_name
883
David Brazdil2df24082019-09-05 11:55:08 +0100884 def run_test(self, suite, test, suite_xml):
885 """Invoke the test platform and request to run a given `test` in given
886 `suite`. Create a new XML node with results under `suite_xml`.
887 Test only invoked if it matches the regex given to constructor."""
David Brazdil3cc24aa2019-09-27 10:24:41 +0100888 if not self.test_re.match(test["name"]):
Andrew Walbranf9463922020-06-05 16:44:42 +0100889 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100890
891 test_xml = ET.SubElement(suite_xml, "testcase")
David Brazdil3cc24aa2019-09-27 10:24:41 +0100892 test_xml.set("name", test["name"])
893 test_xml.set("classname", suite["name"])
Andrew Walbranf9463922020-06-05 16:44:42 +0100894
J-Alvesd459b562022-12-05 14:56:33 +0000895 if (self.skip_long_running_tests and test["is_long_running"]) or test["skip_test"]:
Andrew Walbranf9463922020-06-05 16:44:42 +0100896 print(" SKIP", test["name"])
897 test_xml.set("status", "notrun")
898 skipped_xml = ET.SubElement(test_xml, "skipped")
899 skipped_xml.set("message", "Long running")
900 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=1)
901
J-Alves67c31912023-02-02 13:52:50 +0000902 action_log = "DEBUG" if self.debug else "RUN"
903 print(f" {action_log}", test["name"])
Andrew Walbranf9463922020-06-05 16:44:42 +0100904 log_name = self.get_log_name(suite, test)
905
David Brazdil2df24082019-09-05 11:55:08 +0100906 test_xml.set("status", "run")
907
Andrew Walbran42bf2842020-06-05 18:50:19 +0100908 start_time = time.perf_counter()
Andrew Walbranf9463922020-06-05 16:44:42 +0100909 out = self.driver.run(
David Brazdil3cc24aa2019-09-27 10:24:41 +0100910 log_name, "run {} {}".format(suite["name"], test["name"]),
J-Alves67c31912023-02-02 13:52:50 +0000911 test["is_long_running"] or self.force_long_running,
912 self.debug, self.show_output)
913
Andrew Walbranf9463922020-06-05 16:44:42 +0100914 hftest_out = self.extract_hftest_lines(out)
Andrew Walbran42bf2842020-06-05 18:50:19 +0100915 elapsed_time = time.perf_counter() - start_time
916
917 test_xml.set("time", str(elapsed_time))
David Brazdil2df24082019-09-05 11:55:08 +0100918
Andrew Walbranf9463922020-06-05 16:44:42 +0100919 system_out_xml = ET.SubElement(test_xml, "system-out")
920 system_out_xml.text = out
921
922 if self.is_passed_test(hftest_out):
David Brazdil2df24082019-09-05 11:55:08 +0100923 print(" PASS")
Andrew Walbranf9463922020-06-05 16:44:42 +0100924 return TestRunnerResult(tests_run=1, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100925 else:
David Brazdil623b6812019-09-09 11:41:08 +0100926 print("[x] FAIL --", self.driver.get_run_log(log_name))
David Brazdil2df24082019-09-05 11:55:08 +0100927 failure_xml = ET.SubElement(test_xml, "failure")
Andrew Walbranf9463922020-06-05 16:44:42 +0100928 failure_message = self.get_failure_message(hftest_out) or "Test failed"
929 failure_xml.set("message", failure_message)
930 failure_xml.text = '\n'.join(hftest_out)
931 return TestRunnerResult(tests_run=1, tests_failed=1, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100932
933 def run_suite(self, suite, xml):
934 """Invoke the test platform and request to run all matching tests in
935 `suite`. Create new XML nodes with results under `xml`.
936 Suite skipped if it does not match the regex given to constructor."""
937 if not self.suite_re.match(suite["name"]):
Andrew Walbranf9463922020-06-05 16:44:42 +0100938 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100939
940 print(" SUITE", suite["name"])
941 suite_xml = ET.SubElement(xml, "testsuite")
942 suite_xml.set("name", suite["name"])
Andrew Walbran16ae62e2020-06-05 18:27:46 +0100943 properties_xml = ET.SubElement(suite_xml, "properties")
944
945 property_xml = ET.SubElement(properties_xml, "property")
946 property_xml.set("name", "driver")
947 property_xml.set("value", type(self.driver).__name__)
948
949 if self.driver.args.cpu:
950 property_xml = ET.SubElement(properties_xml, "property")
951 property_xml.set("name", "cpu")
952 property_xml.set("value", self.driver.args.cpu)
David Brazdil2df24082019-09-05 11:55:08 +0100953
954 return self.collect_results(
955 lambda test: self.run_test(suite, test, suite_xml),
956 suite["tests"],
957 suite_xml)
958
959 def run_tests(self):
960 """Run all suites and tests matching regexes given to constructor.
961 Write results to sponge log XML. Return the number of run and failed
962 tests."""
963
964 test_spec = self.get_test_json()
965 timestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
966
967 xml = ET.Element("testsuites")
J-Alves8cc7dbb2021-04-16 10:38:48 +0100968 xml.set("name", self.test_set_up)
David Brazdil2df24082019-09-05 11:55:08 +0100969 xml.set("timestamp", timestamp)
970
971 result = self.collect_results(
972 lambda suite: self.run_suite(suite, xml),
973 test_spec["suites"],
974 xml)
975
976 # Write XML to file.
David Brazdilee5e25d2020-01-24 14:17:45 +0000977 ET.ElementTree(xml).write(self.artifacts.sponge_xml_path,
978 encoding='utf-8', xml_declaration=True)
David Brazdil2df24082019-09-05 11:55:08 +0100979
980 if result.tests_failed > 0:
981 print("[x] FAIL:", result.tests_failed, "of", result.tests_run,
982 "tests failed")
983 elif result.tests_run > 0:
984 print(" PASS: all", result.tests_run, "tests passed")
985
David Brazdil94fd1e92020-02-03 16:45:20 +0000986 # Let the driver clean up.
987 self.driver.finish()
988
David Brazdil2df24082019-09-05 11:55:08 +0100989 return result
Andrew Scullbc7189d2018-08-14 09:35:13 +0100990
Andrew Scullbc7189d2018-08-14 09:35:13 +0100991def Main():
992 parser = argparse.ArgumentParser()
J-Alves8cc7dbb2021-04-16 10:38:48 +0100993 parser.add_argument("--hypervisor")
994 parser.add_argument("--spmc")
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +0000995 parser.add_argument("--el3_spmc", action="store_true")
Andrew Scull23e93a82018-10-26 14:56:04 +0100996 parser.add_argument("--log", required=True)
Andrew Walbran7559fcf2019-05-09 17:11:20 +0100997 parser.add_argument("--out_initrd")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100998 parser.add_argument("--out_partitions")
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000999 parser.add_argument("--initrd")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001000 parser.add_argument("--partitions_json")
Andrew Scullbc7189d2018-08-14 09:35:13 +01001001 parser.add_argument("--suite")
1002 parser.add_argument("--test")
Andrew Walbranbc342d42019-02-05 16:56:02 +00001003 parser.add_argument("--vm_args")
David Brazdil17e76652020-01-29 14:44:19 +00001004 parser.add_argument("--driver", default="qemu")
1005 parser.add_argument("--serial-dev", default="/dev/ttyUSB0")
1006 parser.add_argument("--serial-baudrate", type=int, default=115200)
David Brazdild8013f92020-02-03 16:40:25 +00001007 parser.add_argument("--serial-no-init-wait", action="store_true")
David Brazdil3cc24aa2019-09-27 10:24:41 +01001008 parser.add_argument("--skip-long-running-tests", action="store_true")
Andrew Walbrane1fa70b2020-05-28 11:30:11 +01001009 parser.add_argument("--force-long-running", action="store_true")
J-Alves67c31912023-02-02 13:52:50 +00001010 parser.add_argument("--debug", action="store_true",
1011 help="Makes platforms stall waiting for debugger connection.")
1012 parser.add_argument("--show-output", action="store_true")
Fuad Tabba36c8c2b2019-11-04 16:55:32 +00001013 parser.add_argument("--cpu",
1014 help="Selects the CPU configuration for the run environment.")
Andrew Walbranf636b842020-01-10 11:46:12 +00001015 parser.add_argument("--tfa", action="store_true")
Saul Romero42a13632022-12-20 15:13:36 +00001016 parser.add_argument("--coverage_plugin", default="")
J-Alvesff651e32024-07-23 13:34:56 +01001017 parser.add_argument("--disable_visualisation", action="store_true")
Andrew Scullbc7189d2018-08-14 09:35:13 +01001018 args = parser.parse_args()
David Brazdil2df24082019-09-05 11:55:08 +01001019
J-Alves8cc7dbb2021-04-16 10:38:48 +01001020 # Create class which will manage all test artifacts.
1021 if args.hypervisor and args.spmc:
1022 test_set_up = "hypervisor_and_spmc"
1023 elif args.hypervisor:
1024 test_set_up = "hypervisor"
1025 elif args.spmc:
1026 test_set_up = "spmc"
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +00001027 elif args.el3_spmc:
1028 test_set_up = "el3_spmc"
J-Alves8cc7dbb2021-04-16 10:38:48 +01001029 else:
1030 raise Exception("No Hafnium image provided!\n")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001031
J-Alves8cc7dbb2021-04-16 10:38:48 +01001032 initrd = None
1033 if args.hypervisor and args.initrd:
David Brazdil0dbb41f2019-09-09 18:03:35 +01001034 initrd_dir = os.path.join(args.out_initrd, "obj", args.initrd)
1035 initrd = os.path.join(initrd_dir, "initrd.img")
J-Alves8cc7dbb2021-04-16 10:38:48 +01001036 test_set_up += "_" + args.initrd
Andrew Walbranbc342d42019-02-05 16:56:02 +00001037 vm_args = args.vm_args or ""
David Brazdil2df24082019-09-05 11:55:08 +01001038
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001039 partitions = None
J-Alves6acc5372024-09-11 17:30:11 +01001040 global_run_name = "arch"
J-Alves18a25f92021-05-04 17:47:41 +01001041 if args.driver == "fvp":
1042 if args.partitions_json is not None:
1043 partitions_dir = os.path.join(
1044 args.out_partitions, "obj", args.partitions_json)
1045 partitions = json.load(open(partitions_dir, "r"))
1046 global_run_name = os.path.basename(args.partitions_json).split(".")[0]
1047 elif args.hypervisor:
1048 if args.initrd:
1049 global_run_name = os.path.basename(args.initrd)
1050 else:
1051 global_run_name = os.path.basename(args.hypervisor).split(".")[0]
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001052
David Brazdil2df24082019-09-05 11:55:08 +01001053 # Create class which will manage all test artifacts.
J-Alves6acc5372024-09-11 17:30:11 +01001054 log_dir = os.path.join(os.path.join(args.log, test_set_up), global_run_name)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001055 artifacts = ArtifactsManager(log_dir)
David Brazdil2df24082019-09-05 11:55:08 +01001056
1057 # Create a driver for the platform we want to test on.
J-Alves8cc7dbb2021-04-16 10:38:48 +01001058 driver_args = DriverArgs(artifacts, args.hypervisor, args.spmc, initrd,
Saul Romero42a13632022-12-20 15:13:36 +00001059 vm_args, args.cpu, partitions, global_run_name,
J-Alvesff651e32024-07-23 13:34:56 +01001060 args.coverage_plugin, args.disable_visualisation)
David Brazdil17e76652020-01-29 14:44:19 +00001061
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +00001062 if args.el3_spmc:
J-Alves38223dd2021-04-20 17:31:48 +01001063 # So far only FVP supports tests for SPMC.
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001064 if args.driver != "fvp":
1065 raise Exception("Secure tests can only run with fvp driver")
Shruti Gupta22dbef32023-04-03 10:26:31 +01001066 if args.hypervisor:
1067 driver = FvpDriverEL3SPMCBothWorlds(driver_args)
1068 else:
1069 driver = FvpDriverEL3SPMC(driver_args)
Shruti Gupta2b1e0cd2022-12-20 17:45:24 +00001070 elif args.spmc:
1071 # So far only FVP supports tests for SPMC.
1072 if args.driver != "fvp":
1073 raise Exception("Secure tests can only run with fvp driver")
J-Alves38223dd2021-04-20 17:31:48 +01001074 if args.hypervisor:
1075 driver = FvpDriverBothWorlds(driver_args)
1076 else:
1077 driver = FvpDriverSPMC(driver_args)
J-Alves8cc7dbb2021-04-16 10:38:48 +01001078 elif args.hypervisor:
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001079 if args.driver == "qemu":
J-Alves8cc7dbb2021-04-16 10:38:48 +01001080 out = os.path.dirname(args.hypervisor)
1081 driver = QemuDriver(driver_args, out, args.tfa)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +01001082 elif args.driver == "fvp":
1083 driver = FvpDriverHypervisor(driver_args)
1084 elif args.driver == "serial":
1085 driver = SerialDriver(driver_args, args.serial_dev,
1086 args.serial_baudrate, not args.serial_no_init_wait)
1087 else:
1088 raise Exception("Unknown driver name: {}".format(args.driver))
J-Alves8cc7dbb2021-04-16 10:38:48 +01001089 else:
1090 raise Exception("No Hafnium image provided!\n")
David Brazdil2df24082019-09-05 11:55:08 +01001091
1092 # Create class which will drive test execution.
J-Alves8cc7dbb2021-04-16 10:38:48 +01001093 runner = TestRunner(artifacts, driver, test_set_up, args.suite, args.test,
J-Alves67c31912023-02-02 13:52:50 +00001094 args.skip_long_running_tests, args.force_long_running, args.debug, args.show_output)
David Brazdil2df24082019-09-05 11:55:08 +01001095
1096 # Run tests.
1097 runner_result = runner.run_tests()
1098
1099 # Print error message if no tests were run as this is probably unexpected.
1100 # Return suitable error code.
1101 if runner_result.tests_run == 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +01001102 print("Error: no tests match")
1103 return 10
David Brazdil2df24082019-09-05 11:55:08 +01001104 elif runner_result.tests_failed > 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +01001105 return 1
1106 else:
David Brazdil2df24082019-09-05 11:55:08 +01001107 return 0
Andrew Scullbc7189d2018-08-14 09:35:13 +01001108
1109if __name__ == "__main__":
1110 sys.exit(Main())