Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2019891rwi; Thu, 3 Nov 2022 11:39:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44BVzlheNGAN5KCCn0rU6SPk7NXG36Oa2E1tEO+yok6QAqksqk9pXZqD9RpFivdSfEi83U X-Received: by 2002:a17:902:db12:b0:186:ba4b:a4af with SMTP id m18-20020a170902db1200b00186ba4ba4afmr30910665plx.13.1667500799433; Thu, 03 Nov 2022 11:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667500799; cv=none; d=google.com; s=arc-20160816; b=H4qvW/NhjeIXjacPydQzN9meTUSElhdCi/mFfRV45U5DcUwc8k6XZ5MKnvp5as0bww IugKYdPuy8A9ErPfHAAJiP/tIpoRuPmlYzk864wDVcRMtxHRBEFv3yYCSNvgH7F6Pudh +JXBU06736VgTtRsbb9D0VivZa+1K73qMRUi0YAtq60WWyYZbqhMPN/EmL1vPQB9Urui EPVGWco6dEPqz9qs3WxDwdf+gDaAfoQdOcwyWn41iXJ9sqlawKqmkpQgGvDAnmQbhxxi CPOY0NnJwRKOvwmtUebT8F4FkDKKcMQRuny2Y8JMKnWsvYouEXNFj/NeOWtb9W5/dTzc t4/g== 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=x5UDPV/B3DbeeLLd5UNbXGu4AbVddR846UKz8icVwAg=; b=I1nsXXzSEyIeEgL8SMs59qyTsXvsAmmu5rNtyvuoeVPobMtcAYh8pw9RtvleP63uYD 21sXD6i0uLvyB5TUbW6KFhCUWvQiAwdSKxC7AISge12o5jZzwQBIyY+gXxgSTGiJM9Z4 toNsnvHN6Rt7GWA4RjCbG7z9fQVAThYlQdzX57Sq/L66vtt4knOjzxOL6/oB55nccqnP Gcfs7J+hsM2oGGSWc7cb6Idax7q6pUWvmwjPDZt1oo9ra19J3KhkfgJlgJOGDNDFRYfd UUaeF+2WSb1ntzOPmWLUf32YvGvghIVxxTUzY72Ds8ww5/pzz+NCyrh2ofGeTnNY0e4M bmVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ARL1Z+nO; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a170902cec200b00180680b8f1bsi1765860plg.264.2022.11.03.11.39.46; Thu, 03 Nov 2022 11:39:59 -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=ARL1Z+nO; 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 S231273AbiKCRsm (ORCPT + 97 others); Thu, 3 Nov 2022 13:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbiKCRsU (ORCPT ); Thu, 3 Nov 2022 13:48:20 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 882F61DDE6 for ; Thu, 3 Nov 2022 10:47:48 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id b1-20020a17090a10c100b0020da29fa5e5so1252187pje.2 for ; Thu, 03 Nov 2022 10:47:48 -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=x5UDPV/B3DbeeLLd5UNbXGu4AbVddR846UKz8icVwAg=; b=ARL1Z+nO3QvcQjmNyeaET5LfZwzcYuge5A11iFR6e70VYgXXlHx0UmBGpYP+zmGc6G q9yFicoNpr1w5MlK6VCq3mcp7j7kvFdNBKYDrty3rK5Hnaj+v+lSK8WQDBmnkhyRA1LW sg4hbNrm7x+kJUaUyva3scLdS7rV6Vs9Q18AYTOYF2p9NTo8oE9y8xjMECrv1eR9fHo7 k4WAemX/5vei32E7ZnfyM+v2Kyatx8MOsT9Mxsk6Y+wbWIK+ItpVhSmafBOwCv4rrRV8 U4qyVaL/hEuq5tQj3ALAv4vAopBQ/kq9AyRbPEijppOJ/N1Xc8x3Wj13MP9SOGCtFzu7 Ztww== 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=x5UDPV/B3DbeeLLd5UNbXGu4AbVddR846UKz8icVwAg=; b=lcvRlkjqSu8EYtWfDVrdz/YNNBHD3pvsxKgFXoRzyV1zEjUhuye4PGL+kqoepBW3yr EdmT03KXtPukiIbE50tT5rY4KjOJMtWVMon2H4jTpuPlahYdKRY68EfB6ZX+Yr82drUw IpJ6k79KIdFtECk7amsMSjkKD9Tax+v6lFaXtu4Ip/K73b0hfWb+8oGLvbHfoM3T5T/r Bsr0HvknKRLn/aG9fl7v4S7t7PdqQy7fFN3FOe07HR1HFen71m7529UxEOvTYtyg6v6n d+StzBee4qVlEJifQnG+rpoKsnFU8f31oyLo5A/pvpjUmQAgeXCi/OESf2CK03n7Q7a/ u0IA== X-Gm-Message-State: ACrzQf0sbmCLyPCM6q/R8zJTx5MwxPyR56uQxiwR5fSdeOIm6OjPa1gx rr2RiZpiWcdlvceZbzb0SE0TnZj7XyMSHA== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a17:902:c949:b0:187:2be9:9f0a with SMTP id i9-20020a170902c94900b001872be99f0amr18975485pla.58.1667497668055; Thu, 03 Nov 2022 10:47:48 -0700 (PDT) Date: Thu, 3 Nov 2022 10:47:38 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221103174740.3492603-1-dlatypov@google.com> Subject: [PATCH v2 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 Content-Type: text/plain; charset="UTF-8" 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=unavailable 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 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 --- v1 -> v2: just rebased onto linux-kselftest/kunit --- tools/testing/kunit/kunit_parser.py | 25 ++++++++----------------- tools/testing/kunit/kunit_tool_test.py | 4 +--- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 94dba66feec5..a56c75a973b5 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 @@ -71,27 +72,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 7dcd67003b23..440a273f1d21 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -182,9 +182,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) base-commit: 29ad37f740d302d0f27374edaf85fe8978e45ba9 -- 2.38.1.431.g37b22c650d-goog