From patchwork Tue Sep 13 06:21:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1677118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=MR6v6fyg; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EDVMy20L; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRYJZ3FrGz1ync for ; Tue, 13 Sep 2022 16:21:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 31D623CAB4E for ; Tue, 13 Sep 2022 08:21:32 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id CB7C13CAAE3 for ; Tue, 13 Sep 2022 08:21:08 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 453B8200B9A for ; Tue, 13 Sep 2022 08:21:07 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 584FA5BDE1; Tue, 13 Sep 2022 06:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663050067; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5PD7NvxYbdErXXWZq7jJkZPbjU1S2g7DlAI95i+A/50=; b=MR6v6fyg7S/cWtYpIGkbDJGEdLgICUThBhbR/QhkAtOhhiIRcl9lGkRGGUI1hFJQ+kDafk 3qwJxhW8EddzbfPbKqiLRR0Tw5BKSxhhc7ehO/QR766gPhf1icxnXudGqXpemrKdOg+S8E y/PXtjFgYqjnZlfZtNtOH5vWVtvLimU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663050067; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5PD7NvxYbdErXXWZq7jJkZPbjU1S2g7DlAI95i+A/50=; b=EDVMy20LOFQv5f0EAHLZEPVTcaWfB0FH5C0Wtq17wOQW6Nfc84DHpqPEVbahej7PI21JKd TxWnvzuNv6e5CyAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3988B139B3; Tue, 13 Sep 2022 06:21:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8BO9DFMhIGNKZwAAMHmgww (envelope-from ); Tue, 13 Sep 2022 06:21:07 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Tue, 13 Sep 2022 08:21:02 +0200 Message-Id: <20220913062103.3910-3-pvorel@suse.cz> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913062103.3910-1-pvorel@suse.cz> References: <20220913062103.3910-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/3] fanotify20: Simplify code X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * replace do_test() content with TST_EXP_FD_OR_FAIL() macro * rename variables (shorten, use LTP common names) * remove tc->want_err (not needed) * add macro FLAGS_DESC (stringify) * don't print number of tests (not needed for just 2 tests) Signed-off-by: Petr Vorel --- .../kernel/syscalls/fanotify/fanotify20.c | 81 +++++-------------- 1 file changed, 19 insertions(+), 62 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c index de0fdb782..71310fb86 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify20.c +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2021 Google. All Rights Reserved. + * Copyright (c) 2022 Petr Vorel * * Started by Matthew Bobrowski */ @@ -25,26 +26,21 @@ #include "fanotify.h" #define MOUNT_PATH "fs_mnt" +#define FLAGS_DESC(x) .flags = x, .desc = #x -static int fanotify_fd; +static int fd; static struct test_case_t { - char *name; - unsigned int init_flags; - int want_err; - int want_errno; + unsigned int flags; + char *desc; + int exp_errno; } test_cases[] = { { - "fail on FAN_REPORT_PIDFD | FAN_REPORT_TID", - FAN_REPORT_PIDFD | FAN_REPORT_TID, - 1, - EINVAL, + FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_TID), + .exp_errno = EINVAL, }, { - "pass on FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME", - FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME, - 0, - 0, + FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME), }, }; @@ -57,63 +53,24 @@ static void do_setup(void) REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(FAN_REPORT_PIDFD); } -static void do_test(unsigned int num) +static void do_test(unsigned int i) { - struct test_case_t *tc = &test_cases[num]; + struct test_case_t *tc = &test_cases[i]; - tst_res(TINFO, "Test #%d: %s", num, tc->name); + tst_res(TINFO, "Test %s on %s", tc->exp_errno ? "fail" : "pass", + tc->desc); - fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY); - if (fanotify_fd < 0) { - if (!tc->want_err) { - tst_res(TFAIL, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "failed with error -%d but wanted success", - fanotify_fd, tc->init_flags, errno); - return; - } + TST_EXP_FD_OR_FAIL(fd = fanotify_init(tc->flags, O_RDONLY), + tc->exp_errno); - if (errno != tc->want_errno) { - tst_res(TFAIL, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "failed with an unexpected error code -%d but " - "wanted -%d", - fanotify_fd, tc->init_flags, - errno, tc->want_errno); - return; - } - - tst_res(TPASS, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "failed with error -%d as expected", - fanotify_fd, tc->init_flags, errno); - return; - } - - /* - * Catch test cases that had expected to receive an error upon calling - * fanotify_init() but had unexpectedly resulted in a success. - */ - if (tc->want_err) { - tst_res(TFAIL, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "unexpectedly returned successfully, wanted error -%d", - fanotify_fd, tc->init_flags, tc->want_errno); - return; - } - - tst_res(TPASS, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "successfully initialized notification group", - fanotify_fd, tc->init_flags); - - SAFE_CLOSE(fanotify_fd); + if (fd > 0) + SAFE_CLOSE(fd); } static void do_cleanup(void) { - if (fanotify_fd >= 0) - SAFE_CLOSE(fanotify_fd); + if (fd > 0) + SAFE_CLOSE(fd); } static struct tst_test test = {