Skip to contentSkip to conversation

link/link04: Convert to new API

PATCH In review tangmeng 2 participants 7 messages Oct 29, 2021 – Nov 2, 2021

lore
Share & tools
lore

tangmeng

author
#0 lore raw

PATCH 1/4 link/link04: Convert to new API

---
 testcases/kernel/syscalls/link/link04.c | 140 +++++-------------------
 1 file changed, 29 insertions(+), 111 deletions(-)
testcases/kernel/syscalls/link/link04.c +29 -111
index d9408845e..acc8a7134 100644
@@ -1,65 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR		: Richard Logan
  *  CO-PILOT		: William Roske
  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
- *
- * 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/
- *
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Negative test cases for link(2).
  *
  * This test program should contain test cases where link will fail regardless
  * of who executed it (i.e. joe-user or root)
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <sys/param.h>
 #include <sys/mman.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 static char longpath[PATH_MAX + 2];
 
-struct test_case_t {
+struct tcase_t {
 	char *file1;
 	char *desc1;
 	char *file2;
 	char *desc2;
 	int exp_errno;
-} test_cases[] = {
+} tcases[] = {
 	/* first path is invalid */
 	{"nonexistfile", "non-existent file", "nefile", "nefile", ENOENT},
 	{"", "path is empty string", "nefile", "nefile", ENOENT},
@@ -81,90 +48,41 @@ struct test_case_t {
 	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
 };
 
-char *TCID = "link04";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
+static unsigned int TST_TOTAL = ARRAY_SIZE(tcases);
 
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_link(void)
 {
-	int lc;
-	char *fname1, *fname2;
-	char *desc1, *desc2;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			fname1 = test_cases[i].file1;
-			desc1 = test_cases[i].desc1;
-			fname2 = test_cases[i].file2;
-			desc2 = test_cases[i].desc2;
-
-			TEST(link(fname1, fname2));
-
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO == test_cases[i].exp_errno) {
-					tst_resm(TPASS | TTERRNO,
-						 "link(<%s>, <%s>)",
-						 desc1, desc2);
-				} else {
-					tst_resm(TFAIL | TTERRNO,
-						 "link(<%s>, <%s>) Failed "
-					         "expected errno: %d",
-						 desc1, desc2,
-						 test_cases[i].exp_errno);
-				}
-			} else {
-				tst_resm(TFAIL,
-					 "link(<%s>, <%s>) returned %ld, "
-				         "expected -1, errno:%d",
-					 desc1, desc2, TEST_RETURN,
-					 test_cases[i].exp_errno);
-			}
-		}
+	unsigned int i;
 
