blob: 9e331e3f5caf5ed141b8ef2637e2bb2f26d5d0b0 [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/usr/bin/env python3
2#
3# Copyright (c) 2019, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# After lava job is dispatched, its results will be collected in
9# $WORKSPACE/job_results.yaml file. Parse that file, and exit from this script
10# with the respective exit status
11
12import argparse
13import os
14import sys
15import yaml
16
17
18def report_job_failure():
19 job_url = os.environ["JOB_URL"]
20 build_number = os.environ["BUILD_NUMBER"]
21 print()
22 print("Job failed!")
23 print("See " + "/".join([job_url.rstrip("/"), build_number, "artifact",
24 "job_output.log"]))
25 print()
26 sys.exit(1)
27
28
29def report_job_success():
30 print()
31 print("Job success.")
32 print()
33 sys.exit(0)
34
35
36def parse_cmd_line():
37 parser = argparse.ArgumentParser(description="Parse results from LAVA. "
38 "The results must be provided as a YAML file.")
39 parser.add_argument("--payload-type", default="linux", type=str,
40 help="Type of payload that was used in the test (default: %(default)s)")
41 parser.add_argument("--file",
42 default=os.path.join(os.environ["WORKSPACE"], "job_results.yaml"),
43 type=str, help="YAML file to parse (default: %(default)s)")
44 args = parser.parse_args()
45 return args
46
47
48args = parse_cmd_line()
49
50with open(args.file) as fd:
51 results = yaml.load(fd)
52
53 # Iterate through results. Find the element whose name is "job" in the
54 # "lava" suite. It contains the result of the overall LAVA run.
55 for phase in results:
56 if phase["name"] == "job" and phase["suite"] == "lava":
57 break
58 else:
59 raise Exception("Couldn't find 'job' phase in 'lava' suite in results")
60
61 if phase["result"] != "pass":
62 report_job_failure()
63
64 # If we've simply booted to the Linux shell prompt then we don't need to
65 # further analyze the results from LAVA.
66 if args.payload_type == "linux":
67 report_job_success()
68
69 # If we've run TFTF tests instead, then do some further parsing.
70 # First make sure the test session finished.
71 for phase in filter(lambda p: p["name"] == "lava-test-monitor", results):
72 if phase["result"] != "pass":
73 print("TFTF test session failed. Did it time out?")
74 report_job_failure()
75 break
76 else:
77 raise Exception("Couldn't find 'lava-test-monitor' phase results")
78
79 # Then count the number of tests that failed/skipped.
80 test_failures = 0
81 test_skips = 0
82 for phase in filter(lambda p: p["suite"] == "tftf", results):
83 metadata = phase["metadata"]
84 testcase_name = metadata["case"]
85 testcase_result = metadata["result"]
86 if testcase_result == "fail":
87 test_failures += 1
88 print("=> FAILED: " + testcase_name)
89 elif testcase_result == "skip":
90 test_skips += 1
91 print(" SKIPPED: " + testcase_name)
92
93 # Print a test summary
94 print()
95 if test_failures == 0 and test_skips == 0:
96 print("All tests passed.")
97 else:
98 print("{} tests failed; {} skipped. All other tests passed.".format(
99 test_failures, test_skips))
100
101 if test_failures == 0:
102 report_job_success()
103 else:
104 report_job_failure()