From patchwork Fri Mar 25 01:14:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12791213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70280C433EF for ; Fri, 25 Mar 2022 01:14:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02E1C8D0052; Thu, 24 Mar 2022 21:14:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF9498D004D; Thu, 24 Mar 2022 21:14:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D988D8D0052; Thu, 24 Mar 2022 21:14:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id C20458D004D for ; Thu, 24 Mar 2022 21:14:21 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8DE3224C53 for ; Fri, 25 Mar 2022 01:14:21 +0000 (UTC) X-FDA: 79281137922.12.9945A25 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 199EB4002E for ; Fri, 25 Mar 2022 01:14:20 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E578CB826FE; Fri, 25 Mar 2022 01:14:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0DA4C36AE3; Fri, 25 Mar 2022 01:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170858; bh=nbyQ/0BYVWYhNlOtb8QL9frRoYDtdEEhU+RGzGww2RU=; h=Date:To:From:In-Reply-To:Subject:From; b=0E6gNbzSWUO7PWNpybdFS0jZ7DH1XNuTAPGt4bHeLhLERV/xVAEuotzSKRc4HxnUA pPlLZYB0FORWSAueUjQlnSGamL70iSe5HScXz0QWs7akPdEicnKmoL7HFoMQplwu29 2zl6MKmOK7U+Wq7gsoEwVoNNl0A2jZSgFatZnHzY= Date: Thu, 24 Mar 2022 18:14:18 -0700 To: shuah@kernel.org,keescook@chromium.org,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 114/114] selftests: kselftest framework: provide "finished" helper Message-Id: <20220325011418.A0DA4C36AE3@smtp.kernel.org> X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=0E6gNbzS; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 199EB4002E X-Stat-Signature: 3tprufjahizfioju8tjrmiis4o57s486 X-HE-Tag: 1648170860-740445 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kees Cook Subject: selftests: kselftest framework: provide "finished" helper Instead of having each time that wants to use ksft_exit() have to figure out the internals of kselftest.h, add the helper ksft_finished() that makes sure the passes, xfails, and skips are equal to the test plan count. Link: https://lkml.kernel.org/r/20220201013717.2464392-1-keescook@chromium.org Signed-off-by: Kees Cook Cc: Shuah Khan Signed-off-by: Andrew Morton --- tools/testing/selftests/kselftest.h | 10 ++++++++++ tools/testing/selftests/vm/memfd_secret.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/kselftest.h~selftests-kselftest-framework-provide-finished-helper +++ a/tools/testing/selftests/kselftest.h @@ -28,6 +28,7 @@ * * When all tests are finished, clean up and exit the program with one of: * + * ksft_finished(); * ksft_exit(condition); * ksft_exit_pass(); * ksft_exit_fail(); @@ -235,6 +236,15 @@ static inline int ksft_exit_fail(void) ksft_exit_fail(); \ } while (0) +/** + * ksft_finished() - Exit selftest with success if all tests passed + */ +#define ksft_finished() \ + ksft_exit(ksft_plan == \ + ksft_cnt.ksft_pass + \ + ksft_cnt.ksft_xfail + \ + ksft_cnt.ksft_xskip) + static inline int ksft_exit_fail_msg(const char *msg, ...) { int saved_errno = errno; --- a/tools/testing/selftests/vm/memfd_secret.c~selftests-kselftest-framework-provide-finished-helper +++ a/tools/testing/selftests/vm/memfd_secret.c @@ -282,7 +282,7 @@ int main(int argc, char *argv[]) close(fd); - ksft_exit(!ksft_get_fail_cnt()); + ksft_finished(); } #else /* __NR_memfd_secret */