blob: d4af83381eb4a759c002cdd6fc138e9d4379cea8 [file] [log] [blame]
Andrew Scullbc7189d2018-08-14 09:35:13 +01001#!/usr/bin/env python
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#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
David Brazdil2df24082019-09-05 11:55:08 +010017"""Script which drives invocation of tests and parsing their output to produce
18a results report.
Andrew Scullbc7189d2018-08-14 09:35:13 +010019"""
20
21from __future__ import print_function
22
Andrew Scull3b62f2b2018-08-21 14:26:12 +010023import xml.etree.ElementTree as ET
24
Andrew Scullbc7189d2018-08-14 09:35:13 +010025import argparse
David Brazdil2df24082019-09-05 11:55:08 +010026import collections
Andrew Scull04502e42018-09-03 14:54:52 +010027import datetime
Andrew Scullbc7189d2018-08-14 09:35:13 +010028import json
29import os
30import re
31import subprocess
32import sys
33
Andrew Scull845fc9b2019-04-03 12:44:26 +010034HFTEST_LOG_PREFIX = "[hftest] "
35HFTEST_LOG_FAILURE_PREFIX = "Failure:"
36HFTEST_LOG_FINISHED = "FINISHED"
37
David Brazdil2df24082019-09-05 11:55:08 +010038HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
39 os.path.abspath(__file__))))
David Brazdil5715f042019-08-27 11:11:51 +010040DTC_SCRIPT = os.path.join(HF_ROOT, "build", "image", "dtc.py")
David Brazdil2df24082019-09-05 11:55:08 +010041FVP_BINARY = os.path.join(
42 os.path.dirname(HF_ROOT), "fvp", "Base_RevC_AEMv8A_pkg", "models",
43 "Linux64_GCC-4.9", "FVP_Base_RevC-2xAEMv8A")
44FVP_PREBUILT_DTS = os.path.join(
45 HF_ROOT, "prebuilts", "linux-aarch64", "arm-trusted-firmware",
46 "fvp-base-gicv3-psci-1t.dts")
Andrew Scull845fc9b2019-04-03 12:44:26 +010047
David Brazdil2df24082019-09-05 11:55:08 +010048def read_file(path):
49 with open(path, "r") as f:
50 return f.read()
Andrew Scull845fc9b2019-04-03 12:44:26 +010051
David Brazdil2df24082019-09-05 11:55:08 +010052def write_file(path, to_write, append=False):
53 with open(path, "a" if append else "w") as f:
54 f.write(to_write)
55
56def append_file(path, to_write):
57 write_file(path, to_write, append=True)
58
59def join_if_not_None(*args):
60 return " ".join(filter(lambda x: x, args))
61
62class ArtifactsManager:
63 """Class which manages folder with test artifacts."""
64
65 def __init__(self, log_dir):
66 self.created_files = []
67 self.log_dir = log_dir
68
69 # Create directory.
Andrew Scull845fc9b2019-04-03 12:44:26 +010070 try:
David Brazdil2df24082019-09-05 11:55:08 +010071 os.makedirs(self.log_dir)
72 except OSError:
73 if not os.path.isdir(self.log_dir):
74 raise
75 print("Logs saved under", log_dir)
76
77 # Create files expected by the Sponge test result parser.
78 self.sponge_log_path = self.create_file("sponge_log", ".log")
79 self.sponge_xml_path = self.create_file("sponge_log", ".xml")
80
David Brazdil623b6812019-09-09 11:41:08 +010081 def gen_file_path(self, basename, extension):
82 """Generate path to a file in the log directory."""
83 return os.path.join(self.log_dir, basename + extension)
84
David Brazdil2df24082019-09-05 11:55:08 +010085 def create_file(self, basename, extension):
86 """Create and touch a new file in the log folder. Ensure that no other
87 file of the same name was created by this instance of ArtifactsManager.
88 """
89 # Determine the path of the file.
David Brazdil623b6812019-09-09 11:41:08 +010090 path = self.gen_file_path(basename, extension)
David Brazdil2df24082019-09-05 11:55:08 +010091
92 # Check that the path is unique.
93 assert(path not in self.created_files)
94 self.created_files += [ path ]
95
96 # Touch file.
97 with open(path, "w") as f:
98 pass
99
100 return path
Andrew Scullbc7189d2018-08-14 09:35:13 +0100101
David Brazdil623b6812019-09-09 11:41:08 +0100102 def get_file(self, basename, extension):
103 """Return path to a file in the log folder. Assert that it was created
104 by this instance of ArtifactsManager."""
105 path = self.gen_file_path(basename, extension)
106 assert(path in self.created_files)
107 return path
108
Andrew Scullbc7189d2018-08-14 09:35:13 +0100109
David Brazdil2df24082019-09-05 11:55:08 +0100110# Tuple holding the arguments common to all driver constructors.
111# This is to avoid having to pass arguments from subclasses to superclasses.
112DriverArgs = collections.namedtuple("DriverArgs", [
113 "artifacts",
114 "kernel",
115 "initrd",
David Brazdil0dbb41f2019-09-09 18:03:35 +0100116 "manifest",
David Brazdil2df24082019-09-05 11:55:08 +0100117 "vm_args",
118 ])
Marc Bonnici0a125632019-04-01 13:46:52 +0100119
Andrew Walbran98656252019-03-14 14:52:29 +0000120
David Brazdil2df24082019-09-05 11:55:08 +0100121# State shared between the common Driver class and its subclasses during
122# a single invocation of the target platform.
123DriverRunState = collections.namedtuple("DriverRunState", [
124 "log_path",
David Brazdil0dbb41f2019-09-09 18:03:35 +0100125 "ret_code",
David Brazdil2df24082019-09-05 11:55:08 +0100126 ])
Andrew Walbran98656252019-03-14 14:52:29 +0000127
128
David Brazdil0dbb41f2019-09-09 18:03:35 +0100129class DriverRunException(Exception):
130 """Exception thrown if subprocess invoked by a driver returned non-zero
131 status code. Used to fast-exit from a driver command sequence."""
132 pass
133
134
David Brazdil2df24082019-09-05 11:55:08 +0100135class Driver:
136 """Parent class of drivers for all testable platforms."""
137
138 def __init__(self, args):
139 self.args = args
140
David Brazdil623b6812019-09-09 11:41:08 +0100141 def get_run_log(self, run_name):
142 """Return path to the main log of a given test run."""
143 return self.args.artifacts.get_file(run_name, ".log")
144
David Brazdil2df24082019-09-05 11:55:08 +0100145 def start_run(self, run_name):
146 """Hook called by Driver subclasses before they invoke the target
147 platform."""
David Brazdil0dbb41f2019-09-09 18:03:35 +0100148 return DriverRunState(
149 self.args.artifacts.create_file(run_name, ".log"), 0)
David Brazdil2df24082019-09-05 11:55:08 +0100150
151 def exec_logged(self, run_state, exec_args):
152 """Run a subprocess on behalf of a Driver subclass and append its
153 stdout and stderr to the main log."""
David Brazdil0dbb41f2019-09-09 18:03:35 +0100154 assert(run_state.ret_code == 0)
David Brazdil2df24082019-09-05 11:55:08 +0100155 with open(run_state.log_path, "a") as f:
156 f.write("$ {}\r\n".format(" ".join(exec_args)))
157 f.flush()
David Brazdil0dbb41f2019-09-09 18:03:35 +0100158 ret_code = subprocess.call(exec_args, stdout=f, stderr=f)
159 if ret_code != 0:
160 run_state = DriverRunState(run_state.log_path, ret_code)
161 raise DriverRunException()
David Brazdil2df24082019-09-05 11:55:08 +0100162
David Brazdil0dbb41f2019-09-09 18:03:35 +0100163 def finish_run(self, run_state):
David Brazdil2df24082019-09-05 11:55:08 +0100164 """Hook called by Driver subclasses after they finished running the
165 target platform. `ret_code` argument is the return code of the main
166 command run by the driver. A corresponding log message is printed."""
167 # Decode return code and add a message to the log.
168 with open(run_state.log_path, "a") as f:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100169 if run_state.ret_code == 124:
David Brazdil2df24082019-09-05 11:55:08 +0100170 f.write("\r\n{}{} timed out\r\n".format(
171 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100172 elif run_state.ret_code != 0:
David Brazdil2df24082019-09-05 11:55:08 +0100173 f.write("\r\n{}{} process return code {}\r\n".format(
David Brazdil0dbb41f2019-09-09 18:03:35 +0100174 HFTEST_LOG_PREFIX, HFTEST_LOG_FAILURE_PREFIX,
175 run_state.ret_code))
David Brazdil2df24082019-09-05 11:55:08 +0100176
177 # Append log of this run to full test log.
178 log_content = read_file(run_state.log_path)
179 append_file(
180 self.args.artifacts.sponge_log_path,
181 log_content + "\r\n\r\n")
182 return log_content
Andrew Walbran98656252019-03-14 14:52:29 +0000183
David Brazdil0dbb41f2019-09-09 18:03:35 +0100184 def overlay_dtb(self, run_state, base_dtb, overlay_dtb, out_dtb):
185 """Overlay `overlay_dtb` over `base_dtb` into `out_dtb`."""
186 dtc_args = [
187 DTC_SCRIPT, "overlay",
188 out_dtb, base_dtb, overlay_dtb,
189 ]
190 self.exec_logged(run_state, dtc_args)
191
Andrew Walbran98656252019-03-14 14:52:29 +0000192
David Brazdil2df24082019-09-05 11:55:08 +0100193class QemuDriver(Driver):
194 """Driver which runs tests in QEMU."""
195
196 def __init__(self, args):
197 Driver.__init__(self, args)
198
David Brazdil0dbb41f2019-09-09 18:03:35 +0100199 def gen_exec_args(self, test_args, dtb_path=None, dumpdtb_path=None):
David Brazdil2df24082019-09-05 11:55:08 +0100200 """Generate command line arguments for QEMU."""
201 exec_args = [
202 "timeout", "--foreground", "10s",
203 "./prebuilts/linux-x64/qemu/qemu-system-aarch64",
Andrew Scull2925e422019-10-04 13:29:53 +0100204 "-machine", "virt,virtualization=on,gic_version=3",
David Brazdil2df24082019-09-05 11:55:08 +0100205 "-cpu", "cortex-a57", "-smp", "4", "-m", "64M",
David Brazdil2df24082019-09-05 11:55:08 +0100206 "-nographic", "-nodefaults", "-serial", "stdio",
Andrew Scull2925e422019-10-04 13:29:53 +0100207 "-d", "unimp", "-kernel", self.args.kernel,
David Brazdil2df24082019-09-05 11:55:08 +0100208 ]
209
David Brazdil0dbb41f2019-09-09 18:03:35 +0100210 if dtb_path:
211 exec_args += ["-dtb", dtb_path]
212
213 if dumpdtb_path:
214 exec_args += ["-machine", "dumpdtb=" + dumpdtb_path]
215
David Brazdil2df24082019-09-05 11:55:08 +0100216 if self.args.initrd:
217 exec_args += ["-initrd", self.args.initrd]
218
219 vm_args = join_if_not_None(self.args.vm_args, test_args)
220 if vm_args:
221 exec_args += ["-append", vm_args]
222
223 return exec_args
224
David Brazdil0dbb41f2019-09-09 18:03:35 +0100225 def dump_dtb(self, run_state, test_args, path):
226 dumpdtb_args = self.gen_exec_args(test_args, dumpdtb_path=path)
227 self.exec_logged(run_state, dumpdtb_args)
228
David Brazdil2df24082019-09-05 11:55:08 +0100229 def run(self, run_name, test_args):
230 """Run test given by `test_args` in QEMU."""
231 run_state = self.start_run(run_name)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100232
233 try:
234 dtb_path = None
235
236 # If manifest DTBO specified, dump DTB from QEMU and overlay them.
237 if self.args.manifest:
238 base_dtb_path = self.args.artifacts.create_file(
239 run_name, ".base.dtb")
240 dtb_path = self.args.artifacts.create_file(run_name, ".dtb")
241 self.dump_dtb(run_state, test_args, base_dtb_path)
242 self.overlay_dtb(
243 run_state, base_dtb_path, self.args.manifest, dtb_path)
244
245 # Execute test in QEMU..
246 exec_args = self.gen_exec_args(test_args, dtb_path=dtb_path)
247 self.exec_logged(run_state, exec_args)
248 except DriverRunException:
249 pass
250
251 return self.finish_run(run_state)
Andrew Scullbc7189d2018-08-14 09:35:13 +0100252
253
David Brazdil2df24082019-09-05 11:55:08 +0100254class FvpDriver(Driver):
255 """Driver which runs tests in ARM FVP emulator."""
256
257 def __init__(self, args):
258 Driver.__init__(self, args)
259
260 def gen_dts(self, dts_path, test_args, initrd_start, initrd_end):
261 """Create a DeviceTree source which will be compiled into a DTB and
262 passed to FVP for a test run."""
263 vm_args = join_if_not_None(self.args.vm_args, test_args)
264 write_file(dts_path, read_file(FVP_PREBUILT_DTS))
265 append_file(dts_path, """
266 / {{
267 chosen {{
268 bootargs = "{}";
269 stdout-path = "serial0:115200n8";
270 linux,initrd-start = <{}>;
271 linux,initrd-end = <{}>;
272 }};
273 }};
274 """.format(vm_args, initrd_start, initrd_end))
275
276 def gen_fvp_args(
277 self, initrd_start, uart0_log_path, uart1_log_path, dtb_path):
278 """Generate command line arguments for FVP."""
279 fvp_args = [
280 "timeout", "--foreground", "40s",
281 FVP_BINARY,
282 "-C", "pctl.startup=0.0.0.0",
283 "-C", "bp.secure_memory=0",
284 "-C", "cluster0.NUM_CORES=4",
285 "-C", "cluster1.NUM_CORES=4",
286 "-C", "cache_state_modelled=0",
287 "-C", "bp.vis.disable_visualisation=true",
288 "-C", "bp.vis.rate_limit-enable=false",
289 "-C", "bp.terminal_0.start_telnet=false",
290 "-C", "bp.terminal_1.start_telnet=false",
291 "-C", "bp.terminal_2.start_telnet=false",
292 "-C", "bp.terminal_3.start_telnet=false",
293 "-C", "bp.pl011_uart0.untimed_fifos=1",
294 "-C", "bp.pl011_uart0.unbuffered_output=1",
295 "-C", "bp.pl011_uart0.out_file=" + uart0_log_path,
296 "-C", "bp.pl011_uart1.out_file=" + uart1_log_path,
297 "-C", "cluster0.cpu0.RVBAR=0x04020000",
298 "-C", "cluster0.cpu1.RVBAR=0x04020000",
299 "-C", "cluster0.cpu2.RVBAR=0x04020000",
300 "-C", "cluster0.cpu3.RVBAR=0x04020000",
301 "-C", "cluster1.cpu0.RVBAR=0x04020000",
302 "-C", "cluster1.cpu1.RVBAR=0x04020000",
303 "-C", "cluster1.cpu2.RVBAR=0x04020000",
304 "-C", "cluster1.cpu3.RVBAR=0x04020000",
305 "--data", "cluster0.cpu0=prebuilts/linux-aarch64/arm-trusted-firmware/bl31.bin@0x04020000",
306 "--data", "cluster0.cpu0=" + dtb_path + "@0x82000000",
307 "--data", "cluster0.cpu0=" + self.args.kernel + "@0x80000000",
308 "-C", "bp.ve_sysregs.mmbSiteDefault=0",
309 "-C", "bp.ve_sysregs.exit_on_shutdown=1",
310 ]
311
312 if self.args.initrd:
313 fvp_args += [
314 "--data",
315 "cluster0.cpu0={}@{}".format(
316 self.args.initrd, hex(initrd_start))
317 ]
318
319 return fvp_args
320
321 def run(self, run_name, test_args):
322 run_state = self.start_run(run_name)
323
David Brazdil0dbb41f2019-09-09 18:03:35 +0100324 base_dts_path = self.args.artifacts.create_file(run_name, ".base.dts")
325 base_dtb_path = self.args.artifacts.create_file(run_name, ".base.dtb")
David Brazdil2df24082019-09-05 11:55:08 +0100326 dtb_path = self.args.artifacts.create_file(run_name, ".dtb")
327 uart0_log_path = self.args.artifacts.create_file(run_name, ".uart0.log")
328 uart1_log_path = self.args.artifacts.create_file(run_name, ".uart1.log")
329
330 initrd_start = 0x84000000
331 if self.args.initrd:
332 initrd_end = initrd_start + os.path.getsize(self.args.initrd)
333 else:
334 initrd_end = 0x85000000 # Default value
335
David Brazdil0dbb41f2019-09-09 18:03:35 +0100336 try:
337 # Create a DT to pass to FVP.
338 self.gen_dts(base_dts_path, test_args, initrd_start, initrd_end)
David Brazdil2df24082019-09-05 11:55:08 +0100339
David Brazdil0dbb41f2019-09-09 18:03:35 +0100340 # Compile DTS to DTB.
341 dtc_args = [
342 DTC_SCRIPT, "compile", "-i", base_dts_path, "-o", base_dtb_path,
343 ]
344 self.exec_logged(run_state, dtc_args)
345
346 # If manifest DTBO specified, overlay it.
347 if self.args.manifest:
348 self.overlay_dtb(
349 run_state, base_dtb_path, self.args.manifest, dtb_path)
350 else:
351 dtb_path = base_dtb_path
352
353 # Run FVP.
354 fvp_args = self.gen_fvp_args(
355 initrd_start, uart0_log_path, uart1_log_path, dtb_path)
356 self.exec_logged(run_state, fvp_args)
357 except DriverRunException:
358 pass
David Brazdil2df24082019-09-05 11:55:08 +0100359
360 # Append UART0 output to main log.
361 append_file(run_state.log_path, read_file(uart0_log_path))
David Brazdil0dbb41f2019-09-09 18:03:35 +0100362 return self.finish_run(run_state)
David Brazdil2df24082019-09-05 11:55:08 +0100363
364
365# Tuple used to return information about the results of running a set of tests.
366TestRunnerResult = collections.namedtuple("TestRunnerResult", [
367 "tests_run",
368 "tests_failed",
369 ])
370
371
372class TestRunner:
373 """Class which communicates with a test platform to obtain a list of
374 available tests and driving their execution."""
375
376 def __init__(self, artifacts, driver, image_name, suite_regex, test_regex):
377 self.artifacts = artifacts
378 self.driver = driver
379 self.image_name = image_name
380
381 self.suite_re = re.compile(suite_regex or ".*")
382 self.test_re = re.compile(test_regex or ".*")
383
384 def extract_hftest_lines(self, raw):
385 """Extract hftest-specific lines from a raw output from an invocation
386 of the test platform."""
387 lines = []
388 for line in raw.splitlines():
389 if line.startswith("VM "):
390 line = line[len("VM 0: "):]
391 if line.startswith(HFTEST_LOG_PREFIX):
392 lines.append(line[len(HFTEST_LOG_PREFIX):])
393 return lines
394
395 def get_test_json(self):
396 """Invoke the test platform and request a JSON of available test and
397 test suites."""
398 out = self.driver.run("json", "json")
399 hf_out = "\n".join(self.extract_hftest_lines(out))
400 try:
401 return json.loads(hf_out)
402 except ValueError as e:
403 print(out)
404 raise e
405
406 def collect_results(self, fn, it, xml_node):
407 """Run `fn` on every entry in `it` and collect their TestRunnerResults.
408 Insert "tests" and "failures" nodes to `xml_node`."""
409 tests_run = 0
410 tests_failed = 0
411 for i in it:
412 sub_result = fn(i)
413 assert(sub_result.tests_run >= sub_result.tests_failed)
414 tests_run += sub_result.tests_run
415 tests_failed += sub_result.tests_failed
416
417 xml_node.set("tests", str(tests_run))
418 xml_node.set("failures", str(tests_failed))
419 return TestRunnerResult(tests_run, tests_failed)
420
421 def is_passed_test(self, test_out):
422 """Parse the output of a test and return True if it passed."""
423 return \
424 len(test_out) > 0 and \
425 test_out[-1] == HFTEST_LOG_FINISHED and \
426 not any(l.startswith(HFTEST_LOG_FAILURE_PREFIX) for l in test_out)
427
428 def run_test(self, suite, test, suite_xml):
429 """Invoke the test platform and request to run a given `test` in given
430 `suite`. Create a new XML node with results under `suite_xml`.
431 Test only invoked if it matches the regex given to constructor."""
432 if not self.test_re.match(test):
433 return TestRunnerResult(tests_run=0, tests_failed=0)
434
435 print(" RUN", test)
436 log_name = suite["name"] + "." + test
437
438 test_xml = ET.SubElement(suite_xml, "testcase")
439 test_xml.set("name", test)
440 test_xml.set("classname", suite['name'])
441 test_xml.set("status", "run")
442
443 out = self.extract_hftest_lines(self.driver.run(
444 log_name, "run {} {}".format(suite["name"], test)))
445
446 if self.is_passed_test(out):
447 print(" PASS")
448 return TestRunnerResult(tests_run=1, tests_failed=0)
449 else:
David Brazdil623b6812019-09-09 11:41:08 +0100450 print("[x] FAIL --", self.driver.get_run_log(log_name))
David Brazdil2df24082019-09-05 11:55:08 +0100451 failure_xml = ET.SubElement(test_xml, "failure")
452 # TODO: set a meaningful message and put log in CDATA
453 failure_xml.set("message", "Test failed")
454 return TestRunnerResult(tests_run=1, tests_failed=1)
455
456 def run_suite(self, suite, xml):
457 """Invoke the test platform and request to run all matching tests in
458 `suite`. Create new XML nodes with results under `xml`.
459 Suite skipped if it does not match the regex given to constructor."""
460 if not self.suite_re.match(suite["name"]):
461 return TestRunnerResult(tests_run=0, tests_failed=0)
462
463 print(" SUITE", suite["name"])
464 suite_xml = ET.SubElement(xml, "testsuite")
465 suite_xml.set("name", suite["name"])
466
467 return self.collect_results(
468 lambda test: self.run_test(suite, test, suite_xml),
469 suite["tests"],
470 suite_xml)
471
472 def run_tests(self):
473 """Run all suites and tests matching regexes given to constructor.
474 Write results to sponge log XML. Return the number of run and failed
475 tests."""
476
477 test_spec = self.get_test_json()
478 timestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
479
480 xml = ET.Element("testsuites")
481 xml.set("name", self.image_name)
482 xml.set("timestamp", timestamp)
483
484 result = self.collect_results(
485 lambda suite: self.run_suite(suite, xml),
486 test_spec["suites"],
487 xml)
488
489 # Write XML to file.
490 with open(self.artifacts.sponge_xml_path, "w") as f:
491 ET.ElementTree(xml).write(f, encoding='utf-8', xml_declaration=True)
492
493 if result.tests_failed > 0:
494 print("[x] FAIL:", result.tests_failed, "of", result.tests_run,
495 "tests failed")
496 elif result.tests_run > 0:
497 print(" PASS: all", result.tests_run, "tests passed")
498
499 return result
Andrew Scullbc7189d2018-08-14 09:35:13 +0100500
501
502def Main():
503 parser = argparse.ArgumentParser()
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000504 parser.add_argument("image")
Andrew Scullbc7189d2018-08-14 09:35:13 +0100505 parser.add_argument("--out", required=True)
Andrew Scull23e93a82018-10-26 14:56:04 +0100506 parser.add_argument("--log", required=True)
Andrew Walbran7559fcf2019-05-09 17:11:20 +0100507 parser.add_argument("--out_initrd")
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000508 parser.add_argument("--initrd")
Andrew Scullbc7189d2018-08-14 09:35:13 +0100509 parser.add_argument("--suite")
510 parser.add_argument("--test")
Andrew Walbranbc342d42019-02-05 16:56:02 +0000511 parser.add_argument("--vm_args")
Andrew Walbran98656252019-03-14 14:52:29 +0000512 parser.add_argument("--fvp", type=bool)
Andrew Scullbc7189d2018-08-14 09:35:13 +0100513 args = parser.parse_args()
David Brazdil2df24082019-09-05 11:55:08 +0100514
Andrew Scullbc7189d2018-08-14 09:35:13 +0100515 # Resolve some paths.
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000516 image = os.path.join(args.out, args.image + ".bin")
517 initrd = None
David Brazdil0dbb41f2019-09-09 18:03:35 +0100518 manifest = None
David Brazdil2df24082019-09-05 11:55:08 +0100519 image_name = args.image
Andrew Scull7fd4bb72018-12-08 23:40:12 +0000520 if args.initrd:
David Brazdil0dbb41f2019-09-09 18:03:35 +0100521 initrd_dir = os.path.join(args.out_initrd, "obj", args.initrd)
522 initrd = os.path.join(initrd_dir, "initrd.img")
523 manifest = os.path.join(initrd_dir, "manifest.dtbo")
David Brazdil2df24082019-09-05 11:55:08 +0100524 image_name += "_" + args.initrd
Andrew Walbranbc342d42019-02-05 16:56:02 +0000525 vm_args = args.vm_args or ""
David Brazdil2df24082019-09-05 11:55:08 +0100526
527 # Create class which will manage all test artifacts.
528 artifacts = ArtifactsManager(os.path.join(args.log, image_name))
529
530 # Create a driver for the platform we want to test on.
David Brazdil0dbb41f2019-09-09 18:03:35 +0100531 driver_args = DriverArgs(artifacts, image, initrd, manifest, vm_args)
David Brazdil2df24082019-09-05 11:55:08 +0100532 if args.fvp:
533 driver = FvpDriver(driver_args)
534 else:
535 driver = QemuDriver(driver_args)
536
537 # Create class which will drive test execution.
538 runner = TestRunner(artifacts, driver, image_name, args.suite, args.test)
539
540 # Run tests.
541 runner_result = runner.run_tests()
542
543 # Print error message if no tests were run as this is probably unexpected.
544 # Return suitable error code.
545 if runner_result.tests_run == 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +0100546 print("Error: no tests match")
547 return 10
David Brazdil2df24082019-09-05 11:55:08 +0100548 elif runner_result.tests_failed > 0:
Andrew Scullbc7189d2018-08-14 09:35:13 +0100549 return 1
550 else:
David Brazdil2df24082019-09-05 11:55:08 +0100551 return 0
Andrew Scullbc7189d2018-08-14 09:35:13 +0100552
553if __name__ == "__main__":
554 sys.exit(Main())