From patchwork Tue Jul 12 15:34:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Utr0Xd2T; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=yN0b9ZbX; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4Z36phkz9sB4 for ; Wed, 13 Jul 2022 01:34:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 68E963CA54E for ; Tue, 12 Jul 2022 17:34:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (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 134423CA588 for ; Tue, 12 Jul 2022 17:34:26 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id D46D21400DB8 for ; Tue, 12 Jul 2022 17:34:25 +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 13C7622A1B for ; Tue, 12 Jul 2022 15:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640064; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjIpS9XtjMKRf3y+1UeZNbAdfMoN2Le3jQYRxDXczkI=; b=Utr0Xd2TvU495CAvj3iZwnhjgekNgxgGdez1o8I3bIW4cpG0upiQ5tnJxhIlX7ZFl5V1rW gUKFitexlAV8wNgqtNYHj6PrhVK+0N7Tj8kE9ScJkoSG4sk8BJIExQw0lG9X0SRRrhgD3W HRJE+2/cGPTbJISTWLzhkDfp3l5nt8M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640064; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjIpS9XtjMKRf3y+1UeZNbAdfMoN2Le3jQYRxDXczkI=; b=yN0b9ZbXm4SfVA4srJ1rDnZ2NzWTli0p4eJVjpRROEQJth4ZV+TacMsvQiu6JDyOxbspRS vcaOUreYDtPGafCA== 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 7853613A94 for ; Tue, 12 Jul 2022 15:34:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DOE+Dn+UzWIofAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:23 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:09 +0530 Message-Id: <20220712153417.14551-2-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/9] Rewrite rename01.c using new LTP API 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" Rewrite using new LTP API and enable the test to run on all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename01.c | 267 +++++--------------- 1 file changed, 66 insertions(+), 201 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename01.c b/testcases/kernel/syscalls/rename/rename01.c index e7de18ff4..159341d09 100644 --- a/testcases/kernel/syscalls/rename/rename01.c +++ b/testcases/kernel/syscalls/rename/rename01.c @@ -1,218 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename01 - * - * DESCRIPTION - * This test will verify the rename(2) syscall basic functionality. - * Verify rename() works when the "new" file or directory does not exist. - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * 1. "old" is plain file, new does not exists - * create the "old" file, make sure the "new" file - * dose not exist - * rename the "old" to the "new" file - * verify the "new" file points to the "old" file - * verify the "old" file does not exist +/*\ + * [Description] * - * 2. "old" is a directory,"new" does not exists - * create the "old" directory, make sure "new" - * dose not exist - * rename the "old" to the "new" - * verify the "new" points to the "old" - * verify the "old" does not exist - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * USAGE - * rename01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. - */ -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); - -char *TCID = "rename01"; -int TST_TOTAL = 2; - -char fname[255], mname[255]; -char fdir[255], mdir[255]; -struct stat buf1; -dev_t f_olddev, d_olddev; -ino_t f_oldino, d_oldino; - -struct test_case_t { - char *name1; - char *name2; - char *desc; - dev_t *olddev; - ino_t *oldino; -} TC[] = { - /* comment goes here */ - { - fname, mname, "file", &f_olddev, &f_oldino}, - /* comment goes here */ - { - fdir, mdir, "directory", &d_olddev, &d_oldino} -}; - -int main(int ac, char **av) -{ - int lc; - int i; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - - TEST(rename(TC[i].name1, TC[i].name2)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "call failed unexpectedly"); - continue; - } - - SAFE_STAT(cleanup, TC[i].name2, &buf1); - - /* - * verify the new file or directory is the - * same as the old one - */ - if (buf1.st_dev != *TC[i].olddev || - buf1.st_ino != *TC[i].oldino) { - tst_resm(TFAIL, "rename() failed: the " - "new %s points to a different " - "inode/location", TC[i].desc); - continue; - } - /* - * verify that the old file or directory - * does not exist - */ - if (stat(fname, &buf1) != -1) { - tst_resm(TFAIL, "the old %s still " - "exists", TC[i].desc); - continue; - } - - tst_resm(TPASS, "functionality is correct " - "for renaming a %s", TC[i].desc); - } - /* reset things in case we are looping */ - SAFE_RENAME(cleanup, mname, fname); - - SAFE_RENAME(cleanup, mdir, fdir); - } - - cleanup(); - tst_exit(); - -} - -/* - * setup() - performs all ONE TIME setup for this test. + * Verify rename() when the newpath file or directory does not exist. */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - TEST_PAUSE; +#include +#include "tst_test.h" - /* Create a temporary directory and make it current. */ - tst_tmpdir(); +#define MNT_POINT "mntpoint" - sprintf(fname, "./tfile_%d", getpid()); - sprintf(mname, "./rnfile_%d", getpid()); - sprintf(fdir, "./tdir_%d", getpid()); - sprintf(mdir, "./rndir_%d", getpid()); +static const char *old_file_name = "oldfile"; +static const char *old_dir_name = "olddir"; +static const char *new_file_name = "newfile"; +static const char *new_dir_name = "newdir"; - SAFE_TOUCH(cleanup, fname, 0700, NULL); +static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st; - SAFE_STAT(cleanup, fname, &buf1); - - f_olddev = buf1.st_dev; - f_oldino = buf1.st_ino; +static inline void swap(const char **a, const char **b) +{ + const char *tmp__ = *a; + *a = *b; + *b = tmp__; +} - /* create "old" directory */ - SAFE_MKDIR(cleanup, fdir, 00770); +static void setup(void) +{ + SAFE_CHDIR(MNT_POINT); - SAFE_STAT(cleanup, fdir, &buf1); + SAFE_TOUCH(old_file_name, 0700, NULL); + SAFE_MKDIR(old_dir_name, 00770); - d_olddev = buf1.st_dev; - d_oldino = buf1.st_ino; + SAFE_STAT(old_file_name, &old_file_st); + SAFE_STAT(old_dir_name, &old_dir_st); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void run(void) { - - /* - * Remove the temporary directory. - */ - tst_rmdir(); + TST_EXP_PASS(rename(old_file_name, new_file_name), + "rename(%s, %s)", + old_file_name, new_file_name); + TST_EXP_PASS(rename(old_dir_name, new_dir_name), + "rename(%s, %s)", + old_dir_name, new_dir_name); + + SAFE_STAT(new_file_name, &new_file_st); + SAFE_STAT(new_dir_name, &new_dir_st); + + TST_EXP_EQ_LU(old_file_st.st_dev, new_file_st.st_dev); + TST_EXP_EQ_LU(old_file_st.st_ino, new_file_st.st_ino); + + TST_EXP_EQ_LU(old_dir_st.st_dev, new_dir_st.st_dev); + TST_EXP_EQ_LU(old_dir_st.st_ino, new_dir_st.st_ino); + + TST_EXP_FAIL(stat(old_file_name, &old_file_st), + ENOENT, + "stat(%s, &old_file_st)", + old_file_name); + TST_EXP_FAIL(stat(old_dir_name, &old_dir_st), + ENOENT, + "stat(%s, &old_dir_st)", + old_dir_name); + + /* reset between loops */ + swap(&old_file_name, &new_file_name); + swap(&old_dir_name, &new_dir_name); } + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=V3d3uy5E; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=aSUIGV86; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4Yn0jFGz9sB4 for ; Wed, 13 Jul 2022 01:34:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 01B6D3CA310 for ; Tue, 12 Jul 2022 17:34:35 +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 [IPv6:2001:4b78:1:20::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 1F6473CA588 for ; Tue, 12 Jul 2022 17:34:29 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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 07962200ACD for ; Tue, 12 Jul 2022 17:34:27 +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 8A2E3229E2 for ; Tue, 12 Jul 2022 15:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640067; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CmRE93Z9rZN1nl1Rp+oTe6IFLVGv86rxr6L1q6RZabM=; b=V3d3uy5EyJiT7n2NbTPnQgqmn9MBqfZuSFSzN4zfNbPSvm+/dj4XNb5jhoEHq9KrHgeMyD B92QIUT0UUiW3lN2Ont+oiTjf8vqgpjoOttk4uhlbkz87NBR5vL8Owed/JUfChXFPrAS0M 2ssGXhk70+ivHS1xhI8SBJO1JAE1KO4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640067; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CmRE93Z9rZN1nl1Rp+oTe6IFLVGv86rxr6L1q6RZabM=; b=aSUIGV862p3lTdNtDSG/BSE9exT1LqXzxNJX5F7upQhhXEWalEbL3IISc7bw8h7vzg63Yg 2Xpmtegj5FQiPpCQ== 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 0557B13A94 for ; Tue, 12 Jul 2022 15:34:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id w/HXLYKUzWIrfAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:26 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:10 +0530 Message-Id: <20220712153417.14551-3-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 2/9] Remove rename02.c 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" rename02.c is redundant as same testcase is covered in rename01.c Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- runtest/syscalls | 1 - testcases/kernel/syscalls/rename/.gitignore | 1 - testcases/kernel/syscalls/rename/rename02.c | 192 -------------------- 3 files changed, 194 deletions(-) delete mode 100644 testcases/kernel/syscalls/rename/rename02.c diff --git a/runtest/syscalls b/runtest/syscalls index 88c31db06..8139c37d6 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1132,7 +1132,6 @@ removexattr02 removexattr02 rename01 rename01 rename01A symlink01 -T rename01 -rename02 rename02 rename03 rename03 rename04 rename04 rename05 rename05 diff --git a/testcases/kernel/syscalls/rename/.gitignore b/testcases/kernel/syscalls/rename/.gitignore index 6c10aeabd..f95cf7d21 100644 --- a/testcases/kernel/syscalls/rename/.gitignore +++ b/testcases/kernel/syscalls/rename/.gitignore @@ -1,5 +1,4 @@ /rename01 -/rename02 /rename03 /rename04 /rename05 diff --git a/testcases/kernel/syscalls/rename/rename02.c b/testcases/kernel/syscalls/rename/rename02.c deleted file mode 100644 index 51c278faa..000000000 --- a/testcases/kernel/syscalls/rename/rename02.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * - */ -/* $Id: rename02.c,v 1.8 2009/11/02 13:57:18 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : rename02 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for rename(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) rename(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the rename(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * rename(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include -#include -#include -#include -#include -#include "test.h" - -void setup(); -void cleanup(); - -char *TCID = "rename02"; -int TST_TOTAL = 1; - -int fd; -char fname[255], mname[255]; - -int main(int ac, char **av) -{ - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call rename(2) - */ - TEST(rename(fname, mname)); - - /* check return code */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "rename(%s, %s) Failed, errno=%d : %s", - fname, mname, TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TPASS, "rename(%s, %s) returned %ld", - fname, mname, TEST_RETURN); - if (unlink(mname) == -1) { - tst_resm(TWARN, - "unlink(%s) Failed, errno=%d : %s", - mname, errno, strerror(errno)); - } - SAFE_TOUCH(cleanup, fname, 0700, NULL); - } - } - - cleanup(); - tst_exit(); - -} - -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - sprintf(fname, "./tfile_%d", getpid()); - sprintf(mname, "./rnfile_%d", getpid()); - SAFE_TOUCH(cleanup, fname, 0700, NULL); -} - -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) -{ - - tst_rmdir(); -} From patchwork Tue Jul 12 15:34:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655483 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ED4MP8s9; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xvKIm6I5; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4ZJ5r2pz9sB4 for ; Wed, 13 Jul 2022 01:35:04 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3F8363CA539 for ; Tue, 12 Jul 2022 17:35:02 +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 972D93CA508 for ; Tue, 12 Jul 2022 17:34:32 +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 C8419200AC5 for ; Tue, 12 Jul 2022 17:34:31 +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 1593F22A75 for ; Tue, 12 Jul 2022 15:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640071; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lDVtkuEA2oAAkTmka31FAr7cdnFMP5560vdeJQMcnRo=; b=ED4MP8s9fuJWjj5KckKI+/hr4wlkzLHFl7EUKolUUN0uDCjTe7H37kLSMN98Rq9jKTHOj/ mqh7e26SZIcPNQy5lpgGteB3N/uv9/Ub4H/J3ZUe0djEiho9aj01i98I46zgLNLaCWnThG HCeOG/wJIZf+dxvRS1Ca8SaclIKtHwg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640071; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lDVtkuEA2oAAkTmka31FAr7cdnFMP5560vdeJQMcnRo=; b=xvKIm6I5/ZG7BJ10ZqinWdEbJEl9LRplzHb2v8iYeaPLpa0In+pSk9oCGZceDMzr/7EcjR +RGFwjCgbNKPEXDg== 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 8643F13A94 for ; Tue, 12 Jul 2022 15:34:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MWKLEYaUzWIzfAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:30 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:11 +0530 Message-Id: <20220712153417.14551-4-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 3/9] Rewrite rename03.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename03.c | 279 +++++--------------- 1 file changed, 61 insertions(+), 218 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename03.c b/testcases/kernel/syscalls/rename/rename03.c index 396e95c4d..652fa3bdb 100644 --- a/testcases/kernel/syscalls/rename/rename03.c +++ b/testcases/kernel/syscalls/rename/rename03.c @@ -1,230 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename03 - * - * DESCRIPTION - * This test will verify that rename(2) functions correctly - * when the "new" file or directory exists - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. +/*\ + * [Description] * - * Test: - * Loop if the proper options are given. - * 1. both old and new file exist - * create the "old" file and the "new" file - * rename the "old" to the "new" file - * verify the "new" file points to the "old" file - * verify the "old" file does not exists - * 2. both old file and new directory exist - * create the "old" and the "new" directory - * rename the "old" to the "new" directory - * verify the "new" points to the "old" directory - * verify the "old" does not exists - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * USAGE - * rename03 [-c n] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. - */ -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -void setup(); -void setup2(); -void cleanup(); - -char *TCID = "rename03"; -int TST_TOTAL = 2; - -char fname[255], mname[255]; -char fdir[255], mdir[255]; -struct stat buf1, buf2; -dev_t f_olddev, d_olddev; -ino_t f_oldino, d_oldino; - -struct test_case_t { - char *name1; - char *name2; - char *desc; - dev_t *olddev; - ino_t *oldino; -} TC[] = { - { - fname, mname, "file", &f_olddev, &f_oldino}, { - fdir, mdir, "directory", &d_olddev, &d_oldino} -}; - -int main(int ac, char **av) -{ - int lc; - int i; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* set up the files and directories for the tests */ - setup2(); - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - - TEST(rename(TC[i].name1, TC[i].name2)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "call failed unexpectedly"); - continue; - } - - SAFE_STAT(cleanup, TC[i].name2, &buf2); - - /* - * verify the new file or directory is the - * same as the old one - */ - if (buf2.st_dev != *TC[i].olddev || - buf2.st_ino != *TC[i].oldino) { - tst_resm(TFAIL, "rename() failed: the " - "new %s points to a different " - "inode/location", TC[i].desc); - continue; - } - /* - * verify that the old file or directory - * does not exist - */ - if (stat(fname, &buf2) != -1) { - tst_resm(TFAIL, "the old %s still " - "exists", TC[i].desc); - continue; - } - - tst_resm(TPASS, "functionality is correct " - "for renaming a %s", TC[i].desc); - } - - /* reset things in case we are looping */ - - /* unlink the new file */ - SAFE_UNLINK(cleanup, mname); - - /* remove the new directory */ - SAFE_RMDIR(cleanup, mdir); - } - - cleanup(); - tst_exit(); - -} - -/* - * setup() - performs all ONE TIME setup for this test. + * Verify rename(2) functions correctly when the newpath + * file or directory (empty) exists. */ -void setup(void) -{ - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; +#include +#include +#include "tst_test.h" - /* Create a temporary directory and make it current. */ - tst_tmpdir(); +#define MNT_POINT "mntpoint" +#define OLD_FILE_NAME MNT_POINT"/oldfile" +#define NEW_FILE_NAME MNT_POINT"/newfile" +#define OLD_DIR_NAME MNT_POINT"/olddir" +#define NEW_DIR_NAME MNT_POINT"/newdir" - sprintf(fname, "./tfile_%d", getpid()); - sprintf(mname, "./rnfile_%d", getpid()); - sprintf(fdir, "./tdir_%d", getpid()); - sprintf(mdir, "./rndir_%d", getpid()); -} +static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st; -/* - * setup2() - set up the files and directories for the tests - */ -void setup2(void) +static void run(void) { - SAFE_TOUCH(cleanup, fname, 0700, NULL); - - SAFE_STAT(cleanup, fname, &buf1); - - /* save original file's dev and ino */ - f_olddev = buf1.st_dev; - f_oldino = buf1.st_ino; - - SAFE_TOUCH(cleanup, mname, 0700, NULL); - - /* create "old" directory */ - SAFE_MKDIR(cleanup, fdir, 00770); - SAFE_STAT(cleanup, fdir, &buf1); - - d_olddev = buf1.st_dev; - d_oldino = buf1.st_ino; - - /* create another directory */ - SAFE_MKDIR(cleanup, mdir, 00770); + SAFE_TOUCH(OLD_FILE_NAME, 0700, NULL); + SAFE_MKDIR(OLD_DIR_NAME, 00770); + SAFE_TOUCH(NEW_FILE_NAME, 0700, NULL); + SAFE_MKDIR(NEW_DIR_NAME, 00770); + + SAFE_STAT(OLD_FILE_NAME, &old_file_st); + SAFE_STAT(OLD_DIR_NAME, &old_dir_st); + + TST_EXP_PASS(rename(OLD_FILE_NAME, NEW_FILE_NAME), + "rename(%s, %s)", + OLD_FILE_NAME, NEW_FILE_NAME); + TST_EXP_PASS(rename(OLD_DIR_NAME, NEW_DIR_NAME), + "rename(%s, %s)", + OLD_DIR_NAME, NEW_DIR_NAME); + + SAFE_STAT(NEW_FILE_NAME, &new_file_st); + SAFE_STAT(NEW_DIR_NAME, &new_dir_st); + + TST_EXP_EQ_LU(old_file_st.st_dev, new_file_st.st_dev); + TST_EXP_EQ_LU(old_file_st.st_ino, new_file_st.st_ino); + + TST_EXP_EQ_LU(old_dir_st.st_dev, new_dir_st.st_dev); + TST_EXP_EQ_LU(old_dir_st.st_ino, new_dir_st.st_ino); + + TST_EXP_FAIL(stat(OLD_FILE_NAME, &old_file_st), + ENOENT, + "stat(%s, &old_file_st)", + OLD_FILE_NAME); + TST_EXP_FAIL(stat(OLD_DIR_NAME, &old_dir_st), + ENOENT, + "stat(%s, &old_dir_st)", + OLD_DIR_NAME); + + /* cleanup between loops */ + SAFE_UNLINK(NEW_FILE_NAME); + SAFE_RMDIR(NEW_DIR_NAME); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=n45x7wgb; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6w4OZtBW; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4ZX4HKhz9sB4 for ; Wed, 13 Jul 2022 01:35:16 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 74A373CA72B for ; Tue, 12 Jul 2022 17:35:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (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 2196E3CA592 for ; Tue, 12 Jul 2022 17:34:35 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id 5C38B1A004A4 for ; Tue, 12 Jul 2022 17:34:35 +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 B2FF8229E2 for ; Tue, 12 Jul 2022 15:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640074; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2JduWW+6FEnqnLR6EExPmWwwmYJZVd+B3+YcvrAoa28=; b=n45x7wgbJ3uLkxKWxWLXHSFpQZDd3YDPDzf8w7Vjy07GUbm/dv4Csmy3wtOnJ68L54LciU siSYybIv83Pn9YowT3PY2BAzHv808Cjp6hKB53zJIKBQlRVw0o6aIswv6g9zsbAjx8Bbbw akXPJNbrPfmp0oxNGToObbL4yVvbICw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640074; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2JduWW+6FEnqnLR6EExPmWwwmYJZVd+B3+YcvrAoa28=; b=6w4OZtBWlYr7zU992PV5IWbCIzSkFN0edorYSPerak//fBvsQu+dgohG0Mk8oz4cSkApQE BNneW3aejYRW4vCw== 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 2F3F913A94 for ; Tue, 12 Jul 2022 15:34:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yZNmN4mUzWI3fAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:33 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:12 +0530 Message-Id: <20220712153417.14551-5-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 4/9] Rewrite rename04.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename04.c | 204 ++++---------------- 1 file changed, 36 insertions(+), 168 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename04.c b/testcases/kernel/syscalls/rename/rename04.c index 32594a776..d1d7161b8 100644 --- a/testcases/kernel/syscalls/rename/rename04.c +++ b/testcases/kernel/syscalls/rename/rename04.c @@ -1,182 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename04 - * - * DESCRIPTION - * This test will verify that rename(2) failed when newpath is - * a non-empty directory and return EEXIST or ENOTEMPTY - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * create the "old" directory and the "new" directory - * create a file uner the "new" directory - * - * Test: - * Loop if the proper options are given. - * rename the "old" to the "new" directory - * verify rename() failed and returned ENOTEMPTY - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * USAGE - * rename04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer +/*\ + * [Description] * - * RESTRICTIONS - * None. + * Verify that rename() fails with EEXIST or ENOTEMPTY when + * newpath is a non-empty directory. */ -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" +#include +#include "tst_test.h" -void setup(); -void cleanup(); +#define MNT_POINT "mntpoint" +#define DIR1 "dir1" +#define DIR2 "dir2" +#define TEMP_FILE DIR2"/tmpfile" -char *TCID = "rename04"; -int TST_TOTAL = 1; - -int fd; -char tstfile[40]; -char fdir[255], mdir[255]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main(int ac, char **av) +static void setup(void) { - int lc; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* rename a directory to a non-empty directory */ - - /* Call rename(2) */ - TEST(rename(fdir, mdir)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "rename(%s, %s) succeeded unexpectedly", - fdir, mdir); - continue; - } - - if (TEST_ERRNO == ENOTEMPTY) { - tst_resm(TPASS, "rename() returned ENOTEMPTY"); - } else if (TEST_ERRNO == EEXIST) { - tst_resm(TPASS, "rename() returned EEXIST"); - } else { - tst_resm(TFAIL, "Expected ENOTEMPTY or EEXIST got %d", - TEST_ERRNO); - } - - } - - /* - * cleanup and exit - */ - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_MKDIR(DIR1, 00770); + SAFE_MKDIR(DIR2, 00770); + SAFE_TOUCH(TEMP_FILE, 0700, NULL); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(fdir, "./tdir_%d", getpid()); - sprintf(mdir, "./rndir_%d", getpid()); - sprintf(tstfile, "%s/tstfile_%d", mdir, getpid()); - - /* create "old" directory */ - SAFE_MKDIR(cleanup, fdir, 00770); - - SAFE_STAT(cleanup, fdir, &buf1); - - /* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - - /* create another directory */ - SAFE_MKDIR(cleanup, mdir, 00770); - - SAFE_TOUCH(cleanup, tstfile, 0700, NULL); - - SAFE_STAT(cleanup, mdir, &buf2); - - /* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; + TEST(rename(DIR1, DIR2)); + + if (TST_RET == -1 && (TST_ERR == ENOTEMPTY || TST_ERR == EEXIST)) + tst_res(TPASS | TERRNO, "rename() failed as expected"); + else if (TST_RET == 0) + tst_res(TFAIL, "rename() succeeded unexpectedly"); + else + tst_res(TFAIL | TERRNO, "rename() failed, but not with expected errno"); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mntpoint = MNT_POINT, + .mount_device = 1, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wXVc2w6O; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qaaR6z4x; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4Zn4P04z9sB4 for ; Wed, 13 Jul 2022 01:35:29 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EE4E03CA508 for ; Tue, 12 Jul 2022 17:35:25 +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 [IPv6:2001:4b78:1:20::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 8E3B73CA5E8 for ; Tue, 12 Jul 2022 17:34:39 +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 EA9D3200AC5 for ; Tue, 12 Jul 2022 17:34:38 +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 3CB641F747 for ; Tue, 12 Jul 2022 15:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640078; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6Z9mHIViDQI5PznvlYKrTBCoJgW2c+IJblpXn5fKf6g=; b=wXVc2w6OD9UA9TcSIh/4vZJx1qkNR0y9BzdiITvMGmcKVhoemPZZ09vrB2Zjq3kToase0C ZVjGsKLr0xTKEqINyDi3IjxaNrg1NHTTdEyEC8MP7rJnNeg6Ksz7UClAv16eDhXBa4yvS3 fmcOSQdryxinD4TRLMOyOyHlL0VPZTg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640078; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6Z9mHIViDQI5PznvlYKrTBCoJgW2c+IJblpXn5fKf6g=; b=qaaR6z4x7FMoPW61rEw2UAEO8mUoW+itPTFi1HwO6lEvQJGp/6Kj04N9TmeIVcg0J24qZg YGsZHuJQcO0Bg3AA== 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 ADCA113A94 for ; Tue, 12 Jul 2022 15:34:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6b5OG42UzWI9fAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:37 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:13 +0530 Message-Id: <20220712153417.14551-6-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 5/9] Rewrite rename05.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename05.c | 193 +++----------------- 1 file changed, 28 insertions(+), 165 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename05.c b/testcases/kernel/syscalls/rename/rename05.c index db10720fe..7894a9214 100644 --- a/testcases/kernel/syscalls/rename/rename05.c +++ b/testcases/kernel/syscalls/rename/rename05.c @@ -1,179 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename05 - * - * DESCRIPTION - * This test will verify that rename(2) fails with EISDIR - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * create the "old" file and the "new" directory - * rename the "old" file to the "new" directory - * - * Test: - * Loop if the proper options are given. - * verify rename() failed and returned EISDIR - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * USAGE - * rename05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer +/*\ + * [Description] * - * RESTRICTIONS - * None. + * Verify that rename(2) fails with EISDIR when + * oldpath is not a directory and newpath is an existing directory. */ -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" +#include +#include "tst_test.h" -void setup(); -void cleanup(); +#define MNT_POINT "mntpoint" +#define TEMP_FILE "tmpfile" +#define TEMP_DIR "tmpdir" -char *TCID = "rename05"; -int TST_TOTAL = 1; - -int fd; -char fname[255], mdir[255]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main(int ac, char **av) +static void setup(void) { - int lc; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* attempt to rename a file to a directory */ - /* Call rename(2) */ - TEST(rename(fname, mdir)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "rename(%s, %s) succeed unexpected", - fname, mdir); - continue; - } - - if (errno != EISDIR) { - tst_resm(TFAIL, "Expected EISDIR got %d", TEST_ERRNO); - } else { - tst_resm(TPASS, "rename() returned EISDIR"); - } - } - - /* - * cleanup and exit - */ - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_TOUCH(TEMP_FILE, 0700, NULL); + SAFE_MKDIR(TEMP_DIR, 00770); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(mdir, "./rndir_%d", getpid()); - sprintf(fname, "./tfile_%d", getpid()); - - /* create "old" file */ - SAFE_TOUCH(cleanup, fname, 0700, NULL); - SAFE_STAT(cleanup, fname, &buf1); - - /* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - - /* create another directory */ - if (stat(mdir, &buf2) != -1) { - tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir); - } - - SAFE_MKDIR(cleanup, mdir, 00770); - - SAFE_STAT(cleanup, mdir, &buf2); - - /* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; + TST_EXP_FAIL(rename(TEMP_FILE, TEMP_DIR), + EISDIR); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); - - /* - * Exit with return code appropriate for results. - */ - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MtAPt7tZ; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=JROWFXZI; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4b21h85z9sB4 for ; Wed, 13 Jul 2022 01:35:42 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0D3D83CA775 for ; Tue, 12 Jul 2022 17:35:40 +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 [IPv6:2001:4b78:1:20::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 4AB643CA2BE for ; Tue, 12 Jul 2022 17:34:44 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 3E405200ACD for ; Tue, 12 Jul 2022 17:34:42 +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 B9BFA1F747 for ; Tue, 12 Jul 2022 15:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640081; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ujIMelnnmWKfxO4LWo9mmbmGKxV7v0Vrhjvf/Lcgvk=; b=MtAPt7tZPTFvH1XDoLygjKHKriZIsZ6mZuvw0Q58zPDDoo6hPTdlda7VpSu9uMQ6Ca2GDy V3rLIJe20NiaE/4FUaHUEYGKfhjyHUNGnVh277FyK21llyZhnmG8m0XInDahapgsXdRTlO hIW+cPrHjfZoPl7qIBchVbZTpoJ2N84= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640081; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ujIMelnnmWKfxO4LWo9mmbmGKxV7v0Vrhjvf/Lcgvk=; b=JROWFXZIbxnknG39txPdpneitffLTloE7Iq8dbniQ/XfCpPHt/nqerDHUKwEH10RIfGhRv Fx81eWXdD7Ut1UCw== 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 3800013A94 for ; Tue, 12 Jul 2022 15:34:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b1gyOpCUzWJDfAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:40 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:14 +0530 Message-Id: <20220712153417.14551-7-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 6/9] Rewrite rename06.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename06.c | 187 +++----------------- 1 file changed, 28 insertions(+), 159 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename06.c b/testcases/kernel/syscalls/rename/rename06.c index e415b4158..82665d1c2 100644 --- a/testcases/kernel/syscalls/rename/rename06.c +++ b/testcases/kernel/syscalls/rename/rename06.c @@ -1,173 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename06 - * - * DESCRIPTION - * This test will verify that rename(2) failed in EINVAL - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * create the "old" directory - * create the "new" directory under the "old" directory - * - * Test: - * Loop if the proper options are given. - * rename the "old" to the "new" directory - * verify rename() failed and returned EINVAL - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * USAGE - * rename06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. +/*\ + * [Description] * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. + * Verify that rename(2) fails with EINVAL when + * an attempt is made to make a directory a subdirectory of itself. */ -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); -char *TCID = "rename06"; -int TST_TOTAL = 1; +#include +#include "tst_test.h" -int fd; -char fdir[255], mdir[255]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; +#define MNT_POINT "mntpoint" +#define DIR1 "dir1" +#define DIR2 DIR1"/dir2" -int main(int ac, char **av) +static void setup(void) { - int lc; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* rename a directory to a subdirectory of itself */ - /* Call rename(2) */ - TEST(rename(fdir, mdir)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "rename(%s, %s) succeed unexpected", - fdir, mdir); - continue; - } - - if (errno != EINVAL) { - tst_resm(TFAIL, "Expected EINVAL got %d", TEST_ERRNO); - } else { - tst_resm(TPASS, "rename() returned EINVAL"); - } - } - - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_MKDIR(DIR1, 00770); + SAFE_MKDIR(DIR2, 00770); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(fdir, "./tdir_%d", getpid()); - sprintf(mdir, "%s/rndir_%d", fdir, getpid()); - - /* create "old" directory */ - if (stat(fdir, &buf1) != -1) { - tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir); - } - SAFE_MKDIR(cleanup, fdir, 00770); - SAFE_STAT(cleanup, fdir, &buf1); - /* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - - /* create another directory */ - if (stat(mdir, &buf2) != -1) { - tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir); - } - SAFE_MKDIR(cleanup, mdir, 00770); - - SAFE_STAT(cleanup, mdir, &buf2); - - /* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; + TST_EXP_FAIL(rename(DIR1, DIR2), + EINVAL); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=zc2NcOIF; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Zma8JfJN; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4bG1f4rz9sB4 for ; Wed, 13 Jul 2022 01:35:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B2F1D3CA727 for ; Tue, 12 Jul 2022 17:35:51 +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 94DB23CA25D for ; Tue, 12 Jul 2022 17:34:46 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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 EB00C600944 for ; Tue, 12 Jul 2022 17:34:45 +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 43B5422A79 for ; Tue, 12 Jul 2022 15:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640085; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dpCk4BE2+utaujLpgELEsJcFf2tnc4mhjWG43gFyoeg=; b=zc2NcOIFE/cjsSlCbES2IduShjhvmjRIzJJbqf/YCDLnuDym8AB+cvvR2ahYJXS3lcyW+/ uBSx/fNZ/ch5aBBa+kMSaJwulF/GNQZwW1tIpJcvc7Xuz5GiY1ZtzpGS+DJyaitGEfLRtU jSgzCtR+MfMfapL+gSn0cGCZZz4WZsI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640085; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dpCk4BE2+utaujLpgELEsJcFf2tnc4mhjWG43gFyoeg=; b=Zma8JfJN7xMMilvfZ/HDU1zNONXQhVNHHb0ZncJ3VdsRLWpCRkaJoptgXp5OlvVlajx2Ey vVpzBWhBSZp86SAw== 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 B342313A94 for ; Tue, 12 Jul 2022 15:34:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /xjDHJSUzWJHfAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:44 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:15 +0530 Message-Id: <20220712153417.14551-8-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 7/9] Rewrite rename07.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename07.c | 171 ++++---------------- 1 file changed, 30 insertions(+), 141 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename07.c b/testcases/kernel/syscalls/rename/rename07.c index 5b95f84bb..51338dbf4 100644 --- a/testcases/kernel/syscalls/rename/rename07.c +++ b/testcases/kernel/syscalls/rename/rename07.c @@ -1,154 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * NAME - * rename07 - * - * DESCRIPTION - * This test will verify that rename(2) failed in ENOTDIR - * - * CALLS - * stat,open,rename,mkdir,close - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * create the "old" directory and the "new" file - * rename the "old" directory to the "new" file - * - * Test: - * Loop if the proper options are given. - * verify rename() failed and returned ENOTDIR - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created.* - * USAGE - * rename07 [-c n] [-e] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar + */ + +/*\ + * [Description] * - * HISTORY - * 07/2001 Ported by Wayne Boyer + * Verify that rename(2) fails with ENOTDIR, when + * oldpath is a directory and newpath exists but is not a directory. * - * RESTRICTIONS - * None. */ -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); -char *TCID = "rename07"; -int TST_TOTAL = 1; +#include +#include "tst_test.h" -int fd; -char mname[255], fdir[255]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; +#define MNT_POINT "mntpoint" +#define TEMP_DIR "tmpdir" +#define TEMP_FILE "tmpfile" -int main(int ac, char **av) +static void setup(void) { - int lc; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* rename a directory to a file */ - /* Call rename(2) */ - TEST(rename(fdir, mname)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "rename(%s, %s) succeeded unexpectedly", - fdir, mname); - continue; - } - - if (TEST_ERRNO != ENOTDIR) { - tst_resm(TFAIL, "Expected ENOTDIR got %d", TEST_ERRNO); - } else { - tst_resm(TPASS, "rename() returned ENOTDIR"); - } - } - - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_MKDIR(TEMP_DIR, 00770); + SAFE_TOUCH(TEMP_FILE, 0700, NULL); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(fdir, "./rndir_%d", getpid()); - sprintf(mname, "./tfile_%d", getpid()); - - /* create "old" directory */ - if (stat(fdir, &buf1) != -1) { - tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir); - } - - SAFE_MKDIR(cleanup, fdir, 00770); - - SAFE_STAT(cleanup, fdir, &buf1); - - /* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - - SAFE_TOUCH(cleanup, mname, 0700, NULL); - - SAFE_STAT(cleanup, mname, &buf2); - - /* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; + TST_EXP_FAIL(rename(TEMP_DIR, TEMP_FILE), + ENOTDIR); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ffdMc/gR; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=pjaPe5uT; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4bT3vwxz9sB4 for ; Wed, 13 Jul 2022 01:36:05 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C35D13CA7FB for ; Tue, 12 Jul 2022 17:36:02 +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 02AB33CA4E4 for ; Tue, 12 Jul 2022 17:34:49 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id 808C360096E for ; Tue, 12 Jul 2022 17:34:49 +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 C11FD1F980 for ; Tue, 12 Jul 2022 15:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640088; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HdZsfHk+7fcBUIQnliOIy3CnmffIsX6aSjHAJGlcaA=; b=ffdMc/gRkR2TvBF0v29TNXfOCtKrm/nS7Gh65W821RWuTMwwQ+eNgGdzkrZ2EXTXEpCK+D 3Bvs1GeGE2weI4c8yC3l8b9hErbxYZfyDnjUqRg/0kcWIXtn1R+v/OhAaG/mFi6WF/NdMS bvVPd9SGhzlr1ACYI8x/+K36FpYz4TU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640088; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HdZsfHk+7fcBUIQnliOIy3CnmffIsX6aSjHAJGlcaA=; b=pjaPe5uTrAKJ54DKaixxrjr2qtpGuOotOEPlxADivEmwo65ql3xZirZHXPMqq17QVkV7nH E3zriezhtkDV1lDQ== 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 3E3DC13A94 for ; Tue, 12 Jul 2022 15:34:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CKkWAJiUzWJQfAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:48 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:16 +0530 Message-Id: <20220712153417.14551-9-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> 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 v3 8/9] Rewrite rename08.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename08.c | 205 +++----------------- 1 file changed, 29 insertions(+), 176 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename08.c b/testcases/kernel/syscalls/rename/rename08.c index 2efdfd390..8a9a9b344 100644 --- a/testcases/kernel/syscalls/rename/rename08.c +++ b/testcases/kernel/syscalls/rename/rename08.c @@ -1,190 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename08 - * - * DESCRIPTION - * This test will verify that rename(2) syscall failed in EFAULT - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * Create a valid file to use in the rename() call. - * - * Test: - * Loop if the proper options are given. - * 1. "old" is a valid file, newpath points to address - * outside allocated address space - * rename the "old" to the "new" file - * verify rename() failed with error EFAULT - * - * 2. "old" points to address outside allocated address space - * ,"new" is a valid file - * rename the "old" to the "new" - * verify rename() failed with error EFAULT - * - * 3. oldpath and newpath are all NULL - * try to rename NULL to NULL - * verify rename() failed with error EFAULT - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created.* - * USAGE - * rename08 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer +/*\ + * [Description] * - * RESTRICTIONS - * None. + * Verify that rename(2) fails with EFAULT, when + * oldpath or newpath points outside of accessible address space. */ -#include -#include -#include -#include -#include -#include "test.h" +#include +#include "tst_test.h" -void setup(); -void cleanup(); +#define MNT_POINT "mntpoint" +#define TEMP_FILE "tmpfile" +#define INVALID_PATH ((void *)-1) -char *TCID = "rename08"; - -char *bad_addr = 0; - -int fd; -char fname[255]; - -struct test_case_t { - char *fd; - char *fd2; - int error; -} TC[] = { -#if !defined(UCLINUX) - /* "new" file is invalid - EFAULT */ - { - fname, (char *)-1, EFAULT}, - /* "old" file is invalid - EFAULT */ - { - (char *)-1, fname, EFAULT}, -#endif - /* both files are NULL - EFAULT */ - { - NULL, NULL, EFAULT} -}; - -int TST_TOTAL = ARRAY_SIZE(TC); - -int main(int ac, char **av) +static void setup(void) { - int lc; - int i; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - - TEST(rename(TC[i].fd, TC[i].fd2)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, "expected failure - " - "errno = %d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - %d : %s - " - "expected %d", TEST_ERRNO, - strerror(TEST_ERRNO), TC[i].error); - } - } - } - - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_TOUCH(TEMP_FILE, 0700, NULL); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(fname, "./tfile_%d", getpid()); - - SAFE_TOUCH(cleanup, fname, 0700, NULL); - -#if !defined(UCLINUX) - bad_addr = mmap(0, 1, PROT_NONE, - MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); - if (bad_addr == MAP_FAILED) { - tst_brkm(TBROK, cleanup, "mmap failed"); - } - TC[0].fd2 = bad_addr; - TC[1].fd = bad_addr; -#endif + TST_EXP_FAIL(rename(INVALID_PATH, TEMP_FILE), + EFAULT); + TST_EXP_FAIL(rename(TEMP_FILE, INVALID_PATH), + EFAULT); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +}; From patchwork Tue Jul 12 15:34:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1655489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bPGFW7F8; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6NcSwK8V; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj4bj28PCz9sB4 for ; Wed, 13 Jul 2022 01:36:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B86573CA564 for ; Tue, 12 Jul 2022 17:36:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (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 B22B33CA584 for ; Tue, 12 Jul 2022 17:34:53 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id E5E071400DA4 for ; Tue, 12 Jul 2022 17:34:52 +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 49D0A1F980 for ; Tue, 12 Jul 2022 15:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657640092; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dCy8kNQLeK3ujTfnYvOWx1qLJGhi4gcggxr0ViiC728=; b=bPGFW7F8ivf3zRCelEcL8OzE5pzNtLWzwfHjmhyIqB5qyPK0OLjH0PUWTYR3iIoHIHr6zX IeONcOg0gQ/FZ+i17BdvOMZ/BPmkLXX61EiRqZxu47yCvPkXcSLroHrHPBXXBxseJE2Cnl obSk137IF8bMrbPWRfKeJ4tOg92SjL8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657640092; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dCy8kNQLeK3ujTfnYvOWx1qLJGhi4gcggxr0ViiC728=; b=6NcSwK8VMX4QyfVbeuHPRgvaMLxKnL9ZoWWLoehky6UK10CcbMcOpQ61bycAxyGGkRtwzX nxVCPhdVjx0fpIDw== 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 BB79313A94 for ; Tue, 12 Jul 2022 15:34:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rcDHHpuUzWJafAAAMHmgww (envelope-from ) for ; Tue, 12 Jul 2022 15:34:51 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 12 Jul 2022 21:04:17 +0530 Message-Id: <20220712153417.14551-10-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712153417.14551-1-akumar@suse.de> References: <20220712153417.14551-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 9/9] Rewrite rename10.c using new LTP API 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" Rewrite using new LTP API and enable all filesystems Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/rename/rename10.c | 187 +++----------------- 1 file changed, 27 insertions(+), 160 deletions(-) diff --git a/testcases/kernel/syscalls/rename/rename10.c b/testcases/kernel/syscalls/rename/rename10.c index 4f0933320..444f65366 100644 --- a/testcases/kernel/syscalls/rename/rename10.c +++ b/testcases/kernel/syscalls/rename/rename10.c @@ -1,175 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * NAME - * rename10 - * - * DESCRIPTION - * This test will verify that rename(2) syscall fails with ENAMETOOLONG - * and ENOENT - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * create the "old" file - * - * Test: - * Loop if the proper options are given. - * 1. rename the "old" to the "new" file - * verify rename() failed with error ENAMETOOLONG - * - * 2. "new" path contains a directory that does not exist - * rename the "old" to the "new" - * verify rename() failed with error ENOENT - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created.* - * - * USAGE - * rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. +/*\ + * [Description] * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. + * Verify that rename(2) fails with ENAMETOOLONG, when + * oldpath or newpath is too long. */ -#include -#include -#include -#include - -#include "test.h" - -void setup(); -void cleanup(); -char *TCID = "rename10"; -int TST_TOTAL = 2; +#include +#include "tst_test.h" -char badmname[] = - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; +#define MNT_POINT "mntpoint" +#define TEMP_FILE "tmpfile" -int fd; -char fname[255], mname[255]; -char mdir[255]; - -struct test_case_t { - char *fd1; - char *fd2; - int error; -} TC[] = { - /* badmname is too long for a file name - ENAMETOOLONG */ - { - fname, badmname, ENAMETOOLONG}, - /* mname contains a directory component which does not exist - ENOENT */ - { - fname, mname, ENOENT} -}; +static char long_path[NAME_MAX + 1] = {[0 ... NAME_MAX] = 'a'}; -int main(int ac, char **av) +static void setup(void) { - int lc; - int i; - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - - TEST(rename(TC[i].fd1, TC[i].fd2)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, "expected failure - " - "errno = %d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - %d : %s - " - "expected %d", TEST_ERRNO, - strerror(TEST_ERRNO), TC[i].error); - } - } - } - - cleanup(); - tst_exit(); - + SAFE_CHDIR(MNT_POINT); + SAFE_TOUCH(TEMP_FILE, 0700, NULL); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - sprintf(fname, "./tfile_%d", getpid()); - sprintf(mdir, "./rndir_%d", getpid()); - sprintf(mname, "%s/rnfile_%d", mdir, getpid()); - - SAFE_TOUCH(cleanup, fname, 0700, NULL); + TST_EXP_FAIL(rename(TEMP_FILE, long_path), + ENAMETOOLONG); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNT_POINT, + .all_filesystems = 1 +};