+	for (i = 0; i < TST_TOTAL; i++) {
+		TST_EXP_FAIL(link(tcases[i].file1, tcases[i].file2),
+				tcases[i].exp_errno, "link(<%s>, <%s>)",
+				tcases[i].desc1, tcases[i].desc2);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
 static void setup(void)
 {
-	int n;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
+	unsigned int i;
 
 	memset(longpath, 'a', PATH_MAX+1);
-	SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
-	SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
-	SAFE_MKDIR(cleanup, "dir", 0777);
+	SAFE_TOUCH("regfile", 0777, NULL);
+	SAFE_TOUCH("regfile2", 0777, NULL);
+	SAFE_MKDIR("dir", 0777);
 
-	void *bad_addr = tst_get_bad_addr(cleanup);
+	void *bad_addr = tst_get_bad_addr(NULL);
 
-	for (n = 0; n < TST_TOTAL; n++) {
-		if (!test_cases[n].file1)
-			test_cases[n].file1 = bad_addr;
+	for (i = 0; i < TST_TOTAL; i++) {
+		if (!tcases[i].file1)
+			tcases[i].file1 = bad_addr;
 
-		if (!test_cases[n].file2)
-			test_cases[n].file2 = bad_addr;
+		if (!tcases[i].file2)
+			tcases[i].file2 = bad_addr;
 	}
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+};
Signature · 7 lines
2.20.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

PATCH 2/4 link/link05: Convert to new API

---
 testcases/kernel/syscalls/link/link05.c | 159 ++++++------------------
 1 file changed, 37 insertions(+), 122 deletions(-)
testcases/kernel/syscalls/link/link05.c +37 -122
index 5981ae62f..28d6079f5 100644
@@ -1,161 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR		: Richard Logan
  *  CO-PILOT		: William Roske
  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
- *
- * 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/
  */
 
 /*
  * Test if link(2) fails with EMLINK.
  */
 
-#include <sys/types.h>
-#include <fcntl.h>
+#include <stdio.h>
 #include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
-static void help(void);
-
-char *TCID = "link05";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #define BASENAME	"lkfile"
 
 static char fname[255];
 
-static char *links_arg;
-
-option_t options[] = {
-	{"N:", NULL, &links_arg},
-	{NULL, NULL, NULL}
-};
-
 static int nlinks = 1000;
 
-int main(int ac, char **av)
+static void verify_link(void)
 {
-	int lc;
 	struct stat fbuf, lbuf;
 	int cnt;
 	char lname[255];
 
-	tst_parse_opts(ac, av, options, &help);
-
-	if (links_arg) {
-		nlinks = atoi(links_arg);
-
-		if (nlinks == 0) {
-			tst_brkm(TBROK, NULL,
-			         "nlinks is not a positive number");
-		}
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s%d", fname, cnt);
+		TST_EXP_PASS(link(fname, lname), "link(%s, %s)", fname, lname);
 	}
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
-			TEST(link(fname, lname));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "link(%s, %s) Failed, errno=%d : %s",
-					 fname, lname, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			}
-		}
-
-		SAFE_STAT(cleanup, fname, &fbuf);
+	SAFE_STAT(fname, &fbuf);
 
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s%d", fname, cnt);
 
-			SAFE_STAT(cleanup, lname, &lbuf);
-			if (fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 ||
-			    (fbuf.st_nlink != lbuf.st_nlink)) {
+		SAFE_STAT(lname, &lbuf);
+		if (fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 ||
+		    (fbuf.st_nlink != lbuf.st_nlink)) {
 
-				tst_resm(TFAIL,
-					 "link(%s, %s[1-%d]) ret %ld for %d "
-				         "files, stat values do not match %d %d",
-					 fname, fname, nlinks,
-					 TEST_RETURN, nlinks,
-					 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
-				break;
-			}
-		}
-		if (cnt >= nlinks) {
-			tst_resm(TPASS,
-				 "link(%s, %s[1-%d]) ret %ld for %d files, "
-			         "stat linkcounts match %d",
-				 fname, fname, nlinks, TEST_RETURN,
-				 nlinks, (int)fbuf.st_nlink);
-		}
-
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
-			SAFE_UNLINK(cleanup, lname);
+			tst_res(TFAIL,
+				 "link(%s, %s[1-%d]) ret %ld for %d "
+				 "files, stat values do not match %d %d",
+				 fname, fname, nlinks,
+				 TST_RET, nlinks,
+				 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
+			break;
 		}
 	}
+	if (cnt >= nlinks) {
+		tst_res(TPASS,
+			 "link(%s, %s[1-%d]) ret %ld for %d files, "
+			 "stat linkcounts match %d",
+			 fname, fname, nlinks, TST_RET,
+			 nlinks, (int)fbuf.st_nlink);
+	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void help(void)
-{
-	printf("  -N #links : create #links hard links every iteration\n");
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s%d", fname, cnt);
+		SAFE_UNLINK(lname);
+	}
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	sprintf(fname, "%s_%d", BASENAME, getpid());
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
+	SAFE_TOUCH(fname, 0700, NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+};
Signature · 7 lines
2.20.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw

PATCH 3/4 link/link06: Convert to new API

In reply to tangmeng
---
 testcases/kernel/syscalls/link/link06.c | 99 +++++--------------------
 1 file changed, 17 insertions(+), 82 deletions(-)
testcases/kernel/syscalls/link/link06.c +17 -82
index 17b38ad43..305a5417c 100644
@@ -1,113 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) Bull S.A. 2001
  * Copyright (c) International Business Machines  Corp., 2001
  * 06/2002 Ported by Jacky Malcles
  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
- *
- * 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
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Verify that, link() fails with -1 and sets errno to EACCES when Write access
  * to the directory containing newpath is not allowed for the process's
  * effective uid.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define NOBODY_USER	99
 #define MODE_TO S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IXOTH|S_IROTH
 
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "link06";
-int TST_TOTAL = 1;
-
 #define OLDPATH "oldpath"
 #define NEWPATH "newpath"
 
-int main(int ac, char **av)
+static void verify_link(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(link(OLDPATH, NEWPATH));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "link() returned %ld, "
-				 "expected -1, errno=%d", TEST_RETURN,
-				 EACCES);
-		} else {
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "link() fails with expected "
-					 "error EACCES errno:%d", TEST_ERRNO);
-			} else {
-				tst_resm(TFAIL, "link() fails with "
-					 "errno=%d, expected errno=%d",
-					 TEST_ERRNO, EACCES);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(link(OLDPATH, NEWPATH), EACCES);
 }
 
 static void setup(void)
 {
 	struct passwd *nobody_pwd;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	/* Modify mode permissions on test directory */
-	SAFE_CHMOD(cleanup, ".", MODE_TO);
+	SAFE_CHMOD(".", MODE_TO);
 
-	SAFE_TOUCH(cleanup, OLDPATH, 0777, NULL);
-	nobody_pwd = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, nobody_pwd->pw_uid);
+	SAFE_TOUCH(OLDPATH, 0777, NULL);
+	nobody_pwd = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(nobody_pwd->pw_uid);
 }
 
