提交 00f75043 编写于 作者: D Daniel Latypov 提交者: Shuah Khan

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: NDaniel Latypov <dlatypov@google.com>
Reviewed-by: NDavid Gow <davidgow@google.com>
Reviewed-by: NBrendan Higgins <brendanhiggins@google.com>
Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
上级 31231092
...@@ -216,13 +216,17 @@ def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> Tuple[ ...@@ -216,13 +216,17 @@ def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> Tuple[
parse_end = time.time() parse_end = time.time()
if request.json: if request.json:
json_obj = kunit_json.get_json_result( json_str = kunit_json.get_json_result(
test=test_result, test=test_result,
def_config='kunit_defconfig', def_config='kunit_defconfig',
build_dir=request.build_dir, build_dir=request.build_dir)
json_path=request.json)
if request.json == 'stdout': 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: if test_result.status != kunit_parser.TestStatus.SUCCESS:
return KunitResult(KunitStatus.TEST_FAILURE, parse_end - parse_start), test_result return KunitResult(KunitStatus.TEST_FAILURE, parse_end - parse_start), test_result
......
...@@ -51,15 +51,7 @@ def _get_group_json(test: Test, def_config: str, ...@@ -51,15 +51,7 @@ def _get_group_json(test: Test, def_config: str,
return test_group return test_group
def get_json_result(test: Test, def_config: str, def get_json_result(test: Test, def_config: str,
build_dir: Optional[str], json_path: str) -> str: build_dir: Optional[str]) -> str:
test_group = _get_group_json(test, def_config, build_dir) test_group = _get_group_json(test, def_config, build_dir)
test_group["name"] = "KUnit Test Group" test_group["name"] = "KUnit Test Group"
json_obj = json.dumps(test_group, indent=4) return json.dumps(test_group, indent=4)
if json_path != 'stdout':
with open(json_path, 'w') as result_path:
result_path.write(json_obj)
root = __file__.split('tools/testing/kunit/')[0]
kunit_parser.print_with_timestamp(
"Test results stored in %s" %
os.path.join(root, result_path.name))
return json_obj
...@@ -469,8 +469,7 @@ class KUnitJsonTest(unittest.TestCase): ...@@ -469,8 +469,7 @@ class KUnitJsonTest(unittest.TestCase):
json_obj = kunit_json.get_json_result( json_obj = kunit_json.get_json_result(
test=test_result, test=test_result,
def_config='kunit_defconfig', def_config='kunit_defconfig',
build_dir=None, build_dir=None)
json_path='stdout')
return json.loads(json_obj) return json.loads(json_obj)
def test_failed_test_json(self): def test_failed_test_json(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册