From patchwork Tue Sep 6 09:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1674622 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=D5k5HYvZ; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=PXThTQ3+; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMKl840NCz1yhd for ; Tue, 6 Sep 2022 19:26:28 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 645BC3CA6F9 for ; Tue, 6 Sep 2022 11:26:24 +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 [217.194.8.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 1B34F3C93EF for ; Tue, 6 Sep 2022 11:26:21 +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 115FE1001169 for ; Tue, 6 Sep 2022 11:26:20 +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 689331F9B7; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1662456380; 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=rH8KUEbLq3ibqMYMQQJxjZ/H5aA+IpDVRf58vriGRXQ=; b=D5k5HYvZDpLJ2Fwu8EN1xdNYE6cfVBtM/u7/8pxksv78hmmMnrAWSW74/vZq3QTuCPNBlA 9jtxBb8q1rKP7amVb97UdX5N1wPiYTM20wTvbt0dn3kSU/kSDzSergSppHWeun9dvKBvwp xyzNgKEdtLBJhSd1F4iMqQmkIFJotcc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1662456380; 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=rH8KUEbLq3ibqMYMQQJxjZ/H5aA+IpDVRf58vriGRXQ=; b=PXThTQ3+z4//M6JSBh3V0xhRq8/IeuaxhJGKXtPUbXaqq0O55C1we/uRaWP8ZcUo2T9XBW Tc38qCC4D4XHURBg== 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 3486513A93; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eJ5HCzwSF2NTawAAMHmgww (envelope-from ); Tue, 06 Sep 2022 09:26:20 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Tue, 6 Sep 2022 11:26:13 +0200 Message-Id: <20220906092615.15116-2-pvorel@suse.cz> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906092615.15116-1-pvorel@suse.cz> References: <20220906092615.15116-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 1/3] tst_test_macros: Add 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: , Cc: Jan Kara , Matthew Bobrowski Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Combine TST_EXP_FD() and 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..a2dfaac13 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_ERRNO(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 6 09:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1674623 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=k6rhf4ZM; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0ECM+m3/; 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 4MMKlJ3y53z1yhd for ; Tue, 6 Sep 2022 19:26:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 03F803CA76C for ; Tue, 6 Sep 2022 11:26:34 +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 1025D3C285E for ; Tue, 6 Sep 2022 11:26:21 +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 56A82200B8C for ; Tue, 6 Sep 2022 11:26:21 +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 AB9661F8AF; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1662456380; 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=YRBXw2EIOf+YTeJKZ1vvmA0dT9Dv8BSSmCnZdXK66cY=; b=k6rhf4ZMfeFMEZgRYYFUkKTiYRU0OAcMbC/E8x/B622/ncQuWQHgxi23Lu616WDgOB1bHy w7cn+C7Cx/26VMabQPcPEQMO3mNklAmQRgAOQYn1PYWBYUYwjq/1kzp8I365MAW4hUq0hx +RzsToGtI2+G7jLy/YdtM61B9gT3ZAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1662456380; 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=YRBXw2EIOf+YTeJKZ1vvmA0dT9Dv8BSSmCnZdXK66cY=; b=0ECM+m3/HXYS/rxcsuzqs4GNaR7ZnC7TpgW2FdI360BpDfHZ4uZWxxx6o7h+t5H9zDLnap 5HlMT8byx9YyoEDA== 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 7534013A93; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cOSkGjwSF2NTawAAMHmgww (envelope-from ); Tue, 06 Sep 2022 09:26:20 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Tue, 6 Sep 2022 11:26:14 +0200 Message-Id: <20220906092615.15116-3-pvorel@suse.cz> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906092615.15116-1-pvorel@suse.cz> References: <20220906092615.15116-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 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: , Cc: Jan Kara , Matthew Bobrowski Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * replace do_test() content with TST_EXP_FD_ERRNO() 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 Reviewed-by: Amir Goldstein Reviewed-by: Matthew Bobrowski --- .../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..badc4c369 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_ERRNO(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 6 09:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1674626 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=wlxXgob6; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9CIvUsS0; 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 4MMKlh5xRXz1yhd for ; Tue, 6 Sep 2022 19:26:56 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 74FE23CA768 for ; Tue, 6 Sep 2022 11:26:54 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.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 picard.linux.it (Postfix) with ESMTPS id 1BA323C285E for ; Tue, 6 Sep 2022 11:26:22 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id 589A4600B2D for ; Tue, 6 Sep 2022 11:26:21 +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 EA12833BB8; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1662456380; 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=0FvaZ9Au7YlCn1dzaaT5H5pXOK5wM2JHJ4MBDyMtvkU=; b=wlxXgob6qz8OWfU2CuZiKgSRaxYiCUlfRPrjS3sNuAiRVFWefyVcrAfDsbrsCxorZWgSCc nkH4/32tfz3PaalQ49CAlWQjLjwzRbDZDYVnmieF/rzsq30sOpggw5QE/GtOlUnv4Y/q4/ RDgBXuQb47DRlTHDs1rZqkCk//ubnKc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1662456380; 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=0FvaZ9Au7YlCn1dzaaT5H5pXOK5wM2JHJ4MBDyMtvkU=; b=9CIvUsS0BJlTcTWIMUjmVhxNZ9ECF6OYVhaEYO1R5icaD2f8/jYiCSUyhNG/BxwaW8pl+J InI/cibz8nZnMeAA== 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 B979513A93; Tue, 6 Sep 2022 09:26:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OMS6KjwSF2NTawAAMHmgww (envelope-from ); Tue, 06 Sep 2022 09:26:20 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Tue, 6 Sep 2022 11:26:15 +0200 Message-Id: <20220906092615.15116-4-pvorel@suse.cz> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906092615.15116-1-pvorel@suse.cz> References: <20220906092615.15116-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.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-2.smtp.seeweb.it Subject: [LTP] [PATCH 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: , Cc: Jan Kara , Matthew Bobrowski Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" That greatly simplifies the code. Signed-off-by: Petr Vorel Reviewed-by: Amir Goldstein Reviewed-by: Matthew Bobrowski --- .../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 aa4db586e..47d013c9f 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 */ @@ -48,6 +49,7 @@ static int fan_report_target_fid_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[] = { @@ -111,7 +113,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) { @@ -120,101 +121,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_ERRNO(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_ERRNO(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)