Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6520512rwb; Tue, 22 Nov 2022 14:46:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wKb3uHX/BMQs20LTRMWPvtNmEqR+cbcBwDqIPJblcTzs+cAeDKW8VU6PfPMBBsFSl4h+H X-Received: by 2002:a17:906:fcd0:b0:7ad:b8c0:3057 with SMTP id qx16-20020a170906fcd000b007adb8c03057mr21578114ejb.440.1669157213373; Tue, 22 Nov 2022 14:46:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669157213; cv=none; d=google.com; s=arc-20160816; b=GsmGELBSxNDQ/8Oe+5DLxu2FiBV18/gV9Ta31xdGJVBqaHN8pqSUM8io6aihqlCsPa zpkNAMrYASkJgHGuKSaBX1q5wC/EOzTC9xZE94q4NZ/jRRp80Qf5V2lsIxYAtXGejelB 76eN2NNAk+HaHiEOGd+7SGLNZE3GMvAD1RoU8kUE6Uq43unMLm+7YEhGhA5/HxmQ+amV 33mCca6ii5zMfnk8U42xscdEMrr9d9AI9nDmzQeeqMZXMEEx3C5SPr0R13E7miXqIpKV WYLH4ubj3iRdHFictB9udNz5nUpFMBkGaFr0jr78pDI6dL24lbVoMHoBXGV28KThXta6 2coQ== 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=rEBpVA9Ugn8l6tDbRhwVlz6+57EToTDnZh9CWQeel1A=; b=pV6msGxZKZAP/5i+Gn+JWW0nawck3plkFd7eRGa/DJkQM8nQ3dmbGX4bCoF55ozBEN Css7Z0zcJnEe7Al1jWSoW5ZogeaxSm05ZExv7dLuk8ingkkzv51QPVjTZA+hqhnIyIk3 /1HmbrwEVe3BBIAmyPuWKj12LnPnaLSaDC6zNAy0EfkU36awcRKrhhtE2CLfgCryIdtg k799UfhSlxfBruwH7PieOcFwgTKL2njahHsAEmAWLfwGn2+15Fwb96CkzyhU9ELHjQQA HAYt33bgQ54WS3LIDk+ZmQ6uVoyMvH3yxw3pOYltWcryHLc2+OXPZx2CYWl02IPvpdk5 ppKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rwcNuFQa; 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 mp8-20020a1709071b0800b0078cffe5dcdesi14115499ejc.451.2022.11.22.14.46.31; Tue, 22 Nov 2022 14:46:53 -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=rwcNuFQa; 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 S234993AbiKVWG1 (ORCPT + 89 others); Tue, 22 Nov 2022 17:06:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235009AbiKVWGQ (ORCPT ); Tue, 22 Nov 2022 17:06:16 -0500 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F231C6CA23 for ; Tue, 22 Nov 2022 14:06:13 -0800 (PST) Received: by mail-ot1-x32b.google.com with SMTP id db10-20020a0568306b0a00b0066d43e80118so10207071otb.1 for ; Tue, 22 Nov 2022 14:06:13 -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=rEBpVA9Ugn8l6tDbRhwVlz6+57EToTDnZh9CWQeel1A=; b=rwcNuFQa2cDWon8KDwDoP45/9XzV5mW9DBbsdnUlssW1hiYqRt5mLGFiGYVmGKYPhA jpt2Mx6vEgAfiRw22gE67VlbKma1CNHOm3SdH/QNTrlhX7zuWS8b/Yw0DWVQTQeorakb zH4DJiF4Fh5yLUVrNj4PHQl32JSP+5iOeYt4RshuG31wSbKmVvzqpdT5wUEsNIWvO41x QxPNEeygRgYVsgju1M85LLArqUZNnGTGy3lCQQePAUETjIFHoX3LivE2TgCVpidaJj1Z P8rvu2FsXcDaZ3JTMzm/25chz3YCGNavyHsbXqmeSicCSQZsQ2yCmw0uInsmDPjOijeP iXTQ== 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=rEBpVA9Ugn8l6tDbRhwVlz6+57EToTDnZh9CWQeel1A=; b=7Z5HVN0E2riAnw1iFUSpE8fvq9KZgfa3k1XRDJnbP3K4/CwjhZTz04lOOM7e//koYq HSEhC48Ntj3GIYmnrCSTBVmGYnoPLoXhNRikvknFV3TX077co8raCKyStO9q43ojF1XM 8z6OknlvGa/eYGNqnCo3maOmjnCWf1jpQR4AZbfjY+zV8SZdFGZHkhoUs/zdiyS8iwwo J1uj5bRp8H4l6b+nS/FU7SSdBFk7T3PWC/g05uvK4jShxEinsDdR4q7Ynn+qNBP6maVy 77hlaRH0rWUupOQQrPWIWpV9TderXYf9vBG9ZATW7JcoeiJ1O0RDaQut/cZpa6Hu2bEZ OLDA== X-Gm-Message-State: ANoB5pmfIY8jeLK7zuB25I+iSohpH6dyfSlg8UEw2rHLgX2yqdZLyZrq fTTERVRkPvae7of+vZ4IJjMKrPqgy8TPk1tiUyRSeA== X-Received: by 2002:a9d:1d7:0:b0:668:73ff:e96 with SMTP id e81-20020a9d01d7000000b0066873ff0e96mr3018318ote.256.1669154772162; Tue, 22 Nov 2022 14:06:12 -0800 (PST) MIME-Version: 1.0 References: <20221121184743.1123556-1-rmoar@google.com> In-Reply-To: From: Rae Moar Date: Tue, 22 Nov 2022 17:06:00 -0500 Message-ID: Subject: Re: [PATCH v2 1/2] kunit: tool: parse KTAP compliant test output To: Daniel Latypov 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 3:51 PM Daniel Latypov wrote: > > 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 w= ith > > the KTAP version 1 specification format found here: > > https://kernel.org/doc/html/latest/dev-tools/ktap.html. Ensure the pars= er > > 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= /commit/?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 hea= der > > 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 testin= g > > 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 abili= ty > > 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_e= xecutor_test =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Yeah I agree, this looks much better. > > else: > > - message +=3D f' ({test.expected_count} subtests= )' > > + message +=3D f'({test.expected_count} subtests)= ' > > stdout.print_with_timestamp(format_test_divider(message, len(me= ssage))) > > > > 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], i= s_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: i= nt, 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: i= nt, 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 versio= n 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 = contatining > > typo: contatin =3D> contain Oops, I will change this. > > > + # 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 " # Subtes= t"). > > Optional: do we want to extend kunit_tool_test.py to validate this logic = too? > 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)')) > I like this addition. I will add this test to kunit_tool_test.py. > Daniel