public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/6] Convert utime tests to new LTP API
@ 2022-06-17 17:20 Avinesh Kumar
  2022-06-17 17:20 ` [LTP] [PATCH 1/6] Rewrite utime01.c using " Avinesh Kumar
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp


Avinesh Kumar (6):
  Rewrite utime01.c using new LTP API
  Rewrite utime02.c using new LTP API
  Remove unnecessary header includes
  Rewrite utime04.c using new LTP API
  Rewrite utime05.c using new LTP API
  Rewrite utime06.c using new LTP API

 testcases/kernel/syscalls/utime/utime01.c | 250 ++++----------------
 testcases/kernel/syscalls/utime/utime02.c | 265 +++++-----------------
 testcases/kernel/syscalls/utime/utime03.c |   5 +-
 testcases/kernel/syscalls/utime/utime04.c | 204 +++--------------
 testcases/kernel/syscalls/utime/utime05.c | 218 ++++--------------
 testcases/kernel/syscalls/utime/utime06.c | 196 +++++-----------
 6 files changed, 234 insertions(+), 904 deletions(-)

-- 
2.36.1


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 1/6] Rewrite utime01.c using new LTP API
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 10:17   ` Cyril Hrubis
  2022-06-17 17:20 ` [LTP] [PATCH 2/6] Rewrite utime02.c " Avinesh Kumar
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime01.c | 250 ++++------------------
 1 file changed, 45 insertions(+), 205 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
index 1e6862515..acdb07076 100644
--- a/testcases/kernel/syscalls/utime/utime01.c
+++ b/testcases/kernel/syscalls/utime/utime01.c
@@ -1,223 +1,63 @@
+// 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
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime01
- *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the current time, if the times argument
- *  is null, and the user ID of the process is "root".
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to the current time.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   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,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime01 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-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 John George
- *		-Ported
- *
- * Restrictions:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * [Description]
+ *  Verify that the system call utime() successfully changes the last
+ *  access and modification times of a file to the current time if the
+ *  times argument is NULL and the user ID of the process is "root".
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <time.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
 
-char *TCID = "utime01";
-int TST_TOTAL = 1;
-time_t curr_time;		/* current time in seconds */
+#include "tst_test.h"
+#include "tst_clocks.h"
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
+#define FILE_MODE	0444
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	long type;
-	time_t modf_time, access_time;
-	time_t pres_time;	/* file modification/access/present time */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-		if (tst_kvercmp(2, 6, 18) < 0)
-			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
-				" on %s filesystem before 2.6.18",
-				 tst_fs_type_name(type));
-		break;
-	case TST_V9FS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do utime on a file on %s filesystem",
-			 tst_fs_type_name(type));
-		break;
-	}
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to the current time.
-		 */
-		TEST(utime(TEMP_FILE, NULL));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Sleep for a second so that mod time and
-			 * access times will be different from the
-			 * current time
-			 */
-			sleep(2);
-
-			/*
-			 * Get the current time now, after calling
-			 * utime(2)
-			 */
-			pres_time = time(NULL);
-
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if (modf_time <= curr_time ||
-			    modf_time >= pres_time ||
-			    access_time <= curr_time ||
-			    access_time >= pres_time) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, NULL) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;
-	}
-
-	cleanup();
-	tst_exit();
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
 }
 
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
+static void run(void)
 {
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Get the current time */
-	curr_time = time(NULL);
+	struct stat stat_buf;
+	time_t pre_time, post_time;
+
+	pre_time = tst_get_fs_timestamp();
+	TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE);
+	if (!TST_PASS) {
+		tst_res(TFAIL | TTERRNO, "utime(%s) failed", TEMP_FILE);
+		return;
+	}
+	post_time = tst_get_fs_timestamp();
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-	/*
-	 * Sleep for a second so that mod time and access times will be
-	 * different from the current time
-	 */
-	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
+	if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time)
+		tst_res(TFAIL, "utime() did not set expected mtime");
 
+	if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time)
+		tst_res(TFAIL, "utime() did not set expected atime");
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
+	}
+};
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 2/6] Rewrite utime02.c using new LTP API
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
  2022-06-17 17:20 ` [LTP] [PATCH 1/6] Rewrite utime01.c using " Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 10:19   ` Cyril Hrubis
  2022-06-17 17:20 ` [LTP] [PATCH 3/6] Remove unnecessary header includes Avinesh Kumar
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime02.c | 265 +++++-----------------
 1 file changed, 53 insertions(+), 212 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime02.c b/testcases/kernel/syscalls/utime/utime02.c
index 14d5e18c9..59df9953b 100644
--- a/testcases/kernel/syscalls/utime/utime02.c
+++ b/testcases/kernel/syscalls/utime/utime02.c
@@ -1,238 +1,79 @@
+// 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
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime02
- *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the current time, under the following
- *  constraints,
- *	- The times argument is null.
+/*\
+ * [Description]
+ *  Verify that the system call utime() successfully changes the last
+ *  access and modification times of a file to the current time,
+ *  under the following constraints:
+ *	- The times argument is NULL.
  *	- The user ID of the process is not "root".
  *	- The file is owned by the user ID of the process.
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to the current time.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   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,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *	utime02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-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 John George
- *		-Ported
- *
- * Restrictions:
- *
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
 #include <pwd.h>
-#include <time.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
 
-char *TCID = "utime02";
-int TST_TOTAL = 1;
-time_t curr_time;		/* current time in seconds */
+#include "tst_test.h"
+#include "tst_clocks.h"
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
+#define FILE_MODE	0444
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
+#define TEST_USERNAME "nobody"
 
-int main(int ac, char **av)
-{
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	long type;
-	time_t modf_time, access_time;
-	time_t pres_time;	/* file modification/access/present time */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-		if (tst_kvercmp(2, 6, 18) < 0)
-			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
-				" on %s filesystem before 2.6.18",
-				 tst_fs_type_name(type));
-		break;
-	case TST_V9FS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do utime on a file on %s filesystem",
-			 tst_fs_type_name(type));
-		break;
-	}
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to the current time.
-		 */
-		TEST(utime(TEMP_FILE, NULL));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Sleep for a second so that mod time and
-			 * access times will be different from the
-			 * current time
-			 */
-			sleep(2);
-
-			/*
-			 * Get the current time now, after calling
-			 * utime(2)
-			 */
-			pres_time = time(NULL);
-
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if (modf_time <= curr_time ||
-			    modf_time >= pres_time ||
-			    access_time <= curr_time ||
-			    access_time >= pres_time) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, NULL) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
+static void setup(void)
 {
-	int fildes;		/* file handle for temp file */
+	struct passwd *pw;
 
-	tst_require_root();
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
+	SAFE_CHOWN(TEMP_FILE, pw->pw_uid, pw->pw_gid);
 
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Get the current time */
-	curr_time = time(NULL);
-
-	/*
-	 * Sleep for a second so that mod time and access times will be
-	 * different from the current time
-	 */
-	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
 
+	SAFE_SETEUID(pw->pw_uid);
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
+static void run(void)
 {
+	struct stat stat_buf;
+	time_t pre_time, post_time;
+
+	pre_time = tst_get_fs_timestamp();
+	TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE);
+	if (!TST_PASS) {
+		tst_res(TFAIL | TTERRNO, "utime(%s) failed", TEMP_FILE);
+		return;
+	}
+	post_time = tst_get_fs_timestamp();
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-	tst_rmdir();
+	if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time)
+		tst_res(TFAIL, "utime() did not set expected mtime");
 
+	if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time)
+		tst_res(TFAIL, "utime() did not set expected atime");
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
+	}
+};
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 3/6] Remove unnecessary header includes
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
  2022-06-17 17:20 ` [LTP] [PATCH 1/6] Rewrite utime01.c using " Avinesh Kumar
  2022-06-17 17:20 ` [LTP] [PATCH 2/6] Rewrite utime02.c " Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 10:24   ` Cyril Hrubis
  2022-06-17 17:20 ` [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API Avinesh Kumar
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime03.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index 2358fd70b..0c64518d2 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -18,11 +18,8 @@
  * - The user ID of the process has write access to the file.
  */
 
-#include <sys/types.h>
 #include <pwd.h>
 #include <utime.h>
-#include <sys/stat.h>
-#include <time.h>
 
 #include "tst_test.h"
 #include "tst_uid.h"
@@ -60,7 +57,7 @@ static void run(void)
 	struct stat statbuf;
 	time_t mintime, maxtime;
 
-	utbuf.modtime = time(0) - 5;
+	utbuf.modtime = tst_get_fs_timestamp() - 5;
 	utbuf.actime = utbuf.modtime + 1;
 	TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf));
 	SAFE_STAT(TEMP_FILE, &statbuf);
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
                   ` (2 preceding siblings ...)
  2022-06-17 17:20 ` [LTP] [PATCH 3/6] Remove unnecessary header includes Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 12:38   ` Cyril Hrubis
  2022-06-17 17:20 ` [LTP] [PATCH 5/6] Rewrite utime05.c " Avinesh Kumar
  2022-06-17 17:20 ` [LTP] [PATCH 6/6] Rewrite utime06.c " Avinesh Kumar
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime04.c | 204 ++++------------------
 1 file changed, 37 insertions(+), 167 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime04.c b/testcases/kernel/syscalls/utime/utime04.c
