All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] accept4: Use tst_variant
@ 2020-03-23 22:49 Petr Vorel
  2020-03-23 22:49 ` [LTP] [PATCH 2/3] accept4: Remove fallback definitions Petr Vorel
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Petr Vorel @ 2020-03-23 22:49 UTC (permalink / raw)
  To: ltp

to test both raw syscall and libc implementation.

This allows remove glibc specific __GLIBC_PREREQ() macro.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
I guess __NR_socketcall is for x86 and other old architectures,
but we still want to use it, right?

Kind regards,
Petr

 .../kernel/syscalls/accept4/accept4_01.c      | 49 ++++++++++---------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index 29e18f27d..a596b9b1a 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -2,9 +2,9 @@
 
 /*
  * Copyright (C) 2008, Linux Foundation,
+ * Copyright (c) 2020 Petr Vorel <petr.vorel@gmail.com>
  * written by Michael Kerrisk <mtk.manpages@gmail.com>
  * Initial Porting to LTP by Subrata <subrata@linux.vnet.ibm.com>
- *
  */
 
 #define _GNU_SOURCE
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <linux/net.h>
 
 #include "tst_test.h"
 #include "lapi/fcntl.h"
@@ -31,18 +32,17 @@
 # define SOCK_NONBLOCK   O_NONBLOCK
 #endif
 
-#if defined(SYS_ACCEPT4)	/* the socketcall() number */
-#define USE_SOCKETCALL 1
-#endif
+static const char *variant_desc[] = {
+	"libc accept4()",
+	"__NR_accept4 syscall",
+	"__NR_socketcall SYS_ACCEPT4 syscall"};
 
 static struct sockaddr_in *conn_addr, *accept_addr;
 static int listening_fd;
 
-#if !(__GLIBC_PREREQ(2, 10))
 static int
 accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
 {
-#if USE_SOCKETCALL
 	long args[6];
 
 	args[0] = fd;
@@ -51,11 +51,7 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
 	args[3] = flags;
 
 	return tst_syscall(__NR_socketcall, SYS_ACCEPT4, args);
-#else
-	return tst_syscall(__NR_accept4, fd, sockaddr, addrlen, flags);
-#endif
 }
-#endif
 
 static int create_listening_socket(void)
 {
@@ -80,6 +76,8 @@ static int create_listening_socket(void)
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing variant: %s", variant_desc[tst_variant]);
+
 	memset(conn_addr, 0, sizeof(*conn_addr));
 	conn_addr->sin_family = AF_INET;
 	conn_addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -106,6 +104,7 @@ static struct test_case {
 static void verify_accept4(unsigned int nr)
 {
 	struct test_case *tcase = &tcases[nr];
+	int flags = tcase->cloexec | tcase->nonblock;
 	int connfd, acceptfd;
 	int fdf, flf, fdf_pass, flf_pass, fd_cloexec, fd_nonblock;
 	socklen_t addrlen;
@@ -114,20 +113,25 @@ static void verify_accept4(unsigned int nr)
 	SAFE_CONNECT(connfd, (struct sockaddr *)conn_addr, sizeof(*conn_addr));
 	addrlen = sizeof(*accept_addr);
 
-#if !(__GLIBC_PREREQ(2, 10))
-	TEST(accept4_01(listening_fd, (struct sockaddr *)accept_addr, &addrlen,
-				tcase->cloexec | tcase->nonblock));
-#else
-	TEST(accept4(listening_fd, (struct sockaddr *)accept_addr, &addrlen,
-				tcase->cloexec | tcase->nonblock));
-#endif
-	if (TST_RET == -1) {
-		if (TST_ERR == ENOSYS)
-			tst_brk(TCONF, "syscall __NR_accept4 not supported");
-		else
-			tst_brk(TBROK | TTERRNO, "accept4 failed");
+	switch (tst_variant) {
+	case 0:
+		TEST(accept4(listening_fd, (struct sockaddr *)accept_addr,
+			     &addrlen, flags));
+	break;
+	case 1:
+		TEST(tst_syscall(__NR_accept4, listening_fd,
+				 (struct sockaddr *)accept_addr,
+				 &addrlen, flags));
+	break;
+	case 2:
+		TEST(accept4_01(listening_fd, (struct sockaddr *)accept_addr,
+				&addrlen, flags));
+	break;
 	}
 
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "accept4 failed");
+
 	acceptfd = TST_RET;
 
 	/* Test to see if O_CLOEXEC is as expected */
@@ -161,6 +165,7 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
+	.test_variants = 3,
 	.test = verify_accept4,
 	.bufs = (struct tst_buffers []) {
 		{&conn_addr, .size = sizeof(*conn_addr)},
-- 
2.25.1


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

* [LTP] [PATCH 2/3] accept4: Remove fallback definitions
  2020-03-23 22:49 [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
@ 2020-03-23 22:49 ` Petr Vorel
  2020-03-24 23:36   ` Cyril Hrubis
  2020-03-23 22:49 ` [LTP] [PATCH 3/3] travis: Update musl build Petr Vorel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2020-03-23 22:49 UTC (permalink / raw)
  To: ltp

