Skip to contentSkip to conversation

accept4: Use tst_variant

PATCH New Petr Vorel 4 participants 9 messages Mar 23, 2020 – Mar 24, 2020

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/3 accept4: Use tst_variant

to test both raw syscall and libc implementation.

This allows remove glibc specific __GLIBC_PREREQ() macro.

---
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(-)
testcases/kernel/syscalls/accept4/accept4_01.c +27 -22
index 29e18f27d..a596b9b1a 100644
@@ -2,9 +2,9 @@
 
 /*
  * Copyright (C) 2008, Linux Foundation,
+ * Copyright (c) 2020 Petr Vorel <[email protected]>
  * written by Michael Kerrisk <[email protected]>
  * Initial Porting to LTP by Subrata <[email protected]>
- *
  */
 
 #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)},
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/3 accept4: Use tst_variant

Hi,

Quoted 2 lines

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

#2 lore raw

PATCH 1/3 accept4: Use tst_variant

Hi,

Quoted 8 lines
Quoted 2 lines

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

#3 lore raw

PATCH 1/3 accept4: Use tst_variant

Quoted 5 lines · Petr Vorel

Hi,

Quoted 2 lines
Quoted 2 lines

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

Quoted 9 lines
Quoted 1 line

Maybe I should have kept just 2 variants (libc implementation and only

one

Quoted 4 lines

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:

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200324/33144ed9/attachment.htm>
author
#4 lore raw

PATCH 2/3 accept4: Remove fallback definitions

In reply to Petr Vorel

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

---
 testcases/kernel/syscalls/accept4/accept4_01.c | 7 -------
 1 file changed, 7 deletions(-)
testcases/kernel/syscalls/accept4/accept4_01.c +0 -7
index a596b9b1a..55aa210ae 100644
@@ -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",
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH 3/3 travis: Update musl build

In reply to Petr Vorel

accept4_01.c was fixed in previous build.

---
 travis/alpine.sh | 1 -
 1 file changed, 1 deletion(-)
travis/alpine.sh +0 -1
index 233dae78e..b2c1fff9e 100755
@@ -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 \
Signature · 1 line
2.25.1
#7 lore raw

PATCH 1/3 accept4: Use tst_variant

In reply to Petr Vorel

Hi!

Quoted 9 lines
testcases/kernel/syscalls/accept4/accept4_01.c +0 -2
-#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;

testcases/kernel/syscalls/accept4/accept4_01.c accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags) · line 58

Quoted 8 lines
testcases/kernel/syscalls/accept4/accept4_01.c +0 -4
@@ -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.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#8 lore raw

PATCH 1/3 accept4: Use tst_variant

Hi Cyril,

Quoted 13 lines

testcases/kernel/syscalls/accept4/accept4_01.c accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags) · line 58

Quoted 9 lines
testcases/kernel/syscalls/accept4/accept4_01.c +0 -4
@@ -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().

Quoted 1 line

Acked otherwise.

Thanks, patchset pushed with this fix.

Kind regards,
Petr