All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API
@ 2020-04-22 10:45 Yang Xu
  2020-04-22 10:45 ` [LTP] [PATCH v4 2/3] syscalls/pipe2_02: Add new test for pipe2 O_CLOEXEC flag Yang Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Yang Xu @ 2020-04-22 10:45 UTC (permalink / raw)
  To: ltp

Merged pipe2_02.c into pipe2_01.c.

Also, add O_DIRECT flag test. This flag was introduced since
commit 9883035ae7ed ("pipes: add a "packetized pipe" mode for writing").

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 include/lapi/fcntl.h                       |   4 +
 runtest/syscalls                           |   1 -
 testcases/kernel/syscalls/pipe2/.gitignore |   1 -
 testcases/kernel/syscalls/pipe2/pipe2_01.c | 234 ++++++---------------
 testcases/kernel/syscalls/pipe2/pipe2_02.c | 175 ---------------
 5 files changed, 65 insertions(+), 350 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/pipe2/pipe2_02.c

diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index 24aa46e1f..576a18daf 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -9,6 +9,10 @@
 #include <fcntl.h>
 #include <sys/socket.h>
 
+#ifndef O_DIRECT
+# define O_DIRECT 040000
+#endif
+
 #ifndef O_CLOEXEC
 # define O_CLOEXEC 02000000
 #endif
diff --git a/runtest/syscalls b/runtest/syscalls
index 9bb72beb2..6c240d375 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -915,7 +915,6 @@ pipe12 pipe12
 pipe13 pipe13
 
 pipe2_01 pipe2_01
-pipe2_02 pipe2_02
 pipe2_04 pipe2_04
 
 pivot_root01 pivot_root01
diff --git a/testcases/kernel/syscalls/pipe2/.gitignore b/testcases/kernel/syscalls/pipe2/.gitignore
index 773450a48..14866e393 100644
--- a/testcases/kernel/syscalls/pipe2/.gitignore
+++ b/testcases/kernel/syscalls/pipe2/.gitignore
@@ -1,3 +1,2 @@
 /pipe2_01
-/pipe2_02
 /pipe2_04
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_01.c b/testcases/kernel/syscalls/pipe2/pipe2_01.c
index 5f3ad8f0f..038072127 100644
--- a/testcases/kernel/syscalls/pipe2/pipe2_01.c
+++ b/testcases/kernel/syscalls/pipe2/pipe2_01.c
@@ -1,186 +1,74 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
-/* Copyright (c) International Business Machines  Corp., 2009                 */
-/*                                                                            */
-/* 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    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        pipe2_01.c                                                    */
-/*                                                                            */
-/* Description: This Program tests the new system call introduced in 2.6.27.  */
-/*              Ulrich??s comment as in:                                       */
-/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=ed8cae8ba01348bfd83333f4648dd807b04d7f08 */
-/*              says:                                                         */
-/* This patch introduces the new syscall pipe2 which is like pipe but it also */
-/* takes an additional parameter which takes a flag value.  This patch        */
-/* implements the handling of O_CLOEXEC for the flag.  I did not add support  */
-/* for the new syscall for the architectures which have a special sys_pipe    */
-/* implementation.  I think the maintainers of those archs have the chance to */
-/* go with the unified implementation but that's up to them.                  */
-/*                                                                            */
-/* The implementation introduces do_pipe_flags.  I did that instead of        */
-/* changing all callers of do_pipe because some of the callers are written in */
-/* assembler. I would probably screw up changing the assembly code.  To avoid */
-/* breaking code do_pipe is now a small wrapper around do_pipe_flags.  Once   */
-/* all callers are changed over to do_pipe_flags the old do_pipe function can */
-/* be removed.                                                                */
-/* The following test must be adjusted for architectures other than x86 and   */
-/* x86-64 and in case the syscall numbers changed.                            */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* pipe2_01 [-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.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   pipe2_01                                                      */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <fcntl.h>
+// SPDX-License-Identifier: GPL-2.0-or-late
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ *
+ * Author: Ulrich Drepper <drepper@redhat.com>
+ *
+ * History:
+ * Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>
+ * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
+ * Converted into new api - Apri 15 2020 - Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
-
-#include "test.h"
 #include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
-
-char *TCID = "pipe2_01";
-int testno;
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    cleanup                                                       */
-/*                                                                            */
-/* Description: Performs all one time clean up for this test on successful    */
-/*              completion,  premature exit or  failure. Closes all temporary */
-/*              files, removes all temporary directories exits the test with  */
-/*              appropriate return code by calling tst_exit() function.       */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*              On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                            */
-/******************************************************************************/
-void cleanup(void)
-{
+static int fds[2];
 
-	tst_rmdir();
-
-}
+static struct tcase {
+	int flags;
+	int cmd;
+	int check_read_end;
+	char *message;
+} tcases[] = {
+	{0, F_GETFD, 1, "Test pipe2 with 0 flag"},
+	{O_CLOEXEC, F_GETFD, 1, "Test pipe2 using O_CLOEXEC flag"},
+	/*
+	 * It may get EINVAL error on older kernel because this flag was
+	 * introduced since kernel 3.4. We only test flag in write end
+	 * because this flag was used to make pipe buffer marked with the
+	 * PIPE_BUF_FLAG_PACKET flag. In read end, kernel also checks buffer
+	 * flag instead of O_DIRECT. So it make no sense to check this flag
+	 * in fds[0].
+	 */
+	{O_DIRECT, F_GETFL, 0, "Test pipe2 using O_DIRECT flag"},
+	{O_NONBLOCK, F_GETFL, 1, "Test pipe2 using O_NONBLOCK flag"},
+};
 
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    setup                                                         */
-/*                                                                            */
-/* Description: Performs all one time setup for this test. This function is   */
-/*              typically used to capture signals, create temporary dirs      */
-/*              and temporary files that may be used in the course of this    */
-/*              test.                                                         */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits by calling cleanup().                      */
-/*              On success - returns 0.                                       */
-/*                                                                            */
-/******************************************************************************/
-void setup(void)
+static void cleanup(void)
 {
-	/* Capture signals if any */
-	/* Create temporary directories */
-	TEST_PAUSE;
-	tst_tmpdir();
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
+	if (fds[1] > 1)
+		SAFE_CLOSE(fds[1]);
 }
 
-int main(int argc, char *argv[])
+static void verify_pipe2(unsigned int n)
 {
-	int fd[2], i, coe;
-	int lc;
+	struct tcase *tc = &tcases[n];
+	int get_flag = 0, i = 0;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-	if ((tst_kvercmp(2, 6, 27)) < 0) {
-		tst_brkm(TCONF,
-			 NULL,
-			 "This test can only run on kernels that are 2.6.27 and higher");
+	tst_res(TINFO, "%s ", tc->message);
+	SAFE_PIPE2(fds, tc->flags);
+	for (i = 0; i < 2; i++) {
+		if (i == 0 && !tc->check_read_end)
+			continue;
+		get_flag = SAFE_FCNTL(fds[i], tc->cmd);
+		if ((get_flag && tc->flags) || (tc->flags == get_flag))
+			tst_res(TPASS, "pipe2 fds[%d] gets expected flag(%d)", i, tc->flags);
+		else
+			tst_res(TFAIL, "pipe2 fds[%d] doesn't get expected flag(%d), get flag(%d)",
+					i, tc->flags, get_flag);
 	}
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			if (ltp_syscall(__NR_pipe2, fd, 0) != 0) {
-				tst_brkm(TFAIL, cleanup, "pipe2(0) failed");
-			}
-			for (i = 0; i < 2; ++i) {
-				coe = fcntl(fd[i], F_GETFD);
-				if (coe == -1) {
-					tst_brkm(TBROK, cleanup,
-						 "fcntl failed");
-				}
-				if (coe & FD_CLOEXEC) {
-					tst_brkm(TFAIL,
-						 cleanup, "pipe2(0) set close-on-exit for fd[%d]",
-						 i);
-				}
-			}
-			close(fd[0]);
-			close(fd[1]);
-
-			if (ltp_syscall(__NR_pipe2, fd, O_CLOEXEC) != 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "pipe2(O_CLOEXEC) failed");
-			}
-			for (i = 0; i < 2; ++i) {
-				coe = fcntl(fd[i], F_GETFD);
-				if (coe == -1) {
-					tst_brkm(TBROK, cleanup,
-						 "fcntl failed");
-				}
-				if ((coe & FD_CLOEXEC) == 0) {
-					tst_brkm(TFAIL,
-						 cleanup, "pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]",
-						 i);
-				}
-			}
-			close(fd[0]);
-			close(fd[1]);
-			tst_resm(TPASS, "pipe2(O_CLOEXEC) PASSED");
-			cleanup();
-		}
-	}
-	tst_exit();
+	cleanup();
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_pipe2,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_02.c b/testcases/kernel/syscalls/pipe2/pipe2_02.c
deleted file mode 100644
index 39f02ff8c..000000000
--- a/testcases/kernel/syscalls/pipe2/pipe2_02.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
-/* Copyright (c) International Business Machines  Corp., 2009                 */
-/*                                                                            */
-/* 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    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        pipe2_02.c                                                    */
-/*                                                                            */
-/* Description: This Program tests the new system call introduced in 2.6.27.  */
-/*              Ulrich??s comment as in:                                       */
-/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=be61a86d7237dd80510615f38ae21d6e1e98660c */
-/* which says:                                                                */
-/* This patch adds O_NONBLOCK support to pipe2.  It is minimally more involved*/
-/* than the patches for eventfd et.al but still trivial.  The interfaces of   */
-/* the create_write_pipe and create_read_pipe helper functions were changed   */
-/* and the one other caller as well.                                          */
-/* The following test must be adjusted for architectures other than x86 and   */
-/* x86-64 and in case the syscall numbers changed.                            */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* pipe2_02 [-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.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   pipe2_02                                                      */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
-
-#include "test.h"
-#include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
-
-char *TCID = "pipe2_02";
-int testno;
-int TST_TOTAL = 1;
-
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    cleanup                                                       */
-/*                                                                            */
-/* Description: Performs all one time clean up for this test on successful    */
-/*              completion,  premature exit or  failure. Closes all temporary */
-/*              files, removes all temporary directories exits the test with  */
-/*              appropriate return code by calling tst_exit() function.       */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*              On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                            */
-/******************************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
-
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    setup                                                         */
-/*                                                                            */
-/* Description: Performs all one time setup for this test. This function is   */
-/*              typically used to capture signals, create temporary dirs      */
-/*              and temporary files that may be used in the course of this    */
-/*              test.                                                         */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits by calling cleanup().                      */
-/*              On success - returns 0.                                       */
-/*                                                                            */
-/******************************************************************************/
-void setup(void)
-{
-	/* Capture signals if any */
-	/* Create temporary directories */
-	TEST_PAUSE;
-	tst_tmpdir();
-}
-
-int main(int argc, char *argv[])
-{
-	int fds[2], fl, i;
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-	if ((tst_kvercmp(2, 6, 27)) < 0) {
-		tst_brkm(TCONF,
-			 NULL,
-			 "This test can only run on kernels that are 2.6.27 and higher");
-	}
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			if (ltp_syscall(__NR_pipe2, fds, 0) == -1) {
-				tst_brkm(TFAIL, cleanup, "pipe2(0) failed");
-			}
-			for (i = 0; i < 2; ++i) {
-				fl = fcntl(fds[i], F_GETFL);
-				if (fl == -1) {
-					tst_brkm(TBROK, cleanup,
-						 "fcntl failed");
-				}
-				if (fl & O_NONBLOCK) {
-					tst_brkm(TFAIL,
-						 cleanup, "pipe2(0) set non-blocking mode for fds[%d]",
-						 i);
-				}
-				close(fds[i]);
-			}
-
-			if (ltp_syscall(__NR_pipe2, fds, O_NONBLOCK) == -1) {
-				tst_brkm(TFAIL, cleanup,
-					 "pipe2(O_NONBLOCK) failed");
-			}
-			for (i = 0; i < 2; ++i) {
-				fl = fcntl(fds[i], F_GETFL);
-				if (fl == -1) {
-					tst_brkm(TBROK, cleanup,
-						 "fcntl failed");
-				}
-				if ((fl & O_NONBLOCK) == 0) {
-					tst_brkm(TFAIL,
-						 cleanup, "pipe2(O_NONBLOCK) does not set non-blocking mode for fds[%d]\n",
-						 i);
-				}
-				close(fds[i]);
-			}
-			tst_resm(TPASS, "pipe2(O_NONBLOCK) PASSED");
-			cleanup();
-		}
-	}
-	tst_exit();
-}
-- 
2.23.0




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

* [LTP] [PATCH v4 2/3] syscalls/pipe2_02: Add new test for pipe2 O_CLOEXEC flag
  2020-04-22 10:45 [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Yang Xu
@ 2020-04-22 10:45 ` Yang Xu
  2020-04-22 10:45 ` [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag Yang Xu
  2020-04-26  9:31 ` [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Li Wang
  2 siblings, 0 replies; 14+ messages in thread
From: Yang Xu @ 2020-04-22 10:45 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/pipe2/.gitignore    |  1 +
 testcases/kernel/syscalls/pipe2/pipe2_02.c    | 67 +++++++++++++++++++
 .../kernel/syscalls/pipe2/pipe2_02_child.c    | 26 +++++++
 4 files changed, 95 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_02.c
 create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_02_child.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 6c240d375..9bb72beb2 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -915,6 +915,7 @@ pipe12 pipe12
 pipe13 pipe13
 
 pipe2_01 pipe2_01
+pipe2_02 pipe2_02
 pipe2_04 pipe2_04
 
 pivot_root01 pivot_root01
diff --git a/testcases/kernel/syscalls/pipe2/.gitignore b/testcases/kernel/syscalls/pipe2/.gitignore
index 14866e393..773450a48 100644
--- a/testcases/kernel/syscalls/pipe2/.gitignore
+++ b/testcases/kernel/syscalls/pipe2/.gitignore
@@ -1,2 +1,3 @@
 /pipe2_01
+/pipe2_02
 /pipe2_04
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_02.c b/testcases/kernel/syscalls/pipe2/pipe2_02.c
new file mode 100644
index 000000000..e02857e38
--- /dev/null
+++ b/testcases/kernel/syscalls/pipe2/pipe2_02.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ *
+ * This case is designed to test the basic functionality about the
+ * O_CLOEXEC flag of pipe2.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+
+#define TESTBIN "pipe2_02_child"
+static int fds[2];
+
+static void cleanup(void)
+{
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
+	if (fds[1] > 0)
+		SAFE_CLOSE(fds[1]);
+}
+
+static void verify_pipe2(void)
+{
+	int pid, status;
+	char buf[20];
+
+	SAFE_PIPE2(fds, O_CLOEXEC);
+	sprintf(buf, "%d", fds[1]);
+	pid = SAFE_FORK();
+	if (pid == 0)
+		SAFE_EXECLP(TESTBIN, TESTBIN, buf, NULL);
+
+	SAFE_WAIT(&status);
+	if (WIFEXITED(status)) {
+		switch (WEXITSTATUS(status)) {
+		case 0:
+			tst_res(TPASS, "test O_CLOEXEC for pipe2 success");
+		break;
+		case 1:
+			tst_res(TFAIL, "test O_CLOEXEC for pipe2 failed");
+		break;
+		default:
+			tst_brk(TBROK, "execlp() failed");
+		}
+	} else {
+		tst_brk(TBROK, "%s exits with unexpected error", TESTBIN);
+	}
+	cleanup();
+}
+
+static const char *const resfile[] = {
+	TESTBIN,
+	NULL,
+};
+
+static struct tst_test test = {
+	.resource_files = resfile,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.test_all = verify_pipe2,
+};
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_02_child.c b/testcases/kernel/syscalls/pipe2/pipe2_02_child.c
new file mode 100644
index 000000000..fa0f881e9
--- /dev/null
+++ b/testcases/kernel/syscalls/pipe2/pipe2_02_child.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv)
+{
+	int fd;
+
+	if (argc != 2) {
+		fprintf(stderr, "Only two arguments: %s <fd>\n", argv[0]);
+		exit(1);
+	}
+
+	fd = atoi(argv[1]);
+	if (fcntl(fd, F_GETFL) < 0 && errno == EBADF)
+		return 0;
+
+	return 1;
+}
-- 
2.23.0




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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-22 10:45 [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Yang Xu
  2020-04-22 10:45 ` [LTP] [PATCH v4 2/3] syscalls/pipe2_02: Add new test for pipe2 O_CLOEXEC flag Yang Xu
@ 2020-04-22 10:45 ` Yang Xu
  2020-04-23  8:08   ` Li Wang
  2020-04-26  9:31 ` [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Li Wang
  2 siblings, 1 reply; 14+ messages in thread
From: Yang Xu @ 2020-04-22 10:45 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/pipe2/.gitignore |   1 +
 testcases/kernel/syscalls/pipe2/pipe2_03.c | 172 +++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 9bb72beb2..16add02d3 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -916,6 +916,7 @@ pipe13 pipe13
 
 pipe2_01 pipe2_01
 pipe2_02 pipe2_02
+pipe2_03 pipe2_03
 pipe2_04 pipe2_04
 
 pivot_root01 pivot_root01
diff --git a/testcases/kernel/syscalls/pipe2/.gitignore b/testcases/kernel/syscalls/pipe2/.gitignore
index 773450a48..ede1da65e 100644
--- a/testcases/kernel/syscalls/pipe2/.gitignore
+++ b/testcases/kernel/syscalls/pipe2/.gitignore
@@ -1,3 +1,4 @@
 /pipe2_01
 /pipe2_02
+/pipe2_03
 /pipe2_04
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_03.c b/testcases/kernel/syscalls/pipe2/pipe2_03.c
new file mode 100644
index 000000000..0314f9eda
--- /dev/null
+++ b/testcases/kernel/syscalls/pipe2/pipe2_03.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ *
+ * This case is designed to test the basic functionality about the
+ * O_DIRECT flag of pipe2.
+ *
+ * It includes three sub tests.
+ * 1) Each write(2) to the pipe is dealt with as a separate packet, and
+ * read(2)s from the pipe will read one packet at a time.
+ * 2) Writes of greater than PIPE_BUF bytes (see pipe(7)) will be split
+ * into multiple packet.
+ * 3)If a read(2) specifies a buffer size that is smaller than the next
+ * packet, then the requested number of bytes are read, and the excess
+ * bytes in the packet are discarded.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <linux/limits.h>
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+
+static int fds[2], packet_num, pipe_size;
+static char *wrbuf;
+static char *rdbuf;
+static void check_peer_rw(void);
+static void check_split(void);
+static void check_discard(void);
+
+static void (*test_func[])(void) = {check_peer_rw, check_split, check_discard};
+
+static void check_peer_rw(void)
+{
+	int i, pid;
+
+	SAFE_PIPE2(fds, O_DIRECT | O_NONBLOCK);
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		SAFE_CLOSE(fds[1]);
+		memset(rdbuf, 0, pipe_size);
+		TST_CHECKPOINT_WAIT(0);
+		for (i = 0; i < packet_num; i++) {
+			TEST(SAFE_READ(0, fds[0], rdbuf, pipe_size));
+			if (TST_RET != 1)
+				tst_res(TFAIL,
+					"Each read(2) doesn't read a separate packet, return %ld", TST_RET);
+		}
+		tst_res(TPASS, "Each read(2) reads a separate packet");
+		 _exit(0);
+	}
+
+	SAFE_CLOSE(fds[0]);
+	for (i = 0; i < packet_num; i++)
+		SAFE_WRITE(1, fds[1], "x", 1);
+
+	TEST(write(fds[1], "x", 1));
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "write succeeded unexpectedly");
+	} else {
+		if (TST_ERR == EAGAIN)
+			tst_res(TPASS, "Each write(2) uses a separate packet");
+		else
+			tst_res(TFAIL | TTERRNO, "write failed, expected EAGAIN but got");
+	}
+	TST_CHECKPOINT_WAKE(0);
+	tst_reap_children();
+	SAFE_CLOSE(fds[1]);
+}
+
+static void check_split(void)
+{
+	int i, pid;
+
+	SAFE_PIPE2(fds, O_DIRECT);
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		SAFE_CLOSE(fds[1]);
+		memset(rdbuf, 0, pipe_size);
+		TST_CHECKPOINT_WAIT(0);
+		for (i = 0; i < 2; i++) {
+			TEST(SAFE_READ(0, fds[0], rdbuf, pipe_size));
+			if (TST_RET != PIPE_BUF)
+				tst_res(TFAIL,
+					"write(higner than PIPE_BUF) split into multiple packet, return %ld", TST_RET);
+		}
+		tst_res(TPASS, "write(higner than PIPE_BUF) split into multiple packet");
+		 _exit(0);
+	}
+	SAFE_CLOSE(fds[0]);
+	SAFE_WRITE(1, fds[1], wrbuf, PIPE_BUF * 2);
+	TST_CHECKPOINT_WAKE(0);
+	tst_reap_children();
+	SAFE_CLOSE(fds[1]);
+}
+
+static void check_discard(void)
+{
+	int pid;
+	char tmp_buf[20];
+	char tmp_secondbuf[20];
+
+	SAFE_PIPE2(fds, O_DIRECT);
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		SAFE_CLOSE(fds[1]);
+		TST_CHECKPOINT_WAIT(0);
+		TEST(SAFE_READ(0, fds[0], tmp_buf, 20));
+		if (TST_RET != 20)
+			tst_res(TFAIL,
+				"the excess bytes in the packet isn't discarded by read, return %ld", TST_RET);
+		TEST(SAFE_READ(0, fds[0], tmp_secondbuf, 20));
+		if (TST_RET == 1) {
+			if (!memcmp(tmp_secondbuf, "1", 1))
+				tst_res(TPASS,
+					"the excess bytes in the packet is discarded by read, only read 1");
+			else
+				tst_res(TFAIL,
+					"the excess bytes in the packet is discarded by read, expect 1 got %s", tmp_secondbuf);
+		}
+		 _exit(0);
+	}
+	SAFE_CLOSE(fds[0]);
+	SAFE_WRITE(1, fds[1], wrbuf, PIPE_BUF);
+	SAFE_WRITE(1, fds[1], "1", 1);
+	TST_CHECKPOINT_WAKE(0);
+	tst_reap_children();
+	SAFE_CLOSE(fds[1]);
+}
+
+static void verify_pipe2(unsigned int n)
+{
+	(*test_func[n])();
+}
+
+static void setup(void)
+{
+	SAFE_PIPE2(fds, O_DIRECT);
+	pipe_size = SAFE_FCNTL(fds[1], F_GETPIPE_SZ);
+	wrbuf = SAFE_MALLOC(PIPE_BUF * 2);
+	rdbuf = SAFE_MALLOC(pipe_size);
+	memset(wrbuf, 'x', PIPE_BUF * 2);
+	packet_num = pipe_size / PIPE_BUF;
+	SAFE_CLOSE(fds[0]);
+	SAFE_CLOSE(fds[1]);
+}
+
+static void cleanup(void)
+{
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
+	if (fds[1] > 0)
+		SAFE_CLOSE(fds[1]);
+	if (wrbuf)
+		free(wrbuf);
+	if (rdbuf)
+		free(rdbuf);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.test = verify_pipe2,
+	.tcnt = ARRAY_SIZE(test_func),
+	.needs_checkpoints = 1,
+};
-- 
2.23.0




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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-22 10:45 ` [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag Yang Xu
@ 2020-04-23  8:08   ` Li Wang
  2020-04-23  8:45     ` Yang Xu
  0 siblings, 1 reply; 14+ messages in thread
From: Li Wang @ 2020-04-23  8:08 UTC (permalink / raw)
  To: ltp

On Wed, Apr 22, 2020 at 6:47 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com>
wrote:

> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> ---
>  runtest/syscalls                           |   1 +
>  testcases/kernel/syscalls/pipe2/.gitignore |   1 +
>  testcases/kernel/syscalls/pipe2/pipe2_03.c | 172 +++++++++++++++++++++
>  3 files changed, 174 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_03.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 9bb72beb2..16add02d3 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -916,6 +916,7 @@ pipe13 pipe13
>
>  pipe2_01 pipe2_01
>  pipe2_02 pipe2_02
> +pipe2_03 pipe2_03
>  pipe2_04 pipe2_04
>
>  pivot_root01 pivot_root01
> diff --git a/testcases/kernel/syscalls/pipe2/.gitignore
> b/testcases/kernel/syscalls/pipe2/.gitignore
> index 773450a48..ede1da65e 100644
> --- a/testcases/kernel/syscalls/pipe2/.gitignore
> +++ b/testcases/kernel/syscalls/pipe2/.gitignore
> @@ -1,3 +1,4 @@
>  /pipe2_01
>  /pipe2_02
> +/pipe2_03
>  /pipe2_04
> diff --git a/testcases/kernel/syscalls/pipe2/pipe2_03.c
> b/testcases/kernel/syscalls/pipe2/pipe2_03.c
> new file mode 100644
> index 000000000..0314f9eda
> --- /dev/null
> +++ b/testcases/kernel/syscalls/pipe2/pipe2_03.c
> @@ -0,0 +1,172 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> + *
> + * This case is designed to test the basic functionality about the
> + * O_DIRECT flag of pipe2.
> + *
> + * It includes three sub tests.
> + * 1) Each write(2) to the pipe is dealt with as a separate packet, and
> + * read(2)s from the pipe will read one packet at a time.
> + * 2) Writes of greater than PIPE_BUF bytes (see pipe(7)) will be split
> + * into multiple packet.
> + * 3)If a read(2) specifies a buffer size that is smaller than the next
> + * packet, then the requested number of bytes are read, and the excess
> + * bytes in the packet are discarded.
> + */
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <linux/limits.h>
> +#include "lapi/fcntl.h"
> +#include "tst_test.h"
> +
> +static int fds[2], packet_num, pipe_size;
> +static char *wrbuf;
> +static char *rdbuf;
> +static void check_peer_rw(void);
> +static void check_split(void);
> +static void check_discard(void);
> +
> +static void (*test_func[])(void) = {check_peer_rw, check_split,
> check_discard};
> +
> +static void check_peer_rw(void)
> +{
> +       int i, pid;
> +
> +       SAFE_PIPE2(fds, O_DIRECT | O_NONBLOCK);
> +
> +       pid = SAFE_FORK();
> +       if (!pid) {
> +               SAFE_CLOSE(fds[1]);
> +               memset(rdbuf, 0, pipe_size);
> +               TST_CHECKPOINT_WAIT(0);
> +               for (i = 0; i < packet_num; i++) {
> +                       TEST(SAFE_READ(0, fds[0], rdbuf, pipe_size));
> +                       if (TST_RET != 1)
> +                               tst_res(TFAIL,
> +                                       "Each read(2) doesn't read a
> separate packet, return %ld", TST_RET);
> +               }
> +               tst_res(TPASS, "Each read(2) reads a separate packet");
> +                _exit(0);
> +       }
> +
> +       SAFE_CLOSE(fds[0]);
> +       for (i = 0; i < packet_num; i++)
> +               SAFE_WRITE(1, fds[1], "x", 1);
> +
>

I got a failure on the ppc64le platform(page size: 65536kB).

# ./pipe2_03
tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
pipe_size = 1048576
PIPE_BUF = 4096
packet_num = 256
safe_macros.c:457: BROK: pipe2_03.c:58:
write(4,0x1001d2b8,18446744073709551615) failed: EAGAIN/EWOULDBLOCK (11)
-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200423/ab57c8b1/attachment.htm>

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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-23  8:08   ` Li Wang
@ 2020-04-23  8:45     ` Yang Xu
  2020-04-23 10:04       ` Li Wang
  0 siblings, 1 reply; 14+ messages in thread
