Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4450443ioa; Wed, 27 Apr 2022 04:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzuA0o72OV8554IT3WC3toeZqnZi2z/TKfVUt2lKm4OqpsvE1g20+3Czx8mwY5WC0WKzlV X-Received: by 2002:a17:90b:3850:b0:1da:2df7:46c7 with SMTP id nl16-20020a17090b385000b001da2df746c7mr4021213pjb.123.1651058164742; Wed, 27 Apr 2022 04:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651058164; cv=none; d=google.com; s=arc-20160816; b=00dIGjq2kajh/vR63tr+6TZi+5uHuQccgCtfOggsusgYnHuHkcvEx16FJLtjU9S4fH iHOQXsjh5W1e2qYEb18IH0pBA4Tn4xDvlzecEK7d70RUYCNr9bHTKsatcsTy8oXNs9PF sxd9KjNPLHzsCGdsmKMdz6Ul8ZPgQLPk8Efp+sEViCUkMsrVC/Ldea1HDivwiw+Zd3ry Ef5OAjsYbkra8FDni6vJE2qzg++sNYamTL1iO2OKwXixq9d6k9lT3MP+NTnU67gEKFjq IK3mscWF5+MRw8dNvV2c6GvpCXQ6QIULroukW+DCdHiMGufimxkyylw7aKRtGwuZ/lVQ Dilw== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=or5Qq2p7tQiEUi1yK0d0OBa9R3d0Zk6QJTQ8FgXJE+o=; b=OBABRtG4pTZ12mBhFJsrdxi9VKmjabzLK8bXcqneWQcjJd/lAB4owVfBPfw3PqZ5m6 qaISoq5QUK5Oo7p2rESUPDUVsRAPkKA/DGQMDMVJuO8rZCwEIIF85jwPQ9s+W1MEkZdr yHveVBgFfo4/VXGvWX4bqzpA6pMZcDXVC5+T/jy08Syfc2yhinYyOC7kXMbnK812gqxN spY3Rf01smMvBuYBoZEsHQOwCzqD+pp9Ywi3yUyv+b9F1drd6rMfiCCy0Ieux6Co4cBA JCS+D9n8ekb+IM68afiNBX0wOfeLhI3G+yNbdcERJFySLAlUvHnHNLc/VqqD3EkpciMg wYCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZkCcDwTB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bg1-20020a056a02010100b003816043f0f9si1191837pgb.750.2022.04.27.04.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZkCcDwTB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1F84306726; Wed, 27 Apr 2022 03:09:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349144AbiDZRhL (ORCPT + 99 others); Tue, 26 Apr 2022 13:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349112AbiDZRhC (ORCPT ); Tue, 26 Apr 2022 13:37:02 -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 29D529398C for ; Tue, 26 Apr 2022 10:33:54 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id d22-20020a25add6000000b00645d796034fso10310592ybe.2 for ; Tue, 26 Apr 2022 10:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=or5Qq2p7tQiEUi1yK0d0OBa9R3d0Zk6QJTQ8FgXJE+o=; b=ZkCcDwTB2+WctizJTQngKWojlMstlRfAqBs/079sDbtyHpseXXnpVsAD6yBLnCHPfy P7OhCQkVW8Eu3aMBKfWLi84413eq2P7Ue5EUwbHZ3WzNfo0jg1wPvODme2yAjManRV38 7/KnD9g/WsklSuj/G6yfpmqzabo12NyMF7u+aCx3HhVp9i6q0E+75A0H4PNNCYzFFFbI 8w+2GiBKm5ZtDmUYpehkNekuROPBpMMyVfJdshXK1nTvwiGZPrYYAXmNWTqeSfuRTd// 2Pe5FdXFc7iD8Glnm5263Rd5ZNKLHDyvtunVom6AakO5jf0I4Xa76D+AK7qJNFXOIoKM XQRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=or5Qq2p7tQiEUi1yK0d0OBa9R3d0Zk6QJTQ8FgXJE+o=; b=lITgvArUNtHg1eASt9KQYGM8BjXVP594jCXx0s8YmVNRH8IbbdPq3oLwnf83sFfA5G TkxufsZ5ldclZ8dVPlj8owqunqrojx1MxH6feqzjHBTETvjgq3TY+Stkgrr3coDCkM0S OAHnRG45L3eg7UU42mYN+6V9IXFl1JLYzbrm6OrbVlZURka3xxueU8RsjJOEDwvu/GJw vaWgZGIU/tXcMID12u7TSZ1Frax+8g4cwYi6EHubs9MMLY6K1B+S3/UE+wfp3FPSjz7a w8g8Be0CK2a+L1wCJDafaa8YmNvVnlJK9dox8Ac2DX+ikl7kXaeePq3Z09gqCUc6PW8o vnMw== X-Gm-Message-State: AOAM531XGviWnNQlDYd3KTyjD9fNosm9sPhb6P15A+UPL4gixv1hI0pu DWuPSFKlhO6EzVIaUFzFdDCant4uNhDQPA== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:b03d:8d64:4a06:2c5f]) (user=dlatypov job=sendgmr) by 2002:a25:da84:0:b0:648:423e:57b0 with SMTP id n126-20020a25da84000000b00648423e57b0mr13859274ybf.137.1650994433438; Tue, 26 Apr 2022 10:33:53 -0700 (PDT) Date: Tue, 26 Apr 2022 10:33:34 -0700 In-Reply-To: <20220426173334.3871399-1-dlatypov@google.com> Message-Id: <20220426173334.3871399-3-dlatypov@google.com> Mime-Version: 1.0 References: <20220426173334.3871399-1-dlatypov@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH 3/3] kunit: tool: minor cosmetic cleanups in kunit_parser.py From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: 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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no 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 There should be no behavioral changes from this patch. This patch removes redundant comment text, inlines a function used in only one place, and other such minor tweaks. Signed-off-by: Daniel Latypov --- tools/testing/kunit/kunit_parser.py | 71 +++++++---------------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 45c2c5837281..d56d530fab24 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -46,10 +46,8 @@ class Test(object): def __str__(self) -> str: """Returns string representation of a Test class object.""" - return ('Test(' + str(self.status) + ', ' + self.name + - ', ' + str(self.expected_count) + ', ' + - str(self.subtests) + ', ' + str(self.log) + ', ' + - str(self.counts) + ')') + return (f'Test({self.status}, {self.name}, {self.expected_count}, ' + f'{self.subtests}, {self.log}, {self.counts})') def __repr__(self) -> str: """Returns string representation of a Test class object.""" @@ -58,7 +56,7 @@ class Test(object): def add_error(self, error_message: str) -> None: """Records an error that occurred while parsing this test.""" self.counts.errors += 1 - print_error('Test ' + self.name + ': ' + error_message) + print_with_timestamp(red('[ERROR]') + f' Test: {self.name}: {error_message}') class TestStatus(Enum): """An enumeration class to represent the status of a test.""" @@ -92,8 +90,7 @@ class TestCounts: self.errors = 0 def __str__(self) -> str: - """Returns the string representation of a TestCounts object. - """ + """Returns the string representation of a TestCounts object.""" return ('Passed: ' + str(self.passed) + ', Failed: ' + str(self.failed) + ', Crashed: ' + str(self.crashed) + @@ -130,30 +127,19 @@ class TestCounts: if self.total() == 0: return TestStatus.NO_TESTS elif self.crashed: - # If one of the subtests crash, the expected status - # of the Test is crashed. + # Crashes should take priority. return TestStatus.TEST_CRASHED elif self.failed: - # Otherwise if one of the subtests fail, the - # expected status of the Test is failed. return TestStatus.FAILURE elif self.passed: - # Otherwise if one of the subtests pass, the - # expected status of the Test is passed. + # No failures or crashes, looks good! return TestStatus.SUCCESS else: - # Finally, if none of the subtests have failed, - # crashed, or passed, the expected status of the - # Test is skipped. + # We have only skipped tests. return TestStatus.SKIPPED def add_status(self, status: TestStatus) -> None: - """ - Increments count of inputted status. - - Parameters: - status - status to be added to the TestCounts object - """ + """Increments the count for `status`.""" if status == TestStatus.SUCCESS: self.passed += 1 elif status == TestStatus.FAILURE: @@ -283,11 +269,9 @@ def check_version(version_num: int, accepted_versions: List[int], test - Test object for current test being parsed """ if version_num < min(accepted_versions): - test.add_error(version_type + - ' version lower than expected!') + test.add_error(f'{version_type} version lower than expected!') elif version_num > max(accepted_versions): - test.add_error( - version_type + ' version higher than expected!') + test.add_error(f'{version_type} version higer than expected!') def parse_ktap_header(lines: LineStream, test: Test) -> bool: """ @@ -440,8 +424,7 @@ def parse_test_result(lines: LineStream, test: Test, # Check test num num = int(match.group(2)) if num != expected_num: - test.add_error('Expected test number ' + - str(expected_num) + ' but found ' + str(num)) + test.add_error(f'Expected test number {expected_num} but found {num}') # Set status of test object status = match.group(1) @@ -529,7 +512,7 @@ def format_test_divider(message: str, len_message: int) -> str: # calculate number of dashes for each side of the divider len_1 = int(difference / 2) len_2 = difference - len_1 - return ('=' * len_1) + ' ' + message + ' ' + ('=' * len_2) + return ('=' * len_1) + f' {message} ' + ('=' * len_2) def print_test_header(test: Test) -> None: """ @@ -545,20 +528,13 @@ def print_test_header(test: Test) -> None: message = test.name if test.expected_count: if test.expected_count == 1: - message += (' (' + str(test.expected_count) + - ' subtest)') + message += ' (1 subtest)' else: - message += (' (' + str(test.expected_count) + - ' subtests)') + message += f' ({test.expected_count} subtests)' print_with_timestamp(format_test_divider(message, len(message))) def print_log(log: Iterable[str]) -> None: - """ - Prints all strings in saved log for test in yellow. - - Parameters: - log - Iterable object with all strings saved in log for test - """ + """Prints all strings in saved log for test in yellow.""" for m in log: print_with_timestamp(yellow(m)) @@ -635,20 +611,7 @@ def print_summary_line(test: Test) -> None: color = yellow else: color = red - counts = test.counts - print_with_timestamp(color('Testing complete. ' + str(counts))) - -def print_error(error_message: str) -> None: - """ - Prints error message with error format. - - Example: - "[ERROR] Test example: missing test plan!" - - Parameters: - error_message - message describing error - """ - print_with_timestamp(red('[ERROR] ') + error_message) + print_with_timestamp(color(f'Testing complete. {test.counts}')) # Other methods: @@ -794,7 +757,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str]) -> Test: def parse_run_tests(kernel_output: Iterable[str]) -> Test: """ Using kernel output, extract KTAP lines, parse the lines for test - results and print condensed test results and summary line . + results and print condensed test results and summary line. Parameters: kernel_output - Iterable object contains lines of kernel output -- 2.36.0.rc2.479.g8af0fa9b8e-goog