index 5253f768a..4b516f403 100644
--- a/testcases/kernel/syscalls/utime/utime04.c
+++ b/testcases/kernel/syscalls/utime/utime04.c
@@ -1,190 +1,60 @@
+// 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
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime04
- *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the time specified by times argument, if
- *  the times argument is not null, and the user ID of the process is "root".
- *
- * Expected Result:
- *   utime succeeds returning zero and sets the access and modification
- *   times of the file to that specified by the times argument.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   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,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime04 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-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 John George
- *		-Ported
- *
- * Restrictions:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * [Description]
+ *  Verify that the system call utime() successfully changes the last
+ *  access and modification times of a file to the values specified by
+ *  times argument, under the following constraints:
+ *  - The times argument is not NULL.
+ *  - The user ID of the process is "root".
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
-#define NEW_TIME	10000
-
-char *TCID = "utime04";
-int TST_TOTAL = 1;
+#define FILE_MODE	0444
+#define NEW_MODF_TIME	10000
+#define NEW_ACCESS_TIME	20000
 
-struct utimbuf times;		/* struct. buffer for utime() */
+static struct utimbuf times;
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	time_t modf_time, access_time;
-	/* file modification/access time */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to that specified by
-		 * times argument.
-		 */
-		TEST(utime(TEMP_FILE, &times));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if ((modf_time != NEW_TIME) ||
-			    (access_time != NEW_TIME)) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, &times) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;	/* incr TEST_LOOP counter */
-	}
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
 
