From nobody Fri Sep 19 04:11:07 2025 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 2E148C43217 for ; Tue, 29 Nov 2022 00:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbiK2ANG (ORCPT ); Mon, 28 Nov 2022 19:13:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234642AbiK2AMm (ORCPT ); Mon, 28 Nov 2022 19:12:42 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540376553 for ; Mon, 28 Nov 2022 16:12:40 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id on5-20020a17090b1d0500b0021821a07953so13074810pjb.4 for ; Mon, 28 Nov 2022 16:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=X881tlPDVXUlMgACZfZTZeyY92tnJLZ+/B1dNTIs8Gc=; b=Oi0ZjD5sM55sEXkn34mnC5VjQu6xKzBRPB+GDVOF2EnL4UyIrAVAj+ELyBOEjwwDGW s52xHTMYBS43CadhoSIW0qCfFLr9/dNXGbYqxREAcpO5ADcuQcbGGoVLhGcyFqOifAYz ojnWNbwTYlIyOmygoDbJnXy2VtgXqs/+yjKkqA2rMMM90MtJyW8+/OEsUGu7j28fquOe yOvSTpwtVyfqFbCa/Z053nvtEqBPgJ3feWv7yramCZQ80+/cUgNFfd/Hu0S7PmVXRryp Q/eyB0R27WV76y4VZNh25H39JHBqzfwP/Gr7dqgkyyzpXjcPx4HmPcDa9Lj/VZGtOJAy T8zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=X881tlPDVXUlMgACZfZTZeyY92tnJLZ+/B1dNTIs8Gc=; b=g3xILbF4RjxVQBw5aZTaLIUZ4pbFPvvTA/rY/SNct1NuCvAkMas1uh+dwLQCbStjCQ RCdGWLfvUEpMfuO/lIUXk2oePlx+qTczL/DuRFlQjHpff43l1mgrc8nM+8dOlX0WauqK Uf7Ikx3C/+4Q3OiHne2akqs/X0MUvJ/zeEhEfLhKH/hLFJejTeYqA2ObfDYDXrHzOjYr e4IrakkewZs4dzEPLCS3pQjUZGhzAysAUdEP0r6IhySrSlXsuD9GkWSKmxqxarIXRuy7 BeANzWNkgilvF9RC2MbTlOo/5+kuaYOyDXgKg6vrsZlRVbhPW2j3SZELAveAf5BpEnMj EqQA== X-Gm-Message-State: ANoB5plyVbf8Vg4tLpZ6BIljh7TE7GQZPXrpLxhT/7TtzZ4ePcm2C0iP YvEG1bwvO4TcIrxXPoKe3SzLHKE813XMCQ== X-Google-Smtp-Source: AA0mqf7PIX8W1qzdvgiGt+aiUTDXV/YuuvuJ0Eo/G0bko1Yy573w+vZmfwFWp89lUQwQZ4vFaPcQTbgi/vUM/w== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a05:6a00:408b:b0:56b:ca57:ba8c with SMTP id bw11-20020a056a00408b00b0056bca57ba8cmr35465110pfb.43.1669680759811; Mon, 28 Nov 2022 16:12:39 -0800 (PST) Date: Mon, 28 Nov 2022 16:12:34 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221129001234.606653-1-dlatypov@google.com> Subject: [PATCH] kunit: tool: don't include KTAP headers and the like in the test log From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: rmoar@google.com, 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-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We print the "test log" on failure. This is meant to be all the kernel output that happened during the test. But we also include the special KTAP lines in it, which are often redundant. E.g. we include the "not ok" line in the log, right before we print that the test case failed... [13:51:48] Expected 2 + 1 =3D=3D 2, but [13:51:48] 2 + 1 =3D=3D 3 (0x3) [13:51:48] not ok 1 example_simple_test [13:51:48] [FAILED] example_simple_test More full example after this patch: [13:51:48] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D exampl= e (4 subtests) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [13:51:48] # example_simple_test: initializing [13:51:48] # example_simple_test: EXPECTATION FAILED at lib/kunit/kunit-exa= mple-test.c:29 [13:51:48] Expected 2 + 1 =3D=3D 2, but [13:51:48] 2 + 1 =3D=3D 3 (0x3) [13:51:48] [FAILED] example_simple_test Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Rae Moar --- tools/testing/kunit/kunit_parser.py | 8 ++++---- tools/testing/kunit/kunit_tool_test.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kuni= t_parser.py index 4cc2f8b7ecd0..99b8f058db40 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -295,7 +295,7 @@ def parse_ktap_header(lines: LineStream, test: Test) ->= bool: check_version(version_num, TAP_VERSIONS, 'TAP', test) else: return False - test.log.append(lines.pop()) + lines.pop() return True =20 TEST_HEADER =3D re.compile(r'^# Subtest: (.*)$') @@ -318,8 +318,8 @@ def parse_test_header(lines: LineStream, test: Test) ->= bool: match =3D TEST_HEADER.match(lines.peek()) if not match: return False - test.log.append(lines.pop()) test.name =3D match.group(1) + lines.pop() return True =20 TEST_PLAN =3D re.compile(r'1\.\.([0-9]+)') @@ -345,9 +345,9 @@ def parse_test_plan(lines: LineStream, test: Test) -> b= ool: if not match: test.expected_count =3D None return False - test.log.append(lines.pop()) expected_count =3D int(match.group(1)) test.expected_count =3D expected_count + lines.pop() return True =20 TEST_RESULT =3D re.compile(r'^(ok|not ok) ([0-9]+) (- )?([^#]*)( # .*)?$') @@ -409,7 +409,7 @@ def parse_test_result(lines: LineStream, test: Test, # Check if line matches test result line format if not match: return False - test.log.append(lines.pop()) + lines.pop() =20 # Set name of test object if skip_match: diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index d7f669cbf2a8..1ef921ac4331 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -84,6 +84,10 @@ class KUnitParserTest(unittest.TestCase): self.print_mock =3D mock.patch('kunit_printer.Printer.print').start() self.addCleanup(mock.patch.stopall) =20 + def noPrintCallContains(self, substr: str): + for call in self.print_mock.mock_calls: + self.assertNotIn(substr, call.args[0]) + def assertContains(self, needle: str, haystack: kunit_parser.LineStream): # Clone the iterator so we can print the contents on failure. copy, backup =3D itertools.tee(haystack) @@ -327,6 +331,19 @@ class KUnitParserTest(unittest.TestCase): result =3D kunit_parser.parse_run_tests(file.readlines()) self.print_mock.assert_any_call(StrContains('suite (1 subtest)')) =20 + def test_show_test_output_on_failure(self): + output =3D """ + KTAP version 1 + 1..1 + Test output. + not ok 1 test1 + """ + result =3D kunit_parser.parse_run_tests(output.splitlines()) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) + + self.print_mock.assert_any_call(StrContains('Test output.')) + self.noPrintCallContains('not ok 1 test1') + def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream: return kunit_parser.LineStream(enumerate(strs, start=3D1)) =20 base-commit: 11300092f6f4dc4103ac4bd950d62f94effc736a --=20 2.38.1.584.g0f3c55d4c2-goog