Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp548294pxb; Thu, 20 Jan 2022 20:01:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJx31ZKISxG+stToJwki8LmUyxjzqKEZfCYlgOxrwIzTl3c+sOYJe6fFAXB3v2dyx2lqAbNO X-Received: by 2002:a17:902:a60f:b0:14a:ced9:113d with SMTP id u15-20020a170902a60f00b0014aced9113dmr1984463plq.31.1642737670066; Thu, 20 Jan 2022 20:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642737670; cv=none; d=google.com; s=arc-20160816; b=FyiaeS60A5dc16XwNbPvZJDj+NxzNu7N3l6PbWAH8v4johAAQSyBCG6wGoHp8rI2XY 1BVX54NDktr8834Us3k54n0nKYIyeeChEdaZ+/zjNy8g0dI0wwnKru78rSJnxRKNuQZi NUDcKuuRhqglDTDWeJNzwSO0p3wSdwCgVICjm23hacUivZZoF3jd1hScRNBfbQ3YLFlX 5lvibNxFJrZ94E+eWNMuzUfhYLc9UMBX+xmG/WCmSHSvPmuNNBgkPHOoNAfJF8BTrP7x iLoI2GeSVAzSsAJSWaiJdPm7Cp5kiSLDJssM8yPyioT5x0Rylm/FP5DouVUp7J1GQKjX DDzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=fmfn3We7VsrsY7wrkxlW3pR6M2dzD1H8QDdPZW64NZc=; b=is14dlx/mnryx6z8Xq06uj2/mAD7E+8sNbG2HR9Q5WsdIQligpw576G0l3l6g0uM8Y +LvkIG90AuHLLdrSTZnmFitbfc2eYHn/G/pmWVdVtLcXg76ShRcItBvxEGtoe9zMxkSv qq2LbCfKF9Na+wTFH7M3nKdcRRqbZ/HRw3Q99FVuF2rPZuTCpxVdbEKY6KDxvGd3udnO 0I3nwos71qwkUgdHph4jfubSmGOKl8rhX1AvgqTLVVWZMLz+stUIDt7EqoJePkUGF73T riATSc2RQGuFQU5lGnHR0HQ0LRC1wpb1YK24MUiV6DKOaDGyEum9E1+YIGVXFjAXZDBq 2RJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=f+21jvzp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si4818629plr.259.2022.01.20.20.00.57; Thu, 20 Jan 2022 20:01:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=f+21jvzp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348615AbiARTJh (ORCPT + 99 others); Tue, 18 Jan 2022 14:09:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348627AbiARTJd (ORCPT ); Tue, 18 Jan 2022 14:09:33 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9BA7C06161C for ; Tue, 18 Jan 2022 11:09:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id g7-20020a25bdc7000000b00611c616bc76so31221238ybk.5 for ; Tue, 18 Jan 2022 11:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fmfn3We7VsrsY7wrkxlW3pR6M2dzD1H8QDdPZW64NZc=; b=f+21jvzpsJ3yL5GfZIkzW7/2AvnrtvGj3rlxRCr81yyiW38TLpyLkPfPt4EbUh8xlS NatkFdyZfC2w2iye2j9apDGvJ+JjccLnw5Hva3N+zUWyjD94JOh2Lr2eGMPSIEIcvoqq 7hN4DYKwyFQVg2tlRK/gcoOlfBlPqIDEUSSeZO8FUpTE+C0QwKor9V8lvhmXb6Ukq3JZ +QTtvABrDPNjIe9mIQUtdsZJu5RVSUeS/wjNEu/uv5f8Un+ocQgQX2pv+06qwHTRev5l p99f4AqQtRMvJGGZOIV1N1yh6pK+Zb8JY4Kqk3Rp63yDc+WNDnV5WLR+X18e2pwMg7UJ Sgag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fmfn3We7VsrsY7wrkxlW3pR6M2dzD1H8QDdPZW64NZc=; b=I+uexOi69fasIc6h1PS5OOKuJYy19RHOgAJHnrGccMbw2G6I8+w4LKlL1V7Xb2NWTl nPw7I+3ht2exEEZrjwSs0WpGG1CCCvxcwswkPd3CHZAOSCUUcmK+rI8FZ2gSc7kWiVLS 82C9P/DNghwxIWRjfNm0CrKanocw7Bvh5bcZapHuuQlMvzPPZ7bUsenBh1ee41LxQxVU P4ecYXTHDKwStzzmHU10N53F2vi3Ef2FOibUfctYKQBEHivsddjGIVOPCHsUU1FATsLh cMNh5BMYY+LxgSfKHjc8E5R1hxFbJhua3z0IYuxgyXC1J7gnNF0WMA2jsRg/jNUiP1on tZig== X-Gm-Message-State: AOAM533IKvoNI5Ce/LIGQHvQKMBZItED3J0Css/LGXuJu8FEgkJpt5qF AmdUevX+vBWzcaUTtzSBytMfooQH6w3JtQ== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:7fc9:5977:ab73:1d36]) (user=dlatypov job=sendgmr) by 2002:a25:7e46:: with SMTP id z67mr6316308ybc.595.1642532972177; Tue, 18 Jan 2022 11:09:32 -0800 (PST) Date: Tue, 18 Jan 2022 11:09:19 -0800 In-Reply-To: <20220118190922.1557074-1-dlatypov@google.com> Message-Id: <20220118190922.1557074-2-dlatypov@google.com> Mime-Version: 1.0 References: <20220118190922.1557074-1-dlatypov@google.com> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [PATCH 2/5] kunit: tool: make --json handling a bit clearer From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/testing/kunit/kunit.py | 12 ++++++++---- tools/testing/kunit/kunit_json.py | 12 ++---------- tools/testing/kunit/kunit_tool_test.py | 3 +-- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 9274c6355809..bd2f7f088c72 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -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 diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 6862671709bc..61091878f51e 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -51,15 +51,7 @@ def _get_group_json(test: Test, def_config: str, return test_group 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["name"] = "KUnit Test Group" - json_obj = 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 + return json.dumps(test_group, indent=4) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 352369dffbd9..f7cbc248a405 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -469,8 +469,7 @@ class KUnitJsonTest(unittest.TestCase): json_obj = kunit_json.get_json_result( test=test_result, def_config='kunit_defconfig', - build_dir=None, - json_path='stdout') + build_dir=None) return json.loads(json_obj) def test_failed_test_json(self): -- 2.34.1.703.g22d0c6ccf7-goog