-	cleanup();
-	tst_exit();
+	times.modtime = NEW_MODF_TIME;
+	times.actime = NEW_ACCESS_TIME;
 }
 
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
+static void run(void)
 {
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
+	struct stat stat_buf;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	TST_EXP_PASS(utime(TEMP_FILE, &times), "utime(%s, &times)", TEMP_FILE);
 
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
+	if (!TST_PASS) {
+		tst_res(TFAIL | TTERRNO, "utime(%s, &times) failed", TEMP_FILE);
+		return;
+	}
 
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-	/* Initialize the modification and access time in the times arg */
-	times.actime = NEW_TIME;
-	times.modtime = NEW_TIME;
+	if (stat_buf.st_mtime != NEW_MODF_TIME)
+		tst_res(TFAIL, "utime() did not set expected mtime");
 
+	if (stat_buf.st_atime != NEW_ACCESS_TIME)
+		tst_res(TFAIL, "utime() did not set expected atime");
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_tmpdir = 1
+};
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 5/6] Rewrite utime05.c using new LTP API
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
                   ` (3 preceding siblings ...)
  2022-06-17 17:20 ` [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 12:40   ` Cyril Hrubis
  2022-06-17 17:20 ` [LTP] [PATCH 6/6] Rewrite utime06.c " Avinesh Kumar
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime05.c | 218 +++++-----------------
 1 file changed, 45 insertions(+), 173 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime05.c b/testcases/kernel/syscalls/utime/utime05.c
index b2d2450bf..c289fcd2f 100644
--- a/testcases/kernel/syscalls/utime/utime05.c
+++ b/testcases/kernel/syscalls/utime/utime05.c
@@ -1,200 +1,72 @@
+// 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
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime05
- *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the value specified by the times argument
- *  under the following constraints,
- *		- The times argument is not null,
- *		- The user ID of the process is not "root".
- *		- The file is owned by the user ID of the process.
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to that specified by the times argument.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   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,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *		where,	-c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-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 John George
- *		-Ported
- *
- * Restrictions:
- *
+/*\
+ * [Description]
+ *  Verify that the system call utime() successfully changes the last
+ *  access and modification times of a file to the values specified by
+ *  times argument, under the following constraints:
+ *	- The times argument is not NULL.
+ *	- The user ID of the process is not "root".
+ *	- The file is owned by the user ID of the process.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
 #include <pwd.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
-#define NEW_TIME	10000
-
-char *TCID = "utime05";
-int TST_TOTAL = 1;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+#define FILE_MODE	0444
+#define NEW_MODF_TIME	10000
+#define NEW_ACCESS_TIME	20000
 
-struct utimbuf times;		/* struct. buffer for utime() */
+#define TEST_USERNAME "nobody"
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
+static struct utimbuf times;
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	time_t modf_time, access_time;
-	/* file modification/access time */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to that specified by
-		 * times argument.
-		 */
-		TEST(utime(TEMP_FILE, &times));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if ((modf_time != NEW_TIME) ||
-			    (access_time != NEW_TIME)) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, &times) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;	/* incr TEST_LOOP counter */
-	}
+	struct passwd *pw;
 
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
 
-	tst_require_root();
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
+	SAFE_SETEUID(pw->pw_uid);
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
 
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
+	times.actime = NEW_ACCESS_TIME;
+	times.modtime = NEW_MODF_TIME;
+}
 
-	TEST_PAUSE;
+static void run(void)
+{
+	struct stat stat_buf;
 
-	tst_tmpdir();
+	TST_EXP_PASS(utime(TEMP_FILE, &times), "utime(%s, &times)", TEMP_FILE);
 
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
+	if (!TST_PASS) {
+		tst_res(TFAIL | TTERRNO, "utime(%s, &times) failed", TEMP_FILE);
+		return;
+	}
 
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-	/* Initialize the modification and access time in the times arg */
-	times.actime = NEW_TIME;
-	times.modtime = NEW_TIME;
+	if (stat_buf.st_mtime != NEW_MODF_TIME)
+		tst_res(TFAIL, "utime() did not set expected mtime");
 
+	if (stat_buf.st_atime != NEW_ACCESS_TIME)
+		tst_res(TFAIL, "utime() did not set expected atime");
 }
 
