Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1243151pxb; Fri, 21 Jan 2022 13:11:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx95wFavZPWkIQut/i2mmlqXgCv9R8k0DDBoemoC7lGXkCn9+S3KXBcL10QqC2Qzbi7YBcD X-Received: by 2002:a17:90b:4c50:: with SMTP id np16mr2481687pjb.208.1642799477703; Fri, 21 Jan 2022 13:11:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799477; cv=none; d=google.com; s=arc-20160816; b=wZRTONzl/yzGuWVTr7++XGEvAJDFSvQjVOQPwp+Wsdt+lAKfXhaVca1FCCb2Pqa/bs jaIaL4+ONZkXAyz684/TxOQqKs+Ehr/KkKHxIe+4e60cy4g/26u6XCiHQfjgmwlXpkto OttGIkow/30EBNgP1ZvtHbNZFmts22VNLPB4y33eT33UBNpzoyvkSmEWyUj3DHe02eeX i0aH9qvy/NekWE74f/fFKHKBVwMvDCEj367kK+qHcSIgVIAt+X7s67djGAtgctrixjZX Y5dzxdmubm/0E240v1nU2JWkVtuKC8jIS5wQAixFHa7J64d5ms2afaPGYpWsT7/poJfy +gcg== 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=lRg1Hi7fshLwZOXJunSDXWp8Mi+a04TIBKVjfzILXqc=; b=pxFcosmg97br+zXj3suTBpgAFwtPcMiag7r7Gd+RNoEjaNCUtqXqBMUU/5q5TRAN+i s3Vllz66wCGUMbtAIeImvrJClhUCpXVEzPeOPMQYyr3XkBaDBWk7dIaKX89lc2o0Hzaz ip7sRqqRmk0+HuZopO+pDQDGOPXOZAMHKXpI0NQKnhkhZd+HH1jQ9O49RDhL/A58+KiP I9/W1uYLWWs5kgLwb8ZXNbKVd4tnzmzYaJJBx9JZ0O/76kkm/MKrycdLrceMU2NzY2T6 tUCN6+4bQ4dL+syHG0PYQ3i9nFzrtIstsmSLGd1wefsedaQCgjf9mhU0ILk2n+/ptYZj 6sAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=M6g6UzMt; 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 i3si9236990plr.610.2022.01.21.13.11.05; Fri, 21 Jan 2022 13:11:17 -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=M6g6UzMt; 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 S1359245AbiATI36 (ORCPT + 99 others); Thu, 20 Jan 2022 03:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359204AbiATI3r (ORCPT ); Thu, 20 Jan 2022 03:29:47 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6852BC061574 for ; Thu, 20 Jan 2022 00:29:46 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id n8so10310219wmk.3 for ; Thu, 20 Jan 2022 00:29:46 -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=lRg1Hi7fshLwZOXJunSDXWp8Mi+a04TIBKVjfzILXqc=; b=M6g6UzMtANcIE6R4pMS/wZvbQfFH0RkIxyOzQqhAI5EN/IntkdglHlmWBK62vPP7id vmQbKOeMQsm6tAmbtdp9N9+5FB1ESJ1eFJZrmZqngpPN2G7CzWA7v8wJm4WciJotfe9f 3C6m2J0VKRBONU6jHsG4xee3adDuJMIRxucBHV9tylitRlr2WiO25ICuIIvHEUSwid3a 3jHTR3fvwAWYe4QCOhzzgztvTzOutWRX7vsbG6dj3dyhFhxOoFhHX2lzLr5M6eyHMg9d 1OahmGnGpJVPOS+VoO1jlj52rq+crn4c1xr6XEgJP1ohOuQKkqVq+1cwLN4BwHh5FH1H F3dQ== 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=lRg1Hi7fshLwZOXJunSDXWp8Mi+a04TIBKVjfzILXqc=; b=g54PW8f5j+wYNwQsQPq0O2cmF+LShN+3p8kGzY7sf5y24QoTbxZ2Z9wuFlJ4r4qivS 2M8UGeoOJjn9rWYmFAYSji+BZ1r8ZtPjZww4YXyZxi5EnA5BIA9i45zmedbu4m0OqdHI v3hyat+RwwiOttHQJnxleeuH3VarECL2vbUZb5Y86paRrOCaMTbuOnxq6uDcYKcIHSRb b00SiLTPH4xYaeZMyw8gBXXqPgrjNWEbyaCxhGCEQl0F01loWKJXesVXCKGZQyaQnTnL mj+Dw3y7d/gXMxvG04vLkbI/uFi/hP+MUGIzv8agswg2xEnzdXWjoY4djDRmMJvSUooL pcmg== X-Gm-Message-State: AOAM530vskPTElFcrACNWrzq7HGp0jGGx+j5c4FIipJeh48V1CU46gXK B8wfXds97RMCxg6JGuWRzolgt3beMghVJ5E6F9g0Zw== X-Received: by 2002:a5d:6e8a:: with SMTP id k10mr33643975wrz.113.1642667384748; Thu, 20 Jan 2022 00:29:44 -0800 (PST) MIME-Version: 1.0 References: <20220118190922.1557074-1-dlatypov@google.com> In-Reply-To: <20220118190922.1557074-1-dlatypov@google.com> From: David Gow Date: Thu, 20 Jan 2022 16:29:33 +0800 Message-ID: Subject: Re: [PATCH 1/5] kunit: tool: drop mostly unused KunitResult.result field 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: > > This field is only used to pass along the parsed Test object from > parse_tests(). > Everywhere else the `result` field is ignored. > > Instead make parse_tests() explicitly return a KunitResult and Test so > we can retire the `result` field. > > Signed-off-by: Daniel Latypov > --- I personally prefer having the Test as part of the result -- it gives a slightly rust-esque sense of needing to check the actual result before using anything that's parsed. (Also, I'm still not used to the whole multiple return value thing, which is not as clear as an explicit named struct member, IMHO). That being said, we're not actually checking the result before using the Test, and certainly the use of Any and mashing a textual error message in the same field is rather unpleasant. My ideal solution would be to rename 'result' to something more sensible ('parsed_test', maybe?), and make it explicitly a Test rather than Any (and either add a separate field for the textual error message, or remove it as in this patch, having noticed that it's almost completely redundant to the enum). That being said, I can live with the current solution, but'd ideally like a comment or something to make the return value Tuple a bit more obvious. Thoughts? -- David > tools/testing/kunit/kunit.py | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py > index 7a706f96f68d..9274c6355809 100755 > --- a/tools/testing/kunit/kunit.py > +++ b/tools/testing/kunit/kunit.py > @@ -17,7 +17,7 @@ assert sys.version_info >= (3, 7), "Python version is too old" > > from dataclasses import dataclass > from enum import Enum, auto > -from typing import Any, Iterable, Sequence, List, Optional > +from typing import Iterable, List, Optional, Sequence, Tuple > > import kunit_json > import kunit_kernel > @@ -32,7 +32,6 @@ class KunitStatus(Enum): > @dataclass > class KunitResult: > status: KunitStatus > - result: Any > elapsed_time: float > > @dataclass > @@ -82,10 +81,8 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree, > config_end = time.time() > if not success: > return KunitResult(KunitStatus.CONFIG_FAILURE, > - 'could not configure kernel', > config_end - config_start) > return KunitResult(KunitStatus.SUCCESS, > - 'configured kernel successfully', > config_end - config_start) > > def build_tests(linux: kunit_kernel.LinuxSourceTree, > @@ -100,14 +97,11 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree, > build_end = time.time() > if not success: > return KunitResult(KunitStatus.BUILD_FAILURE, > - 'could not build kernel', > build_end - build_start) > if not success: > return KunitResult(KunitStatus.BUILD_FAILURE, > - 'could not build kernel', > build_end - build_start) > return KunitResult(KunitStatus.SUCCESS, > - 'built kernel successfully', > build_end - build_start) > > def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree, > @@ -173,14 +167,14 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - > filter_glob=filter_glob, > build_dir=request.build_dir) > > - result = parse_tests(request, run_result) > + _, test_result = parse_tests(request, run_result) > # run_kernel() doesn't block on the kernel exiting. > # That only happens after we get the last line of output from `run_result`. > # So exec_time here actually contains parsing + execution time, which is fine. > test_end = time.time() > exec_time += test_end - test_start > > - test_counts.add_subtest_counts(result.result.counts) > + test_counts.add_subtest_counts(test_result.counts) > > if len(filter_globs) == 1 and test_counts.crashed > 0: > bd = request.build_dir > @@ -189,7 +183,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - > bd, bd, kunit_kernel.get_outfile_path(bd), bd, sys.argv[0])) > > kunit_status = _map_to_overall_status(test_counts.get_status()) > - return KunitResult(status=kunit_status, result=result, elapsed_time=exec_time) > + return KunitResult(status=kunit_status, elapsed_time=exec_time) > > def _map_to_overall_status(test_status: kunit_parser.TestStatus) -> KunitStatus: > if test_status in (kunit_parser.TestStatus.SUCCESS, kunit_parser.TestStatus.SKIPPED): > @@ -197,7 +191,7 @@ def _map_to_overall_status(test_status: kunit_parser.TestStatus) -> KunitStatus: > else: > return KunitStatus.TEST_FAILURE > > -def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> KunitResult: > +def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> Tuple[KunitResult, kunit_parser.Test]: > parse_start = time.time() > > test_result = kunit_parser.Test() > @@ -231,11 +225,9 @@ def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> KunitR > print(json_obj) > > if test_result.status != kunit_parser.TestStatus.SUCCESS: > - return KunitResult(KunitStatus.TEST_FAILURE, test_result, > - parse_end - parse_start) > + return KunitResult(KunitStatus.TEST_FAILURE, parse_end - parse_start), test_result > > - return KunitResult(KunitStatus.SUCCESS, test_result, > - parse_end - parse_start) > + return KunitResult(KunitStatus.SUCCESS, parse_end - parse_start), test_result > > def run_tests(linux: kunit_kernel.LinuxSourceTree, > request: KunitRequest) -> KunitResult: > @@ -513,7 +505,7 @@ def main(argv, linux=None): > request = KunitParseRequest(raw_output=cli_args.raw_output, > build_dir='', > json=cli_args.json) > - result = parse_tests(request, kunit_output) > + result, _ = parse_tests(request, kunit_output) > if result.status != KunitStatus.SUCCESS: > sys.exit(1) > else: > > base-commit: f079ab01b5609fb0c9acc52c88168bf1eed82373 > -- > 2.34.1.703.g22d0c6ccf7-goog >