From patchwork Thu Mar 13 19:27:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rae Moar X-Patchwork-Id: 14015842 X-Patchwork-Delegate: brendanhiggins@google.com Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 452081F2BA9 for ; Thu, 13 Mar 2025 19:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741894044; cv=none; b=BkJWuScXONszewUNXmVGlf+yRT5TdYjOdya4G7hS85NVHLeplpRh5oaDeuVStmOYq5gB+ZkeKSNB7I7S75yc6g3ipmknSZAPH85rQVq9olQeTa2oQ7t+E1cAlnnzLZlag8zXB7mnUs+/kxvCUJAkPLDpkfX/tSeXbzj8zx4mU0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741894044; c=relaxed/simple; bh=ILIt1I4K0yqsx2yeqHM01aYQOroUH63iR+NR+X1/jzw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=C6BAyx88hHTRZhbLUq20zYcQur/MnzBCEzOcnRqdt8O9ShwJnJUIQbfFap3vbtDjzyIGABG7i7a6uDc3wUg7GhIMdPk/AF0G9uUVAv9++InhtDMlJIaaJoshfqR4st1SuifEWudmii2opUdFe/SfFsUizfZzZQvaD1YlRBl6YuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--rmoar.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GyEKrDub; arc=none smtp.client-ip=209.85.222.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--rmoar.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GyEKrDub" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7c0a71aaf9fso322995985a.3 for ; Thu, 13 Mar 2025 12:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741894042; x=1742498842; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Flzo3lVXN6Qb29UsmAIPXEQO4WxyqMDpwWQQUOakg/A=; b=GyEKrDubZNrDsnddwJG8wfLf7QgcpHD9SL1LfAkhYSSJG9DIPEfMpilre2G2u5k8gD aWEjT2+PAYdTQKHgqRqk6NHcOQT2PvcvmibLeI6xItGVIuflcrLakzGpjrBDryvAV+8H ytA8pTqM2vpPpMQ/rI+qsHdvcjlzvqSV0ATKn6MYsdDZiTtyPuy9GCf2u5Dz1/vcJACZ GwT5T16v/sIzSA1IziEXE4vhAOrFOnJdAkjmSw1xKBafoQp2M98piq/bs40GlhxAl0Cv fzVcFBJX9B2HQjVw9YtqGnmcbXeUNeTUufMmA6QxxnaaUy2wsjDGisurFucAwaYXIFf/ 0tAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741894042; x=1742498842; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Flzo3lVXN6Qb29UsmAIPXEQO4WxyqMDpwWQQUOakg/A=; b=Vf31FuE9GJsAnFTOXW2Cl+4Jw0R9pdXluJ32a14Cw56hY01aHtnssa4MHjyaA7XEzB OeWbM2X6qIUG9rJxVIE3a1ztvNZNG8ecaq15LyZaZtqjbSOoj1vmLnuZ4QsF5sE+83T+ cYwv4BNTURo9bUn0P0NY6CrXJ6Qv6g96WRZuLvYXjX0pbJN2xo4daC7MOVxHZ7jv9V0F Ws8jHrO3sp+CeWoFOL2Yblh7IKOokGPNugvnDrali+sZpGuFIz50xbh/jkG9CqEiKloy keTU/MylG0VGRLDi/cVOEIrl3yDz1HA+qXllcpoWduHLIuKbOTjh/nKtOFHkbQR0Rybo rkSw== X-Forwarded-Encrypted: i=1; AJvYcCUCO+y+SpVnHGWd7tYr/E3cPboCWwCFxMN/uCZXZxIVC9nX7/9pGbuXhLUsCbZ8cZWRxanybJiD1NqaxAFqugM=@vger.kernel.org X-Gm-Message-State: AOJu0YxwkxN5+27O4LH2f/OEmx6d8D3sEEUzbVH5Lm7t8d4qYEqvD01f A53RyQ9af4nSU3bTh5JaD156OomnkC6B13pc9umj+MpJ2s+ic5I5xOJhtTJDtbYlLThVtTDsmg= = X-Google-Smtp-Source: AGHT+IEhCEWKmQjlaJ2Hf9ADlQ1vji3WEjuildMcB96v9vZqW2qrPWk46XWEkANhfAWxGwXSXAbZlKWs4Q== X-Received: from qkd1.prod.google.com ([2002:a05:620a:a001:b0:7c3:cc0d:22fb]) (user=rmoar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:2713:b0:7c5:67ac:a826 with SMTP id af79cd13be357-7c579fafb41mr102376685a.50.1741894042243; Thu, 13 Mar 2025 12:27:22 -0700 (PDT) Date: Thu, 13 Mar 2025 19:27:13 +0000 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250313192714.1380005-1-rmoar@google.com> Subject: [PATCH v3 1/2] kunit: tool: Fix bug in parsing test plan From: Rae Moar To: shuah@kernel.org, davidgow@google.com Cc: jackmanb@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Rae Moar A bug was identified where the KTAP below caused an infinite loop: TAP version 13 ok 4 test_case 1..4 The infinite loop was caused by the parser not parsing a test plan if following a test result line. Fix this bug by parsing test plan line to avoid the infinite loop. Signed-off-by: Rae Moar Reviewed-by: David Gow --- Changes since v2: - None, adds test in second patch tools/testing/kunit/kunit_parser.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) base-commit: 0619a4868fc1b32b07fb9ed6c69adc5e5cf4e4b2 diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 29fc27e8949b..da53a709773a 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -759,7 +759,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: # If parsing the main/top-level test, parse KTAP version line and # test plan test.name = "main" - ktap_line = parse_ktap_header(lines, test, printer) + parse_ktap_header(lines, test, printer) test.log.extend(parse_diagnostic(lines)) parse_test_plan(lines, test) parent_test = True @@ -768,13 +768,12 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: # the KTAP version line and/or subtest header line ktap_line = parse_ktap_header(lines, test, printer) subtest_line = parse_test_header(lines, test) + test.log.extend(parse_diagnostic(lines)) + parse_test_plan(lines, test) parent_test = (ktap_line or subtest_line) if parent_test: - # If KTAP version line and/or subtest header is found, attempt - # to parse test plan and print test header - test.log.extend(parse_diagnostic(lines)) - parse_test_plan(lines, test) print_test_header(test, printer) + expected_count = test.expected_count subtests = [] test_num = 1 From patchwork Thu Mar 13 19:27:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rae Moar X-Patchwork-Id: 14015843 X-Patchwork-Delegate: brendanhiggins@google.com Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CFD31F37B8 for ; Thu, 13 Mar 2025 19:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741894048; cv=none; b=p98tHfr9gLDArANRHx1gzNxNbCZYjFjan0mmSVlT6Y2EbxExG+KPobxD/Uz2gsRh4wBRHtxvhpxNJ89r/k+WOrDbf3plpnLKl+3iTh1+yl2yEatQJaPGdzg9s5Rh9gyiVpxvQMrwok3gdy1t0JDf0LNnwpr2DJ7RdGzch1YRNmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741894048; c=relaxed/simple; bh=KrBlLCuENNqmAXVG7c3+/aqpGnMQ9/bc/NOxjGDGs0U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BDGmv6oco21pkrX/pwwhzqIoUtr1WCpENNQrHaU/3i9hZjij6AYSgvuPQ58tJls0Dz2hOFPJs+nOXSUt8y3i6lbTGER/kp+m/6QzUl8al9mNkDQA0SEFziCQVqddVecFnWU82w37xdBdU7sLf+kGQfLDfZE/5XY4wgST2lnmDNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--rmoar.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rXN9Jwju; arc=none smtp.client-ip=209.85.219.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--rmoar.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rXN9Jwju" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6e8feea216aso46178266d6.0 for ; Thu, 13 Mar 2025 12:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741894044; x=1742498844; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QZ3Mm17hODYwuzWnxvtURLhRnjoSjhRLoip0t8b11co=; b=rXN9Jwjubd6oyzjen+mmS9k4ogZ6tjRnMp+PIB1GrgklTIcowcerWR0XQwTt1YF1xU pntxHPA68VpL1qZI0zxoOqnWvQ6WjIjVX46wB6KiexmprVTFeP0He8EEJpHO5IxheN37 1wAiLH94tI7szTbtqshesuf0PboiFBNR20egXOeuFozLFkujG8w7sfbiusvUnp02ttSX U9UyKz9ej0OP/zPiX5tsalzzr1kFEGJQ3AdItCb/0EEQiDisa5lQmCAQSLr8hcgyDdme Nx1RwObfwJNdgAIGGMm8gAPbRYOczSSCUivpu4gCtnyJhrM6hjh/i2zPAAE4H9FoTdGM DlTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741894044; x=1742498844; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QZ3Mm17hODYwuzWnxvtURLhRnjoSjhRLoip0t8b11co=; b=cXeVXyFcjhjChBio9mf8aVra+yA2NNpWOhorBMltlVjlxrD+yV/2NFBgj/bCy3DF2+ AJTo1RlxZyyKMjWax97a9Vl3E6bfK+g/XkLo7cGVTGEAi/zeDzfj234zSyMUyHb2Fk2d YlSEksP8WhdWY3Rie1Q8HvPS7zMRb9nERvQyotbqSiHnU/I92Cr/RmQFODIu+yF/QT2L WQGwAhlPnW7EqgZMS3PNIeuvUfBW59odMavQd+rig91mL7VTBmF+rPWY2UwAIJLMJeCF lWpo567iGcnaTNJxebZv/g+WX2yX/5A3NMQ4u8Afb8X45W5gVpZmT6B6K9n5M/6Hdz52 +eUQ== X-Forwarded-Encrypted: i=1; AJvYcCU77pzMfmINgYNSHG55cy7fMsuFnl3f08tcaIH9QbeBrZI+LQlJo8MDuWwyJLhn/vz+pL3Gsq+y8CmpWVh3rVw=@vger.kernel.org X-Gm-Message-State: AOJu0YyJtonxfB6bh51M6dnbb+9Yz94NlJ2moUyCFd47D55GP4+EECET FGrg8x+mKtcg4CqH14al2zqSoxbLan+kHpueO8OT1n6ThHx71bOz6uBsZN6TspxyyMQe5Z2zZA= = X-Google-Smtp-Source: AGHT+IHUUkUlx830CBpJPHMfzFNdP1ycZ9vkfSY6GnZkeGYCtQvF2FUhUcJ6pbIDO6vFgtx9ZVgMs/nRng== X-Received: from qtbhj5.prod.google.com ([2002:a05:622a:6205:b0:476:7266:9db9]) (user=rmoar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:1a1e:b0:474:f5fb:b11a with SMTP id d75a77b69052e-476ba8b317bmr46779441cf.3.1741894044398; Thu, 13 Mar 2025 12:27:24 -0700 (PDT) Date: Thu, 13 Mar 2025 19:27:14 +0000 In-Reply-To: <20250313192714.1380005-1-rmoar@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250313192714.1380005-1-rmoar@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Message-ID: <20250313192714.1380005-2-rmoar@google.com> Subject: [PATCH v3 2/2] kunit: tool: add test to check parsing late test plan From: Rae Moar To: shuah@kernel.org, davidgow@google.com Cc: jackmanb@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Rae Moar Add test to check for the infinite loop caused by the inability to parse a late test plan. The test parses the following output: TAP version 13 ok 4 test4 1..4 Signed-off-by: Rae Moar Reviewed-by: David Gow --- Changes since v2: - Adds this patch to add a test for this behavior tools/testing/kunit/kunit_tool_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 0bcb0cc002f8..5ff4f6ffd873 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -363,6 +363,17 @@ class KUnitParserTest(unittest.TestCase): self.print_mock.assert_any_call(StrContains(' Indented more.')) self.noPrintCallContains('not ok 1 test1') + def test_parse_late_test_plan(self): + output = """ + TAP version 13 + ok 4 test4 + 1..4 + """ + result = kunit_parser.parse_run_tests(output.splitlines(), stdout) + # Missing test results after test plan should alert a suspected test crash. + self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status) + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, crashed=1, errors=1)) + def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream: return kunit_parser.LineStream(enumerate(strs, start=1))