-/*
- * void
- * cleanup() -	performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- *		Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_tmpdir = 1
+};
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH 6/6] Rewrite utime06.c using new LTP API
  2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
                   ` (4 preceding siblings ...)
  2022-06-17 17:20 ` [LTP] [PATCH 5/6] Rewrite utime05.c " Avinesh Kumar
@ 2022-06-17 17:20 ` Avinesh Kumar
  2022-06-21 12:59   ` Cyril Hrubis
  5 siblings, 1 reply; 13+ messages in thread
From: Avinesh Kumar @ 2022-06-17 17:20 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/utime/utime06.c | 196 ++++++----------------
 1 file changed, 53 insertions(+), 143 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime06.c b/testcases/kernel/syscalls/utime/utime06.c
index 6d80677e4..aad5268ca 100644
--- a/testcases/kernel/syscalls/utime/utime06.c
+++ b/testcases/kernel/syscalls/utime/utime06.c
@@ -1,174 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) International Business Machines  Corp., 2001
- *	07/2001 John George
- *
- * 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 John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Description:
- * 1. Verify that the system call utime() fails to set the modification
- *    and access times of a file to the current time, under the following
- *    constraints,
- *	 - The times argument is null.
+/*\
+ * [Description]
+ * 1. Verify that the system call utime() fails to change the last access
+ *    and modification times of a file to the current time, and errno is
+ *    set to EACCES, when
+ *	 - The times argument is NULL.
+ *   - The user ID of the process does not match the owner of the file.
  *	 - The user ID of the process is not "root".
- * 2. Verify that the system call utime() fails to set the modification
- *    and access times of a file if the specified file doesn't exist.
- * 3. Verify that the system call utime() fails to set the modification
- *    and access times of a file to the current time, under the following
- *    constraints,
- *	 - The times argument is not null.
+ * 2. Verify that the system call utime() fails to change the last access
+ *    and modification times of a file, and the errno is set to ENOENT,
+ *    when
+ *    - The specified file does not exist.
+ * 3. Verify that the system call utime() fails to change the last access
+ *    and modification times of a file to the current time, and errno is
+ *    set to EPERM, when
+ *	 - The times argument is not NULL.
+ *   - The user ID of the process does not match the owner of the file.
  *	 - The user ID of the process is not "root".
- * 4. Verify that the system call utime() fails to set the modification
- *    and access times of a file that resides on a read-only file system.
+ * 4. Verify that the system call utime() fails to change the last access
+ *    and modification times of a file, and errno is set to EROFS, when
+ *   - The path resides on a read-only filesystem.
  */
 
-#include <errno.h>
-#include <fcntl.h>
 #include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
 #include <utime.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mount.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TEMP_FILE	"tmp_file"
 #define MNT_POINT	"mntpoint"
+#define FILE_MODE	0644
+#define TEST_USERNAME "nobody"
 
-char *TCID = "utime06";
-static struct passwd *ltpuser;
 static const struct utimbuf times;
-static const char *dev;
-static int mount_flag;
-static void setup_nobody(void);
-static void cleanup_nobody(void);
 
