All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH 6/8] syscalls/link08: Rewrite to the new library
Date: Thu,  5 Apr 2018 16:01:52 +0200	[thread overview]
Message-ID: <20180405140154.6218-7-chrubis@suse.cz> (raw)
In-Reply-To: <20180405140154.6218-1-chrubis@suse.cz>

+ Make use of .needs_rofs

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/link/link08.c | 115 +++++++-------------------------
 1 file changed, 25 insertions(+), 90 deletions(-)

diff --git a/testcases/kernel/syscalls/link/link08.c b/testcases/kernel/syscalls/link/link08.c
index 8cb72d1df..986d5552e 100644
--- a/testcases/kernel/syscalls/link/link08.c
+++ b/testcases/kernel/syscalls/link/link08.c
@@ -15,7 +15,6 @@
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
  */
 /*
  * Test Description:
@@ -32,134 +31,70 @@
  *   4. link() fails with -1 return value and sets errno to ELOOP
  *      if too many symbolic links were encountered in resolving path.
  */
-
-#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 <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
 			 S_IXGRP|S_IROTH|S_IXOTH)
 #define MNT_POINT	"mntpoint"
 #define TEST_FILE	"testfile"
 #define TEST_FILE1	"testfile1"
-#define TEST_FILE2	"mntpoint/testfile3"
+#define TEST_FILE2	"mntpoint/file"
 #define TEST_FILE3	"mntpoint/testfile4"
 
 static char test_file4[PATH_MAX] = ".";
 static void setup(void);
-static void cleanup(void);
-
-static const char *device;
-static int mount_flag;
 
-static struct test_case_t {
+static struct tcase {
 	char *oldpath;
 	char *newpath;
 	int exp_errno;
-} test_cases[] = {
+} tcases[] = {
 	{TEST_FILE1, TEST_FILE, EPERM},
 	{TEST_FILE2, TEST_FILE, EXDEV},
 	{TEST_FILE2, TEST_FILE3, EROFS},
 	{test_file4, TEST_FILE, ELOOP},
 };
 
-static void link_verify(const struct test_case_t *);
-
-char *TCID = "link08";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void link_verify(unsigned int i)
 {
-	int i, lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	struct tcase *tc = &tcases[i];
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			link_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-static void link_verify(const struct test_case_t *tc)
-{
 	TEST(link(tc->oldpath, tc->newpath));
 
 	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "link succeeded unexpectedly");
+		tst_res(TFAIL, "link() succeeded unexpectedly (%li)",
+		        TEST_RETURN);
 		return;
 	}
 
 	if (TEST_ERRNO == tc->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "link failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "link failed unexpectedly; expected: %d - %s",
-			 tc->exp_errno, strerror(tc->exp_errno));
+		tst_res(TPASS | TTERRNO, "link() failed as expected");
+		return;
 	}
-}
 
+	tst_res(TFAIL | TTERRNO,
+		"link() failed unexpectedly; expected: %d - %s",
+		tc->exp_errno, tst_strerrno(tc->exp_errno));
+}
 
 static void setup(void)
 {
 	int i;
-	const char *fs_type;
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to acquire device");
 
-	SAFE_MKDIR(cleanup, TEST_FILE1, DIR_MODE);
+	SAFE_MKDIR(TEST_FILE1, DIR_MODE);
 
-	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
-	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
+	SAFE_MKDIR("test_eloop", DIR_MODE);
+	SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop");
 	for (i = 0; i < 43; i++)
 		strcat(test_file4, "/test_eloop");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
-	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, 0, NULL);
-	mount_flag = 1;
-
-	SAFE_TOUCH(cleanup, TEST_FILE2, 0644, NULL);
-	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type,
-		   MS_REMOUNT | MS_RDONLY, NULL);
 }
 
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(MNT_POINT) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = link_verify,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.needs_rofs = 1,
+	.mntpoint = MNT_POINT,
+};
-- 
2.13.6


  parent reply	other threads:[~2018-04-05 14:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-05 14:01 [LTP] Make use of .needs_rofs Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 1/8] lib/tst_test.c: mntpoint implies tmpdir Cyril Hrubis
2018-04-10  8:58   ` Xiao Yang
2018-04-10  9:14     ` Cyril Hrubis
2018-04-10  9:46       ` Xiao Yang
2018-04-10 10:21         ` Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 2/8] lib/tst_test: Populate the read-only fs Cyril Hrubis
2018-04-18 14:29   ` Cyril Hrubis
2018-04-23  8:45   ` Petr Vorel
2018-04-23 13:59     ` Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 3/8] syscalls/chmod06: Rewrite the new library Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 4/8] syscalls/rmdir02: Make use of .needs_rofs Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 5/8] syscalls/mkdirat02: Rewrite to the new library Cyril Hrubis
2018-04-05 14:01 ` Cyril Hrubis [this message]
2018-04-05 14:01 ` [LTP] [RFC PATCH 7/8] syscalls/utimes01: " Cyril Hrubis
2018-04-05 14:01 ` [LTP] [RFC PATCH 8/8] syscalls/fchmod06: Convert " Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180405140154.6218-7-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.