public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] fcntl/fcntl29.c: add F_DUPFD_CLOEXEC test for fcntl(2)
@ 2013-12-05  3:43 Xiaoguang Wang
  2013-12-05  5:24 ` Mike Frysinger
  0 siblings, 1 reply; 4+ messages in thread
From: Xiaoguang Wang @ 2013-12-05  3:43 UTC (permalink / raw)
  To: ltp-list

create a new case to test F_DUPFD_CLOEXEC for fcntl(2)

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 runtest/syscalls                          |   2 +
 testcases/kernel/syscalls/fcntl/fcntl29.c | 117 ++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl29.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 717342e..cace2ca 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -251,6 +251,8 @@ fcntl27 fcntl27
 fcntl27_64 fcntl27_64
 fcntl28 fcntl28
 fcntl28_64 fcntl28_64
+fcntl29 fcntl29
+fcntl29_64 fcntl29_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/fcntl29.c b/testcases/kernel/syscalls/fcntl/fcntl29.c
new file mode 100644
index 0000000..095a316
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl29.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2013 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+/*
+ * Description:
+ * Verify that,
+ *   Basic test for fcntl(2) using F_DUPFD_CLOEXEC argument.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+
+char *TCID = "fcntl29";
+
+#if defined(F_DUPFD_CLOEXEC)
+static void setup(void);
+static void cleanup(void);
+
+static int test_fd;
+static int dup_fd;
+
+int TST_TOTAL = 1;
+
+int main(int ac, char **av)
+{
+	int lc;
+	char *msg;
+	int i;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++) {
+			TEST(fcntl(test_fd, F_DUPFD_CLOEXEC, dup_fd));
+			if (TEST_RETURN < 0) {
+				tst_brkm(TFAIL | TTERRNO, cleanup, "fcntl "
+					 "test F_DUPFD_CLOEXEC failed");
+			}
+
+			TEST(fcntl(TEST_RETURN, F_GETFD));
+			if (TEST_RETURN < 0) {
+				tst_brkm(TFAIL | TTERRNO, cleanup, "fcntl "
+					 "test F_GETFD failed");
+			}
+
+			if (TEST_RETURN & FD_CLOEXEC) {
+				tst_resm(TPASS, "fcntl test "
+					 "F_DUPFD_CLOEXEC success");
+			} else {
+				tst_resm(TFAIL, "fcntl test "
+					 "F_DUPFD_CLOEXEC fail");
+			}
+
+			SAFE_CLOSE(cleanup, dup_fd);
+		}
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	tst_tmpdir();
+
+	TEST_PAUSE;
+
+	test_fd = SAFE_CREAT(cleanup, "testfile", 0644);
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+
+	tst_rmdir();
+}
+#else
+
+int main(int ac, char **av)
+{
+	tst_brkm(TCONF, NULL, "This test can only run on kernels"
+		 "that are 2.6.24 and higher");
+}
+#endif
-- 
1.8.2.1


------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [LTP] [PATCH 1/3] fcntl/fcntl29.c: add F_DUPFD_CLOEXEC test for fcntl(2)
@ 2013-12-05 11:41 Xiaoguang Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Xiaoguang Wang @ 2013-12-05 11:41 UTC (permalink / raw)
  To: ltp-list


create a new case to test F_DUPFD_CLOEXEC for fcntl(2)

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 runtest/syscalls                          |   2 +
 testcases/kernel/syscalls/fcntl/fcntl29.c | 124 ++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl29.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 717342e..cace2ca 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -251,6 +251,8 @@ fcntl27 fcntl27
 fcntl27_64 fcntl27_64
 fcntl28 fcntl28
 fcntl28_64 fcntl28_64
+fcntl29 fcntl29
+fcntl29_64 fcntl29_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/fcntl29.c b/testcases/kernel/syscalls/fcntl/fcntl29.c
new file mode 100644
index 0000000..5202086
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl29.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2013 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+/*
+ * Description:
+ * Verify that,
+ *   Basic test for fcntl(2) using F_DUPFD_CLOEXEC argument.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+
+char *TCID = "fcntl29";
+
+#if defined(F_DUPFD_CLOEXEC)
+static void setup(void);
+static void cleanup(void);
+
+static int test_fd;
+static int dup_fd;
+
+int TST_TOTAL = 1;
+
+int main(int ac, char **av)
+{
+	int lc;
+	char *msg;
+	int i;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++) {
+			TEST(fcntl(test_fd, F_DUPFD_CLOEXEC, dup_fd));
+			if (TEST_RETURN < 0) {
+				tst_brkm(TFAIL | TTERRNO, cleanup, "fcntl "
+					 "test F_DUPFD_CLOEXEC failed");
+			}
+
+			TEST(fcntl(TEST_RETURN, F_GETFD));
+			if (TEST_RETURN < 0) {
+				tst_brkm(TFAIL | TTERRNO, cleanup, "fcntl "
+					 "test F_GETFD failed");
+			}
+
+			if (TEST_RETURN & FD_CLOEXEC) {
+				tst_resm(TPASS, "fcntl test "
+					 "F_DUPFD_CLOEXEC success");
+			} else {
+				tst_resm(TFAIL, "fcntl test "
+					 "F_DUPFD_CLOEXEC fail");
+			}
+
+			SAFE_CLOSE(cleanup, dup_fd);
+		}
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	if ((tst_kvercmp(2, 6, 24)) < 0) {
+		tst_brkm(TCONF, NULL, "This test can only run on kernels"
+			 "that are 2.6.24 and higher");
+	}
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	tst_tmpdir();
+
+	TEST_PAUSE;
+
+	test_fd = SAFE_CREAT(cleanup, "testfile", 0644);
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+
+	SAFE_CLOSE(NULL, test_fd);
+
+	tst_rmdir();
+}
+#else
+
+int main(int ac, char **av)
+{
+	tst_brkm(TCONF, NULL, "This test can only run on kernels"
+		 "that are 2.6.24 and higher");
+}
+#endif
-- 
1.8.2.1



------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2013-12-05 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05  3:43 [LTP] [PATCH 1/3] fcntl/fcntl29.c: add F_DUPFD_CLOEXEC test for fcntl(2) Xiaoguang Wang
2013-12-05  5:24 ` Mike Frysinger
2013-12-05  5:29   ` Wanlong Gao
  -- strict thread matches above, loose matches on Subject: below --
2013-12-05 11:41 Xiaoguang Wang

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