All of lore.kernel.org
 help / color / mirror / Atom feed
From: QI Fuli <fukuri.sai@gmail.com>
To: ltp@lists.linux.it
Cc: QI Fuli <qi.fuli@fujitsu.com>
Subject: [LTP] [PATCH v6 4/5] syscalls/dup2/dup204: Convert to new API
Date: Mon, 20 Sep 2021 12:37:04 +0900	[thread overview]
Message-ID: <20210920033705.20544-5-qi.fuli@fujitsu.com> (raw)
In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com>

From: QI Fuli <qi.fuli@fujitsu.com>

Signed-off-by: QI Fuli <qi.fuli@fujitsu.com>
---
 testcases/kernel/syscalls/dup2/dup204.c | 147 +++++++-----------------
 1 file changed, 40 insertions(+), 107 deletions(-)

diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c
index a357bc17e..c9304d5c3 100644
--- a/testcases/kernel/syscalls/dup2/dup204.c
+++ b/testcases/kernel/syscalls/dup2/dup204.c
@@ -1,128 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * [Description]
  *
- *   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.
+ * Test whether the inode number are the same for both file descriptors.
  *
- *   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
- */
-
-/*
- * NAME
- *	dup204.c
- *
- * DESCRIPTION
- *	Testcase to check the basic functionality of dup2(2).
- *
- * ALGORITHM
- *	attempt to call dup2() on read/write ends of a pipe
- *
- * USAGE:  <for command-line>
- *  dup204 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * RESTRICTION
- *	NONE
  */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-void setup();
-void cleanup();
+static int fd[2] = {-1, -1};
+static int nfd[2] = {10, 20};
 
-char *TCID = "dup204";
-int TST_TOTAL = 2;
-
-int fd[2];
-int nfd[2];
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int i;
-	struct stat oldbuf, newbuf;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(dup2(fd[i], nfd[i]));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			SAFE_FSTAT(cleanup, fd[i], &oldbuf);
-			SAFE_FSTAT(cleanup, nfd[i], &newbuf);
+	SAFE_PIPE(fd);
+}
 
-			if (oldbuf.st_ino != newbuf.st_ino)
-				tst_resm(TFAIL, "original and duped "
-					 "inodes do not match");
-			else
-				tst_resm(TPASS, "original and duped "
-					 "inodes are the same");
+static void cleanup(void)
+{
+	unsigned int i;
 
-			SAFE_CLOSE(cleanup, TEST_RETURN);
-		}
+	for (i = 0; i < ARRAY_SIZE(fd); i++) {
+		close(fd[i]);
+		close(nfd[i]);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void run(unsigned int i)
 {
-	fd[0] = -1;
+	struct stat oldbuf, newbuf;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST(dup2(fd[i], nfd[i]));
+	if (TST_RET == -1) {
+		tst_res(TFAIL, "call failed unexpectedly");
+		return;
+	}
 
-	TEST_PAUSE;
+	SAFE_FSTAT(fd[i], &oldbuf);
+	SAFE_FSTAT(nfd[i], &newbuf);
 
-	tst_tmpdir();
+	if (oldbuf.st_ino != newbuf.st_ino)
+		tst_res(TFAIL, "original inode(%ld) and duped inode(%ld) "
+				"do not match", oldbuf.st_ino, newbuf.st_ino);
+	else
+		tst_res(TPASS, "original inode(%ld) and duped inode(%ld) "
+				"are the same", oldbuf.st_ino, newbuf.st_ino);
 
-	SAFE_PIPE(cleanup, fd);
+	SAFE_CLOSE(TST_RET);
 }
 
-void cleanup(void)
-{
-	int i;
-
-	for (i = 0; i < (int)ARRAY_SIZE(fd); i++) {
-		close(fd[i]);
-		close(nfd[i]);
-	}
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(fd),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
-- 
2.31.1


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

  parent reply	other threads:[~2021-09-20  3:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20  3:37 [LTP] [PATCH v6 0/5] Convert syscalls/dup2/dup2{01...05} to new API QI Fuli
2021-09-20  3:37 ` [LTP] [PATCH v6 1/5] syscalls/dup2/dup201: Convert " QI Fuli
2021-09-20  3:37 ` [LTP] [PATCH v6 2/5] syscalls/dup2/dup202: " QI Fuli
2021-09-20  3:37 ` [LTP] [PATCH v6 3/5] syscalls/dup2/dup203: " QI Fuli
2021-09-20  3:37 ` QI Fuli [this message]
2021-09-20  3:37 ` [LTP] [PATCH v6 5/5] syscalls/dup2/dup205: " QI Fuli
2021-09-20  5:32 ` [LTP] [PATCH v6 0/5] Convert syscalls/dup2/dup2{01...05} " Xiao Yang

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=20210920033705.20544-5-qi.fuli@fujitsu.com \
    --to=fukuri.sai@gmail.com \
    --cc=ltp@lists.linux.it \
    --cc=qi.fuli@fujitsu.com \
    /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.