From: Yang Xu @ 2020-04-23  8:45 UTC (permalink / raw)
  To: ltp

Hi Li

> 
> 
> On Wed, Apr 22, 2020 at 6:47 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com 
> <mailto:xuyang2018.jy@cn.fujitsu.com>> wrote:
> 
>     Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com
>     <mailto:xuyang2018.jy@cn.fujitsu.com>>
>     ---
>      ?runtest/syscalls? ? ? ? ? ? ? ? ? ? ? ? ? ?|? ?1 +
>      ?testcases/kernel/syscalls/pipe2/.gitignore |? ?1 +
>      ?testcases/kernel/syscalls/pipe2/pipe2_03.c | 172 +++++++++++++++++++++
>      ?3 files changed, 174 insertions(+)
>      ?create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_03.c
> 
>     diff --git a/runtest/syscalls b/runtest/syscalls
>     index 9bb72beb2..16add02d3 100644
>     --- a/runtest/syscalls
>     +++ b/runtest/syscalls
>     @@ -916,6 +916,7 @@ pipe13 pipe13
> 
>      ?pipe2_01 pipe2_01
>      ?pipe2_02 pipe2_02
>     +pipe2_03 pipe2_03
>      ?pipe2_04 pipe2_04
> 
>      ?pivot_root01 pivot_root01
>     diff --git a/testcases/kernel/syscalls/pipe2/.gitignore
>     b/testcases/kernel/syscalls/pipe2/.gitignore
>     index 773450a48..ede1da65e 100644
>     --- a/testcases/kernel/syscalls/pipe2/.gitignore
>     +++ b/testcases/kernel/syscalls/pipe2/.gitignore
>     @@ -1,3 +1,4 @@
>      ?/pipe2_01
>      ?/pipe2_02
>     +/pipe2_03
>      ?/pipe2_04
>     diff --git a/testcases/kernel/syscalls/pipe2/pipe2_03.c
>     b/testcases/kernel/syscalls/pipe2/pipe2_03.c
>     new file mode 100644
>     index 000000000..0314f9eda
>     --- /dev/null
>     +++ b/testcases/kernel/syscalls/pipe2/pipe2_03.c
>     @@ -0,0 +1,172 @@
>     +// SPDX-License-Identifier: GPL-2.0-or-later
>     +/*
>     + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
>     + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com
>     <mailto:xuyang2018.jy@cn.fujitsu.com>>
>     + *
>     + * This case is designed to test the basic functionality about the
>     + * O_DIRECT flag of pipe2.
>     + *
>     + * It includes three sub tests.
>     + * 1) Each write(2) to the pipe is dealt with as a separate packet, and
>     + * read(2)s from the pipe will read one packet at a time.
>     + * 2) Writes of greater than PIPE_BUF bytes (see pipe(7)) will be split
>     + * into multiple packet.
>     + * 3)If a read(2) specifies a buffer size that is smaller than the next
>     + * packet, then the requested number of bytes are read, and the excess
>     + * bytes in the packet are discarded.
>     + */
>     +#define _GNU_SOURCE
>     +#include <stdio.h>
>     +#include <unistd.h>
>     +#include <stdlib.h>
>     +#include <linux/limits.h>
>     +#include "lapi/fcntl.h"
>     +#include "tst_test.h"
>     +
>     +static int fds[2], packet_num, pipe_size;
>     +static char *wrbuf;
>     +static char *rdbuf;
>     +static void check_peer_rw(void);
>     +static void check_split(void);
>     +static void check_discard(void);
>     +
>     +static void (*test_func[])(void) = {check_peer_rw, check_split,
>     check_discard};
>     +
>     +static void check_peer_rw(void)
>     +{
>     +? ? ? ?int i, pid;
>     +
>     +? ? ? ?SAFE_PIPE2(fds, O_DIRECT | O_NONBLOCK);
>     +
>     +? ? ? ?pid = SAFE_FORK();
>     +? ? ? ?if (!pid) {
>     +? ? ? ? ? ? ? ?SAFE_CLOSE(fds[1]);
>     +? ? ? ? ? ? ? ?memset(rdbuf, 0, pipe_size);
>     +? ? ? ? ? ? ? ?TST_CHECKPOINT_WAIT(0);
>     +? ? ? ? ? ? ? ?for (i = 0; i < packet_num; i++) {
>     +? ? ? ? ? ? ? ? ? ? ? ?TEST(SAFE_READ(0, fds[0], rdbuf, pipe_size));
>     +? ? ? ? ? ? ? ? ? ? ? ?if (TST_RET != 1)
>     +? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?tst_res(TFAIL,
>     +? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"Each read(2) doesn't read a
>     separate packet, return %ld", TST_RET);
>     +? ? ? ? ? ? ? ?}
>     +? ? ? ? ? ? ? ?tst_res(TPASS, "Each read(2) reads a separate packet");
>     +? ? ? ? ? ? ? ? _exit(0);
>     +? ? ? ?}
>     +
>     +? ? ? ?SAFE_CLOSE(fds[0]);
>     +? ? ? ?for (i = 0; i < packet_num; i++)
>     +? ? ? ? ? ? ? ?SAFE_WRITE(1, fds[1], "x", 1);
>     +
> 
> 
> I got a failure on the ppc64le platform(page size: 65536kB).
> 
> # ./pipe2_03
> tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
> pipe_size = 1048576
> PIPE_BUF = 4096
> packet_num = 256
> safe_macros.c:457: BROK: pipe2_03.c:58: 
> write(4,0x1001d2b8,18446744073709551615) failed: EAGAIN/EWOULDBLOCK (11)
I think we should remove PIPE_BUF and use page_size  because we use a 
page to store data not a fixed size buffer in kernel. as below(also, 
man-pages[1] is need to update):

-#include <linux/limits.h>
  #include "lapi/fcntl.h"
  #include "tst_test.h"

-static int fds[2], packet_num, pipe_size;
+static int fds[2], packet_num, pipe_size, page_size;
  static char *wrbuf;
  static char *rdbuf;
  static void check_peer_rw(void);
@@ -84,15 +83,15 @@ static void check_split(void)
                 TST_CHECKPOINT_WAIT(0);
                 for (i = 0; i < 2; i++) {
                         TEST(SAFE_READ(0, fds[0], rdbuf, pipe_size));
-                       if (TST_RET != PIPE_BUF)
+                       if (TST_RET != page_size)
                                 tst_res(TFAIL,
-                                       "write(higner than PIPE_BUF) 
split into multiple packet, return %ld", TST_RET);
+                                       "write(higner than page_size) 
split into multiple packet, return %ld", TST_RET);
                 }
-               tst_res(TPASS, "write(higner than PIPE_BUF) split into 
multiple packet");
+               tst_res(TPASS, "write(higner than page_size) split into 
multiple packet");
                  _exit(0);
         }
         SAFE_CLOSE(fds[0]);
-       SAFE_WRITE(1, fds[1], wrbuf, PIPE_BUF * 2);
+       SAFE_WRITE(1, fds[1], wrbuf, page_size * 2);
         TST_CHECKPOINT_WAKE(0);
         tst_reap_children();
         SAFE_CLOSE(fds[1]);
@@ -126,7 +125,7 @@ static void check_discard(void)
                  _exit(0);
         }
         SAFE_CLOSE(fds[0]);
-       SAFE_WRITE(1, fds[1], wrbuf, PIPE_BUF);
+       SAFE_WRITE(1, fds[1], wrbuf, page_size);
         SAFE_WRITE(1, fds[1], "1", 1);
         TST_CHECKPOINT_WAKE(0);
         tst_reap_children();
@@ -142,10 +141,11 @@ static void setup(void)
  {
         SAFE_PIPE2(fds, O_DIRECT);
         pipe_size = SAFE_FCNTL(fds[1], F_GETPIPE_SZ);
-       wrbuf = SAFE_MALLOC(PIPE_BUF * 2);
+       page_size = getpagesize();
+       wrbuf = SAFE_MALLOC(page_size * 2);
         rdbuf = SAFE_MALLOC(pipe_size);
-       memset(wrbuf, 'x', PIPE_BUF * 2);
-       packet_num = pipe_size / PIPE_BUF;
+       memset(wrbuf, 'x', page_size * 2);
+       packet_num = pipe_size / page_size;

I have tested this on aarch64 system(64kb page size) and it pass.

[1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/man7/pipe.7#n260
> -- 
> Regards,
> Li Wang



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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-23  8:45     ` Yang Xu
@ 2020-04-23 10:04       ` Li Wang
  2020-04-23 10:30         ` Yang Xu
  0 siblings, 1 reply; 14+ messages in thread
From: Li Wang @ 2020-04-23 10:04 UTC (permalink / raw)
  To: ltp

On Thu, Apr 23, 2020 at 4:45 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com>
wrote:

> ...
> > I got a failure on the ppc64le platform(page size: 65536kB).
> >
> > # ./pipe2_03
> > tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
> > pipe_size = 1048576
> > PIPE_BUF = 4096
> > packet_num = 256
> > safe_macros.c:457: BROK: pipe2_03.c:58:
> > write(4,0x1001d2b8,18446744073709551615) failed: EAGAIN/EWOULDBLOCK (11)
> I think we should remove PIPE_BUF and use page_size  because we use a
> page to store data not a fixed size buffer in kernel. as below(also,
> man-pages[1] is need to update):
>

Emm, If PIPE_BUF doesn't work correctly, shouldn't this a kernel pipe bug?
I think we need to take a close look at what happened there but not to
replace by using page_size directly.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200423/14abc40f/attachment.htm>

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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-23 10:04       ` Li Wang
@ 2020-04-23 10:30         ` Yang Xu
  2020-04-26 11:59           ` Li Wang
  0 siblings, 1 reply; 14+ messages in thread
From: Yang Xu @ 2020-04-23 10:30 UTC (permalink / raw)
  To: ltp

Hi LI

> 
> 
> On Thu, Apr 23, 2020 at 4:45 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com 
> <mailto:xuyang2018.jy@cn.fujitsu.com>> wrote:
> 
>     ...
>      > I got a failure on the ppc64le platform(page size: 65536kB).
>      >
>      > # ./pipe2_03
>      > tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
>      > pipe_size = 1048576
>      > PIPE_BUF = 4096
>      > packet_num = 256
>      > safe_macros.c:457: BROK: pipe2_03.c:58:
>      > write(4,0x1001d2b8,18446744073709551615) failed:
>     EAGAIN/EWOULDBLOCK (11)
>     I think we should remove PIPE_BUF and use page_size? because we use a
>     page to store data not a fixed size buffer in kernel. as below(also,
>     man-pages[1] is need to update):
> 
> 
> Emm, If PIPE_BUF doesn't work correctly, shouldn't this a kernel pipe 
> bug? I think we need to take a close look at what happened there but not 
> to replace by?using page_size directly.
> -- 
It is only defined in limit.h(I only think it is a error in limit.h) and 
  PIPE_BUF doesn't be used in kernel.

In kernel code, pipes use struct pipe_buffer to store buffer data and 
other info,
struct pipe_buffer {
         struct page *page; //alloc page to store data
         unsigned int offset, len;
         const struct pipe_buf_operations *ops;
         unsigned int flags; //
         unsigned long private;
};

as my pipe2_01.c said we only make buf with PIPE_BUF_FLAG_PACKET flag in 
write end , and read will check this flag.  This unit is a page instead 
of this PIPE_BUF macro.

Best Regards
Yang Xu
> Regards,
> Li Wang



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

* [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API
  2020-04-22 10:45 [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Yang Xu
  2020-04-22 10:45 ` [LTP] [PATCH v4 2/3] syscalls/pipe2_02: Add new test for pipe2 O_CLOEXEC flag Yang Xu
  2020-04-22 10:45 ` [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag Yang Xu
@ 2020-04-26  9:31 ` Li Wang
  2 siblings, 0 replies; 14+ messages in thread
From: Li Wang @ 2020-04-26  9:31 UTC (permalink / raw)
  To: ltp

Hi Xu,

Patch1/3 and 2/3 pushed with some modifications(code indent and kver
checks).

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200426/6fe6d66b/attachment.htm>

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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-23 10:30         ` Yang Xu
@ 2020-04-26 11:59           ` Li Wang
  2020-04-26 17:45               ` Linus Torvalds
  0 siblings, 1 reply; 14+ messages in thread
From: Li Wang @ 2020-04-26 11:59 UTC (permalink / raw)
  To: ltp

On Thu, Apr 23, 2020 at 6:32 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com>
wrote:

> Hi LI
>
> >
> >
> > On Thu, Apr 23, 2020 at 4:45 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com
> > <mailto:xuyang2018.jy@cn.fujitsu.com>> wrote:
> >
> >     ...
> >      > I got a failure on the ppc64le platform(page size: 65536kB).
> >      >
> >      > # ./pipe2_03
> >      > tst_test.c:1246: INFO: Timeout per run is 0h 05m 00s
> >      > pipe_size = 1048576
> >      > PIPE_BUF = 4096
> >      > packet_num = 256
> >      > safe_macros.c:457: BROK: pipe2_03.c:58:
> >      > write(4,0x1001d2b8,18446744073709551615) failed:
> >     EAGAIN/EWOULDBLOCK (11)
> >     I think we should remove PIPE_BUF and use page_size  because we use a
> >     page to store data not a fixed size buffer in kernel. as below(also,
> >     man-pages[1] is need to update):
> >
> >
> > Emm, If PIPE_BUF doesn't work correctly, shouldn't this a kernel pipe
> > bug? I think we need to take a close look at what happened there but not
> > to replace by using page_size directly.
> > --
> It is only defined in limit.h(I only think it is a error in limit.h) and
>   PIPE_BUF doesn't be used in kernel.
>

[PAGE_SIZE or PIPE_BUFF]

From kernel code seems you are right. The pipe indeed takes use of
PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode
(marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the
PIPE_BUF is the correct atomic unit. Since PIPE_BUF is defined to 4kB that
is equal to PAGE_SIZE on x86_64 so your test gets PASS there.

I feel confused about whether it's a kernel pipe bug or just need to
correct the manual page.

@Linus, can you give some advice on this? Thanks!


> In kernel code, pipes use struct pipe_buffer to store buffer data and
> other info,
> struct pipe_buffer {
>          struct page *page; //alloc page to store data
>          unsigned int offset, len;
>          const struct pipe_buf_operations *ops;
>          unsigned int flags; //
>          unsigned long private;
> };
>
> as my pipe2_01.c said we only make buf with PIPE_BUF_FLAG_PACKET flag in
> write end , and read will check this flag.  This unit is a page instead
> of this PIPE_BUF macro.
>
> Best Regards
> Yang Xu
> > Regards,
> > Li Wang
>
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200426/205b68e5/attachment.htm>

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

* Re: [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-26 11:59           ` Li Wang
@ 2020-04-26 17:45               ` Linus Torvalds
  0 siblings, 0 replies; 14+ messages in thread
From: Linus Torvalds @ 2020-04-26 17:45 UTC (permalink / raw)
  To: Li Wang; +Cc: Yang Xu, LTP List, linux-kernel, David Howells

On Sun, Apr 26, 2020 at 4:59 AM Li Wang <liwang@redhat.com> wrote:
>
> From kernel code seems you are right. The pipe indeed takes use of PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode (marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the PIPE_BUF is the correct atomic unit.

The manual is correct.

PIPE_BUF is the size we _guarantee_ can be used atomically.

The fact that in practice we do have bigger buffers on some platforms
is an implementation detail.

Yes, that implementation detail can be visible, but basically any test
code that tries to test for "what if we use a bigger bug that
PIPE_BUF" is buggy. It's simply not guaranteed to work any more.

O_DIRECT is kind of immaterial, except it's just one of those things
where the atomic size is slightly more visible. But basically,
packetized pipes with bigger packets than PIPE_BUF is random behavior.
It may work. It may not.

                Linus

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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
@ 2020-04-26 17:45               ` Linus Torvalds
  0 siblings, 0 replies; 14+ messages in thread
From: Linus Torvalds @ 2020-04-26 17:45 UTC (permalink / raw)
  To: ltp

On Sun, Apr 26, 2020 at 4:59 AM Li Wang <liwang@redhat.com> wrote:
>
> From kernel code seems you are right. The pipe indeed takes use of PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode (marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the PIPE_BUF is the correct atomic unit.

The manual is correct.

PIPE_BUF is the size we _guarantee_ can be used atomically.

The fact that in practice we do have bigger buffers on some platforms
is an implementation detail.

Yes, that implementation detail can be visible, but basically any test
code that tries to test for "what if we use a bigger bug that
PIPE_BUF" is buggy. It's simply not guaranteed to work any more.

O_DIRECT is kind of immaterial, except it's just one of those things
where the atomic size is slightly more visible. But basically,
packetized pipes with bigger packets than PIPE_BUF is random behavior.
It may work. It may not.

                Linus

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

* Re: [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-26 17:45               ` Linus Torvalds
@ 2020-04-30  3:23                 ` Yang Xu
  -1 siblings, 0 replies; 14+ messages in thread
From: Yang Xu @ 2020-04-30  3:23 UTC (permalink / raw)
  To: Linus Torvalds, Li Wang; +Cc: LTP List, linux-kernel, David Howells

Hi Linus


> On Sun, Apr 26, 2020 at 4:59 AM Li Wang <liwang@redhat.com> wrote:
>>
>>  From kernel code seems you are right. The pipe indeed takes use of PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode (marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the PIPE_BUF is the correct atomic unit.
> 
> The manual is correct.
> 
> PIPE_BUF is the size we _guarantee_ can be used atomically.
> 
> The fact that in practice we do have bigger buffers on some platforms
> is an implementation detail.
> 
> Yes, that implementation detail can be visible, but basically any test
> code that tries to test for "what if we use a bigger bug that
> PIPE_BUF" is buggy. It's simply not guaranteed to work any more.
> 
> O_DIRECT is kind of immaterial, except it's just one of those things
> where the atomic size is slightly more visible. But basically,
> packetized pipes with bigger packets than PIPE_BUF is random behavior.
> It may work. It may not.
Thanks for your explanation. I am more curious about the user scene of 
this flag.

@Li, so how to design this test? In this test, we don't have complex 
scene to test this automic unit.

Best Regards
Yang Xu
> 
>                  Linus
> 
> 



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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
@ 2020-04-30  3:23                 ` Yang Xu
  0 siblings, 0 replies; 14+ messages in thread
From: Yang Xu @ 2020-04-30  3:23 UTC (permalink / raw)
  To: ltp

Hi Linus


> On Sun, Apr 26, 2020 at 4:59 AM Li Wang <liwang@redhat.com> wrote:
>>
>>  From kernel code seems you are right. The pipe indeed takes use of PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode (marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the PIPE_BUF is the correct atomic unit.
> 
> The manual is correct.
> 
> PIPE_BUF is the size we _guarantee_ can be used atomically.
> 
> The fact that in practice we do have bigger buffers on some platforms
> is an implementation detail.
> 
> Yes, that implementation detail can be visible, but basically any test
> code that tries to test for "what if we use a bigger bug that
> PIPE_BUF" is buggy. It's simply not guaranteed to work any more.
> 
> O_DIRECT is kind of immaterial, except it's just one of those things
> where the atomic size is slightly more visible. But basically,
> packetized pipes with bigger packets than PIPE_BUF is random behavior.
> It may work. It may not.
Thanks for your explanation. I am more curious about the user scene of 
this flag.

@Li, so how to design this test? In this test, we don't have complex 
scene to test this automic unit.

Best Regards
Yang Xu
> 
>                  Linus
> 
> 



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

* [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag
  2020-04-30  3:23                 ` Yang Xu
  (?)
@ 2020-04-30  6:57                 ` Li Wang
  -1 siblings, 0 replies; 14+ messages in thread
From: Li Wang @ 2020-04-30  6:57 UTC (permalink / raw)
  To: ltp

Hi Xu,

Yang Xu <xuyang2018.jy@cn.fujitsu.com> wrote:

Hi Linus
>
>
> > On Sun, Apr 26, 2020 at 4:59 AM Li Wang <liwang@redhat.com> wrote:
> >>
> >>  From kernel code seems you are right. The pipe indeed takes use of
> PAGE_SIZE(ppc64le: 64kB) to split the writes data in the packetized mode
> (marked by O_DIRECT). But in the manual page, O_DIRECT indicates us the
> PIPE_BUF is the correct atomic unit.
>


> >
> > The manual is correct.
> >
> > PIPE_BUF is the size we _guarantee_ can be used atomically.
> >
> > The fact that in practice we do have bigger buffers on some platforms
> > is an implementation detail.
> >
> > Yes, that implementation detail can be visible, but basically any test
> > code that tries to test for "what if we use a bigger bug that
> > PIPE_BUF" is buggy. It's simply not guaranteed to work any more.
> >
> > O_DIRECT is kind of immaterial, except it's just one of those things
> > where the atomic size is slightly more visible. But basically,
> > packetized pipes with bigger packets than PIPE_BUF is random behavior.
> > It may work. It may not.
>


> Thanks for your explanation. I am more curious about the user scene of
> this flag.
>
>

> @Li, so how to design this test? In this test, we don't have complex
> scene to test this automic unit.
>

As Linus pointed out that "packetized pipes with bigger packets than
PIPE_BUF is random behavior", it looks the way in your test is not
guaranteed to work correctly, so I would drop the pipe2_03.c patch.
But according to the pipe(7) manual page, we could try to verify writing
data less than PIPE_BUF is atomic, and the pipe read end also should
provide us correct data in one packet at a time.

"
PIPE_BUF
  POSIX.1 says that write(2)s of less than PIPE_BUF bytes must be
  atomic: the output data is written to the pipe as a contiguous sequence
  ...
  POSIX.1 requires PIPE_BUF to be at least 512 bytes. (On Linux, PIPE_BUF
is 4096 bytes.)
  ...

  O_NONBLOCK disabled, n <= PIPE_BUF ...

  O_NONBLOCK enabled, n <= PIPE_BUF ...
"
http://man7.org/linux/man-pages/man7/pipe.7.html

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200430/854ddcf7/attachment.htm>

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

end of thread, other threads:[~2020-04-30  6:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 10:45 [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Yang Xu
2020-04-22 10:45 ` [LTP] [PATCH v4 2/3] syscalls/pipe2_02: Add new test for pipe2 O_CLOEXEC flag Yang Xu
2020-04-22 10:45 ` [LTP] [PATCH v4 3/3] syscalls/pipe2_03: Add new test for pipe2 O_DIRECT flag Yang Xu
2020-04-23  8:08   ` Li Wang
2020-04-23  8:45     ` Yang Xu
2020-04-23 10:04       ` Li Wang
2020-04-23 10:30         ` Yang Xu
2020-04-26 11:59           ` Li Wang
2020-04-26 17:45             ` Linus Torvalds
2020-04-26 17:45               ` Linus Torvalds
2020-04-30  3:23               ` Yang Xu
2020-04-30  3:23                 ` Yang Xu
2020-04-30  6:57                 ` Li Wang
2020-04-26  9:31 ` [LTP] [PATCH v4 1/3] syscalls/pipe2_01: convert into new API Li Wang

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.