Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1243165pxb; Fri, 21 Jan 2022 13:11:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXfl88M6GRaxE+0Jdy8MA/nFPTHkW97dQrK/25CxUGqflqMl8teAQHKqajmhhdL1qMr7l+ X-Received: by 2002:a17:90a:e7ca:: with SMTP id kb10mr2489184pjb.200.1642799479687; Fri, 21 Jan 2022 13:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799479; cv=none; d=google.com; s=arc-20160816; b=W2rgi+2qyaCQlXK7DjCt37CE+4xM+NfylovumuvPeXnt2QWx27zaLhm1neKGTPH4va +KsuN1K38v9C0hi4kKQIhvo8bE7o0M7vYPip7DlbJv7XQfzQJFWHl53m58XISlHfnmIY 8QZitXpW6MphoOO+oW4qIjllaiZtjbK/3PHyibgafzypNPCUOewSNqZs/ZwxhB7ag7ua cUhBbR46FwHsPtfwIRQ1v+0hEnFFaeamHUtOvw0Aq3zt2QzTQcp7aH+pVW32W8QOIle+ EsXxkiqe6qpxmXRSg9IietLDJKwda8GcL9fFv+McqZ6CWqKFdjSbGwUBg75Dafl3B4AV p/Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=S8tEExfe2TjU1utTkKmpF2Z2tqEW48Z+Xz8Z/j98YFQ=; b=Fvi+3d+sCI38J84dYY7uQfqE0ySIVH6nTaO6ttnIBTpVctzopwkK47sMSbqdO41SGr 6ddQVQLIuVMt3K4yPCqlAD11ssbF33DmMiSSsnqwFpHw8Io0xBgYCkT0wnMntenha3Eu RoDCXwBuKsRCsvpxMHDWXtICUlUASC3ONtRmsVvGIINqVj30Kkf3nzBcyBWayw5ZoxBj OfJOByZ4xnYxj2+Ahnm1zLcc9Bsol4f8R63HfWYk7XE74naC/PeCQE1d74vL+1dTVN06 81zSIA77OPBsPylo6002lkyXP5yKB3HYClMaI+SrGAS90T8wK+MoJ5Up0XFNd5yvbEhh W6mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gcCC4nhF; 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 j14si7702558pgc.308.2022.01.21.13.11.07; Fri, 21 Jan 2022 13:11:19 -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=gcCC4nhF; 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 S1359273AbiATIaO (ORCPT + 99 others); Thu, 20 Jan 2022 03:30:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359234AbiATI3x (ORCPT ); Thu, 20 Jan 2022 03:29:53 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A23C061401 for ; Thu, 20 Jan 2022 00:29:53 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so6319607wmb.1 for ; Thu, 20 Jan 2022 00:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S8tEExfe2TjU1utTkKmpF2Z2tqEW48Z+Xz8Z/j98YFQ=; b=gcCC4nhFDZ090TxvYVsjpyos6CdVR+pJR/SbxNDCTGfEoMghQBZaa54tqlF4aoRdUz YmCszEWIzjA2YeDJr2g7ERBvO8awUPyw8D+EMYpA4nWPtega8EVbn5RBwcM6m44OwKVO qf50v4ByPHNaLOA9/ZXAKLwakupWkBmRFDhwwG+gJvIKXjo/qFuHRFb/i4TKltd2/MGA 1iYaR1lP00WQFp6Yud3KHsyvTbZeXecVZcjfczVrpnmnxC9Mcy6pkGiP/22quppgjuZh 2/dBzsLM0vsx9i3NmDYer5Dfhf33Ccj8hkHNH4ik+hluHBqd3paWQeuci3Fk4sM5nQIb phmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S8tEExfe2TjU1utTkKmpF2Z2tqEW48Z+Xz8Z/j98YFQ=; b=5S3UZhXnvy3+RjX5pknmVqDRkDFadwp+zxCj2oERh5a4UwA0IryVjgvLf1E3h1rmYM /c2UcymyZtL6Q2rkMBDZtGdkd+ztiUM/1a1hvsqzWhO63viaFba44TagNbWIK93lWwQu qelCYf8S0Mpe4W6qsfqod7C9bnPYoWT/138e5doRBK+afDSvelB6RP8AisbYFQ1rUwn9 q7PjHWSyqj/admZSEMdGM0x/6x7BFGbewdkDJ9y/YnUocEc+r9mSIISitoveYBTULJSC HAfED0sSMhXcoe6zjaFa8u6zsx00NWd8h8YN0mtwvoiS9dMb8DsknODoObqsQWhElU9d 06tg== X-Gm-Message-State: AOAM5300LqS0Bt/S2DOUsTaFzR/bCFZ/NG2cj52+3+WNzSC9nvyIqEAh g6WGuyoUP8WxALLDICEHPXA6buEshkgjotvQP3EASg== X-Received: by 2002:adf:a34c:: with SMTP id d12mr10459898wrb.80.1642667391675; Thu, 20 Jan 2022 00:29:51 -0800 (PST) MIME-Version: 1.0 References: <20220118190922.1557074-1-dlatypov@google.com> <20220118190922.1557074-2-dlatypov@google.com> In-Reply-To: <20220118190922.1557074-2-dlatypov@google.com> From: David Gow Date: Thu, 20 Jan 2022 16:29:40 +0800 Message-ID: Subject: Re: [PATCH 2/5] kunit: tool: make --json handling a bit clearer To: Daniel Latypov Cc: Brendan Higgins , Linux Kernel Mailing List , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 19, 2022 at 3:09 AM Daniel Latypov wrote: > > 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 > --- This looks good to me. Reviewed-by: David Gow Cheers, -- David > 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 >