They're already defined in lapi/fcntl.h.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 testcases/kernel/syscalls/accept4/accept4_01.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index a596b9b1a..55aa210ae 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -25,13 +25,6 @@
 
 #define PORT_NUM 33333
 
-#ifndef SOCK_CLOEXEC
-# define SOCK_CLOEXEC    O_CLOEXEC
-#endif
-#ifndef SOCK_NONBLOCK
-# define SOCK_NONBLOCK   O_NONBLOCK
-#endif
-
 static const char *variant_desc[] = {
 	"libc accept4()",
 	"__NR_accept4 syscall",
-- 
2.25.1


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

* [LTP] [PATCH 3/3] travis: Update musl build
  2020-03-23 22:49 [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
  2020-03-23 22:49 ` [LTP] [PATCH 2/3] accept4: Remove fallback definitions Petr Vorel
@ 2020-03-23 22:49 ` Petr Vorel
  2020-03-23 23:03 ` [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
  2020-03-24 23:35 ` Cyril Hrubis
  3 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2020-03-23 22:49 UTC (permalink / raw)
  To: ltp

accept4_01.c was fixed in previous build.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 travis/alpine.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/travis/alpine.sh b/travis/alpine.sh
index 233dae78e..b2c1fff9e 100755
--- a/travis/alpine.sh
+++ b/travis/alpine.sh
@@ -30,7 +30,6 @@ echo "WARNING: remove unsupported tests (until they're fixed)"
 cd ..
 rm -rfv \
 	testcases/kernel/sched/process_stress/process.c \
-	testcases/kernel/syscalls/accept4/accept4_01.c \
 	testcases/kernel/syscalls/confstr/confstr01.c \
 	testcases/kernel/syscalls/fmtmsg/fmtmsg01.c \
 	testcases/kernel/syscalls/getcontext/getcontext01.c \
-- 
2.25.1


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

* [LTP] [PATCH 1/3] accept4: Use tst_variant
  2020-03-23 22:49 [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
  2020-03-23 22:49 ` [LTP] [PATCH 2/3] accept4: Remove fallback definitions Petr Vorel
  2020-03-23 22:49 ` [LTP] [PATCH 3/3] travis: Update musl build Petr Vorel
@ 2020-03-23 23:03 ` Petr Vorel
  2020-03-24  6:53   ` Petr Vorel
  2020-03-24 23:35 ` Cyril Hrubis
  3 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2020-03-23 23:03 UTC (permalink / raw)
  To: ltp

Hi,

> I guess __NR_socketcall is for x86 and other old architectures,
> but we still want to use it, right?

Maybe I should have kept just 2 variants (libc implementation and only one
syscall implementation) and chose the correct syscall implementation with
#ifdef SYS_ACCEPT4

Or is there arch which supports both syscall variants?

Kind regards,
Petr

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

* [LTP] [PATCH 1/3] accept4: Use tst_variant
  2020-03-23 23:03 ` [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
@ 2020-03-24  6:53   ` Petr Vorel
  2020-03-24 13:08     ` Li Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2020-03-24  6:53 UTC (permalink / raw)
  To: ltp

Hi,

> > I guess __NR_socketcall is for x86 and other old architectures,
> > but we still want to use it, right?

> Maybe I should have kept just 2 variants (libc implementation and only one
> syscall implementation) and chose the correct syscall implementation with
> #ifdef SYS_ACCEPT4

> Or is there arch which supports both syscall variants?
OK, I can answer myself: ppc64le is example of arch which support both
__NR_accept4 and __NR_socketcall SYS_ACCEPT4.

Kind regards,
Petr

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

* [LTP] [PATCH 1/3] accept4: Use tst_variant
  2020-03-24  6:53   ` Petr Vorel
@ 2020-03-24 13:08     ` Li Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Li Wang @ 2020-03-24 13:08 UTC (permalink / raw)
  To: ltp

On Tue, Mar 24, 2020 at 2:54 PM Petr Vorel <pvorel@suse.cz> wrote:

> Hi,
>
> > > I guess __NR_socketcall is for x86 and other old architectures,
> > > but we still want to use it, right?
>
> > Maybe I should have kept just 2 variants (libc implementation and only
> one
> > syscall implementation) and chose the correct syscall implementation with
> > #ifdef SYS_ACCEPT4
>
> > Or is there arch which supports both syscall variants?
> OK, I can answer myself: ppc64le is example of arch which support both
> __NR_accept4 and __NR_socketcall SYS_ACCEPT4.
>

That's right, I just verified it on my ppc64le(rhel8) platform, so we can
keep the 3 variants test.

For your patchset:
Reviewed-by: Li Wang <liwang@redhat.com>

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

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

* [LTP] [PATCH 1/3] accept4: Use tst_variant
  2020-03-24 23:35 ` Cyril Hrubis
@ 2020-03-24 18:07   ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2020-03-24 18:07 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> > @@ -51,11 +51,7 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
> >  	args[3] = flags;

> >  	return tst_syscall(__NR_socketcall, SYS_ACCEPT4, args);
> > -#else
> > -	return tst_syscall(__NR_accept4, fd, sockaddr, addrlen, flags);
> > -#endif
> >  }
> > -#endif

> This is very minor, however the function should be renamed to something
> as socketcall_accept4().

> Acked otherwise.

Thanks, patchset pushed with this fix.

Kind regards,
Petr

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

* [LTP] [PATCH 1/3] accept4: Use tst_variant
  2020-03-23 22:49 [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
                   ` (2 preceding siblings ...)
  2020-03-23 23:03 ` [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
@ 2020-03-24 23:35 ` Cyril Hrubis
  2020-03-24 18:07   ` Petr Vorel
  3 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2020-03-24 23:35 UTC (permalink / raw)
  To: ltp

Hi!
> -#if !(__GLIBC_PREREQ(2, 10))
>  static int
>  accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
>  {
> -#if USE_SOCKETCALL
>  	long args[6];
>  
>  	args[0] = fd;
> @@ -51,11 +51,7 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
>  	args[3] = flags;
>  
>  	return tst_syscall(__NR_socketcall, SYS_ACCEPT4, args);
> -#else
> -	return tst_syscall(__NR_accept4, fd, sockaddr, addrlen, flags);
> -#endif
>  }
> -#endif

This is very minor, however the function should be renamed to something
as socketcall_accept4().

Acked otherwise.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/3] accept4: Remove fallback definitions
  2020-03-23 22:49 ` [LTP] [PATCH 2/3] accept4: Remove fallback definitions Petr Vorel
@ 2020-03-24 23:36   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2020-03-24 23:36 UTC (permalink / raw)
  To: ltp

Hi!
This is obviously correct, acked.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-03-24 23:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 22:49 [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
2020-03-23 22:49 ` [LTP] [PATCH 2/3] accept4: Remove fallback definitions Petr Vorel
2020-03-24 23:36   ` Cyril Hrubis
2020-03-23 22:49 ` [LTP] [PATCH 3/3] travis: Update musl build Petr Vorel
2020-03-23 23:03 ` [LTP] [PATCH 1/3] accept4: Use tst_variant Petr Vorel
2020-03-24  6:53   ` Petr Vorel
2020-03-24 13:08     ` Li Wang
2020-03-24 23:35 ` Cyril Hrubis
2020-03-24 18:07   ` Petr Vorel

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.