-struct test_case_t {
+static struct tcase {
 	char *pathname;
 	int exp_errno;
-	const struct utimbuf *times;
-	void (*setup_func)(void);
-	void (*cleanup_func)(void);
-} Test_cases[] = {
-	{TEMP_FILE, EACCES, NULL, setup_nobody, cleanup_nobody},
-	{"", ENOENT, NULL, NULL, NULL},
-	{TEMP_FILE, EPERM, &times, setup_nobody, cleanup_nobody},
-	{MNT_POINT, EROFS, NULL, NULL, NULL},
+	const struct utimbuf *utimbuf;
+	char *err_desc;
+} tcases[] = {
+	{TEMP_FILE, EACCES, NULL, "No write access"},
+	{"", ENOENT, NULL, "File not exist"},
+	{TEMP_FILE, EPERM, &times, "Not file owner"},
+	{MNT_POINT, EROFS, NULL, "Read-only filesystem"}
 };
 
-int TST_TOTAL = ARRAY_SIZE(Test_cases);
-static void setup(void);
-static void utime_verify(const struct test_case_t *);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-	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++)
-			utime_verify(&Test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
 
 static void setup(void)
 {
-	const char *fs_type;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_TOUCH(cleanup, TEMP_FILE, 0644, NULL);
-
-	fs_type = tst_dev_fs_type();
-	dev = tst_acquire_device(cleanup);
-	if (!dev)
-		tst_brkm(TCONF, cleanup, "Failed to acquire test device");
-
-	tst_mkfs(cleanup, dev, fs_type, NULL, NULL);
+	struct passwd *pw;
 
-	SAFE_MKDIR(cleanup, MNT_POINT, 0644);
-	SAFE_MOUNT(cleanup, dev, MNT_POINT, fs_type, MS_RDONLY, NULL);
-	mount_flag = 1;
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
 
-	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
+	SAFE_SETEUID(pw->pw_uid);
 }
 
-static void utime_verify(const struct test_case_t *test)
+static void run(unsigned int i)
 {
-	if (test->setup_func != NULL)
-		test->setup_func();
+	struct tcase *tc = &tcases[i];
 
-	TEST(utime(test->pathname, test->times));
-
-	if (test->cleanup_func != NULL)
-		test->cleanup_func();
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "utime succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "utime failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "utime failed unexpectedly; expected: %d - %s",
-			 test->exp_errno, strerror(test->exp_errno));
-	}
-}
-
-static void setup_nobody(void)
-{
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-}
-
-static void cleanup_nobody(void)
-{
-	SAFE_SETEUID(cleanup, 0);
+	tst_res(TINFO, "running %s test", tc->err_desc);
+	TST_EXP_FAIL(utime(tc->pathname, tc->utimbuf),
+				tc->exp_errno, "%s", tc->err_desc);
 }
 
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(MNT_POINT) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", dev);
-
-	if (dev)
-		tst_release_device(dev);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mntpoint = MNT_POINT,
+	.needs_rofs = 1
+};
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 1/6] Rewrite utime01.c using new LTP API
  2022-06-17 17:20 ` [LTP] [PATCH 1/6] Rewrite utime01.c using " Avinesh Kumar
@ 2022-06-21 10:17   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 10:17 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> +/*\
> + * [Description]

Please add newline after the [Description]

> + *  Verify that the system call utime() successfully changes the last
> + *  access and modification times of a file to the current time if the
> + *  times argument is NULL and the user ID of the process is "root".
      ^
      Just single space here please.
>   */
>  
> -#include <stdio.h>
> -#include <unistd.h>
> -#include <sys/types.h>
> -#include <errno.h>
> -#include <fcntl.h>
>  #include <utime.h>
> -#include <string.h>
> -#include <sys/stat.h>
> -#include <signal.h>
> -#include <time.h>
> -
> -#include "test.h"
> -#include "safe_macros.h"
> -
> -#define TEMP_FILE	"tmp_file"
> -#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
>  
> -char *TCID = "utime01";
> -int TST_TOTAL = 1;
> -time_t curr_time;		/* current time in seconds */
> +#include "tst_test.h"
> +#include "tst_clocks.h"
>  
> -void setup();			/* Main setup function of test */
> -void cleanup();			/* cleanup function for the test */
> +#define MNT_POINT	"mntpoint"
> +#define TEMP_FILE	MNT_POINT"/tmp_file"
> +#define FILE_MODE	0444
>  
> -int main(int ac, char **av)
> +static void setup(void)
>  {
> -	struct stat stat_buf;	/* struct buffer to hold file info. */
> -	int lc;
> -	long type;
> -	time_t modf_time, access_time;
> -	time_t pres_time;	/* file modification/access/present time */
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> -
> -	switch ((type = tst_fs_type(cleanup, "."))) {
> -	case TST_NFS_MAGIC:
> -		if (tst_kvercmp(2, 6, 18) < 0)
> -			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
> -				" on %s filesystem before 2.6.18",
> -				 tst_fs_type_name(type));
> -		break;
> -	case TST_V9FS_MAGIC:
> -		tst_brkm(TCONF, cleanup,
> -			 "Cannot do utime on a file on %s filesystem",
> -			 tst_fs_type_name(type));
> -		break;
> -	}
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> -
> -		/*
> -		 * Invoke utime(2) to set TEMP_FILE access and
> -		 * modification times to the current time.
> -		 */
> -		TEST(utime(TEMP_FILE, NULL));
> -
> -		if (TEST_RETURN == -1) {
> -			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
> -		} else {
> -			/*
> -			 * Sleep for a second so that mod time and
> -			 * access times will be different from the
> -			 * current time
> -			 */
> -			sleep(2);
> -
> -			/*
> -			 * Get the current time now, after calling
> -			 * utime(2)
> -			 */
> -			pres_time = time(NULL);
> -
> -			/*
> -			 * Get the modification and access times of
> -			 * temporary file using stat(2).
> -			 */
> -			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
> -			modf_time = stat_buf.st_mtime;
> -			access_time = stat_buf.st_atime;
> -
> -			/* Now do the actual verification */
> -			if (modf_time <= curr_time ||
> -			    modf_time >= pres_time ||
> -			    access_time <= curr_time ||
> -			    access_time >= pres_time) {
> -				tst_resm(TFAIL, "%s access and "
> -					 "modification times not set",
> -					 TEMP_FILE);
> -			} else {
> -				tst_resm(TPASS, "Functionality of "
> -					 "utime(%s, NULL) successful",
> -					 TEMP_FILE);
> -			}
> -		}
> -		tst_count++;
> -	}
> -
> -	cleanup();
> -	tst_exit();
> +	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
>  }
>  
> -/*
> - * void
> - * setup() - performs all ONE TIME setup for this test.
> - *  Create a temporary directory and change directory to it.
> - *  Create a test file under temporary directory and close it
> - */
> -void setup(void)
> +static void run(void)
>  {
> -	int fildes;		/* file handle for temp file */
> -
> -	tst_require_root();
> -
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	/* Creat a temporary file under above directory */
> -	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
> -
> -	/* Close the temporary file created */
> -	SAFE_CLOSE(cleanup, fildes);
> -
> -	/* Get the current time */
> -	curr_time = time(NULL);
> +	struct stat stat_buf;
> +	time_t pre_time, post_time;

The utime03.c makes sure that the actime and modtime are different from
a current time by explicitly setting it before we call utime() with NULL
argument. Can we do the same here please?

> +	pre_time = tst_get_fs_timestamp();
> +	TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE);
> +	if (!TST_PASS) {
> +		tst_res(TFAIL | TTERRNO, "utime(%s) failed", TEMP_FILE);
> +		return;
> +	}
> +	post_time = tst_get_fs_timestamp();
> +	SAFE_STAT(TEMP_FILE, &stat_buf);
>  
> -	/*
> -	 * Sleep for a second so that mod time and access times will be
> -	 * different from the current time
> -	 */
> -	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
> +	if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time)
> +		tst_res(TFAIL, "utime() did not set expected mtime");
>  
> +	if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time)
> +		tst_res(TFAIL, "utime() did not set expected atime");

Jan just send a similar patch that prints the pre_time and post_time as
well to aid debuggin, can you pleas add that too?

See: http://patchwork.ozlabs.org/project/ltp/patch/e942179576028d20ad2c381d442fefec1af6a556.1655797247.git.jstancek@redhat.com/

>  }
>  
> -/*
> - * void
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - *             completion or premature exit.
> - *  Remove the test directory and testfile created in the setup.
> - */
> -void cleanup(void)
> -{
> -
> -	tst_rmdir();
> -
> -}
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.mntpoint = MNT_POINT,
> +	.mount_device = 1,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const[]) {
> +		"vfat",
> +		"exfat",
> +		NULL
> +	}
> +};

Otherwise the changes looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 2/6] Rewrite utime02.c using new LTP API
  2022-06-17 17:20 ` [LTP] [PATCH 2/6] Rewrite utime02.c " Avinesh Kumar
