diff options
Diffstat (limited to 'util/zephyr_to_resultdb.py')
-rwxr-xr-x | util/zephyr_to_resultdb.py | 96 |
1 files changed, 11 insertions, 85 deletions
diff --git a/util/zephyr_to_resultdb.py b/util/zephyr_to_resultdb.py index 6c378bde5c..48bfe151e4 100755 --- a/util/zephyr_to_resultdb.py +++ b/util/zephyr_to_resultdb.py @@ -11,11 +11,8 @@ import argparse import base64 -import datetime import json import os -import pathlib -import re import requests # pylint: disable=import-error @@ -50,7 +47,7 @@ def translate_duration(testcase): if not time: return None - return f"{float(time)/1000:.9f}s" + return f"{time}ms" def testcase_summary(testcase): @@ -62,7 +59,9 @@ def testcase_summary(testcase): or "reason" in testcase or translate_status(testcase["status"]) == "SKIP" ): - html = '<p><text-artifact artifact-id="test_log"></p>' + html = ( + '<p><text-artifact artifact-id="artifact-content-in-request"></p>' + ) return html @@ -83,113 +82,40 @@ def testcase_artifact(testcase): return base64.b64encode(artifact.encode()) -def testsuite_artifact(testsuite): - """Translates ZTEST testcase to ResultDB artifact""" - artifact = "Unknown" - - if "log" in testsuite and testsuite["log"]: - artifact = testsuite["log"] - - return base64.b64encode(artifact.encode()) - - -def testcase_to_result(testsuite, testcase, base_tags, config_tags): - """Translates ZTEST testcase to ResultDB format - See TestResult type in - https://crsrc.org/i/go/src/go.chromium.org/luci/resultdb/sink/proto/v1/test_result.proto - """ +def testcase_to_result(testsuite, testcase): + """Translates ZTEST testcase to ResultDB format""" result = { "testId": testcase["identifier"], "status": translate_status(testcase["status"]), "expected": translate_expected(testcase["status"]), "summaryHtml": testcase_summary(testcase), "artifacts": { - "test_log": { + "artifact-content-in-request": { "contents": testcase_artifact(testcase), - }, - "testsuite_log": { - "contents": testsuite_artifact(testsuite), - }, + } }, + # TODO(b/239952573) Add all test configs as tags "tags": [ + {"key": "category", "value": "ChromeOS/EC"}, {"key": "platform", "value": testsuite["platform"]}, ], "duration": translate_duration(testcase), "testMetadata": {"name": testcase["identifier"]}, } - for (key, value) in base_tags: - result["tags"].append({"key": key, "value": value}) - - for (key, value) in config_tags: - result["tags"].append({"key": key.lower(), "value": value}) - - if result["status"] == "FAIL" and "log" in testcase and testcase["log"]: - assert_msg = re.findall( - r"Assertion failed.*$", testcase["log"], re.MULTILINE - ) - result["failureReason"] = {"primaryErrorMessage": assert_msg[0]} - return result -def get_testsuite_config_tags(twister_dir, testsuite): - """Creates config tags from the testsuite""" - config_tags = [] - suite_path = f"{twister_dir}/{testsuite['platform']}/{testsuite['name']}" - dot_config = f"{suite_path}/zephyr/.config" - - if pathlib.Path(dot_config).exists(): - with open(dot_config) as file: - lines = file.readlines() - - for line in lines: - # Ignore empty lines and comments - if line.strip() and not line.startswith("#"): - result = re.search(r"(\w+)=(.+$)", line) - config_tags.append((result.group(1), result.group(2))) - else: - print(f"Can't find config file for {testsuite['name']}") - - return config_tags - - -def create_base_tags(data): - """Creates base tags needed for Testhaus""" - base_tags = [] - - queued_time = datetime.datetime.fromisoformat( - data["environment"]["run_date"] - ) - base_tags.append( - ("queued_time", queued_time.strftime("%Y-%m-%d %H:%M:%S.%f UTC")) - ) - - base_tags.append(("zephyr_version", data["environment"]["zephyr_version"])) - base_tags.append(("board", data["environment"]["os"])) - base_tags.append(("toolchain", data["environment"]["toolchain"])) - - return base_tags - - def json_to_resultdb(result_file): """Translates Twister json test report to ResultDB format""" with open(result_file) as file: data = json.load(file) results = [] - base_tags = create_base_tags(data) for testsuite in data["testsuites"]: - config_tags = get_testsuite_config_tags( - os.path.dirname(result_file), testsuite - ) for testcase in testsuite["testcases"]: if testcase["status"]: - results.append( - testcase_to_result( - testsuite, testcase, base_tags, config_tags - ) - ) + results.append(testcase_to_result(testsuite, testcase)) file.close() |