Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4861249rwb; Mon, 21 Nov 2022 12:59:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf7bFv8DFZHj1o9e1U1plu6uWwQ6hrM72QPdyW4TDzT1hK8UHEzB6gT3B8Gr0wL4n9RacFwU X-Received: by 2002:a17:906:55c5:b0:78d:3862:4488 with SMTP id z5-20020a17090655c500b0078d38624488mr16128701ejp.683.1669064390882; Mon, 21 Nov 2022 12:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669064390; cv=none; d=google.com; s=arc-20160816; b=azqos7DaqA0Zr4ckwZqIkeGs353j9HVRcG3JbGsmtqWnA4wRGnYU7uRp1Q0TQV41M9 okKO0waB2+9X05tmFpn+Q17KwaTuRslGiw2QiLrNNL75nMXCfEUf1KLuOibdl6KAvVjh 92XKvNRdYl1gxzAco06OxKAW4OrdetLqKJrbtpT9aYdCDh8h1PzSIlMRd+P9P+FsWdOK cFwlBE/fHJvjypt73wo4jQ5D+4g6/Ljg+bOsNWes2e4Dl9Cr7BZWq+6ZJhy2d3y5xn1V nU/wQR8jopjl6SS6+RpSVN7gxQAkHTpNMviXumOS5Z7NcG+yi0jIiXu8dlmnz1BeC7De j5lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Rzk/OoHldFb62sgZsjulPSkjrNjPl5Xo51StZUIwQR4=; b=PQL+bHyhLZ0RS6n420mIlRcmu5qsW+bCnI2KKVk/TzE1cYppv6DlpVe66FfZgG+UVt XYUQY1/6LE8l/hEMzmMWJfTixjPrpabBOtv+E9mrOol4bQF1zLayW6mhbt3UCj/46BDA Fp2jA9Us1PQrPCeUXOE1o39Lwt6ZthGX02E54rBqHum0Vao2VB3PY5gVnu/CwgGe4Fvu p2SDbWEqCQ9xpK0GMGc7ho2qSHTBtf2MrRO9H/O1Xnl3+xvw8zNVk2SYQJzrae1BVN6Y opNhcdw2zeGUK8tB+MxsKQXsidMnaqshp70VTGzQAAdo10kxVSzz/awXWxvn2ycJM+no yKmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oOb+iJxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020aa7dc06000000b00459528ef81bsi8929554edu.324.2022.11.21.12.59.28; Mon, 21 Nov 2022 12:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oOb+iJxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230342AbiKUUvv (ORCPT + 91 others); Mon, 21 Nov 2022 15:51:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiKUUvs (ORCPT ); Mon, 21 Nov 2022 15:51:48 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26CF5C9A92 for ; Mon, 21 Nov 2022 12:51:47 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id c15so15015433ybf.1 for ; Mon, 21 Nov 2022 12:51:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Rzk/OoHldFb62sgZsjulPSkjrNjPl5Xo51StZUIwQR4=; b=oOb+iJxhz4nONMEq0oTcLXm8I9REhxu1SiJRcnUJH7TOoXnCjFr79nrjXAE7cviCER Ll0T/+g62FhTyFnCmhqx9eX3zkv17IvbNRamtQWw7FMBltzjTeTCakJdFjH3GywilbEq QYQvGOqFh+gVdHCta3PorKTg1qb5x9MjMhnNXfugdZMg0T1psFSGnlucv+zgcFXGv3AX Xq2lFsyZGy9EyfFMSKVn9ytYXqDwEAwETzocYb1Oed56RHUxDY+6Pvw9h5P2BoMaOpSN +RlzFrBx0NvME3Tp/7LQ9rrMuVswfWUdzpyQ7R5aqDPWA9/ReSI8O9sJWXR16VSsM3Ge ArQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rzk/OoHldFb62sgZsjulPSkjrNjPl5Xo51StZUIwQR4=; b=h50TB+tucLf7sZrsdW90omSvCiv02hvFzn7/4K30TfUccn4Wbn3kJPL/yG3N7+Jxi0 sBzCs4Jumvo7i0MatXk4FRLVDzJ7Wgxzc1SAt+8HLF1Zaf4GJ5Pe+H8mMITTh5czW9z6 /T/Itrkb123om3ex5MMiku3KZ71nI7HWygVWbG7uWxPDonelYruQTJxKTZ9NaP6mMI9t IXhY0kbL9SFBYnqguFU2ZJZTML3WP/plhSQXO1Tse+iCRHg2sKo2sLS/31p1rQdbSIvd lVEubDS0CqlWo3P0lAc4ZBrjikH7vl8yw2mY7+N1g0i/H2IuQgleoEKllTYInNcpk9pL A9Lw== X-Gm-Message-State: ANoB5pndwmgcK0bRPdrvJRnBj027zDjYJXhh38GJgZ5VY/vAbcE7lJ8C cM8foA2COp/X1z/OVUydB1fG8WeY2ewZCMxsR5g2S8vI+91Acw== X-Received: by 2002:a25:4289:0:b0:6ca:e43:d9ff with SMTP id p131-20020a254289000000b006ca0e43d9ffmr18347709yba.543.1669063906174; Mon, 21 Nov 2022 12:51:46 -0800 (PST) MIME-Version: 1.0 References: <20221121184743.1123556-1-rmoar@google.com> In-Reply-To: <20221121184743.1123556-1-rmoar@google.com> From: Daniel Latypov Date: Mon, 21 Nov 2022 12:51:35 -0800 Message-ID: Subject: Re: [PATCH v2 1/2] kunit: tool: parse KTAP compliant test output To: Rae Moar Cc: brendanhiggins@google.com, davidgow@google.com, skhan@linuxfoundation.org, mauro.chehab@linux.intel.com, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, isabbasso@riseup.net, anders.roxell@linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 21, 2022 at 10:48 AM Rae Moar wrote: > > Change the KUnit parser to be able to parse test output that complies wit= h > the KTAP version 1 specification format found here: > https://kernel.org/doc/html/latest/dev-tools/ktap.html. Ensure the parser > is able to parse tests with the original KUnit test output format as > well. > > KUnit parser now accepts any of the following test output formats: > > Original KUnit test output format: > > TAP version 14 > 1..1 > # Subtest: kunit-test-suite > 1..3 > ok 1 - kunit_test_1 > ok 2 - kunit_test_2 > ok 3 - kunit_test_3 > # kunit-test-suite: pass:3 fail:0 skip:0 total:3 > # Totals: pass:3 fail:0 skip:0 total:3 > ok 1 - kunit-test-suite > > KTAP version 1 test output format: > > KTAP version 1 > 1..1 > KTAP version 1 > 1..3 > ok 1 kunit_test_1 > ok 2 kunit_test_2 > ok 3 kunit_test_3 > ok 1 kunit-test-suite > > New KUnit test output format (changes made in the next patch of > this series): > > KTAP version 1 > 1..1 > KTAP version 1 > # Subtest: kunit-test-suite > 1..3 > ok 1 kunit_test_1 > ok 2 kunit_test_2 > ok 3 kunit_test_3 > # kunit-test-suite: pass:3 fail:0 skip:0 total:3 > # Totals: pass:3 fail:0 skip:0 total:3 > ok 1 kunit-test-suite > > Signed-off-by: Rae Moar > Reviewed-by: Daniel Latypov Still looks good to me overall. As noted offline, this sadly has a conflict with another recent patch, so it won't apply to the kunit branch right now. That's my fault: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/c= ommit/?h=3Dkunit&id=3D2a883a9f5c1f1c7bb9d9116da68e2ef2faeae5b8 I found a few optional nits down below that we could also address in the rebased v3. > Reviewed-by: David Gow > --- > > Changes since v1: > https://lore.kernel.org/all/20221104194705.3245738-2-rmoar@google.com/ > - Switch order of patches to make changes to the parser before making > changes to the test output > - Change placeholder label for test header from =E2=80=9CTest suite=E2=80= =9D to empty > string > - Change parser to approve the new KTAP version line in the subtest heade= r > to be before the subtest header line rather than after. Thanks, as noted on the child patch, I think this will make our lives easier in the future, even if it technically violates the v1 spec (which requires the test plan right after the KTAP header IIUC). Given the wording Diagnostic lines can be anywhere in the test output. I assume most implementations would likely ignore unexpected lines beginning with "# " already. > - Note: Considered changing parser to allow for the top-level of testing > to have a '# Subtest' line as discussed in v1 but this breaks the > missing test plan test. So I think it would be best to add this ability > at a later time or after top-level test name and result lines are > discussed for KTAP v2. Makes sense to me. > message =3D test.name > + if message !=3D "": > + # Add a leading space before the subtest counts only if a= test name > + # is provided using a "# Subtest" header line. > + message +=3D " " > if test.expected_count: > if test.expected_count =3D=3D 1: > - message +=3D ' (1 subtest)' > + message +=3D '(1 subtest)' Thanks, I like this output a lot better than having "Test suite" as a placeholder name. Tested this out by tweaking some kunit output locally and I get [12:39:11] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D (4 subtests) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D [12:39:11] [PASSED] parse_filter_test [12:39:11] [PASSED] filter_suites_test [12:39:11] [PASSED] filter_suites_test_glob_test [12:39:11] [PASSED] filter_suites_to_empty_test [12:39:11] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [PASSED] kunit_exe= cutor_test =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > else: > - message +=3D f' ({test.expected_count} subtests)' > + message +=3D f'({test.expected_count} subtests)' > stdout.print_with_timestamp(format_test_divider(message, len(mess= age))) > > def print_log(log: Iterable[str]) -> None: > @@ -647,7 +653,7 @@ def bubble_up_test_results(test: Test) -> None: > elif test.counts.get_status() =3D=3D TestStatus.TEST_CRASHED: > test.status =3D TestStatus.TEST_CRASHED > > -def parse_test(lines: LineStream, expected_num: int, log: List[str]) -> = Test: > +def parse_test(lines: LineStream, expected_num: int, log: List[str], is_= subtest: bool) -> Test: > """ > Finds next test to parse in LineStream, creates new Test object, > parses any subtests of the test, populates Test object with all > @@ -665,15 +671,32 @@ def parse_test(lines: LineStream, expected_num: int= , log: List[str]) -> Test: > 1..4 > [subtests] > > - - Subtest header line > + - Subtest header (must include either the KTAP version line or > + "# Subtest" header line) > > - Example: > + Example (preferred format with both KTAP version line and > + "# Subtest" line): > + > + KTAP version 1 > + # Subtest: name > + 1..3 > + [subtests] > + ok 1 name > + > + Example (only "# Subtest" line): > > # Subtest: name > 1..3 > [subtests] > ok 1 name > > + Example (only KTAP version line, compliant with KTAP v1 spec): > + > + KTAP version 1 > + 1..3 > + [subtests] > + ok 1 name > + > - Test result line > > Example: > @@ -685,28 +708,29 @@ def parse_test(lines: LineStream, expected_num: int= , log: List[str]) -> Test: > expected_num - expected test number for test to be parsed > log - list of strings containing any preceding diagnostic lines > corresponding to the current test > + is_subtest - boolean indicating whether test is a subtest > > Return: > Test object populated with characteristics and any subtests > """ > test =3D Test() > test.log.extend(log) > - parent_test =3D False > - main =3D parse_ktap_header(lines, test) > - if main: > - # If KTAP/TAP header is found, attempt to parse > + if not is_subtest: > + # If parsing the main/top-level test, parse KTAP version = line and > # test plan > test.name =3D "main" > + ktap_line =3D parse_ktap_header(lines, test) > parse_test_plan(lines, test) > parent_test =3D True > else: > - # If KTAP/TAP header is not found, test must be subtest > - # header or test result line so parse attempt to parser > - # subtest header > - parent_test =3D parse_test_header(lines, test) > + # If not the main test, attempt to parse a test header co= ntatining typo: contatin =3D> contain > + # the KTAP version line and/or subtest header line > + ktap_line =3D parse_ktap_header(lines, test) > + subtest_line =3D parse_test_header(lines, test) > + parent_test =3D (ktap_line or subtest_line) LGTM (this is where we changed to parse the KTAP header before " # Subtest"= ). Optional: do we want to extend kunit_tool_test.py to validate this logic to= o? E.g. given input like KTAP version 1 1..1 KTAP version 1 # Subtest: suite 1..1 ok 1 - test ok 1 - subtest we could assert that the parsed output contains "suite (1 subtest)" i.e. self.print_mock.assert_any_call(StrContains('suite (1 subtest)')) Daniel