-static void cleanup(void)
-{
-	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
Signature · 7 lines
2.20.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH 3/4] link/link06: Convert to new API

Quoted 2 lines

+ TST_EXP_FAIL(link(OLDPATH, NEWPATH), EACCES);

As this is also test failure for link() syscal, can we combine this test content into link04.c?

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw

PATCH 4/4 link/link07: Convert to new API

In reply to tangmeng
---
 testcases/kernel/syscalls/link/link07.c | 104 +++++-------------------
 1 file changed, 20 insertions(+), 84 deletions(-)
testcases/kernel/syscalls/link/link07.c +20 -84
index 09743b59c..e166fe6e8 100644
@@ -1,42 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) Bull S.A. 2001
  * Copyright (c) International Business Machines  Corp., 2001
  *  06/2002 Ported by Jacky Malcles
  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
- *
- * 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
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Verify that, link() fails with -1 and sets errno to EACCES when one of the
  * directories in oldpath or newpath did not allow search (execute) permission.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define MODE_TO S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IXOTH|S_IROTH|S_IWOTH
 #define MODE_TE S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
@@ -45,74 +23,32 @@
 #define TEST_FILE2      "testdir_1/tfile_2"
 #define NEW_TEST_FILE2  "testdir_1/new_tfile_2"
 
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "link07";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_link(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(link(TEST_FILE2, NEW_TEST_FILE2));
-
-		/* Check return code from link(2) */
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL | TTERRNO, "link() returned %ld, "
-				 "expected -1, errno=%d", TEST_RETURN, EACCES);
-		} else {
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS | TTERRNO,
-				         "link() fails with expected error");
-			} else {
-				tst_resm(TFAIL | TTERRNO, "link() failed"
-				         ", expected errno=%d (EACCES)",
-				         EACCES);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(link(TEST_FILE2, NEW_TEST_FILE2), EACCES,
+			"link(%s, %s)", TEST_FILE2, NEW_TEST_FILE2);
 }
 
 static void setup(void)
 {
 	struct passwd *nobody_pwd;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	/* Modify mode permissions on test directory */
-	SAFE_CHMOD(cleanup, ".", MODE_TO);
+	SAFE_CHMOD(".", MODE_TO);
 
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
+	SAFE_MKDIR(DIR_TEMP, MODE_RWX);
+	SAFE_TOUCH(TEST_FILE2, 0666, NULL);
 
 	/* Modify mode permissions on test directory - test conditions */
-	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_TE);
+	SAFE_CHMOD(DIR_TEMP, MODE_TE);
 
-	nobody_pwd = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, nobody_pwd->pw_uid);
+	nobody_pwd = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(nobody_pwd->pw_uid);
 }
 
-static void cleanup(void)
-{
-	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "seteuid(o) failed");
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
Signature · 7 lines
2.20.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH 4/4] link/link07: Convert to new API

And combine this test into link04.c as well.

There wouldn't be very difficult to setup configuration for the specific tcase before testing.

See how madvise02 achieve that for various situation:
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise02.c

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
In reply to tangmeng

Hi Meng,

Quoted 85 lines · tangmeng
---
 testcases/kernel/syscalls/link/link04.c | 140 +++++-------------------
 1 file changed, 29 insertions(+), 111 deletions(-)
testcases/kernel/syscalls/link/link04.c +4 -30
index d9408845e..acc8a7134 100644
@@ -1,65 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR             : Richard Logan
  *  CO-PILOT           : William Roske
  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
- *
- * 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/
- *
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Negative test cases for link(2).
  *
  * This test program should contain test cases where link will fail

