blob: 2e70abf9df6b0d7dbf0b733ea82042c975a5befd [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
Andrew Scullbc7189d2018-08-14 09:35:13 +010029
Andrew Scull845fc9b2019-04-03 12:44:26 +010030HFTEST_LOG_PREFIX = "[hftest] "
31HFTEST_LOG_FAILURE_PREFIX = "Failure:"
32HFTEST_LOG_FINISHED = "FINISHED"
33
David Brazdil17e76652020-01-29 14:44:19 +000034HFTEST_CTRL_GET_COMMAND_LINE = "[hftest_ctrl:get_command_line]"
35HFTEST_CTRL_FINISHED = "[hftest_ctrl:finished]"
36
David Brazdil2df24082019-09-05 11:55:08 +010037HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
38 os.path.abspath(__file__))))
David Brazdil5715f042019-08-27 11:11:51 +010039DTC_SCRIPT = os.path.join(HF_ROOT, "build", "image", "dtc.py")
David Brazdil2df24082019-09-05 11:55:08 +010040FVP_BINARY = os.path.join(
41 os.path.dirname(HF_ROOT), "fvp", "Base_RevC_AEMv8A_pkg", "models",
Olivier Depreze4153042020-10-02 15:24:59 +020042 "Linux64_GCC-6.4", "FVP_Base_RevC-2xAEMv8A")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010043HF_PREBUILTS = os.path.join(HF_ROOT, "prebuilts")
44FVP_PREBUILTS_TFA_TRUSTY_ROOT = os.path.join(
45 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-trusty", "fvp")
David Brazdil2df24082019-09-05 11:55:08 +010046FVP_PREBUILT_DTS = os.path.join(
Olivier Depreza6d2e6d2020-11-06 18:09:50 +010047 FVP_PREBUILTS_TFA_TRUSTY_ROOT, "fvp-base-gicv3-psci-1t.dts")
48
49FVP_PREBUILT_TFA_ROOT = os.path.join(
50 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a", "fvp")
Andrew Scull845fc9b2019-04-03 12:44:26 +010051
David Brazdil2df24082019-09-05 11:55:08 +010052def read_file(path):
53 with open(path, "r") as f:
54 return f.read()
Andrew Scull845fc9b2019-04-03 12:44:26 +010055
David Brazdil2df24082019-09-05 11:55:08 +010056def write_file(path, to_write, append=False):
57 with open(path, "a" if append else "w") as f:
58 f.write(to_write)
59
60def append_file(path, to_write):
61 write_file(path, to_write, append=True)
62
63def join_if_not_None(*args):
64 return " ".join(filter(lambda x: x, args))
65
66class ArtifactsManager:
67 """Class which manages folder with test artifacts."""
68
69 def __init__(self, log_dir):
70 self.created_files = []
71 self.log_dir = log_dir
72
73 # Create directory.
Andrew Scull845fc9b2019-04-03 12:44:26 +010074 try:
David Brazdil2df24082019-09-05 11:55:08 +010075 os.makedirs(self.log_dir)
76 except OSError:
77 if not os.path.isdir(self.log_dir):
78 raise
79 print("Logs saved under", log_dir)
80
81 # Create files expected by the Sponge test result parser.
82 self.sponge_log_path = self.create_file("sponge_log", ".log")
83 self.sponge_xml_path = self.create_file("sponge_log", ".xml")
84
David Brazdil623b6812019-09-09 11:41:08 +010085 def gen_file_path(self, basename, extension):
86 """Generate path to a file in the log directory."""
87 return os.path.join(self.log_dir, basename + extension)
88
David Brazdil2df24082019-09-05 11:55:08 +010089 def create_file(self, basename, extension):
90 """Create and touch a new file in the log folder. Ensure that no other
91 file of the same name was created by this instance of ArtifactsManager.
92 """
93 # Determine the path of the file.
David Brazdil623b6812019-09-09 11:41:08 +010094 path = self.gen_file_path(basename, extension)
David Brazdil2df24082019-09-05 11:55:08 +010095
96 # Check that the path is unique.
97 assert(path not in self.created_files)
98 self.created_files += [ path ]
99
100 # Touch file.
101 with open(path, "w") as f:
102 pass
103
104 return path
Andrew Scullbc7189d2018-08-14 09:35:13 +0100105
David Brazdil623b6812019-09-09 11:41:08 +0100106 def get_file(self, basename, extension):
107 """Return path to a file in the log folder. Assert that it was created
108 by this instance of ArtifactsManager."""
109 path = self.gen_file_path(basename, extension)
110 assert(path in self.created_files)
111 return path
112
Andrew Scullbc7189d2018-08-14 09:35:13 +0100113
David Brazdil2df24082019-09-05 11:55:08 +0100114# Tuple holding the arguments common to all driver constructors.
115# This is to avoid having to pass arguments from subclasses to superclasses.
116DriverArgs = collections.namedtuple("DriverArgs", [
117 "artifacts",
118 "kernel",
119 "initrd",
120 "vm_args",
David Brazdil17e76652020-01-29 14:44:19 +0000121 "cpu",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100122 "partitions"
David Brazdil2df24082019-09-05 11:55:08 +0100123 ])
Marc Bonnici0a125632019-04-01 13:46:52 +0100124
Andrew Walbran98656252019-03-14 14:52:29 +0000125
David Brazdil2df24082019-09-05 11:55:08 +0100126# State shared between the common Driver class and its subclasses during
127# a single invocation of the target platform.
David Brazdil7325eaf2019-09-27 13:04:51 +0100128class DriverRunState:
129 def __init__(self, log_path):
130 self.log_path = log_path
131 self.ret_code = 0
Andrew Walbran98656252019-03-14 14:52:29 +0000132
David Brazdil7325eaf2019-09-27 13:04:51 +0100133 def set_ret_code(self, ret_code):
134 self.ret_code = ret_code
Andrew Walbran98656252019-03-14 14:52:29 +0000135
David Brazdil0dbb41f2019-09-09 18:03:35 +0100136class DriverRunException(Exception):
137 """Exception thrown if subprocess invoked by a driver returned non-zero
138 status code. Used to fast-exit from a driver command sequence."""
139 pass
140
141
David Brazdil2df24082019-09-05 11:55:08 +0100142class Driver:
143 """Parent class of drivers for all testable platforms."""
144
145 def __init__(self, args):
146 self.args = args
147
David Brazdil623b6812019-09-09 11:41:08 +0100148 def get_run_log(self, run_name):
149 """Return path to the main log of a given test run."""
150 return self.args.artifacts.get_file(run_name, ".log")
151
David Brazdil2df24082019-09-05 11:55:08 +0100152 def start_run(self, run_name):
153 """Hook called by Driver subclasses before they invoke the target
154 platform."""
David Brazdil7325eaf2019-09-27 13:04:51 +0100155 return DriverRunState(self.args.artifacts.create_file(run_name, ".log"))
David Brazdil2df24082019-09-05 11:55:08 +0100156
Andrew Walbranf636b842020-01-10 11:46:12 +0000157 def exec_logged(self, run_state, exec_args, cwd=None):
David Brazdil2df24082019-09-05 11:55:08 +0100158 """Run a subprocess on behalf of a Driver subclass and append its
159 stdout and stderr to the main log."""
David Brazdil0dbb41f2019-09-09 18:03:35 +0100160 assert(run_state.ret_code == 0)
David Brazdil2df24082019-09-05 11:55:08 +0100161 with open(run_state.log_path, "a") as f:
162 f.write("$ {}\r\n".format(" ".join(exec_args)))
163 f.flush()
Andrew Walbranf636b842020-01-10 11:46:12 +0000164 ret_code = subprocess.call(exec_args, stdout=f, stderr=f, cwd=cwd)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100165 if ret_code != 0:
David Brazdil7325eaf2019-09-27 13:04:51 +0100166 run_state.set_ret_code(ret_code)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100167 raise DriverRunException()
David Brazdil2df24082019-09-05 11:55:08 +0100168
David Brazdil0dbb41f2019-09-09 18:03:35 +0100169 def finish_run(self, run_state):
David Brazdil2df24082019-09-05 11:55:08 +0100170 """Hook called by Driver subclasses after they finished running the
171 target platform. `ret_code` argument is the return code of the main
172 command run by the driver. A corresponding log message is printed."""
173 # Decode return code and add a message to the log.
174 with open(run_state.log_path, "a") as f:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100175 if run_state.ret_code == 124:
David Brazdil2df24082019-09-05 11:55:08 +0100176 f.write("\r\n{}{} timed out\r\n".format(
177 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100178 elif run_state.ret_code != 0:
David Brazdil2df24082019-09-05 11:55:08 +0100179 f.write("\r\n{}{} process return code {}\r\n".format(
David Brazdil0dbb41f2019-09-09 18:03:35 +0100180 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX,
181 run_state.ret_code))
David Brazdil2df24082019-09-05 11:55:08 +0100182
183 # Append log of this run to full test log.
184 log_content = read_file(run_state.log_path)
185 append_file(
186 self.args.artifacts.sponge_log_path,
187 log_content + "\r\n\r\n")
188 return log_content
Andrew Walbran98656252019-03-14 14:52:29 +0000189
190
David Brazdil2df24082019-09-05 11:55:08 +0100191class QemuDriver(Driver):
192 """Driver which runs tests in QEMU."""
193
Andrew Walbranf636b842020-01-10 11:46:12 +0000194 def __init__(self, args, qemu_wd, tfa):
David Brazdil2df24082019-09-05 11:55:08 +0100195 Driver.__init__(self, args)
Andrew Walbranf636b842020-01-10 11:46:12 +0000196 self.qemu_wd = qemu_wd
197 self.tfa = tfa
David Brazdil2df24082019-09-05 11:55:08 +0100198
David Brazdila2358d42020-01-27 18:51:38 +0000199 def gen_exec_args(self, test_args, is_long_running):
David Brazdil2df24082019-09-05 11:55:08 +0100200 """Generate command line arguments for QEMU."""
David Brazdil3cc24aa2019-09-27 10:24:41 +0100201 time_limit = "120s" if is_long_running else "10s"
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000202 # If no CPU configuration is selected, then test against the maximum
203 # configuration, "max", supported by QEMU.
204 cpu = self.args.cpu or "max"
David Brazdil2df24082019-09-05 11:55:08 +0100205 exec_args = [
David Brazdil3cc24aa2019-09-27 10:24:41 +0100206 "timeout", "--foreground", time_limit,
Andrew Walbranf636b842020-01-10 11:46:12 +0000207 os.path.abspath("prebuilts/linux-x64/qemu/qemu-system-aarch64"),
Andrew Walbrana081a292020-01-23 10:08:42 +0000208 "-machine", "virt,virtualization=on,gic-version=3",
Andrew Walbranf636b842020-01-10 11:46:12 +0000209 "-cpu", cpu, "-smp", "4", "-m", "1G",
David Brazdil2df24082019-09-05 11:55:08 +0100210 "-nographic", "-nodefaults", "-serial", "stdio",
Andrew Walbranf636b842020-01-10 11:46:12 +0000211 "-d", "unimp", "-kernel", os.path.abspath(self.args.kernel),
David Brazdil2df24082019-09-05 11:55:08 +0100212 ]
213
Andrew Walbranf636b842020-01-10 11:46:12 +0000214 if self.tfa:
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100215 bl1_path = os.path.join(
216 HF_PREBUILTS, "linux-aarch64", "trusted-firmware-a-trusty",
217 "qemu", "bl1.bin")
Andrew Walbranf636b842020-01-10 11:46:12 +0000218 exec_args += ["-bios",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100219 os.path.abspath(bl1_path),
220 "-machine", "secure=on", "-semihosting-config",
Andrew Walbranf636b842020-01-10 11:46:12 +0000221 "enable,target=native"]
222
David Brazdil2df24082019-09-05 11:55:08 +0100223 if self.args.initrd:
Andrew Walbranf636b842020-01-10 11:46:12 +0000224 exec_args += ["-initrd", os.path.abspath(self.args.initrd)]
David Brazdil2df24082019-09-05 11:55:08 +0100225
226 vm_args = join_if_not_None(self.args.vm_args, test_args)
227 if vm_args:
228 exec_args += ["-append", vm_args]
229
230 return exec_args
231
David Brazdil3cc24aa2019-09-27 10:24:41 +0100232 def run(self, run_name, test_args, is_long_running):
David Brazdil2df24082019-09-05 11:55:08 +0100233 """Run test given by `test_args` in QEMU."""
234 run_state = self.start_run(run_name)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100235
236 try:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100237 # Execute test in QEMU..
David Brazdila2358d42020-01-27 18:51:38 +0000238 exec_args = self.gen_exec_args(test_args, is_long_running)
Andrew Walbranf636b842020-01-10 11:46:12 +0000239 self.exec_logged(run_state, exec_args,
240 cwd=self.qemu_wd)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100241 except DriverRunException:
242 pass
243
244 return self.finish_run(run_state)
Andrew Scullbc7189d2018-08-14 09:35:13 +0100245
David Brazdil94fd1e92020-02-03 16:45:20 +0000246 def finish(self):
247 """Clean up after running tests."""
248 pass
249
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100250class FvpDriver(Driver, ABC):
251 """Base class for driver which runs tests in Arm FVP emulator."""
David Brazdil2df24082019-09-05 11:55:08 +0100252
253 def __init__(self, args):
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000254 if args.cpu:
255 raise ValueError("FVP emulator does not support the --cpu option.")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100256 super().__init__(args)
David Brazdil2df24082019-09-05 11:55:08 +0100257
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100258 @property
259 @abstractmethod
260 def CPU_START_ADDRESS(self):
261 pass
David Brazdil2df24082019-09-05 11:55:08 +0100262
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100263 @property
264 @abstractmethod
265 def DTB_ADDRESS(self):
266 pass
267
268 @property
269 @abstractmethod
270 def FVP_PREBUILT_BL31(self):
271 pass
272
273 @property
274 @abstractmethod
275 def KERNEL_ADDRESS(self):
276 pass
277
278 def create_dt(self, run_name : str):
279 """Create DT related files, and return respective paths in a tuple
280 (dts,dtb)"""
281 return self.args.artifacts.create_file(run_name, ".dts"), \
282 self.args.artifacts.create_file(run_name, ".dtb")
283
284 def compile_dt(self, run_state, dts_path, dtb_path):
285 """Compile DT calling dtc."""
286 dtc_args = [
287 DTC_SCRIPT, "compile", "-i", dts_path, "-o", dtb_path,
288 ]
289 self.exec_logged(run_state, dtc_args)
290
291 def create_uart_log(self, run_name : str, file_name : str):
292 """Create uart log file, and return path"""
293 return self.args.artifacts.create_file(run_name, file_name)
294
295 def get_img_and_ldadd(self, partitions : dict):
296 ret = []
297 for i, p in enumerate(partitions):
298 with open(p["dts"], "r") as dts:
299 manifest = fdt.parse_dts(dts.read())
300 load_address = manifest.get_property("load_address",
301 f"/hypervisor/vm{str(i+1)}").value
302 ret.append((p["img"], load_address))
303 return ret
304
305 def get_manifests_from_json(self, partitions : list):
306 manifests = ""
307 if partitions is not None:
308 for p in partitions:
309 manifests += read_file(p["dts"])
310 return manifests
311
312 @abstractmethod
313 def gen_dts(self, dts_path, test_args):
314 """Abstract method to generate dts file. This specific to the use case
315 so should be implemented within derived driver"""
316 pass
317
318 @abstractmethod
David Brazdil2df24082019-09-05 11:55:08 +0100319 def gen_fvp_args(
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100320 self, is_long_running, uart0_log_path, uart1_log_path, dtb_path):
David Brazdil2df24082019-09-05 11:55:08 +0100321 """Generate command line arguments for FVP."""
Andrew Walbranee5418e2019-11-27 17:43:05 +0000322 time_limit = "80s" if is_long_running else "40s"
David Brazdil2df24082019-09-05 11:55:08 +0100323 fvp_args = [
Andrew Walbranee5418e2019-11-27 17:43:05 +0000324 "timeout", "--foreground", time_limit,
David Brazdil2df24082019-09-05 11:55:08 +0100325 FVP_BINARY,
J-Alves10446d82021-04-26 11:52:57 +0100326 "-C", "pci.pci_smmuv3.mmu.SMMU_AIDR=2",
327 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B",
328 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002",
329 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714",
330 "-C", "pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472",
331 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002",
332 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR2=0",
333 "-C", "pci.pci_smmuv3.mmu.SMMU_S_IDR3=0",
David Brazdil2df24082019-09-05 11:55:08 +0100334 "-C", "pctl.startup=0.0.0.0",
335 "-C", "bp.secure_memory=0",
336 "-C", "cluster0.NUM_CORES=4",
337 "-C", "cluster1.NUM_CORES=4",
338 "-C", "cache_state_modelled=0",
339 "-C", "bp.vis.disable_visualisation=true",
340 "-C", "bp.vis.rate_limit-enable=false",
341 "-C", "bp.terminal_0.start_telnet=false",
342 "-C", "bp.terminal_1.start_telnet=false",
343 "-C", "bp.terminal_2.start_telnet=false",
344 "-C", "bp.terminal_3.start_telnet=false",
345 "-C", "bp.pl011_uart0.untimed_fifos=1",
346 "-C", "bp.pl011_uart0.unbuffered_output=1",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100347 "-C", f"bp.pl011_uart0.out_file={uart0_log_path}",
348 "-C", f"bp.pl011_uart1.out_file={uart1_log_path}",
349 "-C", f"cluster0.cpu0.RVBAR={self.CPU_START_ADDRESS}",
350 "-C", f"cluster0.cpu1.RVBAR={self.CPU_START_ADDRESS}",
351 "-C", f"cluster0.cpu2.RVBAR={self.CPU_START_ADDRESS}",
352 "-C", f"cluster0.cpu3.RVBAR={self.CPU_START_ADDRESS}",
353 "-C", f"cluster1.cpu0.RVBAR={self.CPU_START_ADDRESS}",
354 "-C", f"cluster1.cpu1.RVBAR={self.CPU_START_ADDRESS}",
355 "-C", f"cluster1.cpu2.RVBAR={self.CPU_START_ADDRESS}",
356 "-C", f"cluster1.cpu3.RVBAR={self.CPU_START_ADDRESS}",
357 "--data",
358 f"cluster0.cpu0={self.FVP_PREBUILT_BL31}@{self.CPU_START_ADDRESS}",
359 "--data", f"cluster0.cpu0={dtb_path}@{self.DTB_ADDRESS}",
360 "--data", f"cluster0.cpu0={self.args.kernel}@{self.KERNEL_ADDRESS}",
David Brazdil2df24082019-09-05 11:55:08 +0100361 "-C", "bp.ve_sysregs.mmbSiteDefault=0",
362 "-C", "bp.ve_sysregs.exit_on_shutdown=1",
363 ]
David Brazdil2df24082019-09-05 11:55:08 +0100364 return fvp_args
365
David Brazdil3cc24aa2019-09-27 10:24:41 +0100366 def run(self, run_name, test_args, is_long_running):
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100367 """ Run test """
David Brazdil2df24082019-09-05 11:55:08 +0100368 run_state = self.start_run(run_name)
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100369 dts_path, dtb_path = self.create_dt(run_name)
370 uart0_log_path = self.create_uart_log(run_name, ".uart0.log")
371 uart1_log_path = self.create_uart_log(run_name, ".uart1.log")
David Brazdil2df24082019-09-05 11:55:08 +0100372
David Brazdil0dbb41f2019-09-09 18:03:35 +0100373 try:
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100374 self.gen_dts(dts_path, test_args)
375 self.compile_dt(run_state, dts_path, dtb_path)
376 fvp_args = self.gen_fvp_args(is_long_running, uart0_log_path,
377 uart1_log_path, dtb_path)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100378 self.exec_logged(run_state, fvp_args)
379 except DriverRunException:
380 pass
David Brazdil2df24082019-09-05 11:55:08 +0100381
382 # Append UART0 output to main log.
383 append_file(run_state.log_path, read_file(uart0_log_path))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100384 return self.finish_run(run_state)
David Brazdil2df24082019-09-05 11:55:08 +0100385
David Brazdil94fd1e92020-02-03 16:45:20 +0000386 def finish(self):
387 """Clean up after running tests."""
388 pass
389
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100390class FvpDriverHypervisor(FvpDriver):
391 """
392 Driver which runs tests in Arm FVP emulator, with hafnium as hypervisor
393 """
394 INITRD_START= 0x84000000
395 INITRD_END = 0x85000000 #Default value, however may change if initrd in args
396
397 def __init__(self, args):
398 self.vms_in_partitions_json = args.partitions and args.partitions["VMs"]
399 super().__init__(args)
400
401 @property
402 def CPU_START_ADDRESS(self):
403 return "0x04020000"
404
405 @property
406 def DTB_ADDRESS(self):
407 return "0x82000000"
408
409 @property
410 def FVP_PREBUILT_BL31(self):
411 return os.path.join(FVP_PREBUILTS_TFA_TRUSTY_ROOT, "bl31.bin")
412
413 @property
414 def KERNEL_ADDRESS(self):
415 return "0x80000000"
416
417 def gen_dts(self, dts_path, test_args):
418 """Create a DeviceTree source which will be compiled into a DTB and
419 passed to FVP for a test run."""
420
421 vm_args = join_if_not_None(self.args.vm_args, test_args)
422 write_file(dts_path, read_file(FVP_PREBUILT_DTS))
423
424 # Write the vm arguments to the partition manifest
425 to_append = f"""
426/ {{
427 chosen {{
428 bootargs = "{vm_args}";
429 stdout-path = "serial0:115200n8";
430 linux,initrd-start = <{self.INITRD_START if self.args.initrd else 0}>;
431 linux,initrd-end = <{self.INITRD_END if self.args.initrd else 0}>;
432 }};
433}};"""
434 if self.vms_in_partitions_json:
435 to_append += self.get_manifests_from_json(self.args.partitions["VMs"])
436
437 append_file(dts_path, to_append)
438
439 def gen_fvp_args(
440 self, is_long_running, uart0_log_path, uart1_log_path, dtb_path):
441 """Generate command line arguments for FVP."""
442
443 fvp_args = super().gen_fvp_args(
444 is_long_running, uart0_log_path, uart1_log_path, dtb_path)
445
446 if self.vms_in_partitions_json:
447 img_ldadd = self.get_img_and_ldadd(self.args.partitions["VMs"])
448 for img, ldadd in img_ldadd:
449 fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"]
450
451 if self.args.initrd:
452 fvp_args += [
453 "--data",
454 f"cluster0.cpu0={self.args.initrd}@{self.INITRD_START}"
455 ]
456 return fvp_args
457
458class FvpDriverSPMC(FvpDriver):
459 """
460 Driver which runs tests in Arm FVP emulator, with hafnium as SPMC
461 """
462 FVP_PREBUILT_SECURE_DTS = os.path.join(
463 HF_ROOT, "test", "vmapi", "fvp-base-spmc.dts")
464 HFTEST_CMD_FILE = os.path.join("/tmp/", "hftest_cmds")
465
466 def __init__(self, args):
467 if args.partitions is None or args.partitions["SPs"] is None:
J-Alves10446d82021-04-26 11:52:57 +0100468 raise Exception("Need to provide SPs in partitions_json")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100469 super().__init__(args)
470
471 @property
472 def CPU_START_ADDRESS(self):
473 return "0x04010000"
474
475 @property
476 def DTB_ADDRESS(self):
477 return "0x0403f000"
478
479 @property
480 def FVP_PREBUILT_BL31(self):
481 return os.path.join(FVP_PREBUILT_TFA_ROOT, "bl31_spmd.bin")
482
483 @property
484 def KERNEL_ADDRESS(self):
485 return "0x6000000"
486
487 def gen_dts(self, dts_path, test_args):
488 """Create a DeviceTree source which will be compiled into a DTB and
489 passed to FVP for a test run."""
490 to_append = self.get_manifests_from_json(self.args.partitions["SPs"])
491 write_file(dts_path, read_file(FvpDriverSPMC.FVP_PREBUILT_SECURE_DTS))
492 append_file(dts_path, to_append)
493
494 def gen_fvp_args(
495 self, is_long_running, uart0_log_path, uart1_log_path, dtb_path):
496 """Generate command line arguments for FVP."""
497 fvp_args = super().gen_fvp_args(
498 is_long_running, uart0_log_path, uart1_log_path, dtb_path)
499 fvp_args += [
500 "-C", f"bp.pl011_uart0.in_file={FvpDriverSPMC.HFTEST_CMD_FILE}",
501 "-C", f"bp.pl011_uart0.shutdown_tag=\"{HFTEST_CTRL_FINISHED}\"",
J-Alvesb5a63992021-04-30 10:23:19 +0100502 "-C", "cluster0.has_arm_v8-5=1",
503 "-C", "cluster1.has_arm_v8-5=1",
504 "-C", "cluster0.has_branch_target_exception=1",
505 "-C", "cluster1.has_branch_target_exception=1",
506 "-C", "cluster0.restriction_on_speculative_execution=2",
507 "-C", "cluster1.restriction_on_speculative_execution=2",
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100508 ]
509 img_ldadd = self.get_img_and_ldadd(self.args.partitions["SPs"])
510 for img, ldadd in img_ldadd:
511 fvp_args += ["--data", f"cluster0.cpu0={img}@{hex(ldadd)}"]
512
513 return fvp_args
514
515 def run(self, run_name, test_args, is_long_running):
516 with open(FvpDriverSPMC.HFTEST_CMD_FILE, "w+") as f:
517 vm_args = join_if_not_None(self.args.vm_args, test_args)
518 f.write(f"{vm_args}\n")
519 return super().run(run_name, test_args, is_long_running)
520
521 def finish(self):
522 """Clean up after running tests."""
523 os.remove(FvpDriverSPMC.HFTEST_CMD_FILE)
David Brazdil2df24082019-09-05 11:55:08 +0100524
David Brazdil17e76652020-01-29 14:44:19 +0000525class SerialDriver(Driver):
526 """Driver which communicates with a device over the serial port."""
527
David Brazdil9d4ed962020-02-06 17:23:48 +0000528 def __init__(self, args, tty_file, baudrate, init_wait):
David Brazdil17e76652020-01-29 14:44:19 +0000529 Driver.__init__(self, args)
David Brazdil9d4ed962020-02-06 17:23:48 +0000530 self.tty_file = tty_file
531 self.baudrate = baudrate
David Brazdil4f9cf9a2020-02-06 17:34:44 +0000532 self.pyserial = importlib.import_module("serial")
David Brazdild8013f92020-02-03 16:40:25 +0000533
David Brazdil9d4ed962020-02-06 17:23:48 +0000534 if init_wait:
David Brazdild8013f92020-02-03 16:40:25 +0000535 input("Press ENTER and then reset the device...")
David Brazdil17e76652020-01-29 14:44:19 +0000536
David Brazdil9d4ed962020-02-06 17:23:48 +0000537 def connect(self):
David Brazdil4f9cf9a2020-02-06 17:34:44 +0000538 return self.pyserial.Serial(self.tty_file, self.baudrate, timeout=10)
David Brazdil9d4ed962020-02-06 17:23:48 +0000539
David Brazdil17e76652020-01-29 14:44:19 +0000540 def run(self, run_name, test_args, is_long_running):
541 """Communicate `test_args` to the device over the serial port."""
542 run_state = self.start_run(run_name)
543
David Brazdil9d4ed962020-02-06 17:23:48 +0000544 with self.connect() as ser:
David Brazdil17e76652020-01-29 14:44:19 +0000545 with open(run_state.log_path, "a") as f:
546 while True:
547 # Read one line from the serial port.
548 line = ser.readline().decode('utf-8')
549 if len(line) == 0:
550 # Timeout
551 run_state.set_ret_code(124)
552 input("Timeout. " +
553 "Press ENTER and then reset the device...")
554 break
555 # Write the line to the log file.
556 f.write(line)
557 if HFTEST_CTRL_GET_COMMAND_LINE in line:
558 # Device is waiting for `test_args`.
559 ser.write(test_args.encode('ascii'))
560 ser.write(b'\r')
561 elif HFTEST_CTRL_FINISHED in line:
562 # Device has finished running this test and will reboot.
563 break
564 return self.finish_run(run_state)
565
David Brazdil94fd1e92020-02-03 16:45:20 +0000566 def finish(self):
567 """Clean up after running tests."""
David Brazdil9d4ed962020-02-06 17:23:48 +0000568 with self.connect() as ser:
David Brazdil94fd1e92020-02-03 16:45:20 +0000569 while True:
570 line = ser.readline().decode('utf-8')
571 if len(line) == 0:
572 input("Timeout. Press ENTER and then reset the device...")
573 elif HFTEST_CTRL_GET_COMMAND_LINE in line:
574 # Device is waiting for a command. Instruct it to exit
575 # the test environment.
576 ser.write("exit".encode('ascii'))
577 ser.write(b'\r')
578 break
579
David Brazdil17e76652020-01-29 14:44:19 +0000580
David Brazdil2df24082019-09-05 11:55:08 +0100581# Tuple used to return information about the results of running a set of tests.
582TestRunnerResult = collections.namedtuple("TestRunnerResult", [
583 "tests_run",
584 "tests_failed",
Andrew Walbranf9463922020-06-05 16:44:42 +0100585 "tests_skipped",
David Brazdil2df24082019-09-05 11:55:08 +0100586 ])
587
588
589class TestRunner:
590 """Class which communicates with a test platform to obtain a list of
591 available tests and driving their execution."""
592
David Brazdil3cc24aa2019-09-27 10:24:41 +0100593 def __init__(self, artifacts, driver, image_name, suite_regex, test_regex,
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100594 skip_long_running_tests, force_long_running):
David Brazdil2df24082019-09-05 11:55:08 +0100595 self.artifacts = artifacts
596 self.driver = driver
597 self.image_name = image_name
David Brazdil3cc24aa2019-09-27 10:24:41 +0100598 self.skip_long_running_tests = skip_long_running_tests
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100599 self.force_long_running = force_long_running
David Brazdil2df24082019-09-05 11:55:08 +0100600
601 self.suite_re = re.compile(suite_regex or ".*")
602 self.test_re = re.compile(test_regex or ".*")
603
604 def extract_hftest_lines(self, raw):
605 """Extract hftest-specific lines from a raw output from an invocation
606 of the test platform."""
607 lines = []
608 for line in raw.splitlines():
J-Alves3dbb8562020-12-01 10:45:37 +0000609 match = re.search(f"^VM \d+: ", line)
610 if match is not None:
611 line = line[match.end():]
David Brazdil2df24082019-09-05 11:55:08 +0100612 if line.startswith(HFTEST_LOG_PREFIX):
613 lines.append(line[len(HFTEST_LOG_PREFIX):])
614 return lines
615
616 def get_test_json(self):
617 """Invoke the test platform and request a JSON of available test and
618 test suites."""
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100619 out = self.driver.run("json", "json", self.force_long_running)
David Brazdil2df24082019-09-05 11:55:08 +0100620 hf_out = "\n".join(self.extract_hftest_lines(out))
621 try:
622 return json.loads(hf_out)
623 except ValueError as e:
624 print(out)
625 raise e
626
627 def collect_results(self, fn, it, xml_node):
628 """Run `fn` on every entry in `it` and collect their TestRunnerResults.
629 Insert "tests" and "failures" nodes to `xml_node`."""
630 tests_run = 0
631 tests_failed = 0
Andrew Walbranf9463922020-06-05 16:44:42 +0100632 tests_skipped = 0
Andrew Walbran42bf2842020-06-05 18:50:19 +0100633 start_time = time.perf_counter()
David Brazdil2df24082019-09-05 11:55:08 +0100634 for i in it:
635 sub_result = fn(i)
636 assert(sub_result.tests_run >= sub_result.tests_failed)
637 tests_run += sub_result.tests_run
638 tests_failed += sub_result.tests_failed
Andrew Walbranf9463922020-06-05 16:44:42 +0100639 tests_skipped += sub_result.tests_skipped
Andrew Walbran42bf2842020-06-05 18:50:19 +0100640 elapsed_time = time.perf_counter() - start_time
David Brazdil2df24082019-09-05 11:55:08 +0100641
Andrew Walbranf9463922020-06-05 16:44:42 +0100642 xml_node.set("tests", str(tests_run + tests_skipped))
David Brazdil2df24082019-09-05 11:55:08 +0100643 xml_node.set("failures", str(tests_failed))
Andrew Walbranf9463922020-06-05 16:44:42 +0100644 xml_node.set("skipped", str(tests_skipped))
Andrew Walbran42bf2842020-06-05 18:50:19 +0100645 xml_node.set("time", str(elapsed_time))
Andrew Walbranf9463922020-06-05 16:44:42 +0100646 return TestRunnerResult(tests_run, tests_failed, tests_skipped)
David Brazdil2df24082019-09-05 11:55:08 +0100647
648 def is_passed_test(self, test_out):
649 """Parse the output of a test and return True if it passed."""
650 return \
651 len(test_out) > 0 and \
652 test_out[-1] == HFTEST_LOG_FINISHED and \
653 not any(l.startswith(HFTEST_LOG_FAILURE_PREFIX) for l in test_out)
654
Andrew Walbranf9463922020-06-05 16:44:42 +0100655 def get_failure_message(self, test_out):
656 """Parse the output of a test and return the message of the first
657 assertion failure."""
658 for i, line in enumerate(test_out):
659 if line.startswith(HFTEST_LOG_FAILURE_PREFIX) and i + 1 < len(test_out):
660 # The assertion message is on the line after the 'Failure:'
661 return test_out[i + 1].strip()
662
663 return None
664
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000665 def get_log_name(self, suite, test):
666 """Returns a string with a generated log name for the test."""
667 log_name = ""
668
669 cpu = self.driver.args.cpu
670 if cpu:
671 log_name += cpu + "."
672
673 log_name += suite["name"] + "." + test["name"]
674
675 return log_name
676
David Brazdil2df24082019-09-05 11:55:08 +0100677 def run_test(self, suite, test, suite_xml):
678 """Invoke the test platform and request to run a given `test` in given
679 `suite`. Create a new XML node with results under `suite_xml`.
680 Test only invoked if it matches the regex given to constructor."""
David Brazdil3cc24aa2019-09-27 10:24:41 +0100681 if not self.test_re.match(test["name"]):
Andrew Walbranf9463922020-06-05 16:44:42 +0100682 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100683
684 test_xml = ET.SubElement(suite_xml, "testcase")
David Brazdil3cc24aa2019-09-27 10:24:41 +0100685 test_xml.set("name", test["name"])
686 test_xml.set("classname", suite["name"])
Andrew Walbranf9463922020-06-05 16:44:42 +0100687
688 if self.skip_long_running_tests and test["is_long_running"]:
689 print(" SKIP", test["name"])
690 test_xml.set("status", "notrun")
691 skipped_xml = ET.SubElement(test_xml, "skipped")
692 skipped_xml.set("message", "Long running")
693 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=1)
694
695 print(" RUN", test["name"])
696 log_name = self.get_log_name(suite, test)
697
David Brazdil2df24082019-09-05 11:55:08 +0100698 test_xml.set("status", "run")
699
Andrew Walbran42bf2842020-06-05 18:50:19 +0100700 start_time = time.perf_counter()
Andrew Walbranf9463922020-06-05 16:44:42 +0100701 out = self.driver.run(
David Brazdil3cc24aa2019-09-27 10:24:41 +0100702 log_name, "run {} {}".format(suite["name"], test["name"]),
Andrew Walbranf9463922020-06-05 16:44:42 +0100703 test["is_long_running"] or self.force_long_running)
704 hftest_out = self.extract_hftest_lines(out)
Andrew Walbran42bf2842020-06-05 18:50:19 +0100705 elapsed_time = time.perf_counter() - start_time
706
707 test_xml.set("time", str(elapsed_time))
David Brazdil2df24082019-09-05 11:55:08 +0100708
Andrew Walbranf9463922020-06-05 16:44:42 +0100709 system_out_xml = ET.SubElement(test_xml, "system-out")
710 system_out_xml.text = out
711
712 if self.is_passed_test(hftest_out):
David Brazdil2df24082019-09-05 11:55:08 +0100713 print(" PASS")
Andrew Walbranf9463922020-06-05 16:44:42 +0100714 return TestRunnerResult(tests_run=1, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100715 else:
David Brazdil623b6812019-09-09 11:41:08 +0100716 print("[x] FAIL --", self.driver.get_run_log(log_name))
David Brazdil2df24082019-09-05 11:55:08 +0100717 failure_xml = ET.SubElement(test_xml, "failure")
Andrew Walbranf9463922020-06-05 16:44:42 +0100718 failure_message = self.get_failure_message(hftest_out) or "Test failed"
719 failure_xml.set("message", failure_message)
720 failure_xml.text = '\n'.join(hftest_out)
721 return TestRunnerResult(tests_run=1, tests_failed=1, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100722
723 def run_suite(self, suite, xml):
724 """Invoke the test platform and request to run all matching tests in
725 `suite`. Create new XML nodes with results under `xml`.
726 Suite skipped if it does not match the regex given to constructor."""
727 if not self.suite_re.match(suite["name"]):
Andrew Walbranf9463922020-06-05 16:44:42 +0100728 return TestRunnerResult(tests_run=0, tests_failed=0, tests_skipped=0)
David Brazdil2df24082019-09-05 11:55:08 +0100729
730 print(" SUITE", suite["name"])
731 suite_xml = ET.SubElement(xml, "testsuite")
732 suite_xml.set("name", suite["name"])
Andrew Walbran16ae62e2020-06-05 18:27:46 +0100733 properties_xml = ET.SubElement(suite_xml, "properties")
734
735 property_xml = ET.SubElement(properties_xml, "property")
736 property_xml.set("name", "driver")
737 property_xml.set("value", type(self.driver).__name__)
738
739 if self.driver.args.cpu:
740 property_xml = ET.SubElement(properties_xml, "property")
741 property_xml.set("name", "cpu")
742 property_xml.set("value", self.driver.args.cpu)
David Brazdil2df24082019-09-05 11:55:08 +0100743
744 return self.collect_results(
745 lambda test: self.run_test(suite, test, suite_xml),
746 suite["tests"],
747 suite_xml)
748
749 def run_tests(self):
750 """Run all suites and tests matching regexes given to constructor.
751 Write results to sponge log XML. Return the number of run and failed
752 tests."""
753
754 test_spec = self.get_test_json()
755 timestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
756
757 xml = ET.Element("testsuites")
758 xml.set("name", self.image_name)
759 xml.set("timestamp", timestamp)
760
761 result = self.collect_results(
762 lambda suite: self.run_suite(suite, xml),
763 test_spec["suites"],
764 xml)
765
766 # Write XML to file.
David Brazdilee5e25d2020-01-24 14:17:45 +0000767 ET.ElementTree(xml).write(self.artifacts.sponge_xml_path,
768 encoding='utf-8', xml_declaration=True)
David Brazdil2df24082019-09-05 11:55:08 +0100769
770 if result.tests_failed > 0:
771 print("[x] FAIL:", result.tests_failed, "of", result.tests_run,
772 "tests failed")
773 elif result.tests_run > 0:
774 print(" PASS: all", result.tests_run, "tests passed")
775
David Brazdil94fd1e92020-02-03 16:45:20 +0000776 # Let the driver clean up.
777 self.driver.finish()
778
David Brazdil2df24082019-09-05 11:55:08 +0100779 return result
Andrew Scullbc7189d2018-08-14 09:35:13 +0100780
Andrew Scullbc7189d2018-08-14 09:35:13 +0100781def Main():
782 parser = argparse.ArgumentParser()
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000783 parser.add_argument("image")
Andrew Scullbc7189d2018-08-14 09:35:13 +0100784 parser.add_argument("--out", required=True)
Andrew Scull23e93a82018-10-26 14:56:04 +0100785 parser.add_argument("--log", required=True)
Andrew Walbran7559fcf2019-05-09 17:11:20 +0100786 parser.add_argument("--out_initrd")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100787 parser.add_argument("--out_partitions")
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000788 parser.add_argument("--initrd")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100789 parser.add_argument("--partitions_json")
Andrew Scullbc7189d2018-08-14 09:35:13 +0100790 parser.add_argument("--suite")
791 parser.add_argument("--test")
Andrew Walbranbc342d42019-02-05 16:56:02 +0000792 parser.add_argument("--vm_args")
David Brazdil17e76652020-01-29 14:44:19 +0000793 parser.add_argument("--driver", default="qemu")
794 parser.add_argument("--serial-dev", default="/dev/ttyUSB0")
795 parser.add_argument("--serial-baudrate", type=int, default=115200)
David Brazdild8013f92020-02-03 16:40:25 +0000796 parser.add_argument("--serial-no-init-wait", action="store_true")
David Brazdil3cc24aa2019-09-27 10:24:41 +0100797 parser.add_argument("--skip-long-running-tests", action="store_true")
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100798 parser.add_argument("--force-long-running", action="store_true")
Fuad Tabba36c8c2b2019-11-04 16:55:32 +0000799 parser.add_argument("--cpu",
800 help="Selects the CPU configuration for the run environment.")
Andrew Walbranf636b842020-01-10 11:46:12 +0000801 parser.add_argument("--tfa", action="store_true")
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100802 parser.add_argument("--secure", action="store_true")
Andrew Scullbc7189d2018-08-14 09:35:13 +0100803 args = parser.parse_args()
David Brazdil2df24082019-09-05 11:55:08 +0100804
Andrew Scullbc7189d2018-08-14 09:35:13 +0100805 # Resolve some paths.
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000806 image = os.path.join(args.out, args.image + ".bin")
807 initrd = None
David Brazdil2df24082019-09-05 11:55:08 +0100808 image_name = args.image
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100809
810 if not args.secure and args.initrd:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100811 initrd_dir = os.path.join(args.out_initrd, "obj", args.initrd)
812 initrd = os.path.join(initrd_dir, "initrd.img")
David Brazdil2df24082019-09-05 11:55:08 +0100813 image_name += "_" + args.initrd
Andrew Walbranbc342d42019-02-05 16:56:02 +0000814 vm_args = args.vm_args or ""
David Brazdil2df24082019-09-05 11:55:08 +0100815
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100816 partitions = None
817 if args.driver == "fvp" and args.partitions_json is not None:
818 partitions_dir = os.path.join(args.out_partitions, "obj", args.partitions_json)
819 partitions = json.load(open(partitions_dir, "r"))
820
David Brazdil2df24082019-09-05 11:55:08 +0100821 # Create class which will manage all test artifacts.
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100822 log_dir = os.path.join(args.log, "hafnium" if not args.secure else "spmc")
823 artifacts = ArtifactsManager(log_dir)
David Brazdil2df24082019-09-05 11:55:08 +0100824
825 # Create a driver for the platform we want to test on.
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100826 driver_args = DriverArgs(artifacts, image, initrd, vm_args, args.cpu,
827 partitions)
David Brazdil17e76652020-01-29 14:44:19 +0000828
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100829 if args.secure:
830 if args.driver != "fvp":
831 raise Exception("Secure tests can only run with fvp driver")
832 driver = FvpDriverSPMC(driver_args)
David Brazdil17e76652020-01-29 14:44:19 +0000833 else:
Olivier Depreza6d2e6d2020-11-06 18:09:50 +0100834 if args.driver == "qemu":
835 driver = QemuDriver(driver_args, args.out, args.tfa)
836 elif args.driver == "fvp":
837 driver = FvpDriverHypervisor(driver_args)
838 elif args.driver == "serial":
839 driver = SerialDriver(driver_args, args.serial_dev,
840 args.serial_baudrate, not args.serial_no_init_wait)
841 else:
842 raise Exception("Unknown driver name: {}".format(args.driver))
David Brazdil2df24082019-09-05 11:55:08 +0100843
844 # Create class which will drive test execution.
David Brazdil3cc24aa2019-09-27 10:24:41 +0100845 runner = TestRunner(artifacts, driver, image_name, args.suite, args.test,
Andrew Walbrane1fa70b2020-05-28 11:30:11 +0100846 args.skip_long_running_tests, args.force_long_running)
David Brazdil2df24082019-09-05 11:55:08 +0100847
848 # Run tests.
849 runner_result = runner.run_tests()
850
851 # Print error message if no tests were run as this is probably unexpected.
852 # Return suitable error code.
853 if runner_result.tests_run == 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +0100854 print("Error: no tests match")
855 return 10
David Brazdil2df24082019-09-05 11:55:08 +0100856 elif runner_result.tests_failed > 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +0100857 return 1
858 else:
David Brazdil2df24082019-09-05 11:55:08 +0100859 return 0
Andrew Scullbc7189d2018-08-14 09:35:13 +0100860
861if __name__ == "__main__":
862 sys.exit(Main())