Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp860031pxv; Thu, 1 Jul 2021 10:53:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQ5iiRm9D+OM9R0U3aEicqDTRolJ4UikAmXuvY247EKWTZ6HkfutUU+wlH4ch6V4mswbcV X-Received: by 2002:a6b:cf05:: with SMTP id o5mr490526ioa.35.1625161999921; Thu, 01 Jul 2021 10:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625161999; cv=none; d=google.com; s=arc-20160816; b=aizBSV8NYVqm2MfPmNzomxbxgZ/lXUz2G1LR3OeLh9e1bKjiNmDsj9TPwucbAYqY5m REPPrWxYmZHf+Yu2K8FtBPnrtNFkzdelBlyvWwEX33NRuj6Q5/5cV86qlvirdk2Q8Oo6 l0Ll8z0TqtuTDa5nb5RAAzyJS9E5kHb2Xty+gmNbQoVaBl6hwqutCrI8rgtvIXqHDhAW QAoBJYewfBdnW5AMhaq9vt4LlcLHkTkmWJCf98QIg4elueCY052T3z68Fs8sgcj1XJ7O n8Gb3sLCax6lORFMqBAxlFkTltetSYAY95DppwvB5JazZMqXJfxUYfCnhlYPJ9CSlPyS ZDgw== 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=TWNh4NT6Sbv641LYm1mUzBahkZ28Mzb42DLCx2xe0ZA=; b=kj96yVEgr4FuaZbtesgN2D7MxWTmg9XqT0I9loVOuEkQ78wSAgfEco1cR/5/ysJEOv CIwHpdCr5TahZ0Imp04/B1zfHaLaxHUL8zo2F0fRPtOkUKHwZWka/WkeXQaBobxUXJ47 WyV7RCHvxnG5WYtM8nZFkBrrjQwjSAaQSCwNCIk3xhqgR7b5TandIOQn0G0566j63F+x Kwbft+sVkmkF7uo4KUTOdkOS5+o7GV0C+nbDtpLbOH6bzTl0PCKElQDGNg8/fmQ1zxHm MOoJFtylrZzudoszT69hAtPuEKIQp1cuMqMummjFWng7kbBLrX2tdvkD53mjVG0hcS+m hQQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="rorNy/OC"; 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 m22si632246jat.35.2021.07.01.10.53.07; Thu, 01 Jul 2021 10:53:19 -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="rorNy/OC"; 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 S230101AbhGARzH (ORCPT + 99 others); Thu, 1 Jul 2021 13:55:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbhGARzG (ORCPT ); Thu, 1 Jul 2021 13:55:06 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDBDC061764 for ; Thu, 1 Jul 2021 10:52:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id t11-20020a056902124bb029055a821867baso3544549ybu.14 for ; Thu, 01 Jul 2021 10:52:35 -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=TWNh4NT6Sbv641LYm1mUzBahkZ28Mzb42DLCx2xe0ZA=; b=rorNy/OC3D360vKowzuz0ZoBEw2kDS1Upmd1ElNP0uIi9b26hzxAgHOCj0FS7VKRPu vsw0AVfuOP4sABf7Qi3KMugltLve4mUZBIMCE1nk086fF6eNjR7cT03uc8j3GTZCw8e9 4V+j2OebhHSLMTzoPR470rJ8PGEoByuQPQGIKN74rNDMzuAd7W2zPXqE4cSAsNAf1gDv o2Ag6lQcEZDhr6lJgtJ8FhYzzhCWhzk69jxo7iyYfs3MF5a3N27KHGPQhZlkLTpZ2Xdw LzMz43NbR9jLLeka0KB+kdGmGHDgh+GJ+eNG8q8l2fevWYuHFbIdrxTAer4nQkK/e5c6 afoA== 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=TWNh4NT6Sbv641LYm1mUzBahkZ28Mzb42DLCx2xe0ZA=; b=qzpw09a76Gci4nyQQB1bfr8R2khj9WDIaedb/Y6qRsek87VCfgsxYXKm+0AHy5yPE0 PketpydHI3BatXCe7siPybq9Krts2oMluhSKr78bkXSljKO/Fam2OD4caM3GEOUP5Q1L CesxBX901O4c0cvRh8CYSulZni4YYghhZOcJsKKCYKrym2X/kKfMmWE7v1JJBFznJmjV r3AlipKpIMClv123tdQecMdy85oZEqW0BWEGaWcjgeqLFdU0afsmTFaXmENAVXy9A9E+ 0NYK/OQ+aguC1QJsfWZjwWKduymbRU50F0rjj1Ltz2Nyzz5+7miTtp0lws1ClxGf2oA2 jKOw== X-Gm-Message-State: AOAM530PULy2v94UuBhHAUhxFUjgWWvhJ6dnk0W1n7ED9n87wJCbXvOy Ne01pNObnGhMg0BU1Tx7c5HCYc4I3g== X-Received: from sunrae.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2814]) (user=rmoar job=sendgmr) by 2002:a25:814b:: with SMTP id j11mr1360198ybm.212.1625161954632; Thu, 01 Jul 2021 10:52:34 -0700 (PDT) Date: Thu, 1 Jul 2021 17:52:31 +0000 Message-Id: <20210701175231.1734589-1-rmoar@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2] 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. Signed-off-by: Rae Moar Reviewed-by: David Gow Reviewed-by: Daniel Latypov --- V1 -> V2: * Simplified log for the test for TAP output with the correct header but no tests * Added examples in commit message of error messages before and after --- 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