From patchwork Tue Jan 18 19:09:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12716802 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 378FDC433EF for ; Tue, 18 Jan 2022 19:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348648AbiARTJf (ORCPT ); Tue, 18 Jan 2022 14:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348391AbiARTJb (ORCPT ); Tue, 18 Jan 2022 14:09:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4735C061574 for ; Tue, 18 Jan 2022 11:09:30 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id b61-20020a25a243000000b006126ea65191so7821926ybi.19 for ; Tue, 18 Jan 2022 11:09:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=Y+WNm4SRT+v0/a8Imp7LUvwXVPmkF4Imu0eAPnXyHIY=; b=ZZORa00GlA7CoqqZHJqUgUHTShPxXbCBwfNgu8zSTsbERei9c7ruuWMpi1znaJeEEB 6BWxI2LQ6ChJswk93WjpKcBno2GG9Svvk1JysMxHyX78mjVuLNP7P0L3AXxc2l4wBgh9 UgCLYWICx9RYPeiWwE9kDVQLjuSPMjczPBD8uOtnTcQkXa0XsLBD+AO7HJZj+ZjesdLc GHqTANmCBJEon4tL04fPHFFFRLpgvEogeuozSsudbWXLZrh9SBNwqAcqDPqnyGrmiymW VdRadFd0xZ5hETSF0aIEOHd/cyY2AtCH5klS30UGMXPrHt1edGdR1B5LKi1+gGtMQPhc lIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Y+WNm4SRT+v0/a8Imp7LUvwXVPmkF4Imu0eAPnXyHIY=; b=M41deC9/Bf9l1v9Mwv9Ov4idzNg1PmzfaaspqHl6cbh/N0a4wt9w2aZuBEwMe1v6Xm 1yndKZ0vqJel9UKo870eK+IlM92mtxQRIChc5tZE9uVAP+LF3ZYj4u2UVPX0DPYdOpvu AhFEhLAdMgp2FuyloCtwftvZ1rcXdtwlvNl7cxfijlzUeuBzQPAl4M9jGgYQR+E42iuH 7OgcSg8gvSzaj0MqYGXjPhAO9u46QEWDon5GnpWO8Kf7CsyiYRXYKxs1mPHjHP7BtDCe 1DL8uPt4RcOl52sj77sepw0ku/1nxgyoWwvcg1cqNZ/hoDPkZZxDm9k6GwEa+LkhlrUH JSHA== X-Gm-Message-State: AOAM530A7dtCGJDPQ+6w6l91MfF+TRlKtHzd8wcKvUJjt6ofVWrjSfj2 hgHFZ61Lkvl/aGY+87XXSMCyhELs1cvFYw== X-Google-Smtp-Source: ABdhPJwn7PPo8uhx2nlkSGOZ6nAex2sT6ImnNbd1j3uwG2LGxKZwPd1nfjg7PDhR0L85WKrldqXWAKFuMBbS0g== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:7fc9:5977:ab73:1d36]) (user=dlatypov job=sendgmr) by 2002:a5b:590:: with SMTP id l16mr32787350ybp.629.1642532970016; Tue, 18 Jan 2022 11:09:30 -0800 (PST) Date: Tue, 18 Jan 2022 11:09:18 -0800 Message-Id: <20220118190922.1557074-1-dlatypov@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [PATCH 1/5] kunit: tool: drop mostly unused KunitResult.result field 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) base-commit: f079ab01b5609fb0c9acc52c88168bf1eed82373 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: From patchwork Tue Jan 18 19:09:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12716803 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95098C433F5 for ; Tue, 18 Jan 2022 19:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348255AbiARTJg (ORCPT ); Tue, 18 Jan 2022 14:09:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348626AbiARTJd (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 D6A18C061574 for ; Tue, 18 Jan 2022 11:09:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 22-20020a250216000000b006120a553e38so17822268ybc.16 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=pBO0pnGcSj0Chau9Hvlg4Bvki7K78zZHKkJQzNjMWdKeoyJ48Z0eTWfczrU+tmvv0N D4Mp2iK4VHvPhV0WC7U7F44MC7I7tax6u3U/5VX8wgwbtZkxtquUmNdw9dHFda8eVWq4 Cy5JXkT4TwYfbEtZp5JuMNSc16yu4ETnvDgJMw1laqvO+5edPwK4hxiEhGv5++l55a+g PUFm49ZVt57sB39f08x2ZRhEbmMr+FcWS19uR9j1z3BwlfgeNgGKPXFsQAaYLLygmNvX n5HSX3JzFc7N0IW8i5zsN42g2XvJig91pbFmxYl4EuUfaU+1svmn57s36CFVJidlhrxb 4TeQ== X-Gm-Message-State: AOAM532VYaQWliT00wp/HdpTxtcoSTmzGVbee2hUq29HxEbC3U4bRJXM sdsUpMZf/5bgaEzZBvVzENIcnzfkplnz4w== X-Google-Smtp-Source: ABdhPJwSFxL26e6iffOomUtTAD4T5f3FLnPtQXUL9frbTS3UYPwdOS6hgRrdXYmGhP7HV4uif82OH1khaQgKrQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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 Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- 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): From patchwork Tue Jan 18 19:09:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12716804 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 005EBC4332F for ; Tue, 18 Jan 2022 19:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348627AbiARTJj (ORCPT ); Tue, 18 Jan 2022 14:09:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245012AbiARTJf (ORCPT ); Tue, 18 Jan 2022 14:09:35 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69E18C061574 for ; Tue, 18 Jan 2022 11:09:35 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 22-20020a250216000000b006120a553e38so17822600ybc.16 for ; Tue, 18 Jan 2022 11:09:35 -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=QxtNo/KbZx5IgHz5z04uslp6z4FHBvH/n/H++ERzScA=; b=TIcbT3J28mGsN75/ffXhPadp0ACFt3wfUEtZOT0VtsvJW7T3V0pbOaiWNGqB5Q75wN GjRWvvIXG1VAyESLdtaYvE/pKWUScvfmC3ZkyFPWZ3KRxI0ZewupHRaBmmLqwprRPESi fSlFW1MF75Dqc2L9i7ijMwM0a5CxwdbEJj+H30HlBr2NeWN0p8mklEouLVvqctEpVTXr oTX8Xp7a8fH5Y0hEcWkiXzHLhQb3Qw2gFhCwOyyRsqETapkJeMLnGuLWdfFsJkyhBOYM GGvqlo+laECpJnd0Ftm2wYRhmRtnawyP5ALf3fqE3bwkPMMzLJaTNQn+DsWTRsXjs4eP rbRA== 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=QxtNo/KbZx5IgHz5z04uslp6z4FHBvH/n/H++ERzScA=; b=jUNdslyxXy0nm9t/BZFNig+MGEVRAuBDa1N61FQPaguZbhSOYgOpCsTEaVvtUV53wo WP2B4AqPu/YsocDfsLWHQVxPw/Fkm5ftVGEaDsnEjkDMVlFgA+iE9huhYqU1ry7k7ipP 3f9L5P8xoWZLro4exn5l+7RxQO4CQDLJ6nCCE6O+rGgocOTDWntvpGIDI6lgP1XFq8Kt ydz2ouCOSO5Uuyy3GWhwyAtgxn2V5dv+mMBg568I0ttEAzwWES4LZE6JPm60L/CA0+MO 8EspZdUYY6FB5+EXFjKH6/8I9/zpv6zmRnkKpQ8Jg8kWf8+OYi9CzXbA4WgWDFic0WCw dBfg== X-Gm-Message-State: AOAM532JokLSSk+Ao276wB97r+KL3sv/aXLeQJ1NeHV5GqUw2+WZLpr3 v7tDgE6YtgqhgIn/77yr2T9HoxzCYtetNQ== X-Google-Smtp-Source: ABdhPJxleYIHreqkjvrzoaXG2AuFv3qsi4KjCyFK4enyPmfwWEIVgu0nzQpIOWBZyg/CwWvmplE/WwIWE9ef1w== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:7fc9:5977:ab73:1d36]) (user=dlatypov job=sendgmr) by 2002:a05:6902:1365:: with SMTP id bt5mr26930889ybb.145.1642532974676; Tue, 18 Jan 2022 11:09:34 -0800 (PST) Date: Tue, 18 Jan 2022 11:09:20 -0800 In-Reply-To: <20220118190922.1557074-1-dlatypov@google.com> Message-Id: <20220118190922.1557074-3-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 3/5] kunit: tool: drop unused KernelDirectoryPath var 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Commit be886ba90cce ("kunit: run kunit_tool from any directory") introduced this variable, but it was unused even in that commit. Since it's still unused now and callers can instead use get_kernel_root_path(), delete this var. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index bd2f7f088c72..4cb91d191f1d 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -63,8 +63,6 @@ class KunitRequest(KunitExecRequest, KunitBuildRequest): pass -KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0] - def get_kernel_root_path() -> str: path = sys.argv[0] if not __file__ else __file__ parts = os.path.realpath(path).split('tools/testing/kunit') From patchwork Tue Jan 18 19:09:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12716805 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D9EEC433FE for ; Tue, 18 Jan 2022 19:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348638AbiARTJk (ORCPT ); Tue, 18 Jan 2022 14:09:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348623AbiARTJi (ORCPT ); Tue, 18 Jan 2022 14:09:38 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BE4FC06173E for ; Tue, 18 Jan 2022 11:09:38 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 191-20020a2504c8000000b006135c8d0c88so585344ybe.13 for ; Tue, 18 Jan 2022 11:09:38 -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=F24wPCt234v4QNUD2Mk9oIJLO93NyHqVoUDE9Wq7Wr4=; b=XTL6t+Oh6LYMIGU4nlCiP7CMITJeohBPQAn/P6hY1sKrkqjrLGeY6gTx2C7MujoZ84 H9QLQC+gLKdeeD/TnAQnnFxqz6xGUun0O4RgkGnvT2wlflyf755CUWHGi0iS37koMsrg xXCkdaG3nYt6ueYDSckmfx/59CemPoZHAcwxK+VDEcyyoS37GUIY1qnGC8+KYpHwiAVC qX8wQWCiCGC+DF/q9DtmjtoYkjoV8bf5M4Opa7RGJxy+cHxUYX+JPYP3sUqEeQADK2lo UvQt1hVr9CkUJEsHgCLC9O0XFn8GNRI6FrvsRCmCAX6gXmdAr1QTd1s1NXvU3JCX3eU5 QZlQ== 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=F24wPCt234v4QNUD2Mk9oIJLO93NyHqVoUDE9Wq7Wr4=; b=2Nqchu2g4XoJPCsblJcj4AYXFCuqWA9mXZBuAM+PwVs3ulMHWTcp9S3jf+7ykvIHLT EA62BiWTo9cVi29PH1WS6wOusHX5jjO+4mIY7Kp7to9WphShLOj6Fk8vIrUFEZjxoB3d MlkPR8l1XMBZp5k+RQwPmTTjAqSttQrKUSnA33e3kiTBZtMvwVlBlSiSuZgc3QRTHKtj 1tKWn8Th7GROv6D/39SyNXazIeb5Q8KcbNeUFQ77zt+YSKEAHB1ifXafCYHy3haMFI8A 840Cbq0d5d8LjQqA1V0G76hkVrbr3Bk7ecTdKXzx6GpXGdQwo1gp8v4QEUwbOfZPHQJS UsGg== X-Gm-Message-State: AOAM531kfaMu2Er6zxtdYGN3AMf4NKF+/wm9mlSxW/XuJhd9q1zQFFP5 HYEh5unSeTKO/gZzMcbFmLSaBdOSCz95rw== X-Google-Smtp-Source: ABdhPJwwWracSLEr3Ecw1tn00jf8OsaRYT0dJuDGecTg5kuRfAblZGyNp3ohYxtbXZAfZzSaWs6J2ZlGs+6rFQ== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:7fc9:5977:ab73:1d36]) (user=dlatypov job=sendgmr) by 2002:a5b:c01:: with SMTP id f1mr31692742ybq.593.1642532977230; Tue, 18 Jan 2022 11:09:37 -0800 (PST) Date: Tue, 18 Jan 2022 11:09:21 -0800 In-Reply-To: <20220118190922.1557074-1-dlatypov@google.com> Message-Id: <20220118190922.1557074-4-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 4/5] kunit: tool: drop last uses of collections.namedtuple 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Since we formally require python3.7+ since commit df4b0807ca1a ("kunit: tool: Assert the version requirement"), we can just use @dataclasses.dataclass instead. In kunit_config.py, we used namedtuple to create a hashable type that had `name` and `value` fields and had to subclass it to define a custom `__str__()`. @datalcass lets us just define one type instead. In qemu_config.py, we use namedtuple to allow modules to define various parameters. Using @dataclass, we can add type-annotations for all these fields, making our code more typesafe and making it easier for users to figure out how to define new configs. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit_config.py | 9 +++++---- tools/testing/kunit/qemu_config.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/testing/kunit/kunit_config.py b/tools/testing/kunit/kunit_config.py index 677354546156..ca33e4b7bcc5 100644 --- a/tools/testing/kunit/kunit_config.py +++ b/tools/testing/kunit/kunit_config.py @@ -6,16 +6,17 @@ # Author: Felix Guo # Author: Brendan Higgins -import collections +from dataclasses import dataclass import re from typing import List, Set CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$' CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$' -KconfigEntryBase = collections.namedtuple('KconfigEntryBase', ['name', 'value']) - -class KconfigEntry(KconfigEntryBase): +@dataclass(frozen=True) +class KconfigEntry: + name: str + value: str def __str__(self) -> str: if self.value == 'n': diff --git a/tools/testing/kunit/qemu_config.py b/tools/testing/kunit/qemu_config.py index 1672f6184e95..0b6a80398ccc 100644 --- a/tools/testing/kunit/qemu_config.py +++ b/tools/testing/kunit/qemu_config.py @@ -5,12 +5,15 @@ # Copyright (C) 2021, Google LLC. # Author: Brendan Higgins -from collections import namedtuple +from dataclasses import dataclass +from typing import List -QemuArchParams = namedtuple('QemuArchParams', ['linux_arch', - 'kconfig', - 'qemu_arch', - 'kernel_path', - 'kernel_command_line', - 'extra_qemu_params']) +@dataclass(frozen=True) +class QemuArchParams: + linux_arch: str + kconfig: str + qemu_arch: str + kernel_path: str + kernel_command_line: str + extra_qemu_params: List[str] From patchwork Tue Jan 18 19:09:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12716806 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D1F3C433F5 for ; Tue, 18 Jan 2022 19:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348679AbiARTJn (ORCPT ); Tue, 18 Jan 2022 14:09:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348646AbiARTJl (ORCPT ); Tue, 18 Jan 2022 14:09:41 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 607AEC061574 for ; Tue, 18 Jan 2022 11:09:40 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id 81-20020a370454000000b00478f3a61beeso39384qke.18 for ; Tue, 18 Jan 2022 11:09:40 -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=lD6lqWX8EnRHxX0zLj6k1wGPtoB3tiWy/CWZlAPTJDU=; b=an/AD+StigzlDSBcUsrKyiMtniDABtx3FjPV3LX+S/5cfZuxEjADmiINc5hsUJqS1j vFTjb4Ul52P09yJ6XxYKzttKNQ/Ib5uuHg4qFDgBDYNo86P9mOJoDPOczuLV4qWlS/cN 8AwBpDQpXYBuR9DHbP0IUyr71FTya6jMiTjSlMTpVq0YP8uyPpVphvD53fCM4EJNPWvr applchaagucZGm05aYWFSks7whPkdUYXEkxL9gvpAPI1Iz4Jc52x6C3LMNniWqH/nOih PE9dXI5P/Lgx5sqNYkPQbUOobP11U+lBaR4ev71T4cEN0g2Cj5VyyBe21F2b/nbEO4CM Ombw== 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=lD6lqWX8EnRHxX0zLj6k1wGPtoB3tiWy/CWZlAPTJDU=; b=b96aYQOyytB9OQrACk0bl17Zxw45iCtaEeOW3yAhik0ItKScYujdIOV7wLV9Qhx75I vIbT58PkiBg0fa//TOblTTiOToyxs/FHnR6w/kaR/n/PRshS+7arSfMFxb6xHpJfQdar +ZQTQSURLBfRvmTOrT3NVED7JCsVOUqxvw0KwtTnn8l1AIjX9Ydyp0ux4z/z+z82Vw5V 83Y2IYP2CeuQbhjq+9MetRvaHBtpMCnvJURhU7U07/vl/0DTIkVIc2X186NIwHsTG/Bi NCZzZsgfx8cS+PzcOV0QLymJhKM6vvP5qq85/9bzYdtYX/QlKvcJt/U/sOyb8a/Q+s5S 5G4A== X-Gm-Message-State: AOAM530eIh2/YKRKFOcMG1cowAAt0GD/8ajXH6r0kOhv6coxoOm+79NS enh43byym7qfr1fWIlaWK/NEHSPGV6SECA== X-Google-Smtp-Source: ABdhPJyIvRFzYjNHUfdXdKwTrT/HLKTC2twyg8uViC+rjfEei3/hOjHQj+ZJiX9u9n5Ps/sLbCQj8EpQA+WuJQ== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:7fc9:5977:ab73:1d36]) (user=dlatypov job=sendgmr) by 2002:ac8:5e4e:: with SMTP id i14mr21505830qtx.221.1642532979560; Tue, 18 Jan 2022 11:09:39 -0800 (PST) Date: Tue, 18 Jan 2022 11:09:22 -0800 In-Reply-To: <20220118190922.1557074-1-dlatypov@google.com> Message-Id: <20220118190922.1557074-5-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 5/5] kunit: tool: simplify code since build_dir can't be None 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org --build_dir is set to a default of '.kunit' since commit ddbd60c779b4 ("kunit: use --build_dir=.kunit as default"), but even before then it was explicitly set to ''. So outside of one unit test, there was no way for the build_dir to be ever be None, and we can simplify code by fixing the unit test and enforcing that via updated type annotations. E.g. this lets us drop `get_file_path()` since it's now exactly equivalent to os.path.join(). Note: there's some `if build_dir` checks that also fail if build_dir is explicitly set to '' that just guard against passing "O=" to make. But running `make O=` works just fine, so drop these checks. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit_json.py | 8 ++-- tools/testing/kunit/kunit_kernel.py | 51 ++++++++++---------------- tools/testing/kunit/kunit_tool_test.py | 2 +- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 61091878f51e..24d103049bca 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -12,12 +12,11 @@ import os import kunit_parser from kunit_parser import Test, TestStatus -from typing import Any, Dict, Optional +from typing import Any, Dict JsonObj = Dict[str, Any] -def _get_group_json(test: Test, def_config: str, - build_dir: Optional[str]) -> JsonObj: +def _get_group_json(test: Test, def_config: str, build_dir: str) -> JsonObj: sub_groups = [] # List[JsonObj] test_cases = [] # List[JsonObj] @@ -50,8 +49,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]) -> str: +def get_json_result(test: Test, def_config: str, build_dir: str) -> str: test_group = _get_group_json(test, def_config, build_dir) test_group["name"] = "KUnit Test Group" return json.dumps(test_group, indent=4) diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index 44bbe54f25f1..fe159e7ff697 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -28,11 +28,6 @@ OUTFILE_PATH = 'test.log' ABS_TOOL_PATH = os.path.abspath(os.path.dirname(__file__)) QEMU_CONFIGS_DIR = os.path.join(ABS_TOOL_PATH, 'qemu_configs') -def get_file_path(build_dir, default): - if build_dir: - default = os.path.join(build_dir, default) - return default - class ConfigError(Exception): """Represents an error trying to configure the Linux kernel.""" @@ -59,17 +54,15 @@ class LinuxSourceTreeOperations(object): def make_arch_qemuconfig(self, kconfig: kunit_config.Kconfig) -> None: pass - def make_allyesconfig(self, build_dir, make_options) -> None: + def make_allyesconfig(self, build_dir: str, make_options) -> None: raise ConfigError('Only the "um" arch is supported for alltests') - def make_olddefconfig(self, build_dir, make_options) -> None: - command = ['make', 'ARCH=' + self._linux_arch, 'olddefconfig'] + def make_olddefconfig(self, build_dir: str, make_options) -> None: + command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig'] if self._cross_compile: command += ['CROSS_COMPILE=' + self._cross_compile] if make_options: command.extend(make_options) - if build_dir: - command += ['O=' + build_dir] print('Populating config with:\n$', ' '.join(command)) try: subprocess.check_output(command, stderr=subprocess.STDOUT) @@ -78,14 +71,12 @@ class LinuxSourceTreeOperations(object): except subprocess.CalledProcessError as e: raise ConfigError(e.output.decode()) - def make(self, jobs, build_dir, make_options) -> None: - command = ['make', 'ARCH=' + self._linux_arch, '--jobs=' + str(jobs)] + def make(self, jobs, build_dir: str, make_options) -> None: + command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)] if make_options: command.extend(make_options) if self._cross_compile: command += ['CROSS_COMPILE=' + self._cross_compile] - if build_dir: - command += ['O=' + build_dir] print('Building with:\n$', ' '.join(command)) try: proc = subprocess.Popen(command, @@ -143,14 +134,12 @@ class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations): def __init__(self, cross_compile=None): super().__init__(linux_arch='um', cross_compile=cross_compile) - def make_allyesconfig(self, build_dir, make_options) -> None: + def make_allyesconfig(self, build_dir: str, make_options) -> None: kunit_parser.print_with_timestamp( 'Enabling all CONFIGs for UML...') - command = ['make', 'ARCH=um', 'allyesconfig'] + command = ['make', 'ARCH=um', 'O=' + build_dir, 'allyesconfig'] if make_options: command.extend(make_options) - if build_dir: - command += ['O=' + build_dir] process = subprocess.Popen( command, stdout=subprocess.DEVNULL, @@ -167,24 +156,24 @@ class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations): def start(self, params: List[str], build_dir: str) -> subprocess.Popen: """Runs the Linux UML binary. Must be named 'linux'.""" - linux_bin = get_file_path(build_dir, 'linux') + linux_bin = os.path.join(build_dir, 'linux') return subprocess.Popen([linux_bin] + params, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, errors='backslashreplace') -def get_kconfig_path(build_dir) -> str: - return get_file_path(build_dir, KCONFIG_PATH) +def get_kconfig_path(build_dir: str) -> str: + return os.path.join(build_dir, KCONFIG_PATH) -def get_kunitconfig_path(build_dir) -> str: - return get_file_path(build_dir, KUNITCONFIG_PATH) +def get_kunitconfig_path(build_dir: str) -> str: + return os.path.join(build_dir, KUNITCONFIG_PATH) -def get_old_kunitconfig_path(build_dir) -> str: - return get_file_path(build_dir, OLD_KUNITCONFIG_PATH) +def get_old_kunitconfig_path(build_dir: str) -> str: + return os.path.join(build_dir, OLD_KUNITCONFIG_PATH) -def get_outfile_path(build_dir) -> str: - return get_file_path(build_dir, OUTFILE_PATH) +def get_outfile_path(build_dir: str) -> str: + return os.path.join(build_dir, OUTFILE_PATH) def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceTreeOperations: config_path = os.path.join(QEMU_CONFIGS_DIR, arch + '.py') @@ -268,7 +257,7 @@ class LinuxSourceTree(object): return False return True - def validate_config(self, build_dir) -> bool: + def validate_config(self, build_dir: str) -> bool: kconfig_path = get_kconfig_path(build_dir) validated_kconfig = kunit_config.parse_file(kconfig_path) if self._kconfig.is_subset_of(validated_kconfig): @@ -283,7 +272,7 @@ class LinuxSourceTree(object): logging.error(message) return False - def build_config(self, build_dir, make_options) -> bool: + def build_config(self, build_dir: str, make_options) -> bool: kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir): os.mkdir(build_dir) @@ -311,7 +300,7 @@ class LinuxSourceTree(object): old_kconfig = kunit_config.parse_file(old_path) return old_kconfig.entries() != self._kconfig.entries() - def build_reconfig(self, build_dir, make_options) -> bool: + def build_reconfig(self, build_dir: str, make_options) -> bool: """Creates a new .config if it is not a subset of the .kunitconfig.""" kconfig_path = get_kconfig_path(build_dir) if not os.path.exists(kconfig_path): @@ -326,7 +315,7 @@ class LinuxSourceTree(object): os.remove(kconfig_path) return self.build_config(build_dir, make_options) - def build_kernel(self, alltests, jobs, build_dir, make_options) -> bool: + def build_kernel(self, alltests, jobs, build_dir: str, make_options) -> bool: try: if alltests: self._ops.make_allyesconfig(build_dir, make_options) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index f7cbc248a405..a3c036a620b2 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -469,7 +469,7 @@ class KUnitJsonTest(unittest.TestCase): json_obj = kunit_json.get_json_result( test=test_result, def_config='kunit_defconfig', - build_dir=None) + build_dir='.kunit') return json.loads(json_obj) def test_failed_test_json(self):