blob: 49d9a59ec4a92098e13ce3eff20b13029046ca3d [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/usr/bin/env python3
2#
Leandro Belli6e0c4462024-12-12 18:46:37 +00003# Copyright (c) 2019-2024 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
Joel Goddard3e091832021-03-30 10:29:47 +010035def scmi_parse_phase(results, case, special_case, expected_skip_count):
Zelalem219df412020-05-17 19:21:20 -050036 pass_count = 0
37 fail_count = 0
38 false_fail_count = 0
Joel Goddard3e091832021-03-30 10:29:47 +010039 skip_count = 0
Zelalem219df412020-05-17 19:21:20 -050040
41 for phase in results:
42 if phase["metadata"]["definition"] == case:
43 if phase["metadata"]["result"] == "pass":
44 pass_count += 1
Joel Goddard3e091832021-03-30 10:29:47 +010045 elif phase["metadata"]["result"] == "skip":
46 skip_count += 1
Zelalem219df412020-05-17 19:21:20 -050047 else:
48 if special_case != "" and phase["metadata"]["case"] == special_case:
49 false_fail_count += 1
50 else:
51 fail_count += 1
52
53 print(case)
54 print("pass_count " + str(pass_count))
55 print("fail_count " + str(fail_count))
56 if special_case != "":
57 print("false_fail_count " + str(false_fail_count))
Joel Goddard3e091832021-03-30 10:29:47 +010058 print("skip_count " + str(skip_count) + " out of expected " + str(expected_skip_count))
59 if (fail_count > 0) or (skip_count > expected_skip_count):
Zelalem219df412020-05-17 19:21:20 -050060 report_job_failure()
61
62def parse_scp_scmi_results():
63 #
64 # All protocols but sensor
65 #
Joel Goddard3e091832021-03-30 10:29:47 +010066 all_prot_expected_skip_count = 9
67 scmi_parse_phase(results, "scp-scmi-all-protocol", "", all_prot_expected_skip_count)
Fathi Boudra422bf772019-12-02 11:10:16 +020068
69def parse_cmd_line():
70 parser = argparse.ArgumentParser(description="Parse results from LAVA. "
71 "The results must be provided as a YAML file.")
72 parser.add_argument("--payload-type", default="linux", type=str,
73 help="Type of payload that was used in the test (default: %(default)s)")
74 parser.add_argument("--file",
75 default=os.path.join(os.environ["WORKSPACE"], "job_results.yaml"),
76 type=str, help="YAML file to parse (default: %(default)s)")
77 args = parser.parse_args()
78 return args
79
80
81args = parse_cmd_line()
82
83with open(args.file) as fd:
Zelalem219df412020-05-17 19:21:20 -050084 results = yaml.safe_load(fd)
Fathi Boudra422bf772019-12-02 11:10:16 +020085
86 # Iterate through results. Find the element whose name is "job" in the
87 # "lava" suite. It contains the result of the overall LAVA run.
88 for phase in results:
89 if phase["name"] == "job" and phase["suite"] == "lava":
90 break
91 else:
92 raise Exception("Couldn't find 'job' phase in 'lava' suite in results")
93
94 if phase["result"] != "pass":
95 report_job_failure()
96
97 # If we've simply booted to the Linux shell prompt then we don't need to
98 # further analyze the results from LAVA.
99 if args.payload_type == "linux":
100 report_job_success()
101
Zelalem219df412020-05-17 19:21:20 -0500102 # If we've run TFTF or SCMI tests instead, then do some further parsing.
103 elif args.payload_type == "tftf":
104 session = "TFTF"
105 suite = "tftf"
106 elif args.payload_type == "scp_tests_scmi":
107 session = "SCMI"
108 suite = "scp-scmi"
109 parse_scp_scmi_results()
110
111 print("All tests passed.")
112 report_job_success()
113 else:
114 raise Exception("Payload not defined")
115
Fathi Boudra422bf772019-12-02 11:10:16 +0200116 # Then count the number of tests that failed/skipped.
117 test_failures = 0
118 test_skips = 0
Zelalem219df412020-05-17 19:21:20 -0500119 for phase in filter(lambda p: p["suite"] == suite, results):
Fathi Boudra422bf772019-12-02 11:10:16 +0200120 metadata = phase["metadata"]
121 testcase_name = metadata["case"]
122 testcase_result = metadata["result"]
123 if testcase_result == "fail":
124 test_failures += 1
125 print("=> FAILED: " + testcase_name)
126 elif testcase_result == "skip":
127 test_skips += 1
128 print(" SKIPPED: " + testcase_name)
129
130 # Print a test summary
131 print()
132 if test_failures == 0 and test_skips == 0:
133 print("All tests passed.")
134 else:
135 print("{} tests failed; {} skipped. All other tests passed.".format(
136 test_failures, test_skips))
137
138 if test_failures == 0:
139 report_job_success()
140 else:
141 report_job_failure()