@ 2022-06-21 10:19   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 10:19 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
Same comments as for utime01.c apply here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 3/6] Remove unnecessary header includes
  2022-06-17 17:20 ` [LTP] [PATCH 3/6] Remove unnecessary header includes Avinesh Kumar
@ 2022-06-21 10:24   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 10:24 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> ---
>  testcases/kernel/syscalls/utime/utime03.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
> index 2358fd70b..0c64518d2 100644
> --- a/testcases/kernel/syscalls/utime/utime03.c
> +++ b/testcases/kernel/syscalls/utime/utime03.c
> @@ -18,11 +18,8 @@
>   * - The user ID of the process has write access to the file.
>   */
>  
> -#include <sys/types.h>
>  #include <pwd.h>
>  #include <utime.h>
> -#include <sys/stat.h>
> -#include <time.h>
>  
>  #include "tst_test.h"
>  #include "tst_uid.h"
> @@ -60,7 +57,7 @@ static void run(void)
>  	struct stat statbuf;
>  	time_t mintime, maxtime;
>  
> -	utbuf.modtime = time(0) - 5;
> +	utbuf.modtime = tst_get_fs_timestamp() - 5;

This change is not explained in the patch description moreover ideally
patches should do one logical change so if we are going to accept these
changes they should be split into a patch that removes includes and
patch that replaces the time(0).

Although usage of time(0) is not really critical here, the difference
between the time(0) and tst_get_fs_timestamp() is that they may be out
of sync by 1 second as they are not incremenented at the exactly same
time. Hence it does not matter if we set time 5 +-1 seconds in the past
since the result is 100% different from current time.

>  	utbuf.actime = utbuf.modtime + 1;
>  	TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf));
>  	SAFE_STAT(TEMP_FILE, &statbuf);
> -- 
> 2.36.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API
  2022-06-17 17:20 ` [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API Avinesh Kumar
@ 2022-06-21 12:38   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 12:38 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> +#define FILE_MODE	0444
> +#define NEW_MODF_TIME	10000
> +#define NEW_ACCESS_TIME	20000
>  
> -struct utimbuf times;		/* struct. buffer for utime() */
> +static struct utimbuf times;
>  
> -void setup();			/* Main setup function of test */
> -void cleanup();			/* cleanup function for the test */
> -
> -int main(int ac, char **av)
> +static void setup(void)
>  {
> -	struct stat stat_buf;	/* struct buffer to hold file info. */
> -	int lc;
> -	time_t modf_time, access_time;
> -	/* file modification/access time */
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> -
> -		/*
> -		 * Invoke utime(2) to set TEMP_FILE access and
> -		 * modification times to that specified by
> -		 * times argument.
> -		 */
> -		TEST(utime(TEMP_FILE, &times));
> -
> -		if (TEST_RETURN == -1) {
> -			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
> -		} else {
> -			/*
> -			 * Get the modification and access times of
> -			 * temporary file using stat(2).
> -			 */
> -			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
> -			modf_time = stat_buf.st_mtime;
> -			access_time = stat_buf.st_atime;
> -
> -			/* Now do the actual verification */
> -			if ((modf_time != NEW_TIME) ||
> -			    (access_time != NEW_TIME)) {
> -				tst_resm(TFAIL, "%s access and "
> -					 "modification times not set",
> -					 TEMP_FILE);
> -			} else {
> -				tst_resm(TPASS, "Functionality of "
> -					 "utime(%s, &times) successful",
> -					 TEMP_FILE);
> -			}
> -		}
> -		tst_count++;	/* incr TEST_LOOP counter */
> -	}
> +	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
>  
> -	cleanup();
> -	tst_exit();
> +	times.modtime = NEW_MODF_TIME;
> +	times.actime = NEW_ACCESS_TIME;

The times structure can be initialized inline as:

static struct utimbuf times = {
	.modtime = NEW_MOD_TIME,
	.actime = NEW_ACC_TIME,
};

>  }
>  
> -/*
> - * void
> - * setup() - performs all ONE TIME setup for this test.
> - *  Create a temporary directory and change directory to it.
> - *  Create a test file under temporary directory and close it
> - */
> -void setup(void)
> +static void run(void)
>  {
> -	int fildes;		/* file handle for temp file */
> -
> -	tst_require_root();
> +	struct stat stat_buf;
>  
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +	TST_EXP_PASS(utime(TEMP_FILE, &times), "utime(%s, &times)", TEMP_FILE);
>  
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	/* Creat a temporary file under above directory */
> -	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
> +	if (!TST_PASS) {
> +		tst_res(TFAIL | TTERRNO, "utime(%s, &times) failed", TEMP_FILE);

The PASS/FAIL message is already printed by the TST_EXP_PASS() macro,
all that you need to to do here is return.

> +		return;
> +	}
>  
> -	/* Close the temporary file created */
> -	SAFE_CLOSE(cleanup, fildes);
> +	SAFE_STAT(TEMP_FILE, &stat_buf);
>  
> -	/* Initialize the modification and access time in the times arg */
> -	times.actime = NEW_TIME;
> -	times.modtime = NEW_TIME;
> +	if (stat_buf.st_mtime != NEW_MODF_TIME)
> +		tst_res(TFAIL, "utime() did not set expected mtime");
>  
> +	if (stat_buf.st_atime != NEW_ACCESS_TIME)
> +		tst_res(TFAIL, "utime() did not set expected atime");

We do have macros for these kind of checks as well, please use them as:

	TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACC_TIME);

