kunit_json.py (6bd0f52ee8f400a558f1c0f33e1f3fd3ef4922a8) | kunit_json.py (ee96d25f2fa657a29ab59345898dc4ff616cfe84) |
---|---|
1# SPDX-License-Identifier: GPL-2.0 2# 3# Generates JSON from KUnit results according to 4# KernelCI spec: https://github.com/kernelci/kernelci-doc/wiki/Test-API 5# 6# Copyright (C) 2020, Google LLC. 7# Author: Heidi Fahim <heidifahim@google.com> 8 | 1# SPDX-License-Identifier: GPL-2.0 2# 3# Generates JSON from KUnit results according to 4# KernelCI spec: https://github.com/kernelci/kernelci-doc/wiki/Test-API 5# 6# Copyright (C) 2020, Google LLC. 7# Author: Heidi Fahim <heidifahim@google.com> 8 |
9from dataclasses import dataclass |
|
9import json 10import os 11 12import kunit_parser 13 14from kunit_parser import Test, TestStatus 15from typing import Any, Dict 16 | 10import json 11import os 12 13import kunit_parser 14 15from kunit_parser import Test, TestStatus 16from typing import Any, Dict 17 |
18@dataclass 19class Metadata: 20 """Stores metadata about this run to include in get_json_result().""" 21 arch: str = 'UM' 22 def_config: str = 'kunit_defconfig' 23 build_dir: str = '' 24 |
|
17JsonObj = Dict[str, Any] 18 19_status_map: Dict[TestStatus, str] = { 20 TestStatus.SUCCESS: "PASS", 21 TestStatus.SKIPPED: "SKIP", 22 TestStatus.TEST_CRASHED: "ERROR", 23} 24 | 25JsonObj = Dict[str, Any] 26 27_status_map: Dict[TestStatus, str] = { 28 TestStatus.SUCCESS: "PASS", 29 TestStatus.SKIPPED: "SKIP", 30 TestStatus.TEST_CRASHED: "ERROR", 31} 32 |
25def _get_group_json(test: Test, def_config: str, build_dir: str) -> JsonObj: | 33def _get_group_json(test: Test, common_fields: JsonObj) -> JsonObj: |
26 sub_groups = [] # List[JsonObj] 27 test_cases = [] # List[JsonObj] 28 29 for subtest in test.subtests: 30 if subtest.subtests: | 34 sub_groups = [] # List[JsonObj] 35 test_cases = [] # List[JsonObj] 36 37 for subtest in test.subtests: 38 if subtest.subtests: |
31 sub_group = _get_group_json(subtest, def_config, 32 build_dir) | 39 sub_group = _get_group_json(subtest, common_fields) |
33 sub_groups.append(sub_group) 34 continue 35 status = _status_map.get(subtest.status, "FAIL") 36 test_cases.append({"name": subtest.name, "status": status}) 37 38 test_group = { 39 "name": test.name, | 40 sub_groups.append(sub_group) 41 continue 42 status = _status_map.get(subtest.status, "FAIL") 43 test_cases.append({"name": subtest.name, "status": status}) 44 45 test_group = { 46 "name": test.name, |
40 "arch": "UM", 41 "defconfig": def_config, 42 "build_environment": build_dir, | |
43 "sub_groups": sub_groups, 44 "test_cases": test_cases, | 47 "sub_groups": sub_groups, 48 "test_cases": test_cases, |
49 } 50 test_group.update(common_fields) 51 return test_group 52 53def get_json_result(test: Test, metadata: Metadata) -> str: 54 common_fields = { 55 "arch": metadata.arch, 56 "defconfig": metadata.def_config, 57 "build_environment": metadata.build_dir, |
|
45 "lab_name": None, 46 "kernel": None, 47 "job": None, 48 "git_branch": "kselftest", 49 } | 58 "lab_name": None, 59 "kernel": None, 60 "job": None, 61 "git_branch": "kselftest", 62 } |
50 return test_group | |
51 | 63 |
52def get_json_result(test: Test, def_config: str, build_dir: str) -> str: 53 test_group = _get_group_json(test, def_config, build_dir) | 64 test_group = _get_group_json(test, common_fields) |
54 test_group["name"] = "KUnit Test Group" 55 return json.dumps(test_group, indent=4) | 65 test_group["name"] = "KUnit Test Group" 66 return json.dumps(test_group, indent=4) |