Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kunit: tool: make --json handling a bit clearer

Currently kunit_json.get_json_result() will output the JSON-ified test
output to json_path, but iff it's not "stdout".

Instead, move the responsibility entirely over to the one caller.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Daniel Latypov and committed by
Shuah Khan
00f75043 31231092

+11 -16
+8 -4
tools/testing/kunit/kunit.py
··· 216 216 parse_end = time.time() 217 217 218 218 if request.json: 219 - json_obj = kunit_json.get_json_result( 219 + json_str = kunit_json.get_json_result( 220 220 test=test_result, 221 221 def_config='kunit_defconfig', 222 - build_dir=request.build_dir, 223 - json_path=request.json) 222 + build_dir=request.build_dir) 224 223 if request.json == 'stdout': 225 - print(json_obj) 224 + print(json_str) 225 + else: 226 + with open(request.json, 'w') as f: 227 + f.write(json_str) 228 + kunit_parser.print_with_timestamp("Test results stored in %s" % 229 + os.path.abspath(request.json)) 226 230 227 231 if test_result.status != kunit_parser.TestStatus.SUCCESS: 228 232 return KunitResult(KunitStatus.TEST_FAILURE, parse_end - parse_start), test_result
+2 -10
tools/testing/kunit/kunit_json.py
··· 51 51 return test_group 52 52 53 53 def get_json_result(test: Test, def_config: str, 54 - build_dir: Optional[str], json_path: str) -> str: 54 + build_dir: Optional[str]) -> str: 55 55 test_group = _get_group_json(test, def_config, build_dir) 56 56 test_group["name"] = "KUnit Test Group" 57 - json_obj = json.dumps(test_group, indent=4) 58 - if json_path != 'stdout': 59 - with open(json_path, 'w') as result_path: 60 - result_path.write(json_obj) 61 - root = __file__.split('tools/testing/kunit/')[0] 62 - kunit_parser.print_with_timestamp( 63 - "Test results stored in %s" % 64 - os.path.join(root, result_path.name)) 65 - return json_obj 57 + return json.dumps(test_group, indent=4)
+1 -2
tools/testing/kunit/kunit_tool_test.py
··· 469 469 json_obj = kunit_json.get_json_result( 470 470 test=test_result, 471 471 def_config='kunit_defconfig', 472 - build_dir=None, 473 - json_path='stdout') 472 + build_dir=None) 474 473 return json.loads(json_obj) 475 474 476 475 def test_failed_test_json(self):