ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 0/3] Rewrite eventfd2 testing suite
@ 2023-03-08 13:23 Andrea Cervesato
  2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Andrea Cervesato @ 2023-03-08 13:23 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

eventfd2 testing suite has been rewritten using new LTP API

Andrea Cervesato (3):
  Rewrite eventfd2_01 test using new LTP API
  Rewrite eventfd2_02 test using new LTP API
  Rewrite eventfd2_03 test using new LTP API

 testcases/kernel/syscalls/eventfd2/eventfd2.h |  18 +++
 .../kernel/syscalls/eventfd2/eventfd2_01.c    | 148 ++++--------------
 .../kernel/syscalls/eventfd2/eventfd2_02.c    | 147 ++++-------------
 .../kernel/syscalls/eventfd2/eventfd2_03.c    | 128 +++++----------
 4 files changed, 119 insertions(+), 322 deletions(-)
 create mode 100644 testcases/kernel/syscalls/eventfd2/eventfd2.h

-- 
2.35.3


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

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

* [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API
  2023-03-08 13:23 [LTP] [PATCH v1 0/3] Rewrite eventfd2 testing suite Andrea Cervesato
@ 2023-03-08 13:23 ` Andrea Cervesato
  2023-03-14 23:40   ` Wei Gao via ltp
  2023-04-05  9:24   ` Cyril Hrubis
  2023-03-08 13:23 ` [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 " Andrea Cervesato
  2023-03-08 13:23 ` [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 " Andrea Cervesato
  2 siblings, 2 replies; 12+ messages in thread
From: Andrea Cervesato @ 2023-03-08 13:23 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/syscalls/eventfd2/eventfd2.h |  18 +++
 .../kernel/syscalls/eventfd2/eventfd2_01.c    | 148 ++++--------------
 2 files changed, 51 insertions(+), 115 deletions(-)
 create mode 100644 testcases/kernel/syscalls/eventfd2/eventfd2.h

diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2.h b/testcases/kernel/syscalls/eventfd2/eventfd2.h
new file mode 100644
index 000000000..5350820b8
--- /dev/null
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static inline int eventfd2(unsigned int count, unsigned int flags)
+{
+	int ret;
+
+	ret = tst_syscall(__NR_eventfd2, count, flags);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "eventfd2");
+
+	return ret;
+}
diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_01.c b/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
index 85ad86d42..3303ca0db 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
@@ -1,119 +1,37 @@
-/******************************************************************************/
-/*                                                                            */
-/* 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:        eventfd2_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=b087498eb5605673b0f260a7620d91818cd72304 */
-/*              says:                                                         */
-/* This patch adds the new eventfd2 syscall.  It extends the old eventfd      */
-/* syscall by one parameter which is meant to hold a flag value.  In this     */
-/* patch the only flag support is EFD_CLOEXEC which causes the close-on-exec  */
-/* flag for the returned file descriptor to be set. A new name EFD_CLOEXEC is */
-/* introduced which in this implementation must have the same value as        */
-/* O_CLOEXEC. 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>                                                 */
-/* eventfd2_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:   eventfd2_01                                                   */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 08 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 08 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
-
-#include "test.h"
-#include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
-
-#define EFD_CLOEXEC O_CLOEXEC
-
-char *TCID = "eventfd2_01";
-int testno;
-int TST_TOTAL = 1;
-
-void cleanup(void)
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that eventfd2 correctly set FD_CLOEXEC flag on file when
+ * EFD_CLOEXEC flag is used.
+ */
+
+#include <fcntl.h>
+#include <sys/eventfd.h>
+#include "tst_test.h"
+#include "eventfd2.h"
+
+static void run(void)
 {
-	tst_rmdir();
-}
+	int fd, flags;
 
-void setup(void)
-{
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+	fd = eventfd2(1, 0);
+	flags = SAFE_FCNTL(fd, F_GETFD);
+	TST_EXP_EXPR((flags & FD_CLOEXEC) == 0, "FD_CLOEXEC is not set");
+	SAFE_CLOSE(fd);
 
-int main(int argc, char *argv[])
-{
-	int fd, coe;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	fd = tst_syscall(__NR_eventfd2, 1, 0);
-	if (fd == -1) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
-	}
-	coe = fcntl(fd, F_GETFD);
-	if (coe == -1) {
-		tst_brkm(TBROK, cleanup, "fcntl failed");
-	}
-	if (coe & FD_CLOEXEC) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(0) set close-on-exec flag");
-	}
-	close(fd);
-
-	fd = tst_syscall(__NR_eventfd2, 1, EFD_CLOEXEC);
-	if (fd == -1) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(EFD_CLOEXEC) failed");
-	}
-	coe = fcntl(fd, F_GETFD);
-	if (coe == -1) {
-		tst_brkm(TBROK, cleanup, "fcntl failed");
-	}
-	if ((coe & FD_CLOEXEC) == 0) {
-		tst_brkm(TFAIL, cleanup,
-			 "eventfd2(EFD_CLOEXEC) does not set close-on-exec flag");
-	}
-	close(fd);
-	tst_resm(TPASS, "eventfd2(EFD_CLOEXEC) Passed");
-	cleanup();
-	tst_exit();
+	fd = eventfd2(1, EFD_CLOEXEC);
+	flags = SAFE_FCNTL(fd, F_GETFD);
+	TST_EXP_EXPR((flags & FD_CLOEXEC) > 0, "FD_CLOEXEC is set");
+	SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.35.3


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

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

* [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 test using new LTP API
  2023-03-08 13:23 [LTP] [PATCH v1 0/3] Rewrite eventfd2 testing suite Andrea Cervesato
  2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
@ 2023-03-08 13:23 ` Andrea Cervesato
  2023-03-14 23:46   ` Wei Gao via ltp
  2023-04-05  9:32   ` Cyril Hrubis
  2023-03-08 13:23 ` [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 " Andrea Cervesato
  2 siblings, 2 replies; 12+ messages in thread
From: Andrea Cervesato @ 2023-03-08 13:23 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../kernel/syscalls/eventfd2/eventfd2_02.c    | 147 ++++--------------
 1 file changed, 33 insertions(+), 114 deletions(-)

diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_02.c b/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
index 5f3b6ee67..cfa0ca0ac 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
@@ -1,118 +1,37 @@
-/******************************************************************************/
-/*                                                                            */
-/* 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:        eventfd2_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=e7d476dfdf0bcfed478a207aecfdc84f81efecaf */
-/* which says:                                                                */
-/* This patch adds support for the EFD_NONBLOCK flag to eventfd2.  The        */
-/* additional changes needed are minimal. The following test must be adjusted */
-/* or architectures other than x86 and x86-64 and in case the syscall numbers */
-/* changed.                                                                   */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* eventfd2_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:   eventfd2_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 <stdio.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
-
-#include "test.h"
-#include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
-
-#define EFD_NONBLOCK O_NONBLOCK
-
-char *TCID = "eventfd2_02";
-int testno;
-int TST_TOTAL = 1;
-
-void cleanup(void)
-{
-	tst_rmdir();
-}
-
-void setup(void)
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that eventfd2 correctly set O_NONBLOCK flag on file when
+ * EFD_NONBLOCK flag is used.
+ */
+
+#include <fcntl.h>
+#include <sys/eventfd.h>
+#include "tst_test.h"
+#include "eventfd2.h"
+
+static void run(void)
 {
-	TEST_PAUSE;
-	tst_tmpdir();
-}
-
-int main(int argc, char *argv[])
-{
-	int fd, fl;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
+	int fd, flags;
 
-	setup();
+	fd = eventfd2(1, 0);
+	flags = SAFE_FCNTL(fd, F_GETFL);
+	TST_EXP_EXPR((flags & O_NONBLOCK) == 0, "O_NONBLOCK is not set");
+	SAFE_CLOSE(fd);
 
-	tst_count = 0;
-	fd = tst_syscall(__NR_eventfd2, 1, 0);
-	if (fd == -1) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
-	}
-	fl = fcntl(fd, F_GETFL);
-	if (fl == -1) {
-		tst_brkm(TBROK, cleanup, "fcntl failed");
-	}
-	if (fl & O_NONBLOCK) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(0) sets non-blocking mode");
-	}
-	close(fd);
-
-	fd = tst_syscall(__NR_eventfd2, 1, EFD_NONBLOCK);
-	if (fd == -1) {
-		tst_brkm(TFAIL, cleanup, "eventfd2(EFD_NONBLOCK) failed");
-	}
-	fl = fcntl(fd, F_GETFL);
-	if (fl == -1) {
-		tst_brkm(TBROK, cleanup, "fcntl failed");
-	}
-	if ((fl & O_NONBLOCK) == 0) {
-		tst_brkm(TFAIL, cleanup,
-			 "eventfd2(EFD_NONBLOCK) didn't set non-blocking mode");
-	}
-	close(fd);
-	tst_resm(TPASS, "eventfd2(EFD_NONBLOCK) PASSED");
-
-	cleanup();
-	tst_exit();
+	fd = eventfd2(1, EFD_NONBLOCK);
+	flags = SAFE_FCNTL(fd, F_GETFL);
+	TST_EXP_EXPR((flags & O_NONBLOCK) > 0, "O_NONBLOCK is set");
+	SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.35.3


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

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

* [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 test using new LTP API
  2023-03-08 13:23 [LTP] [PATCH v1 0/3] Rewrite eventfd2 testing suite Andrea Cervesato
  2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
  2023-03-08 13:23 ` [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 " Andrea Cervesato
@ 2023-03-08 13:23 ` Andrea Cervesato
  2023-03-15  0:47   ` Wei Gao via ltp
  2023-04-05  9:45   ` Cyril Hrubis
  2 siblings, 2 replies; 12+ messages in thread
From: Andrea Cervesato @ 2023-03-08 13:23 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../kernel/syscalls/eventfd2/eventfd2_03.c    | 128 +++++-------------
 1 file changed, 35 insertions(+), 93 deletions(-)

diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_03.c b/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
index 909004edb..e1949fd32 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
@@ -1,139 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *  eventfd-sem by Davide Libenzi (Simple test for eventfd sempahore)
- *  Copyright (C) 2009  Davide Libenzi
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- *  Davide Libenzi <davidel@xmailserver.org>
- *  Reference: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=bcd0b235bf3808dec5115c381cd55568f63b85f0
- *  Reference: http://www.xmailserver.org/eventfd-sem.c
- *  eventfd: testing improved support for semaphore-like behavior in linux-2.6.30
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
+ * This test verifies that eventfd2 semaphore-like support is properly working.
  */
 
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <inttypes.h>
-
-#include "test.h"
-#include "lapi/syscalls.h"
-
-char *TCID = "eventfd2_03";
-int TST_TOTAL = 1;
-
-#ifndef EFD_SEMLIKE
-#define EFD_SEMLIKE (1 << 0)
-#endif
-
-/* Dummy function as syscall from linux_syscall_numbers.h uses cleanup(). */
-void cleanup(void)
-{
-}
-
-static int eventfd2(int count, int flags)
-{
-	return tst_syscall(__NR_eventfd2, count, flags);
-}
+#include <sys/eventfd.h>
+#include "tst_test.h"
+#include "eventfd2.h"
 
 static void xsem_wait(int fd)
 {
 	u_int64_t cntr;
 
-	if (read(fd, &cntr, sizeof(cntr)) != sizeof(cntr)) {
-		perror("reading eventfd");
-		exit(1);
-	}
-	fprintf(stdout, "[%u] wait completed on %d: count=%" PRIu64 "\n",
-		getpid(), fd, cntr);
+	SAFE_READ(0, fd, &cntr, sizeof(cntr));
 }
 
 static void xsem_post(int fd, int count)
 {
 	u_int64_t cntr = count;
 
-	if (write(fd, &cntr, sizeof(cntr)) != sizeof(cntr)) {
-		perror("writing eventfd");
-		exit(1);
-	}
+	SAFE_WRITE(0, fd, &cntr, sizeof(cntr));
 }
 
 static void sem_player(int fd1, int fd2)
 {
-	fprintf(stdout, "[%u] posting 1 on %d\n", getpid(), fd1);
-	xsem_post(fd1, 1);
+	pid_t pid = getpid();
 
-	fprintf(stdout, "[%u] waiting on %d\n", getpid(), fd2);
-	xsem_wait(fd2);
-
-	fprintf(stdout, "[%u] posting 1 on %d\n", getpid(), fd1);
+	tst_res(TINFO, "[%u] posting 1 on fd=%d", pid, fd1);
 	xsem_post(fd1, 1);
 
-	fprintf(stdout, "[%u] waiting on %d\n", getpid(), fd2);
+	tst_res(TINFO, "[%u] waiting on fd=%d", pid, fd2);
 	xsem_wait(fd2);
 
-	fprintf(stdout, "[%u] posting 5 on %d\n", getpid(), fd1);
+	tst_res(TINFO, "[%u] posting 5 on fd=%d", pid, fd1);
 	xsem_post(fd1, 5);
 
-	fprintf(stdout, "[%u] waiting 5 times on %d\n", getpid(), fd2);
+	tst_res(TINFO, "[%u] waiting 5 times on fd=%d", pid, fd2);
 	xsem_wait(fd2);
 	xsem_wait(fd2);
 	xsem_wait(fd2);
 	xsem_wait(fd2);
 	xsem_wait(fd2);
-}
 
-static void usage(char const *prg)
-{
-	fprintf(stderr, "use: %s [-h]\n", prg);
+	tst_res(TPASS, "[%u] received all events", pid);
 }
 
-int main(int argc, char **argv)
+static void run(void)
 {
-	int c, fd1, fd2, status;
 	pid_t cpid_poster, cpid_waiter;
+	int fd1, fd2;
 
-	while ((c = getopt(argc, argv, "h")) != -1) {
-		switch (c) {
-		default:
-			usage(argv[0]);
-			return 1;
-		}
-	}
-	if ((fd1 = eventfd2(0, EFD_SEMLIKE)) == -1 ||
-	    (fd2 = eventfd2(0, EFD_SEMLIKE)) == -1) {
-		perror("eventfd2");
-		return 1;
-	}
-	if ((cpid_poster = fork()) == 0) {
+	fd1 = eventfd2(0, EFD_SEMAPHORE);
+	fd2 = eventfd2(0, EFD_SEMAPHORE);
+
+	cpid_poster = SAFE_FORK();
+	if (!cpid_poster) {
 		sem_player(fd1, fd2);
 		exit(0);
 	}
-	if ((cpid_waiter = fork()) == 0) {
+
+	cpid_waiter = SAFE_FORK();
+	if (!cpid_waiter) {
 		sem_player(fd2, fd1);
 		exit(0);
 	}
-	waitpid(cpid_poster, &status, 0);
-	waitpid(cpid_waiter, &status, 0);
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+};
-- 
2.35.3


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

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

* Re: [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
@ 2023-03-14 23:40   ` Wei Gao via ltp
  2023-03-15  9:08     ` Andrea Cervesato via ltp
  2023-04-05  9:22     ` Cyril Hrubis
  2023-04-05  9:24   ` Cyril Hrubis
  1 sibling, 2 replies; 12+ messages in thread
From: Wei Gao via ltp @ 2023-03-14 23:40 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

On Wed, Mar 08, 2023 at 02:23:33PM +0100, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  testcases/kernel/syscalls/eventfd2/eventfd2.h |  18 +++
>  .../kernel/syscalls/eventfd2/eventfd2_01.c    | 148 ++++--------------
>  2 files changed, 51 insertions(+), 115 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/eventfd2/eventfd2.h
> 
> diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2.h b/testcases/kernel/syscalls/eventfd2/eventfd2.h
> new file mode 100644
> index 000000000..5350820b8
> --- /dev/null
> +++ b/testcases/kernel/syscalls/eventfd2/eventfd2.h
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +
> +static inline int eventfd2(unsigned int count, unsigned int flags)
> +{
> +	int ret;
> +
> +	ret = tst_syscall(__NR_eventfd2, count, flags);
> +	if (ret == -1)
> +		tst_brk(TBROK | TERRNO, "eventfd2");
> +
> +	return ret;
> +}
Normally we need put file or store this file into some lib directory?

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

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

* Re: [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 " Andrea Cervesato
@ 2023-03-14 23:46   ` Wei Gao via ltp
  2023-04-05  9:32   ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Wei Gao via ltp @ 2023-03-14 23:46 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

On Wed, Mar 08, 2023 at 02:23:34PM +0100, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  .../kernel/syscalls/eventfd2/eventfd2_02.c    | 147 ++++--------------
>  1 file changed, 33 insertions(+), 114 deletions(-)
> 
Tested-by: Wei Gao wegao@suse.com

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

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

* Re: [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 " Andrea Cervesato
@ 2023-03-15  0:47   ` Wei Gao via ltp
  2023-04-05  9:45   ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Wei Gao via ltp @ 2023-03-15  0:47 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Tested-by: Wei Gao wegao@suse.com

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

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

* Re: [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API
  2023-03-14 23:40   ` Wei Gao via ltp
@ 2023-03-15  9:08     ` Andrea Cervesato via ltp
  2023-04-05  9:22     ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Andrea Cervesato via ltp @ 2023-03-15  9:08 UTC (permalink / raw)
  To: Wei Gao, Andrea Cervesato; +Cc: ltp

Hi,

On 3/15/23 00:40, Wei Gao wrote:
> On Wed, Mar 08, 2023 at 02:23:33PM +0100, Andrea Cervesato wrote:
>> From: Andrea Cervesato <andrea.cervesato@suse.com>
>>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>>   testcases/kernel/syscalls/eventfd2/eventfd2.h |  18 +++
>>   .../kernel/syscalls/eventfd2/eventfd2_01.c    | 148 ++++--------------
>>   2 files changed, 51 insertions(+), 115 deletions(-)
>>   create mode 100644 testcases/kernel/syscalls/eventfd2/eventfd2.h
>>
>> diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2.h b/testcases/kernel/syscalls/eventfd2/eventfd2.h
>> new file mode 100644
>> index 000000000..5350820b8
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/eventfd2/eventfd2.h
>> @@ -0,0 +1,18 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> + */
>> +
>> +#include "tst_test.h"
>> +#include "lapi/syscalls.h"
>> +
>> +static inline int eventfd2(unsigned int count, unsigned int flags)
>> +{
>> +	int ret;
>> +
>> +	ret = tst_syscall(__NR_eventfd2, count, flags);
>> +	if (ret == -1)
>> +		tst_brk(TBROK | TERRNO, "eventfd2");
>> +
>> +	return ret;
>> +}
> Normally we need put file or store this file into some lib directory?

Common pattern is usually to add a header file (if needed) with the name 
of the testing suite in the folder name of that suite.

Andrea


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

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

* Re: [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API
  2023-03-14 23:40   ` Wei Gao via ltp
  2023-03-15  9:08     ` Andrea Cervesato via ltp
@ 2023-04-05  9:22     ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2023-04-05  9:22 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Hi!
> > +static inline int eventfd2(unsigned int count, unsigned int flags)
> > +{
> > +	int ret;
> > +
> > +	ret = tst_syscall(__NR_eventfd2, count, flags);
> > +	if (ret == -1)
> > +		tst_brk(TBROK | TERRNO, "eventfd2");
> > +
> > +	return ret;
> > +}
> Normally we need put file or store this file into some lib directory?

As long as there are no other testcases that will need this it's okay if
this stays here.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
  2023-03-14 23:40   ` Wei Gao via ltp
@ 2023-04-05  9:24   ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2023-04-05  9:24 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Pushed with two minor changes, thanks.

> +	TST_EXP_EXPR((flags & FD_CLOEXEC) > 0, "FD_CLOEXEC is set");
                        ^
			It's more C-like to do just (flags & FD_CLOEXEC)
			here, i.e. drop the > 0

			And use !(...) for the other case.
-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 " Andrea Cervesato
  2023-03-14 23:46   ` Wei Gao via ltp
@ 2023-04-05  9:32   ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2023-04-05  9:32 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Pushed with the same minor changes as previous one, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 test using new LTP API
  2023-03-08 13:23 ` [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 " Andrea Cervesato
  2023-03-15  0:47   ` Wei Gao via ltp
@ 2023-04-05  9:45   ` Cyril Hrubis
  1 sibling, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2023-04-05  9:45 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

end of thread, other threads:[~2023-04-05  9:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 13:23 [LTP] [PATCH v1 0/3] Rewrite eventfd2 testing suite Andrea Cervesato
2023-03-08 13:23 ` [LTP] [PATCH v1 1/3] Rewrite eventfd2_01 test using new LTP API Andrea Cervesato
2023-03-14 23:40   ` Wei Gao via ltp
2023-03-15  9:08     ` Andrea Cervesato via ltp
2023-04-05  9:22     ` Cyril Hrubis
2023-04-05  9:24   ` Cyril Hrubis
2023-03-08 13:23 ` [LTP] [PATCH v1 2/3] Rewrite eventfd2_02 " Andrea Cervesato
2023-03-14 23:46   ` Wei Gao via ltp
2023-04-05  9:32   ` Cyril Hrubis
2023-03-08 13:23 ` [LTP] [PATCH v1 3/3] Rewrite eventfd2_03 " Andrea Cervesato
2023-03-15  0:47   ` Wei Gao via ltp
2023-04-05  9:45   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).