From patchwork Tue Sep 13 06:21:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1677116 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=2001:1418:10:5::2; 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=WVEtY34Q; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9GXSs5jk; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 legolas.ozlabs.org (Postfix) with ESMTPS id 4MRYJB4ryCz1ync for ; Tue, 13 Sep 2022 16:21:14 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5ACDF3CAAF2 for ; Tue, 13 Sep 2022 08:21:10 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (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 picard.linux.it (Postfix) with ESMTPS id AC85D3CAAE0 for ; Tue, 13 Sep 2022 08:21:08 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-4.smtp.seeweb.it (Postfix) with ESMTPS id 1D2781000D06 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 320625BDE0; 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=CO2iItC2gTvpCcMSDG3HYPaH7fOJyiAkEITb6GjNiZg=; b=WVEtY34QnLuUcNiPUuD9VVKgtvBxnnYmmzilh7hLkf5VMRdAcLJdYGNQS0ckchaWDvSCye DX6sgpPCdDOXwpc0qp84j0bD2KYPSkXMjkT+8/32S6qZU1fjS9CZ8CY1yurp12ERL8SyzF UvyqMO7/I+ltDmg1n2G2hdA75el+UHc= 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=CO2iItC2gTvpCcMSDG3HYPaH7fOJyiAkEITb6GjNiZg=; b=9GXSs5jklNU+dpBm8RiJaK/rOdo20nuVNRxdQqZ58thc2rcKJJ0VfBV6bBcHoS2syesYJA T+ur2MyZus0lyrDQ== 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 142BE139B3; 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 wCWeA1MhIGNKZwAAMHmgww (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:01 +0200 Message-Id: <20220913062103.3910-2-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-4.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_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/3] tst_test_macros: Add TST_EXP_FD_OR_FAIL() macro 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" It calls TST_EXP_FD() or TST_EXP_FAIL(). Signed-off-by: Petr Vorel --- include/tst_test_macros.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h index 2e7b7871c..231c04951 100644 --- a/include/tst_test_macros.h +++ b/include/tst_test_macros.h @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2015-2020 Cyril Hrubis + * Copyright (c) Linux Test Project, 2021-2022 */ #ifndef TST_TEST_MACROS_H__ @@ -93,6 +94,15 @@ extern void *TST_RET_PTR; #SCALL, ##__VA_ARGS__); \ } while (0) +#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...) \ + do { \ + if (ERRNO) \ + TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__); \ + else \ + TST_EXP_FD(SCALL, ##__VA_ARGS__); \ + \ + } while (0) + #define TST_EXP_PID_SILENT(SCALL, ...) TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__) #define TST_EXP_PID(SCALL, ...) \ 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 = { From patchwork Tue Sep 13 06:21:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1677119 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=2001:1418:10:5::2; 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=tTgN6bn0; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=m6LdS5h3; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 4MRYJm4fDFz1ync for ; Tue, 13 Sep 2022 16:21:44 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D45183CAAE1 for ; Tue, 13 Sep 2022 08:21:41 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id DD2243CAAE0 for ; Tue, 13 Sep 2022 08:21:08 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 12406200B98 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-out1.suse.de (Postfix) with ESMTPS id 7F3412247B; 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=MMYf5vH5MzBtWinCckDFU5F8geJ7KODMOKa/PyZrxPA=; b=tTgN6bn0/L+ejNJYEiAVQ6e9oKhhoxF2dLIfGqk/UdZmfvLHgBP+L63d2KaymvS1O9HoRB oXM8t4mdz3sadocqXhLDmTzYYV2CHWkNW8DU4fNP3WksNH30FBSB/tkdpwlJ1jwWaFRKjK cdlyd4kMhHhBlrRavMZvRT6jbTT7G40= 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=MMYf5vH5MzBtWinCckDFU5F8geJ7KODMOKa/PyZrxPA=; b=m6LdS5h3xJXlZMVl7ySKgQrmKAwX8XASw4q7XLrvu7YD7AsWHqcaoOWpAmvRKvYFFj10S9 kqlizYKvKVRT5rCw== 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 60C70139B3; 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 gGUxFlMhIGNKZwAAMHmgww (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:03 +0200 Message-Id: <20220913062103.3910-4-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_PASS, 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 3/3] fanotify14: Use TST_EXP_FD_ERRNO() 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" That greatly simplifies the code. Signed-off-by: Petr Vorel --- .../kernel/syscalls/fanotify/fanotify14.c | 118 +++++------------- 1 file changed, 33 insertions(+), 85 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c index 4a1953b33..594259ccf 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify14.c +++ b/testcases/kernel/syscalls/fanotify/fanotify14.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved. + * Copyright (c) Linux Test Project, 2020-2022 * * Started by Matthew Bobrowski */ @@ -49,6 +50,7 @@ static int ignore_mark_unsupported; static struct test_case_t { unsigned int init_flags; unsigned int mark_flags; + /* zero mask expects to fail on fanotify_init() */ unsigned long long mask; int expected_errno; } test_cases[] = { @@ -140,7 +142,6 @@ static struct test_case_t { static void do_test(unsigned int number) { - int ret; struct test_case_t *tc = &test_cases[number]; if (fan_report_target_fid_unsupported && tc->init_flags & FAN_REPORT_TARGET_FID) { @@ -154,101 +155,48 @@ static void do_test(unsigned int number) return; } - fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY); - if (fanotify_fd < 0) { - if (errno == tc->expected_errno) { - tst_res(TPASS, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " - "failed with error %d as expected", - fanotify_fd, - tc->init_flags, tc->expected_errno); - return; - } - tst_brk(TBROK | TERRNO, - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) failed", - fanotify_fd, - tc->init_flags); - } + TST_EXP_FD_OR_FAIL(fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY), + !tc->mask && tc->expected_errno ? tc->expected_errno : 0); - /* - * A test case with a mask set to zero indicate that they've been - * specifically designed to test and fail on the fanotify_init() - * system call. - */ - if (tc->mask == 0) { - tst_res(TFAIL, - "fanotify_fd=%d fanotify_init(%x, O_RDONLY) " - "unexpectedly succeeded when tests with mask 0 are " - "expected to fail when calling fanotify_init()", - fanotify_fd, - tc->init_flags); + if (fanotify_fd < 0) + return; + + if (!tc->mask) goto out; - } /* Set mark on non-dir only when expecting error ENOTDIR */ const char *path = tc->expected_errno == ENOTDIR ? FILE1 : MNTPOINT; - ret = fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags, - tc->mask, AT_FDCWD, path); - if (ret < 0) { - if (errno == tc->expected_errno) { - tst_res(TPASS, - "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, " - "%llx, AT_FDCWD, %s) failed with error %d " - "as expected", - ret, - fanotify_fd, - tc->mark_flags, - tc->mask, - path, tc->expected_errno); - /* - * ENOTDIR are errors for events/flags not allowed on a non-dir inode. - * Try to set an inode mark on a directory and it should succeed. - * Try to set directory events in filesystem mark mask on non-dir - * and it should succeed. - */ - if (tc->expected_errno == ENOTDIR) { - SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags, - tc->mask, AT_FDCWD, MNTPOINT); - tst_res(TPASS, - "Adding an inode mark on directory did not fail with " - "ENOTDIR error as on non-dir inode"); - } - if (tc->expected_errno == ENOTDIR && - !(tc->mark_flags & FAN_MARK_ONLYDIR)) { - SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags | - FAN_MARK_FILESYSTEM, tc->mask, - AT_FDCWD, FILE1); - tst_res(TPASS, - "Adding a filesystem mark on non-dir did not fail with " - "ENOTDIR error as with an inode mark"); - } + TST_EXP_FD_OR_FAIL(fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags, + tc->mask, AT_FDCWD, path), + tc->expected_errno); - goto out; + /* + * ENOTDIR are errors for events/flags not allowed on a non-dir inode. + * Try to set an inode mark on a directory and it should succeed. + * Try to set directory events in filesystem mark mask on non-dir + * and it should succeed. + */ + if (TST_PASS && tc->expected_errno == ENOTDIR) { + SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags, + tc->mask, AT_FDCWD, MNTPOINT); + tst_res(TPASS, + "Adding an inode mark on directory did not fail with " + "ENOTDIR error as on non-dir inode"); + + if (!(tc->mark_flags & FAN_MARK_ONLYDIR)) { + SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags | + FAN_MARK_FILESYSTEM, tc->mask, + AT_FDCWD, FILE1); + tst_res(TPASS, + "Adding a filesystem mark on non-dir did not fail with " + "ENOTDIR error as with an inode mark"); } - tst_brk(TBROK | TERRNO, - "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, " - "AT_FDCWD, %s) failed", - ret, - fanotify_fd, - tc->mark_flags, - tc->mask, - FILE1); } - tst_res(TFAIL, - "fanotify_fd=%d, ret=%d, fanotify_init(%x, O_RDONLY) and " - "fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) did " - "not return any errors as expected", - fanotify_fd, - ret, - tc->init_flags, - fanotify_fd, - tc->mark_flags, - tc->mask, - FILE1); out: - SAFE_CLOSE(fanotify_fd); + if (fanotify_fd > 0) + SAFE_CLOSE(fanotify_fd); } static void do_setup(void)