Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp137365pxv; Wed, 30 Jun 2021 17:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr/C99+o5CBW0JcxhKsm24b8e/j9LG1fPcdc+fqmXkksm+TtDmmFuSiFTcxuwwAuiXeq8R X-Received: by 2002:a02:956a:: with SMTP id y97mr10891500jah.58.1625098022454; Wed, 30 Jun 2021 17:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625098022; cv=none; d=google.com; s=arc-20160816; b=qQgvByOmzc5mMca6foPjExi3gs4pQ6yv8uiYhCMF5I32ITnYBNA/2WU6jv7TXHSXxA oCgQn+PzQsoEEtb12mxwnXIb9fYQcuk3JI58lUTGWt+sGp4FD21sIQ45CTmWdg0uqff+ 37wM7xZ/qMGyJ2O+35+vcBVN55Gwq6t7mN+vsys5OiyGqVe55fNo1wDZqZz9x8goRDGp NuHsQSmQ91WkyFTTvvKFHmxcXSCSxobGgKxss0/ujKhw4n9pXbqNAOsMeA+Yc80i8ET3 l2x/j8oEqnXf1iqr6y3LNvrjIifxr7xJib0S1OqdHNAVaNwa9Z0KJm11Jk0mYciorhq3 D32A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=226YhLrtPsM+oDAFsh4aHlKR6GWSTsDUiT3rX/tB3l8=; b=UE20r00r62OCcXCumCAUq2v3ZZuCxiZC1O02mPfV/n2DpU7P9cZUCtUmXsIGsjtJsT 8o+BnqMKGr0SUql2wfddu701x1UiGq1Pr2CcWypvwEr32++jei5Rmw1nk2gGLNygjTAV qKIzushEil2/HEgoUuOEr54qLKFvqFL77zXGaMCimwOqyC2ZvNt0swOEZbWHflgF7NRU 6ZcaPcrO4MArhIr5aW5ZAj/les/j1dQGFny6SKKsi2h9nbvBNDsPDLNSv+jhSMf4ZHkZ H5MugbnCd/jqQHedCuYpQwudVPh/0BIMwy0hQR9+V4i8x12U2CFq2nmy7is/o4Lw4QKW lr9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="eD0JLp/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t13si19205979ilq.138.2021.06.30.17.06.42; Wed, 30 Jun 2021 17:07:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="eD0JLp/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236738AbhF3XnI (ORCPT + 99 others); Wed, 30 Jun 2021 19:43:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236647AbhF3XnG (ORCPT ); Wed, 30 Jun 2021 19:43:06 -0400 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 C78C0C061756 for ; Wed, 30 Jun 2021 16:40:17 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id g3-20020a256b030000b0290551bbd99700so6119879ybc.6 for ; Wed, 30 Jun 2021 16:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=226YhLrtPsM+oDAFsh4aHlKR6GWSTsDUiT3rX/tB3l8=; b=eD0JLp/wThW0X3IZnITyXnsxqyXeQoImKsaL7NfcSau/u6KOKKFJj6lOADaNd717HK 0FwFYII0Xd713WO9wlcu3fEAjNe12PVhuuHTjjZQh3V9m4+XgUMLKo32Ix0srIWYJUGT ZPQbZy9TVnL+7nugc0dbBsXCzsA5dmarzVT+94wK/YmVvmOIMhR7D8akx0ucExOD/KmS HZpFj4YItrSDGmcL1OkMpxgAvDT0TFDEy8/jrD59xneMIa7oFTcUHzMkgAVgucjlLV0j I6XuXbvXDFh8BjAoIfsAGYWwuDgSkzkGmLEU8gIDYdaQpeFFI6zQuq8vDnSS74CjhPRg VrOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=226YhLrtPsM+oDAFsh4aHlKR6GWSTsDUiT3rX/tB3l8=; b=kxfYWyDgtBo8xIAh9i+NrrXl3am6RoZz45OaYBpCOBuz+MXdyuTKbR+eqlm21HcfHC MmSxLHGUo8aXQc+r39knAS3f0UDw6/+VfqhKEw9KAbTGuM5lyazRMp1XapSapqV7ElQo NdA7BNFeuBRyhFlbB3y7QHYfTUrzIgzRbAa/+Vr+31eXDS4URl/6b+mZRaBY45BJ+P+y JXYMq45neo/W4LIAMAxxli7vLYBV3GH7Fdn/QCdmZ/D1o9i1knd6DhObLcBURgEwNfkd vBTqPwfpfvDtCN+95374ha94XIpLynAivLcQr3Vq5dvqlpqWrgi4RZVosg3+WMBEbmIS QGtQ== X-Gm-Message-State: AOAM530Vp04V0Wrl5JSO5BCXd8SPHkI7Z7BdiaRsg+emNY3KJCn2RCfA VG2vzHwxfs0E3Gs3t2G2p0OFz8ssGg== X-Received: from sunrae.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2814]) (user=rmoar job=sendgmr) by 2002:a25:f20f:: with SMTP id i15mr47248583ybe.119.1625096416848; Wed, 30 Jun 2021 16:40:16 -0700 (PDT) Date: Wed, 30 Jun 2021 23:39:50 +0000 Message-Id: <20210630233950.1638536-1-rmoar@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH] kunit: tool: Fix error messages for cases of no tests and wrong TAP header From: Rae Moar To: brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com, shuah@kernel.org Cc: kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Rae Moar Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch addresses misleading error messages reported by kunit_tool in two cases. First, in the case of TAP output having an incorrect header format or missing a header, the parser used to output an error message of 'no tests run!'. Now the parser outputs an error message of 'could not parse test results!'. As an example: Before: $ ./tools/testing/kunit/kunit.py parse /dev/null [ERROR] no tests run! ... After: $ ./tools/testing/kunit/kunit.py parse /dev/null [ERROR] could not parse test results! ... Second, in the case of TAP output with the correct header but no tests, the parser used to output an error message of 'could not parse test results!'. Now the parser outputs an error message of 'no tests run!'. As an example: Before: $ echo -e 'TAP version 14\n1..0' | ./tools/testing/kunit/kunit.py parse [ERROR] could not parse test results! After: $ echo -e 'TAP version 14\n1..0' | ./tools/testing/kunit/kunit.py parse [ERROR] no tests run! Additionally, this patch also corrects the tests in kunit_tool_test.py and adds a test to check the error in the case of TAP output with the correct header but no tests (the log for this test was simplified from the first version of this patch). Signed-off-by: Rae Moar --- tools/testing/kunit/kunit_parser.py | 6 ++++-- tools/testing/kunit/kunit_tool_test.py | 16 +++++++++++++--- ...st_is_test_passed-no_tests_run_no_header.log} | 0 ...t_is_test_passed-no_tests_run_with_header.log | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) rename tools/testing/kunit/test_data/{test_is_test_passed-no_tests_run.log => test_is_test_passed-no_tests_run_no_header.log} (100%) create mode 100644 tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_with_header.log diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index c3c524b79db8..b88db3f51dc5 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -338,9 +338,11 @@ def bubble_up_suite_errors(test_suites: Iterable[TestSuite]) -> TestStatus: def parse_test_result(lines: LineStream) -> TestResult: consume_non_diagnostic(lines) if not lines or not parse_tap_header(lines): - return TestResult(TestStatus.NO_TESTS, [], lines) + return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines) expected_test_suite_num = parse_test_plan(lines) - if not expected_test_suite_num: + if expected_test_suite_num == 0: + return TestResult(TestStatus.NO_TESTS, [], lines) + elif expected_test_suite_num is None: return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines) test_suites = [] for i in range(1, expected_test_suite_num + 1): diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index bdae0e5f6197..75045aa0f8a1 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -157,8 +157,18 @@ class KUnitParserTest(unittest.TestCase): kunit_parser.TestStatus.FAILURE, result.status) + def test_no_header(self): + empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log') + with open(empty_log) as file: + result = kunit_parser.parse_run_tests( + kunit_parser.extract_tap_lines(file.readlines())) + self.assertEqual(0, len(result.suites)) + self.assertEqual( + kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, + result.status) + def test_no_tests(self): - empty_log = test_data_path('test_is_test_passed-no_tests_run.log') + empty_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log') with open(empty_log) as file: result = kunit_parser.parse_run_tests( kunit_parser.extract_tap_lines(file.readlines())) @@ -173,7 +183,7 @@ class KUnitParserTest(unittest.TestCase): with open(crash_log) as file: result = kunit_parser.parse_run_tests( kunit_parser.extract_tap_lines(file.readlines())) - print_mock.assert_any_call(StrContains('no tests run!')) + print_mock.assert_any_call(StrContains('could not parse test results!')) print_mock.stop() file.close() @@ -309,7 +319,7 @@ class KUnitJsonTest(unittest.TestCase): result["sub_groups"][1]["test_cases"][0]) def test_no_tests_json(self): - result = self._json_for('test_is_test_passed-no_tests_run.log') + result = self._json_for('test_is_test_passed-no_tests_run_with_header.log') self.assertEqual(0, len(result['sub_groups'])) class StrContains(str): diff --git a/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log b/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_no_header.log similarity index 100% rename from tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log rename to tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_no_header.log diff --git a/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_with_header.log b/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_with_header.log new file mode 100644 index 000000000000..5f48ee659d40 --- /dev/null +++ b/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run_with_header.log @@ -0,0 +1,2 @@ +TAP version 14 +1..0 -- 2.32.0.93.g670b81a890-goog