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>
This commit is contained in:
Daniel Latypov
2022-01-18 11:09:19 -08:00
committed by Shuah Khan
parent 3123109284
commit 00f75043e4
3 changed files with 11 additions and 16 deletions

View File

@@ -216,13 +216,17 @@ def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> Tuple[
parse_end = time.time()
if request.json:
json_obj = kunit_json.get_json_result(
json_str = kunit_json.get_json_result(
test=test_result,
def_config='kunit_defconfig',
build_dir=request.build_dir,
json_path=request.json)
build_dir=request.build_dir)
if request.json == 'stdout':
print(json_obj)
print(json_str)
else:
with open(request.json, 'w') as f:
f.write(json_str)
kunit_parser.print_with_timestamp("Test results stored in %s" %
os.path.abspath(request.json))
if test_result.status != kunit_parser.TestStatus.SUCCESS:
return KunitResult(KunitStatus.TEST_FAILURE, parse_end - parse_start), test_result