>  }
>  
> -/*
> - * void
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - *             completion or premature exit.
> - *  Remove the test directory and testfile created in the setup.
> - */
> -void cleanup(void)
> -{
> -
> -	tst_rmdir();
> -
> -}
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.needs_root = 1,
> +	.needs_tmpdir = 1
> +};
> -- 
> 2.36.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 5/6] Rewrite utime05.c using new LTP API
  2022-06-17 17:20 ` [LTP] [PATCH 5/6] Rewrite utime05.c " Avinesh Kumar
@ 2022-06-21 12:40   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 12:40 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
The same comments as for the previous test apply here.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH 6/6] Rewrite utime06.c using new LTP API
  2022-06-17 17:20 ` [LTP] [PATCH 6/6] Rewrite utime06.c " Avinesh Kumar
@ 2022-06-21 12:59   ` Cyril Hrubis
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-06-21 12:59 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> -/*
> - * Test Description:
> - * 1. Verify that the system call utime() fails to set the modification
> - *    and access times of a file to the current time, under the following
> - *    constraints,
> - *	 - The times argument is null.
> +/*\
> + * [Description]
> + * 1. Verify that the system call utime() fails to change the last access
> + *    and modification times of a file to the current time, and errno is
> + *    set to EACCES, when
> + *	 - The times argument is NULL.
> + *   - The user ID of the process does not match the owner of the file.
>   *	 - The user ID of the process is not "root".

This does not render particulary well in the asciidoc docparser also the
text is way more verbose than it should be. Let's keept it short and to
to point with something as:

 /*\
  * [Description]
  *
  * Verify that utime() fails with:
  * - EACCESS when user does not have rights to modify the file.
  * - ENOENT when specified file does not exists.
  * - ...
  *

> - * 2. Verify that the system call utime() fails to set the modification
> - *    and access times of a file if the specified file doesn't exist.
> - * 3. Verify that the system call utime() fails to set the modification
> - *    and access times of a file to the current time, under the following
> - *    constraints,
> - *	 - The times argument is not null.
> + * 2. Verify that the system call utime() fails to change the last access
> + *    and modification times of a file, and the errno is set to ENOENT,
> + *    when
> + *    - The specified file does not exist.
> + * 3. Verify that the system call utime() fails to change the last access
> + *    and modification times of a file to the current time, and errno is
> + *    set to EPERM, when
> + *	 - The times argument is not NULL.
> + *   - The user ID of the process does not match the owner of the file.
>   *	 - The user ID of the process is not "root".
> - * 4. Verify that the system call utime() fails to set the modification
> - *    and access times of a file that resides on a read-only file system.
> + * 4. Verify that the system call utime() fails to change the last access
> + *    and modification times of a file, and errno is set to EROFS, when
> + *   - The path resides on a read-only filesystem.
>   */
>  
> -#include <errno.h>
> -#include <fcntl.h>
>  #include <pwd.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <signal.h>
> -#include <string.h>
> -#include <unistd.h>
>  #include <utime.h>
> -#include <sys/wait.h>
> -#include <sys/stat.h>
> -#include <sys/types.h>
> -#include <sys/mount.h>
>  
> -#include "test.h"
> -#include "safe_macros.h"
> +#include "tst_test.h"
>  
>  #define TEMP_FILE	"tmp_file"
>  #define MNT_POINT	"mntpoint"
> +#define FILE_MODE	0644
> +#define TEST_USERNAME "nobody"
>  
> -char *TCID = "utime06";
> -static struct passwd *ltpuser;
>  static const struct utimbuf times;
> -static const char *dev;
> -static int mount_flag;
> -static void setup_nobody(void);
> -static void cleanup_nobody(void);
>  
> -struct test_case_t {
> +static struct tcase {
>  	char *pathname;
>  	int exp_errno;
> -	const struct utimbuf *times;
> -	void (*setup_func)(void);
> -	void (*cleanup_func)(void);
> -} Test_cases[] = {
> -	{TEMP_FILE, EACCES, NULL, setup_nobody, cleanup_nobody},
> -	{"", ENOENT, NULL, NULL, NULL},
> -	{TEMP_FILE, EPERM, &times, setup_nobody, cleanup_nobody},
> -	{MNT_POINT, EROFS, NULL, NULL, NULL},
> +	const struct utimbuf *utimbuf;
> +	char *err_desc;
> +} tcases[] = {
> +	{TEMP_FILE, EACCES, NULL, "No write access"},
> +	{"", ENOENT, NULL, "File not exist"},
> +	{TEMP_FILE, EPERM, &times, "Not file owner"},
> +	{MNT_POINT, EROFS, NULL, "Read-only filesystem"}
>  };
>  
> -int TST_TOTAL = ARRAY_SIZE(Test_cases);
> -static void setup(void);
> -static void utime_verify(const struct test_case_t *);
> -static void cleanup(void);
> -
> -int main(int ac, char **av)
> -{
> -	int lc;
> -	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++)
> -			utime_verify(&Test_cases[i]);
> -	}
> -
> -	cleanup();
> -	tst_exit();
> -}
>  
>  static void setup(void)
>  {
> -	const char *fs_type;
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	tst_require_root();
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	SAFE_TOUCH(cleanup, TEMP_FILE, 0644, NULL);
> -
> -	fs_type = tst_dev_fs_type();
> -	dev = tst_acquire_device(cleanup);
> -	if (!dev)
> -		tst_brkm(TCONF, cleanup, "Failed to acquire test device");
> -
> -	tst_mkfs(cleanup, dev, fs_type, NULL, NULL);
> +	struct passwd *pw;
>  
> -	SAFE_MKDIR(cleanup, MNT_POINT, 0644);
> -	SAFE_MOUNT(cleanup, dev, MNT_POINT, fs_type, MS_RDONLY, NULL);
> -	mount_flag = 1;
> +	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
>  
> -	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
> +	pw = SAFE_GETPWNAM(TEST_USERNAME);
> +	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
> +	SAFE_SETEUID(pw->pw_uid);
>  }
>  
> -static void utime_verify(const struct test_case_t *test)
> +static void run(unsigned int i)
>  {
> -	if (test->setup_func != NULL)
> -		test->setup_func();
> +	struct tcase *tc = &tcases[i];
>  
> -	TEST(utime(test->pathname, test->times));
> -
> -	if (test->cleanup_func != NULL)
> -		test->cleanup_func();
> -
> -	if (TEST_RETURN != -1) {
> -		tst_resm(TFAIL, "utime succeeded unexpectedly");
> -		return;
> -	}
> -
> -	if (TEST_ERRNO == test->exp_errno) {
> -		tst_resm(TPASS | TTERRNO, "utime failed as expected");
> -	} else {
> -		tst_resm(TFAIL | TTERRNO,
> -			 "utime failed unexpectedly; expected: %d - %s",
> -			 test->exp_errno, strerror(test->exp_errno));
> -	}
> -}
> -
> -static void setup_nobody(void)
> -{
> -	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
> -}
> -
> -static void cleanup_nobody(void)
> -{
> -	SAFE_SETEUID(cleanup, 0);
> +	tst_res(TINFO, "running %s test", tc->err_desc);

We print the tc->err_desc in the TST_EXP_FAIL() right? No need to print
it twice.

> +	TST_EXP_FAIL(utime(tc->pathname, tc->utimbuf),
> +				tc->exp_errno, "%s", tc->err_desc);
>  }
>  
> -static void cleanup(void)
> -{
> -	if (mount_flag && tst_umount(MNT_POINT) < 0)
> -		tst_resm(TWARN | TERRNO, "umount device:%s failed", dev);
> -
> -	if (dev)
> -		tst_release_device(dev);
> -
> -	tst_rmdir();
> -}
> +static struct tst_test test = {
> +	.setup = setup,
> +	.test = run,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.mntpoint = MNT_POINT,
> +	.needs_rofs = 1
> +};

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-21 12:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-17 17:20 [LTP] [PATCH 0/6] Convert utime tests to new LTP API Avinesh Kumar
2022-06-17 17:20 ` [LTP] [PATCH 1/6] Rewrite utime01.c using " Avinesh Kumar
2022-06-21 10:17   ` Cyril Hrubis
2022-06-17 17:20 ` [LTP] [PATCH 2/6] Rewrite utime02.c " Avinesh Kumar
2022-06-21 10:19   ` Cyril Hrubis
2022-06-17 17:20 ` [LTP] [PATCH 3/6] Remove unnecessary header includes Avinesh Kumar
2022-06-21 10:24   ` Cyril Hrubis
2022-06-17 17:20 ` [LTP] [PATCH 4/6] Rewrite utime04.c using new LTP API Avinesh Kumar
2022-06-21 12:38   ` Cyril Hrubis
2022-06-17 17:20 ` [LTP] [PATCH 5/6] Rewrite utime05.c " Avinesh Kumar
2022-06-21 12:40   ` Cyril Hrubis
2022-06-17 17:20 ` [LTP] [PATCH 6/6] Rewrite utime06.c " Avinesh Kumar
2022-06-21 12:59   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox