From patchwork Wed Nov 2 16:40:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 14392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp18800wru; Wed, 2 Nov 2022 09:46:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5FjTocBK8Vi3LUx/B26r42QY/PV+fV1XZIjQ6D8hVfzbEFyMHSNiSL7jpdhf+kKLPtlRyf X-Received: by 2002:a05:6402:51ca:b0:462:273b:6ad6 with SMTP id r10-20020a05640251ca00b00462273b6ad6mr10621532edd.119.1667407560719; Wed, 02 Nov 2022 09:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407560; cv=none; d=google.com; s=arc-20160816; b=yJYW/bv4zSlu+7qQnGvm/7Xl7OPRfzO+6R6au1EVGo4YNFvbQqyH6wG2sWUtR+/SZV OV8LpVL1O2v4VUN9JxZMKjh5QxtdstiUxCoUo7jOEDDZfmD+7FftdeciIBiFXJktPYHt e2VbAsQvSVChCZy8n9OOSIgqVNblRZndduQI6OJVWSrKNQXRZ1AvDLLXMElxKrNxAsou Y5CI96HaQlwzYsBdpW+pRfMHyCD7Bmq/bCBED5Uv0e7NSYV8G9O6jmSXDpEx7+L7JLtk Dyecb64JU8rB1NEQn1NqlwKivUct1Z8K49xv9GzrWpxhkCZryRCJ9QFBP30YKSJYboUc Df9w== 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:message-id:mime-version:date :dkim-signature; bh=ZjB45a45rutWjA+XLmdtGaPTf89LQ7I82Y87jESqw/E=; b=aX05s8muRXZaA7lWC5tQTFZXWrJBVQ8FLN1inBz6ZWMZK7uumzD+vD4nJp3bk/TsFI ux39JznK5PDx16Ffsm9vH3idwO5xqWXcDRglsNlHSdHPt4U+m/qx8UkiRQ+MoLTRTWro Y00z/wOAH290kqAWDIoaQP0J5oR0/8vV09/X89eYs5TbPBiLmpKRa9KHcKZjQWwzWyAE +g+2C6vmrC4TmowCta7JpN8sl/8tNe4WgILxvBKdp8Ompk4A9EYxOwWPxL5+2VHX09iM 8g31luEc9gC34mT5UDqQ45pKZJHaaN6uQRx0JbyoIfvQHWzOUEPpx6vVJHcfkeTFf/gZ DY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TThmGMaK; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a50d6ce000000b00461606e36dbsi17530487edj.131.2022.11.02.09.45.29; Wed, 02 Nov 2022 09:46:00 -0700 (PDT) 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=TThmGMaK; 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 S232073AbiKBQo6 (ORCPT + 99 others); Wed, 2 Nov 2022 12:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiKBQoi (ORCPT ); Wed, 2 Nov 2022 12:44:38 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3332C1091 for ; Wed, 2 Nov 2022 09:40:42 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3735edd4083so13057957b3.0 for ; Wed, 02 Nov 2022 09:40:42 -0700 (PDT) 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=ZjB45a45rutWjA+XLmdtGaPTf89LQ7I82Y87jESqw/E=; b=TThmGMaKDwr5Yq89Ge7CBv9F3nGKgkxzMezafPFOSGrcBJ62ynXFUl1+A7oOaMXc4B +jQuiVsVT+anfNPfGaAWXZiDOowjg4GflM2pwF894XsOX2UIzrb+DjfCamaRVRUaDI9H rBT/Z63Icyqp6BwC6Y4tkHQ3wGyVnD6/+ayrJE2lY2PEprcJq584Euoi+IrU32cHas2E q6wROmt+Y/acS2U1YWQn2duBlVITJeapYk444PYALlP32+zSB6gogeNgzdyXS4AVdIqn rgt42cIbAAvZMMmxlVRLWqroBNwo52oaFhMHClNLuEVERyAlaOvplSgq6mp2AcNjPJ2+ fYhA== 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=ZjB45a45rutWjA+XLmdtGaPTf89LQ7I82Y87jESqw/E=; b=szYEeMQ/X57xkXTy5d2/zSXtzcgwtEbi9m+RnvPdhXtOh8MqinNAK/6DxbOK0DcN9i dGa0I+BCl3ehT9+xCr3z70uPH0LpllobMgELr+8gqTeY4w+9c+4OK7W1CIsWwb9lCFl4 zoI6h6MSOw9V6WfoJ7zpW+cs0UypDq3W8D1kexSvnA5vkNj1TM6WeCEdAxsVTDuDKVjm g2oxPmvc9BgGHtMMgknXYD5RvJr8HnD32Xw45RyCZb7py7s1th1U5WQ7jU3CEPeQY8sY IhUObzftrx+2t7EcA5igmjaakrm0/92ymBRstvJtp/DuICik95rFtbleiEBRtNxqWwLO Hw/A== X-Gm-Message-State: ACrzQf25jEujw1lxBqlblyEnYDQ0wqAX/xWbP30HNVIPHPs2GpBb6NMw 0QM34jNLh+kumjZmL1Kb7oFx8w7ORvFaMQ== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a25:744d:0:b0:6cb:9331:244b with SMTP id p74-20020a25744d000000b006cb9331244bmr24381988ybc.140.1667407241468; Wed, 02 Nov 2022 09:40:41 -0700 (PDT) Date: Wed, 2 Nov 2022 09:40:03 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102164005.2516646-1-dlatypov@google.com> Subject: [PATCH 1/3] kunit: tool: make TestCounts a dataclass 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748403550777202553?= X-GMAIL-MSGID: =?utf-8?q?1748403550777202553?= Since we're using Python 3.7+, we can use dataclasses to tersen the code. It also lets us create pre-populated TestCounts() objects and compare them in our unit test. (Before, you could only create empty ones). Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit_parser.py | 25 ++++++++----------------- tools/testing/kunit/kunit_tool_test.py | 4 +--- 2 files changed, 9 insertions(+), 20 deletions(-) base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737 diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 1ae873e3e341..f022966858f2 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -10,6 +10,7 @@ # Author: Rae Moar from __future__ import annotations +from dataclasses import dataclass import re import sys @@ -67,27 +68,17 @@ class TestStatus(Enum): NO_TESTS = auto() FAILURE_TO_PARSE_TESTS = auto() +@dataclass class TestCounts: """ Tracks the counts of statuses of all test cases and any errors within a Test. - - Attributes: - passed : int - the number of tests that have passed - failed : int - the number of tests that have failed - crashed : int - the number of tests that have crashed - skipped : int - the number of tests that have skipped - errors : int - the number of errors in the test and subtests - """ - def __init__(self): - """Creates TestCounts object with counts of all test - statuses and test errors set to 0. - """ - self.passed = 0 - self.failed = 0 - self.crashed = 0 - self.skipped = 0 - self.errors = 0 + """ + passed: int = 0 + failed: int = 0 + crashed: int = 0 + skipped: int = 0 + errors: int = 0 def __str__(self) -> str: """Returns the string representation of a TestCounts object.""" diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index e2cd2cc2e98f..9fa4babb2506 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -179,9 +179,7 @@ class KUnitParserTest(unittest.TestCase): kunit_parser.extract_tap_lines( file.readlines())) # A missing test plan is not an error. - self.assertEqual(0, result.counts.errors) - # All tests should be accounted for. - self.assertEqual(10, result.counts.total()) + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0)) self.assertEqual( kunit_parser.TestStatus.SUCCESS, result.status) From patchwork Wed Nov 2 16:40:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 14393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp18953wru; Wed, 2 Nov 2022 09:46:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cQQIaMyOK0kPUdMq/Jq29opQ4QChWB3Khgz7fElhDHG08lSCgnZNFewKZ4rczk+zltD6B X-Received: by 2002:a17:906:1f48:b0:7ae:77d:bac with SMTP id d8-20020a1709061f4800b007ae077d0bacmr3306951ejk.708.1667407585555; Wed, 02 Nov 2022 09:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407585; cv=none; d=google.com; s=arc-20160816; b=Cnd/DaZCOOqFIquDBgWtCFS5sZKjFWVNCiB9HXVmPcb6Md3ibSJDbGLvRkHFUWjTfq Hj7BwbMwE3dJkaJicIUL8T2VwXI6IfDsGe9r0vSkKILjG6hcFoAfamTMhutogvlljSZP vTdR3fUgzanvpWvQieftBCk9NTD2zIncAkBN9vWtxy0Szt4bIbrxKCABXESsv/eGyXps TyGnSTqOOo1HaeYFBMLiVUYIpd2hYn/p2myeH5ZGQBsnbX83d4tkShevq7t6Qxr92DLw tl02envBqC/lNGX629jgHBZxZAr2JS9d3824PCfgBUZia6SRbYqSBRy/67Gy2ykGb/IG 32Ng== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=KIew2SL18zFJ6u7nCVq8c3JgfzFW65AAtUvUlav4Acg=; b=OFfudOMYgmEXZHjikycX8wPn3DfOk3VQ3UK8m3r3LdyeuP/BJaopbIoXDfzu0gGsKw xFt0MbiYQIQz/4DGbsHuMLumLzo4pj8jLhNEEuDDRCN/p8PdtKuU/5XoY07H0qnS9EKg ZOrLRj4qto8psuDtrryiZIqAQcmJpNgDTU2J5fq5m+Ws3XXsKE1HLC2WHrKF/u7wVQvD +D3nUl3n0Rm47HuqtvHh/rldUhlnZX+yOr3CLzFZMvS1SP4HR03Jk/NTeuXUAvLNtq9Y UzNc3zqlDgOlYbMrkFL2wxypiD2Ncp7mbgmuGtcscMcDUWAJeP0258j3yCP6tWux3NTC fbcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=airvtcUY; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go44-20020a1709070dac00b007313312730esi19178790ejc.85.2022.11.02.09.45.49; Wed, 02 Nov 2022 09:46:25 -0700 (PDT) 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=airvtcUY; 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 S232081AbiKBQpH (ORCPT + 99 others); Wed, 2 Nov 2022 12:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232069AbiKBQoj (ORCPT ); Wed, 2 Nov 2022 12:44:39 -0400 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 9CEE7111D for ; Wed, 2 Nov 2022 09:40:43 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id g6-20020a17090a300600b00212f609f6aeso1484265pjb.9 for ; Wed, 02 Nov 2022 09:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KIew2SL18zFJ6u7nCVq8c3JgfzFW65AAtUvUlav4Acg=; b=airvtcUYcZZ8MHdLIhi3pbgBZi6gh+e7/dZtX9JFrnv3hRtBujUKQyyGPN5qk0Y8nt phFxU+70nNgIiGjKiWMhXn7b5yoptQzXEk/ouwpXGh75dSrNYJZOiKAWOP5BemNzSyOb Tdm7veavPLEGXo+SKLYqgOFO2HTT3xiaufEW51KFiU/3PveV9Ab3/jCb/8ZXNnG8ZvPO fqZoPNkoOLVgF7ooqKPcI7pY/L+91nIxxuC+u6uuAIZT3uXaxqRhc1/TtxEUpufDFc7D SdR6pl37Hb2iD4VJQ/Xc/ZkU02fVDASFIoCgeLGeG0hmO67+MmID9x2/2hIDUMztta0u 2K6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=KIew2SL18zFJ6u7nCVq8c3JgfzFW65AAtUvUlav4Acg=; b=ziuKwIaL199Bsw/fEzIYr3ntwh872iENILEdloFiUuLtw/T61NH5THygxJAvrNq8SN 6+A9EzxA/js6w8pxaDqv/i+Q5f2bWOoB2HkLX+3D6K7Osp/awJfjcig+ukWQAqJzc5tc pjlq/EH9+l3NRO7fjoZEggR9zr1BsHTFKEnsBk/DszI2fbKfKrnN6XJ1KsGh26feCRzs GV4atOnZsbk1gjXMAklM+C1HfrJ4KxSBuIOjXkw+W7tSLZCQRKVwU28ZypH4qcqlx5Gm X1VvxsVWX7ZBqvGm2bmRcv8orwV6+ny7puh0JoE+QyrES5whuKtwmp4z3lwIzYn8UBwj x7SQ== X-Gm-Message-State: ACrzQf0+JNFbZ1IxubQYFncMd3Iqj86DtfEaGbXfN3LxFmKEaH70JMMJ t7wNM32EdFVn2E0PzplV0L3yVpC682tTlA== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a17:90b:1bc1:b0:213:e2af:b1f4 with SMTP id oa1-20020a17090b1bc100b00213e2afb1f4mr17299469pjb.47.1667407243096; Wed, 02 Nov 2022 09:40:43 -0700 (PDT) Date: Wed, 2 Nov 2022 09:40:04 -0700 In-Reply-To: <20221102164005.2516646-1-dlatypov@google.com> Mime-Version: 1.0 References: <20221102164005.2516646-1-dlatypov@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102164005.2516646-2-dlatypov@google.com> Subject: [PATCH 2/3] kunit: tool: unit tests all check parser errors, standardize formatting a bit 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748403576607148391?= X-GMAIL-MSGID: =?utf-8?q?1748403576607148391?= Let's verify that the parser isn't reporting any errors for valid inputs. This change also * does result.status checking on one line * makes sure we consistently do it outside of the `with` block Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit_tool_test.py | 93 +++++++++++--------------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 9fa4babb2506..0063773c0fc4 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -133,33 +133,29 @@ class KUnitParserTest(unittest.TestCase): all_passed_log = test_data_path('test_is_test_passed-all_passed.log') with open(all_passed_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual(result.counts.errors, 0) def test_parse_successful_nested_tests_log(self): all_passed_log = test_data_path('test_is_test_passed-all_passed_nested.log') with open(all_passed_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual(result.counts.errors, 0) def test_kselftest_nested(self): kselftest_log = test_data_path('test_is_test_passed-kselftest.log') with open(kselftest_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual(result.counts.errors, 0) def test_parse_failed_test_log(self): failed_log = test_data_path('test_is_test_passed-failure.log') with open(failed_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.FAILURE, - result.status) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) + self.assertEqual(result.counts.errors, 0) def test_no_header(self): empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log') @@ -167,9 +163,8 @@ class KUnitParserTest(unittest.TestCase): result = kunit_parser.parse_run_tests( kunit_parser.extract_tap_lines(file.readlines())) self.assertEqual(0, len(result.subtests)) - self.assertEqual( - kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, - result.status) + self.assertEqual(kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, result.status) + self.assertEqual(result.counts.errors, 1) def test_missing_test_plan(self): missing_plan_log = test_data_path('test_is_test_passed-' @@ -180,9 +175,7 @@ class KUnitParserTest(unittest.TestCase): file.readlines())) # A missing test plan is not an error. self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0)) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) def test_no_tests(self): header_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log') @@ -190,9 +183,8 @@ class KUnitParserTest(unittest.TestCase): result = kunit_parser.parse_run_tests( kunit_parser.extract_tap_lines(file.readlines())) self.assertEqual(0, len(result.subtests)) - self.assertEqual( - kunit_parser.TestStatus.NO_TESTS, - result.status) + self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status) + self.assertEqual(result.counts.errors, 1) def test_no_tests_no_plan(self): no_plan_log = test_data_path('test_is_test_passed-no_tests_no_plan.log') @@ -203,7 +195,7 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual( kunit_parser.TestStatus.NO_TESTS, result.subtests[0].subtests[0].status) - self.assertEqual(1, result.counts.errors) + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=1)) def test_no_kunit_output(self): @@ -215,6 +207,7 @@ class KUnitParserTest(unittest.TestCase): print_mock.assert_any_call(StrContains('could not find any KTAP output!')) print_mock.stop() self.assertEqual(0, len(result.subtests)) + self.assertEqual(result.counts.errors, 1) def test_skipped_test(self): skipped_log = test_data_path('test_skip_tests.log') @@ -222,18 +215,16 @@ class KUnitParserTest(unittest.TestCase): result = kunit_parser.parse_run_tests(file.readlines()) # A skipped test does not fail the whole suite. - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=4, skipped=1)) def test_skipped_all_tests(self): skipped_log = test_data_path('test_skip_all_tests.log') with open(skipped_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SKIPPED, - result.status) + self.assertEqual(kunit_parser.TestStatus.SKIPPED, result.status) + self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5)) def test_ignores_hyphen(self): hyphen_log = test_data_path('test_strip_hyphen.log') @@ -241,9 +232,7 @@ class KUnitParserTest(unittest.TestCase): result = kunit_parser.parse_run_tests(file.readlines()) # A skipped test does not fail the whole suite. - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) self.assertEqual( "sysctl_test", result.subtests[0].name) @@ -257,55 +246,49 @@ class KUnitParserTest(unittest.TestCase): prefix_log = test_data_path('test_config_printk_time.log') with open(prefix_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(result.counts.errors, 0) def test_ignores_multiple_prefixes(self): prefix_log = test_data_path('test_multiple_prefixes.log') with open(prefix_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(result.counts.errors, 0) def test_prefix_mixed_kernel_output(self): mixed_prefix_log = test_data_path('test_interrupted_tap_output.log') with open(mixed_prefix_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(result.counts.errors, 0) def test_prefix_poundsign(self): pound_log = test_data_path('test_pound_sign.log') with open(pound_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(result.counts.errors, 0) def test_kernel_panic_end(self): panic_log = test_data_path('test_kernel_panic_interrupt.log') with open(panic_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.TEST_CRASHED, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertGreaterEqual(result.counts.errors, 1) def test_pound_no_prefix(self): pound_log = test_data_path('test_pound_no_prefix.log') with open(pound_log) as file: result = kunit_parser.parse_run_tests(file.readlines()) - self.assertEqual( - kunit_parser.TestStatus.SUCCESS, - result.status) - self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) + self.assertEqual('kunit-resource-test', result.subtests[0].name) + self.assertEqual(result.counts.errors, 0) def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream: return kunit_parser.LineStream(enumerate(strs, start=1)) From patchwork Wed Nov 2 16:40:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 14394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp19166wru; Wed, 2 Nov 2022 09:47:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pZkBSPyl+LTgMCMtZwscbdJkXZp89XZqpBz4IuNNe0p8Ng24iQNmuhePTTCdHRRkWmNV2 X-Received: by 2002:a17:906:2681:b0:783:6a92:4c38 with SMTP id t1-20020a170906268100b007836a924c38mr24492723ejc.75.1667407621537; Wed, 02 Nov 2022 09:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407621; cv=none; d=google.com; s=arc-20160816; b=vzcTzYHJnWMTKuGJZ1UGVD845lPKo3uwsRx9atJpRXV09/M6IJ0eRLuvdq5T2bohqU sPxaFONqwdNfeJ4iyHWZWpFL8n78xLO/jTcfTFbgfPukPXHAzdGE6p1d5VyXeWAbjexz X5YJzjI33/E+Cn2NJ1SynKN2CozG3g9/qQZJcuTtG/qVH+q7oxFEieC7PBfuHHT580e6 IS0ek4E2EJmpfRa2W4Wgp0kT0IZ0cgLt+tA3KMfqCtHfa143As+p+oRjyzcSTARkVemA OEDnU5smouGn2K5wg6GqA+rAX6cWriiDdfe9ZtOS5h8vu0EYuBjs8t5ePMShzg96iuZU JVbw== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=YpyV4sjuN6nTtNbz4mfvOqF+6FZYm3YsT8sqkJTRsbo=; b=eDu39BGEXO5t0l1vyA/Wl6AGP4e4GTkIgG93TQ6O36NKE+CNQ2rUSYLPnhqR6VYX/O Q4GIpo0hKNm4u7nJAc7fLdPLPXK14S8iHUlL8Cjd8sadcKvfOFcoib4ER/eTzF1HR64d 1e0kvtpnNk9BmGtIKXlbigF3WiXgg6A3M6kEFyxgkyONVk6tIRtib7mjdRtADOakNHGb ZGHeev80PLYSU+ZR8zNakRDSGo9LaX5DwpQg5JHRbRUkl1O4ieUAQ4xUy9CuccB7tKKb hDBPu+fqxSxrv66BYU6sUxZf5YSN715jVcYAlHRe9VGljOh5k67YNujHebE6bn7weg51 zQew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tYOdkg3v; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020aa7d8da000000b0045bfaaab6d1si13198307eds.48.2022.11.02.09.46.25; Wed, 02 Nov 2022 09:47:01 -0700 (PDT) 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=tYOdkg3v; 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 S232075AbiKBQpD (ORCPT + 99 others); Wed, 2 Nov 2022 12:45:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbiKBQoj (ORCPT ); Wed, 2 Nov 2022 12:44:39 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8048510B4 for ; Wed, 2 Nov 2022 09:40:45 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-367f94b9b16so162842097b3.11 for ; Wed, 02 Nov 2022 09:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YpyV4sjuN6nTtNbz4mfvOqF+6FZYm3YsT8sqkJTRsbo=; b=tYOdkg3vf+59PIaLFlt3AchFCjbgSfE5+sKR/Ibm9yt6tvf4L9pmL54S+KOmiWse82 LH5y2tsuRIQlIw6+jxyiY+OBIrhZ59fPZKJj9ay1usM6BRCSTyP5B7d0hybfCT3bG7K6 bVKYaq4DI4E+j1yO6LoRWzS8Ie91OLuCW982zwz/Es9Xl1EedNUp/WcVIGO40vJ/nQIs vG9QINdWWcmb7eFn7AQS0fAe0OTQ0OCKgaoQj9O7tEZ4GjxlXFkLmRGvj9MN+JhMwkj2 4S3KK+LP8iupGAOh/1/c2ii1SS7tBoc2Pt/u4ZQZ0dHrHcfX7i8Lb9NNDlY+L7q2bMea gDLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=YpyV4sjuN6nTtNbz4mfvOqF+6FZYm3YsT8sqkJTRsbo=; b=D4qKFX3Dw0p9+5LVMAQtN2O+6g5tgIsLWc5nKzj6yg/UW+1VOhCppPisd6CDdE55bQ bcum+FRLJQSCM8/KIkGVIM+wcnsp5Z7u2SzACNr2eW1oYLcvqh1fjVXkZzwfH8WJ+m69 eOUfqGXvBSkIjX6WQChOa9ZMCpU6dorSD8bzNfZ6k/d6RJHIGLPleKm2hSaDljNKIMEP D9tnDJLxEOfZNQd6LEzSXPT56WJ1fJfMSa213ILMkrp/wLUy+8elPpaJl8+/HipemBnb iTkuDxeviKDkDZidfAo7N0Q3ed5+cW8x4Yh2f9PBv75MLiBTl4byOt82MCnmalPZJ0iQ ke6w== X-Gm-Message-State: ACrzQf1kDhxoPz/+guGLhu9BTObnkyFFasoOf+d5SntF9pHGvdEyA2bZ RBjWGM/FW1+GjYfAoiXR4lARt5UmnPARtA== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a81:1e10:0:b0:36b:532a:52be with SMTP id e16-20020a811e10000000b0036b532a52bemr23987758ywe.54.1667407244828; Wed, 02 Nov 2022 09:40:44 -0700 (PDT) Date: Wed, 2 Nov 2022 09:40:05 -0700 In-Reply-To: <20221102164005.2516646-1-dlatypov@google.com> Mime-Version: 1.0 References: <20221102164005.2516646-1-dlatypov@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102164005.2516646-3-dlatypov@google.com> Subject: [PATCH 3/3] kunit: tool: remove redundant file.close() call in unit test 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748403613806164742?= X-GMAIL-MSGID: =?utf-8?q?1748403613806164742?= We're using a `with` block above, so the file object is already closed. Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit_tool_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 0063773c0fc4..c41567eaf3c3 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -239,8 +239,6 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual( "example", result.subtests[1].name) - file.close() - def test_ignores_prefix_printk_time(self): prefix_log = test_data_path('test_config_printk_time.log')