regardless
* of who executed it (i.e. joe-user or root)
*/

testcases/kernel/syscalls/link/link04.c +3 -10
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <sys/param.h>
 #include <sys/mman.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 static char longpath[PATH_MAX + 2];
 
-struct test_case_t {
+struct tcase_t {
        char *file1;
        char *desc1;
        char *file2;
        char *desc2;
        int exp_errno;
-} test_cases[] = {
+} tcases[] = {
        /* first path is invalid */
        {"nonexistfile", "non-existent file", "nefile", "nefile", ENOENT},
        {"", "path is empty string", "nefile", "nefile", ENOENT},

testcases/kernel/syscalls/link/link04.c struct test_case_t { · line 52

Quoted 7 lines
testcases/kernel/syscalls/link/link04.c +1 -2
@@ -81,90 +48,41 @@ struct test_case_t {
        {"regfile", "regfile", "regfile2", "regfile2", EEXIST},
 };
 
-char *TCID = "link04";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
+static unsigned int TST_TOTAL = ARRAY_SIZE(tcases);
 

There is no need to define an extra global variable for the test loop.

LTP itself has already supported that to traversing tcase by .tcnt.

For your reference:
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise01.c#L117

Quoted 117 lines
testcases/kernel/syscalls/link/link04.c +21 -70
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_link(void)
 {
-       int lc;
-       char *fname1, *fname2;
-       char *desc1, *desc2;
-       int i;
-
-       tst_parse_opts(ac, av, NULL, NULL);
-
-       setup();
-
-       for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-               tst_count = 0;
-
-               for (i = 0; i < TST_TOTAL; i++) {
-
-                       fname1 = test_cases[i].file1;
-                       desc1 = test_cases[i].desc1;
-                       fname2 = test_cases[i].file2;
-                       desc2 = test_cases[i].desc2;
-
-                       TEST(link(fname1, fname2));
-
-                       if (TEST_RETURN == -1) {
-                               if (TEST_ERRNO == test_cases[i].exp_errno)
 {
-                                       tst_resm(TPASS | TTERRNO,
-                                                "link(<%s>, <%s>)",
-                                                desc1, desc2);
-                               } else {
-                                       tst_resm(TFAIL | TTERRNO,
-                                                "link(<%s>, <%s>) Failed "
-                                                "expected errno: %d",
-                                                desc1, desc2,
-                                                test_cases[i].exp_errno);
-                               }
-                       } else {
-                               tst_resm(TFAIL,
-                                        "link(<%s>, <%s>) returned %ld, "
-                                        "expected -1, errno:%d",
-                                        desc1, desc2, TEST_RETURN,
-                                        test_cases[i].exp_errno);
-                       }
-               }
+       unsigned int i;
 
+       for (i = 0; i < TST_TOTAL; i++) {
+               TST_EXP_FAIL(link(tcases[i].file1, tcases[i].file2),
+                               tcases[i].exp_errno, "link(<%s>, <%s>)",
+                               tcases[i].desc1, tcases[i].desc2);
        }
-
-       cleanup();
-       tst_exit();
 }
 
 static void setup(void)
 {
-       int n;
-
-       tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-       TEST_PAUSE;
-
-       tst_tmpdir();
+       unsigned int i;
 
        memset(longpath, 'a', PATH_MAX+1);
-       SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
-       SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
-       SAFE_MKDIR(cleanup, "dir", 0777);
+       SAFE_TOUCH("regfile", 0777, NULL);
+       SAFE_TOUCH("regfile2", 0777, NULL);
+       SAFE_MKDIR("dir", 0777);
 
-       void *bad_addr = tst_get_bad_addr(cleanup);
+       void *bad_addr = tst_get_bad_addr(NULL);
 
-       for (n = 0; n < TST_TOTAL; n++) {
-               if (!test_cases[n].file1)
-                       test_cases[n].file1 = bad_addr;
+       for (i = 0; i < TST_TOTAL; i++) {
+               if (!tcases[i].file1)
+                       tcases[i].file1 = bad_addr;
 
-               if (!test_cases[n].file2)
-                       test_cases[n].file2 = bad_addr;
+               if (!tcases[i].file2)
+                       tcases[i].file2 = bad_addr;
        }
 }
 
-static void cleanup(void)
-{
-       tst_rmdir();
-}
+static struct tst_test test = {
+       .test_all = verify_link,
+       .setup = setup,
+       .needs_tmpdir = 1,
+};
--

2.20.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp