1 # SPDX-License-Identifier: GPL-2.0
3 # Generates JSON from KUnit results according to
4 # KernelCI spec: https://github.com/kernelci/kernelci-doc/wiki/Test-API
6 # Copyright (C) 2020, Google LLC.
7 # Author: Heidi Fahim <heidifahim@google.com>
14 from kunit_parser
import TestStatus
16 def get_json_result(test_result
, def_config
, build_dir
, json_path
):
19 # Each test suite is mapped to a KernelCI sub_group
20 for test_suite
in test_result
.suites
:
22 "name": test_suite
.name
,
24 "defconfig": def_config
,
25 "build_environment": build_dir
,
30 "git_branch": "kselftest",
33 # TODO: Add attachments attribute in test_case with detailed
34 # failure message, see https://api.kernelci.org/schema-test-case.html#get
35 for case
in test_suite
.cases
:
36 test_case
= {"name": case
.name
, "status": "FAIL"}
37 if case
.status
== TestStatus
.SUCCESS
:
38 test_case
["status"] = "PASS"
39 elif case
.status
== TestStatus
.TEST_CRASHED
:
40 test_case
["status"] = "ERROR"
41 test_cases
.append(test_case
)
42 sub_group
["test_cases"] = test_cases
43 sub_groups
.append(sub_group
)
45 "name": "KUnit Test Group",
47 "defconfig": def_config
,
48 "build_environment": build_dir
,
49 "sub_groups": sub_groups
,
53 "git_branch": "kselftest",
55 json_obj
= json
.dumps(test_group
, indent
=4)
56 if json_path
!= 'stdout':
57 with
open(json_path
, 'w') as result_path
:
58 result_path
.write(json_obj
)
59 root
= __file__
.split('tools/testing/kunit/')[0]
60 kunit_parser
.print_with_timestamp(
61 "Test results stored in %s" %
62 os
.path
.join(root
, result_path
.name
))