From patchwork Thu Feb 24 19:20:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12759158 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 1C0FAC433F5 for ; Thu, 24 Feb 2022 19:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232731AbiBXTVY (ORCPT ); Thu, 24 Feb 2022 14:21:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233686AbiBXTVX (ORCPT ); Thu, 24 Feb 2022 14:21:23 -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 2B7B61F03AD for ; Thu, 24 Feb 2022 11:20:53 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id x1-20020a25a001000000b0061c64ee0196so756967ybh.9 for ; Thu, 24 Feb 2022 11:20:53 -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=vE/X1GbuMiKSRX0usgoudNG0PjnPYCjAGGaX0qNgdQ8=; b=FyIQHr8etZ6mQPzxRUPRdn7PmSB8K6WWQcG0zuVMBr9gpJ/alDA89zNcWsJ4HuE6CC SgTlSwM7IDbbLSAKUZP59OTJEtIB8IZFMGa5PVl+3S1BqdxMEvz1zd3WqUp6DmoXfLVw MDyNu2RMhZiAhfdoTZWxAG0mtU4YSLTE6urpO5x6G1xxSryZmnQKbD4Rpw6pvIxCEbt2 yn5c6PvJOKsMbtUqTwnYRgRJ2HbSxZJlIm56fARhp+LJfl65uZME7oNNb/Ef5JzWKOGz vE5iyL3XqhvmivHQYhP2reoPfdSessoG5yU+JV8uarMTW9k9CcJPvGdWgx5CPISAh5si c1uw== 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=vE/X1GbuMiKSRX0usgoudNG0PjnPYCjAGGaX0qNgdQ8=; b=mIp3Ui9xKiV0u+REfM1kM+usGuRaR+S4B2sDvjM4xxN4wPJKiPLXUBmawRCCNUN1kF EaIwiaMrWLPQ4gYxMxBXOUWq9HgIwgMhYJwon8nNzNUQhTPMjZjujBcl9Geil2kjnfl9 Nih0z8rzlZZV6BTy45E+a9Cpynok+yt+l/bgzCaA2CEPGz3STTgVDG0vXtg8rrZwoKWF U2e0SxHyGjC/CAhGChSWPUOYBKh6f/7JAOcSi6ye4lNRRe3Nw+CihM/htCofOIAZoq0E 9/jzHeEAP3GEkT8Ne8/tAqpYAPjuibSaAP1jKNQWsL64AvxVPwc5DB6fCWsW8qwjBhkf qNhQ== X-Gm-Message-State: AOAM531kX+UwlfL3xJeji9xAwEFPRjtxTM5dHy1di9GHOkaMgjRGC5I3 Zem9yjuxjzQnAqANV7VqbFWKPH4OAudBeA== X-Google-Smtp-Source: ABdhPJx3bs6AIpTEF94dmhDZdm3O1wxL83posi8M5rPdjILtbKKCumct8m3TAQP07sYhvg4456vXi9CepZb2uA== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:96e5:fbf5:15ed:8b6f]) (user=dlatypov job=sendgmr) by 2002:a25:aa4a:0:b0:624:6220:e4f8 with SMTP id s68-20020a25aa4a000000b006246220e4f8mr3869090ybi.531.1645730452359; Thu, 24 Feb 2022 11:20:52 -0800 (PST) Date: Thu, 24 Feb 2022 11:20:34 -0800 Message-Id: <20220224192036.2388302-1-dlatypov@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 1/3] kunit: tool: readability tweaks in KernelCI json generation logic 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 Use a more idiomatic check that a list is non-empty (`if mylist:`) and simplify the function body by dedenting and using a dict to map between the kunit TestStatus enum => KernelCI json status string. The dict hopefully makes it less likely to have bugs like commit 9a6bb30a8830 ("kunit: tool: fix --json output for skipped tests"). Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit_json.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 24d103049bca..14a480d3308a 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -16,24 +16,24 @@ from typing import Any, Dict JsonObj = Dict[str, Any] +_status_map: Dict[TestStatus, str] = { + TestStatus.SUCCESS: "PASS", + TestStatus.SKIPPED: "SKIP", + TestStatus.TEST_CRASHED: "ERROR", +} + def _get_group_json(test: Test, def_config: str, build_dir: str) -> JsonObj: sub_groups = [] # List[JsonObj] test_cases = [] # List[JsonObj] for subtest in test.subtests: - if len(subtest.subtests): + if subtest.subtests: sub_group = _get_group_json(subtest, def_config, build_dir) sub_groups.append(sub_group) - else: - test_case = {"name": subtest.name, "status": "FAIL"} - if subtest.status == TestStatus.SUCCESS: - test_case["status"] = "PASS" - elif subtest.status == TestStatus.SKIPPED: - test_case["status"] = "SKIP" - elif subtest.status == TestStatus.TEST_CRASHED: - test_case["status"] = "ERROR" - test_cases.append(test_case) + continue + status = _status_map.get(subtest.status, "FAIL") + test_cases.append({"name": subtest.name, "status": status}) test_group = { "name": test.name, From patchwork Thu Feb 24 19:20:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12759159 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 84160C433F5 for ; Thu, 24 Feb 2022 19:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbiBXTVg (ORCPT ); Thu, 24 Feb 2022 14:21:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233704AbiBXTV3 (ORCPT ); Thu, 24 Feb 2022 14:21:29 -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 5DB441E522C for ; Thu, 24 Feb 2022 11:20:59 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id r14-20020a5b018e000000b00624f6f97bf4so749428ybl.12 for ; Thu, 24 Feb 2022 11:20:59 -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=5/X2V+LUb5lUAOXbMwMCBLiJRGGwZlFxW0+/UOkBjzQ=; b=I7rTEbob1KpJ25AxqDD6poFdpTi6PO5gSy3hmZbF6mAkZG2JGgNI8NaJK4M4f/qLdo heJBewx4DQLBI06OpVCsai0xlqX4FDjJy4Doy5Wp+1iws5KDD4UmaCWrmXXsXjrr14mD 5oJ9akJgQf583BcLputTjpd0vzhxJ086QOHZCk9DkcLx/a3RRMX6MMo1LtPwQKKjHB9v Eeh8DM/Dh4oR9SyUw2Te7AyVLCCMQ/ds4a5Dtb+nbzL0oTRDrP5nkdoM6cwsClvi3rSE bFLOagVBxroRoa/N6pO0rTLENMkaoc6eE4uOkpH5EADcjsAfcGZtqLxsOyOvHlHFg71S Unjw== 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=5/X2V+LUb5lUAOXbMwMCBLiJRGGwZlFxW0+/UOkBjzQ=; b=vv1fLP+chAKq3IF5MmHl6pvt5Z7eobL4Orj0CvM22e9iJJ3XOrN8X00PTxKRQiIurb RswLVlOCS8eGkhIjozu/Uih6fCmJfaiKo7q5QvRcqhPaoy+Qkk8DWRyby1YT+WmQdWMf gEfLVXdFy0qDHvajD0xwYnPj2NTzxLHWyWYkXY1AO8ocv2iasynqGIeI/q+iYY2EGEKz 2kdu18hEvEVT+0E83Oy1HW4vu7f40+WzpiAJzFhfF1ExL4kJNuhDKcVgpm6kCST8bZs3 l8mNwnF6f4S7fAKaQbDcFySmm8UHuiKkPrKVYTGp+aecZi/IA3BYia2AtXsm05lEcADi FtDA== X-Gm-Message-State: AOAM530lOaHZ0HD9p3Kt2VOJ9Do7S+ERcxZORmeavOoHo4jwaWevp85a 8aV4zwoLspRGWdvOVZtHTAnG81u4Lp8reg== X-Google-Smtp-Source: ABdhPJx4s6dYkJwPQXgMCaM3MkzCoRxl//hffVWfyTTKPUGs5Zfx2oIKatlg/xsI5gXq0xHURGV1kT6EU86Y6g== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:96e5:fbf5:15ed:8b6f]) (user=dlatypov job=sendgmr) by 2002:a25:8748:0:b0:624:783e:d501 with SMTP id e8-20020a258748000000b00624783ed501mr3853640ybn.127.1645730458610; Thu, 24 Feb 2022 11:20:58 -0800 (PST) Date: Thu, 24 Feb 2022 11:20:35 -0800 In-Reply-To: <20220224192036.2388302-1-dlatypov@google.com> Message-Id: <20220224192036.2388302-2-dlatypov@google.com> Mime-Version: 1.0 References: <20220224192036.2388302-1-dlatypov@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 2/3] kunit: tool: refactor how we plumb metadata into JSON 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 When using --json, kunit.py run/exec/parse will produce results in KernelCI json format. As part of that, we include the build_dir that was used, and we (incorrectly) hardcode in the arch, etc. We'll want a way to plumb more values (as well as the correct `arch`), so this patch groups those fields into kunit_json.Metadata type. This patch should have no user visible changes. And since we only used build_dir in KunitParseRequest for json, we can now move it out of that struct and add it into KunitExecRequest, which needs it and used to get it via inheritance. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 16 +++++++------- tools/testing/kunit/kunit_json.py | 29 ++++++++++++++++++-------- tools/testing/kunit/kunit_tool_test.py | 9 ++++---- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 4cb91d191f1d..7dd6ed42141f 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -47,11 +47,11 @@ class KunitBuildRequest(KunitConfigRequest): @dataclass class KunitParseRequest: raw_output: Optional[str] - build_dir: str json: Optional[str] @dataclass class KunitExecRequest(KunitParseRequest): + build_dir: str timeout: int alltests: bool filter_glob: str @@ -153,6 +153,8 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - test_glob = request.filter_glob.split('.', maxsplit=2)[1] filter_globs = [g + '.'+ test_glob for g in filter_globs] + metadata = kunit_json.Metadata(build_dir=request.build_dir) + test_counts = kunit_parser.TestCounts() exec_time = 0.0 for i, filter_glob in enumerate(filter_globs): @@ -165,7 +167,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - filter_glob=filter_glob, build_dir=request.build_dir) - _, test_result = parse_tests(request, run_result) + _, test_result = parse_tests(request, metadata, 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. @@ -189,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]) -> Tuple[KunitResult, kunit_parser.Test]: +def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input_data: Iterable[str]) -> Tuple[KunitResult, kunit_parser.Test]: parse_start = time.time() test_result = kunit_parser.Test() @@ -216,8 +218,7 @@ def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> Tuple[ if request.json: json_str = kunit_json.get_json_result( test=test_result, - def_config='kunit_defconfig', - build_dir=request.build_dir) + metadata=metadata) if request.json == 'stdout': print(json_str) else: @@ -504,10 +505,11 @@ def main(argv, linux=None): else: with open(cli_args.file, 'r', errors='backslashreplace') as f: kunit_output = f.read().splitlines() + # We know nothing about how the result was created! + metadata = kunit_json.Metadata() request = KunitParseRequest(raw_output=cli_args.raw_output, - build_dir='', json=cli_args.json) - result, _ = parse_tests(request, kunit_output) + result, _ = parse_tests(request, metadata, kunit_output) if result.status != KunitStatus.SUCCESS: sys.exit(1) else: diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 14a480d3308a..0a7e29a315ed 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -6,6 +6,7 @@ # Copyright (C) 2020, Google LLC. # Author: Heidi Fahim +from dataclasses import dataclass import json import os @@ -14,6 +15,13 @@ import kunit_parser from kunit_parser import Test, TestStatus from typing import Any, Dict +@dataclass +class Metadata: + """Stores metadata about this run to include in get_json_result().""" + arch: str = 'UM' + def_config: str = 'kunit_defconfig' + build_dir: str = '' + JsonObj = Dict[str, Any] _status_map: Dict[TestStatus, str] = { @@ -22,14 +30,13 @@ _status_map: Dict[TestStatus, str] = { TestStatus.TEST_CRASHED: "ERROR", } -def _get_group_json(test: Test, def_config: str, build_dir: str) -> JsonObj: +def _get_group_json(test: Test, common_fields: JsonObj) -> JsonObj: sub_groups = [] # List[JsonObj] test_cases = [] # List[JsonObj] for subtest in test.subtests: if subtest.subtests: - sub_group = _get_group_json(subtest, def_config, - build_dir) + sub_group = _get_group_json(subtest, common_fields) sub_groups.append(sub_group) continue status = _status_map.get(subtest.status, "FAIL") @@ -37,19 +44,23 @@ def _get_group_json(test: Test, def_config: str, build_dir: str) -> JsonObj: test_group = { "name": test.name, - "arch": "UM", - "defconfig": def_config, - "build_environment": build_dir, "sub_groups": sub_groups, "test_cases": test_cases, + } + test_group.update(common_fields) + return test_group + +def get_json_result(test: Test, metadata: Metadata) -> str: + common_fields = { + "arch": metadata.arch, + "defconfig": metadata.def_config, + "build_environment": metadata.build_dir, "lab_name": None, "kernel": None, "job": None, "git_branch": "kselftest", } - return test_group -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 = _get_group_json(test, common_fields) test_group["name"] = "KUnit Test Group" 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 a3c036a620b2..60806994683c 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -468,8 +468,7 @@ class KUnitJsonTest(unittest.TestCase): test_result = kunit_parser.parse_run_tests(file) json_obj = kunit_json.get_json_result( test=test_result, - def_config='kunit_defconfig', - build_dir='.kunit') + metadata=kunit_json.Metadata()) return json.loads(json_obj) def test_failed_test_json(self): @@ -691,7 +690,7 @@ class KUnitMainTest(unittest.TestCase): self.linux_source_mock.run_kernel.return_value = ['TAP version 14', 'init: random output'] + want got = kunit._list_tests(self.linux_source_mock, - kunit.KunitExecRequest(None, '.kunit', None, 300, False, 'suite*', None, 'suite')) + kunit.KunitExecRequest(None, None, '.kunit', 300, False, 'suite*', None, 'suite')) self.assertEqual(got, want) # Should respect the user's filter glob when listing tests. @@ -706,7 +705,7 @@ class KUnitMainTest(unittest.TestCase): # Should respect the user's filter glob when listing tests. mock_tests.assert_called_once_with(mock.ANY, - kunit.KunitExecRequest(None, '.kunit', None, 300, False, 'suite*.test*', None, 'suite')) + kunit.KunitExecRequest(None, None, '.kunit', 300, False, 'suite*.test*', None, 'suite')) self.linux_source_mock.run_kernel.assert_has_calls([ mock.call(args=None, build_dir='.kunit', filter_glob='suite.test*', timeout=300), mock.call(args=None, build_dir='.kunit', filter_glob='suite2.test*', timeout=300), @@ -719,7 +718,7 @@ class KUnitMainTest(unittest.TestCase): # Should respect the user's filter glob when listing tests. mock_tests.assert_called_once_with(mock.ANY, - kunit.KunitExecRequest(None, '.kunit', None, 300, False, 'suite*', None, 'test')) + kunit.KunitExecRequest(None, None, '.kunit', 300, False, 'suite*', None, 'test')) self.linux_source_mock.run_kernel.assert_has_calls([ mock.call(args=None, build_dir='.kunit', filter_glob='suite.test1', timeout=300), mock.call(args=None, build_dir='.kunit', filter_glob='suite.test2', timeout=300), From patchwork Thu Feb 24 19:20:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12759160 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 198C6C433FE for ; Thu, 24 Feb 2022 19:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233714AbiBXTVi (ORCPT ); Thu, 24 Feb 2022 14:21:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233738AbiBXTVf (ORCPT ); Thu, 24 Feb 2022 14:21:35 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A607251E53 for ; Thu, 24 Feb 2022 11:21:03 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d07ae11460so7941757b3.7 for ; Thu, 24 Feb 2022 11:21:03 -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=XeyKS8RFDw4jOveKpKzpaWOeY5Iszmw9j6umKWFdclY=; b=RGLMCO1Etdpy755zbZrEGgrFJvgWznO+TQvBEcFQPzPb8J0/RUoA1yjnAqVSw+C0VM f174wesSM91IxNRS2ued7Rjo8EeUwimObR1mHdSl7IIpdyCaHp+qIzPUHs68Om6+dZeL nHGw+Y2pAtbJbifYV0sP4xrqs9X/nCpIoS58RtKNe87ka4ozoG8RGxchDv26rSLYgGbi Fr+2mOVyVOnbQScZ68KltzVd2vYWJLvV2YOeQfPw3ACqHOk26dPOiMNs6d4uyBcD7eHR xDSkO0qU5p1lNIuO3x6d9I4XoNIYHcyiv8FarCoMjrrTmiESzUO/2T8j7DhzVWG1NOUV TTfw== 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=XeyKS8RFDw4jOveKpKzpaWOeY5Iszmw9j6umKWFdclY=; b=HNyy6FzGN0yg0L5/npXcO3TupVrYUwO7Oaw+Wde+5ZYtwy3XqnCdl97G42OLi73tfc AXv+vo2CW6yV94CmmG4PcfzET03iui7+k36hlcKpNArWr6l+pTYHrg7IR+it1sEv7vT0 eBBwfH26gLHLdXwC7JDejQW1gXNmEvTIFWLxfXZNdY26uQi4icYiRHfcSdcK143nvSE3 GmW8Ah94Xg523R0eoMLn7zE6Iz0pMjpnXEBAazQEjdfVHyAwHpv+IcaZslWiQ2cY+lv4 kYP+8ksdXb31INMe6kwNBigU5DAz+tQxq95rxnxMW1f1gGK0CXGqGu33ifLiLwn3q/K+ fUWw== X-Gm-Message-State: AOAM530WY7ibw5DHGlpegcagFwIoU7FvxYHw8OicPH3q7xrZ+krKY1ff oSEwJ22vkgDLHNybaVwSyRSF0admbQp3FQ== X-Google-Smtp-Source: ABdhPJxyg2MoliW/bMDs8Trw98DfmYoIgUcWqP9ZDRosz12QtS2nE3rQpgaQ46fTufkIQRuNeMHAGaj0oUThMg== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:96e5:fbf5:15ed:8b6f]) (user=dlatypov job=sendgmr) by 2002:a05:6902:4e2:b0:611:19fc:a30 with SMTP id w2-20020a05690204e200b0061119fc0a30mr3818796ybs.431.1645730462280; Thu, 24 Feb 2022 11:21:02 -0800 (PST) Date: Thu, 24 Feb 2022 11:20:36 -0800 In-Reply-To: <20220224192036.2388302-1-dlatypov@google.com> Message-Id: <20220224192036.2388302-3-dlatypov@google.com> Mime-Version: 1.0 References: <20220224192036.2388302-1-dlatypov@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 3/3] kunit: tool: properly report the used arch for --json, or '' if not known 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 Before, kunit.py always printed "arch": "UM" in its json output, but... 1. With `kunit.py parse`, we could be parsing output from anywhere, so we can't say that. 2. Capitalizing it is probably wrong, as it's `ARCH=um` 3. Commit 87c9c1631788 ("kunit: tool: add support for QEMU") made it so kunit.py could knowingly run a different arch, yet we'd still always claim "UM". This patch addresses all of those. E.g. 1. $ ./tools/testing/kunit/kunit.py parse .kunit/test.log --json | grep -o '"arch.*' | sort -u "arch": "", 2. $ ./tools/testing/kunit/kunit.py run --json | ... "arch": "um", 3. $ ./tools/testing/kunit/kunit.py run --json --arch=x86_64 | ... "arch": "x86_64", Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 2 +- tools/testing/kunit/kunit_json.py | 4 ++-- tools/testing/kunit/kunit_kernel.py | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 7dd6ed42141f..5c03f1546732 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -153,7 +153,7 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) - test_glob = request.filter_glob.split('.', maxsplit=2)[1] filter_globs = [g + '.'+ test_glob for g in filter_globs] - metadata = kunit_json.Metadata(build_dir=request.build_dir) + metadata = kunit_json.Metadata(arch=linux.arch(), build_dir=request.build_dir, def_config='kunit_defconfig') test_counts = kunit_parser.TestCounts() exec_time = 0.0 diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 0a7e29a315ed..1212423fe6bc 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -18,8 +18,8 @@ from typing import Any, Dict @dataclass class Metadata: """Stores metadata about this run to include in get_json_result().""" - arch: str = 'UM' - def_config: str = 'kunit_defconfig' + arch: str = '' + def_config: str = '' build_dir: str = '' JsonObj = Dict[str, Any] diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index fe159e7ff697..bbbe2ffe30b7 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -248,6 +248,8 @@ class LinuxSourceTree(object): kconfig = kunit_config.parse_from_string('\n'.join(kconfig_add)) self._kconfig.merge_in_entries(kconfig) + def arch(self) -> str: + return self._arch def clean(self) -> bool: try: