All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] statfs03: Rewrite using new LTP API
Date: Wed, 23 Nov 2022 21:43:15 +0530	[thread overview]
Message-ID: <20221123161315.7891-1-akumar@suse.de> (raw)

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/statfs/statfs03.c | 173 +++-----------------
 1 file changed, 27 insertions(+), 146 deletions(-)

diff --git a/testcases/kernel/syscalls/statfs/statfs03.c b/testcases/kernel/syscalls/statfs/statfs03.c
index 32aaf830e..2afdbbf04 100644
--- a/testcases/kernel/syscalls/statfs/statfs03.c
+++ b/testcases/kernel/syscalls/statfs/statfs03.c
@@ -1,165 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /*
- *
  *   Copyright (C) Bull S.A. 2001
  *   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
+ *		05/2002 Ported by Jacky Malcles
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	statfs03.c
- *
- * DESCRIPTION
- *	Testcase to check that statfs(2) sets errno to EACCES when
- *	search permission is denied for a component of the path prefix of path.
- *
- * ALGORITHM
- *	 Use a component of the pathname, where search permission
- *	 is denied for a component of the path prefix of path.
- *
- * USAGE:  <for command-line>
- *  statfs03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	05/2002 Ported by Jacky Malcles
- *
- * RESTRICTIONS
- *	NONE
+/*\
+ * [Description]
  *
+ * Verify that statfs(2) fails with errno EACCES when search permission
+ * is denied for a component of the path prefix of path.
  */
-#include <sys/types.h>
-#include <sys/statfs.h>
-#include <sys/stat.h>
-#include <sys/vfs.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include "test.h"
-#include "safe_macros.h"
-#include <pwd.h>
-
-char *TCID = "statfs03";
-int TST_TOTAL = 1;
-int fileHandle = 0;
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-char fname[30] = "testfile";
-char path[50];
-struct statfs buf;
+#include <pwd.h>
+#include "tst_test.h"
 
-void setup(void);
-void cleanup(void);
+#define TEMP_DIR "testdir"
+#define TEMP_DIR2 TEMP_DIR"/subdir"
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	struct passwd *ltpuser;
 
-		TEST(statfs(path, &buf));
+	SAFE_MKDIR(TEMP_DIR, 0444);
+	SAFE_MKDIR(TEMP_DIR2, 0444);
 
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-
-		} else {
-
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), EACCES);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
+	struct statfs buf;
 
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-	SAFE_CHMOD(cleanup, tst_get_tmpdir(), S_IRWXU);
-
-	/* create a test file */
-	sprintf(fname, "%s.%d", fname, getpid());
-	if (mkdir(fname, 0444) == -1) {
-		tst_resm(TFAIL, "creat(2) FAILED to creat temp file");
-	} else {
-		sprintf(path, "%s/%s", fname, fname);
-		if ((fileHandle = creat(path, 0444)) == -1)
-			tst_brkm(TFAIL | TERRNO, cleanup, "creat failed");
-	}
-
-	ltpuser = getpwnam(nobody_uid);
-	if (ltpuser == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "getpwnam failed");
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO | TERRNO, "seteuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-	}
-
+	TST_EXP_FAIL(statfs(TEMP_DIR2, &buf), EACCES);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-	/* reset the process ID to the saved ID (root) */
-	if (setuid(0) == -1) {
-		tst_resm(TINFO, "setuid(0) failed");
-	}
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	close(fileHandle);
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_tmpdir = 1,
+	.needs_root = 1
+};
-- 
2.38.1


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

             reply	other threads:[~2022-11-23 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 16:13 Avinesh Kumar [this message]
2022-11-25  2:05 ` [LTP] [PATCH] statfs03: Rewrite using new LTP API Li Wang

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=20221123161315.7891-1-akumar@suse.de \
    --to=akumar@suse.de \
    --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.