blob: aa85ca3e03abbe2e6b05742c91dd2bbeeb7e09d7 [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
Zelalem219df412020-05-17 19:21:20 -050035def scmi_parse_phase(results, case, special_case):
36 pass_count = 0
37 fail_count = 0
38 false_fail_count = 0
39
40 for phase in results:
41 if phase["metadata"]["definition"] == case:
42 if phase["metadata"]["result"] == "pass":
43 pass_count += 1
44 else:
45 if special_case != "" and phase["metadata"]["case"] == special_case:
46 false_fail_count += 1
47 else:
48 fail_count += 1
49
50 print(case)
51 print("pass_count " + str(pass_count))
52 print("fail_count " + str(fail_count))
53 if special_case != "":
54 print("false_fail_count " + str(false_fail_count))
55 if fail_count > 0:
56 report_job_failure()
57
58def parse_scp_scmi_results():
59 #
60 # All protocols but sensor
61 #
62 scmi_parse_phase(results, "scp-scmi-non-sensor-protocol", "")
63
64 #
65 # Protocol sensor, not reading_get
66 #
67 scmi_parse_phase(results, "scp-scmi-sensor-protocol", "")
68
69 #
70 # Protocol sensor, only reading_get
71 # In this case, we know that the reading from the sensor VBIG will fail
72 # cause the big cluster is OFF. Thus we simply discard that false failure.
73 #
74 JUNO_PVT_SENSOR_VOLT_BIG = "1"
75 scmi_parse_phase(results, "scp-scmi-sensor-protocol-get", JUNO_PVT_SENSOR_VOLT_BIG)
76
77 #
78 # Parse the final overall results
79 # We already know the false failures, discard them
80 #
81 scmi_parse_phase(results, "scp-scmi", "sensor_reading_get_sync_allsensorid_")
Fathi Boudra422bf772019-12-02 11:10:16 +020082
83def parse_cmd_line():
84 parser = argparse.ArgumentParser(description="Parse results from LAVA. "
85 "The results must be provided as a YAML file.")
86 parser.add_argument("--payload-type", default="linux", type=str,
87 help="Type of payload that was used in the test (default: %(default)s)")
88 parser.add_argument("--file",
89 default=os.path.join(os.environ["WORKSPACE"], "job_results.yaml"),
90 type=str, help="YAML file to parse (default: %(default)s)")
91 args = parser.parse_args()
92 return args
93
94
95args = parse_cmd_line()
96
97with open(args.file) as fd:
Zelalem219df412020-05-17 19:21:20 -050098 results = yaml.safe_load(fd)
Fathi Boudra422bf772019-12-02 11:10:16 +020099
100 # Iterate through results. Find the element whose name is "job" in the
101 # "lava" suite. It contains the result of the overall LAVA run.
102 for phase in results:
103 if phase["name"] == "job" and phase["suite"] == "lava":
104 break
105 else:
106 raise Exception("Couldn't find 'job' phase in 'lava' suite in results")
107
108 if phase["result"] != "pass":
109 report_job_failure()
110
111 # If we've simply booted to the Linux shell prompt then we don't need to
112 # further analyze the results from LAVA.
113 if args.payload_type == "linux":
114 report_job_success()
115
Zelalem219df412020-05-17 19:21:20 -0500116 # If we've run TFTF or SCMI tests instead, then do some further parsing.
117 elif args.payload_type == "tftf":
118 session = "TFTF"
119 suite = "tftf"
120 elif args.payload_type == "scp_tests_scmi":
121 session = "SCMI"
122 suite = "scp-scmi"
123 parse_scp_scmi_results()
124
125 print("All tests passed.")
126 report_job_success()
127 else:
128 raise Exception("Payload not defined")
129
Fathi Boudra422bf772019-12-02 11:10:16 +0200130 # First make sure the test session finished.
131 for phase in filter(lambda p: p["name"] == "lava-test-monitor", results):
132 if phase["result"] != "pass":
Zelalem219df412020-05-17 19:21:20 -0500133 print(session + " test session failed. Did it time out?")
Fathi Boudra422bf772019-12-02 11:10:16 +0200134 report_job_failure()
135 break
136 else:
137 raise Exception("Couldn't find 'lava-test-monitor' phase results")
138
139 # Then count the number of tests that failed/skipped.
140 test_failures = 0
141 test_skips = 0
Zelalem219df412020-05-17 19:21:20 -0500142 for phase in filter(lambda p: p["suite"] == suite, results):
Fathi Boudra422bf772019-12-02 11:10:16 +0200143 metadata = phase["metadata"]
144 testcase_name = metadata["case"]
145 testcase_result = metadata["result"]
146 if testcase_result == "fail":
147 test_failures += 1
148 print("=> FAILED: " + testcase_name)
149 elif testcase_result == "skip":
150 test_skips += 1
151 print(" SKIPPED: " + testcase_name)
152
153 # Print a test summary
154 print()
155 if test_failures == 0 and test_skips == 0:
156 print("All tests passed.")
157 else:
158 print("{} tests failed; {} skipped. All other tests passed.".format(
159 test_failures, test_skips))
160
161 if test_failures == 0:
162 report_job_success()
163 else:
164 report_job_failure()