Skip to contentSkip to conversation

shutdown testing suite

PATCH Superseded Andrea Cervesato 3 participants 5 messages May 27, 2024 – Jun 7, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover shutdown testing suite

This testing suite is meant to test shutdown() syscall functionalities. The current LTP version uses shutdown() inside many tests, but none of them is specifically running unit tests for it.

This suite comes with both unit tests for shutdown() flags and error codes.

---
Andrea Cervesato (2):
Add shutdown01 test
Add shutdown02 test

 runtest/syscalls                                |   3 +
 testcases/kernel/syscalls/shutdown/.gitignore   |   2 +
 testcases/kernel/syscalls/shutdown/Makefile     |   7 ++
 testcases/kernel/syscalls/shutdown/shutdown01.c | 136 ++++++++++++++++++++++++
 testcases/kernel/syscalls/shutdown/shutdown02.c |  75 +++++++++++++
 5 files changed, 223 insertions(+)

---
base-commit: 0358f7a2788eed0cbff7f8519b1a0f7f89d36c13
change-id: 20240524-shutdown-c8d7580e916a

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/2 Add shutdown01 test

From: Andrea Cervesato <[email protected]>

This test verifies the following shutdown() functionalities:
* SHUT_RD should enable send() ops but disable recv() ops
* SHUT_WR should enable recv() ops but disable send() ops
* SHUT_RDWR should disable both recv() and send() ops

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/shutdown/.gitignore   |   1 +
 testcases/kernel/syscalls/shutdown/Makefile     |   7 ++
 testcases/kernel/syscalls/shutdown/shutdown01.c | 136 ++++++++++++++++++++++++
 4 files changed, 146 insertions(+)
runtest/syscalls +2 -0
index cf06ee563..dc396415e 100644
@@ -1465,6 +1465,8 @@ shmget04 shmget04
 shmget05 shmget05
 shmget06 shmget06
 
+shutdown01 shutdown01
+
 sigaction01 sigaction01
 sigaction02 sigaction02
 
testcases/kernel/syscalls/shutdown/.gitignore new file +1 -0
new file mode 100644
index 000000000..2df24d1ab
@@ -0,0 +1 @@
+shutdown01
testcases/kernel/syscalls/shutdown/Makefile new file +7 -0
new file mode 100644
index 000000000..8cf1b9024
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/shutdown/shutdown01.c new file +136 -0

136 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/2
#2 lore raw

Re: [LTP] [PATCH 1/2] Add shutdown01 test

Hi Andrea,

...

Quoted 6 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +0 -0
new file mode 100644
index 000000000..b68b14ae8

testcases/kernel/syscalls/shutdown/shutdown01.c line 9

Quoted 9 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +9 -0
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies the following shutdown() functionalities:

nit: here needs to be blank line to get list formatting.

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+ * * SHUT_RD should enable send() ops but disable recv() ops
+ * * SHUT_WR should enable recv() ops but disable send() ops
+ * * SHUT_RDWR should disable both recv() and send() ops
+ */

...

testcases/kernel/syscalls/shutdown/shutdown01.c line 65

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+static void test_shutdown_recv(void)
+{
+	int client_sock;
+	char buff[MSGSIZE] = {0};

Wouldn't it be better to send some data?
Or is it not important, we use guarded buffers?

testcases/kernel/syscalls/shutdown/shutdown01.c line 72

Quoted 7 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +7 -0
+
+	client_sock = start_test();
+
+	tst_res(TINFO, "Testing SHUT_RD flag");
+
+	TST_EXP_PASS(shutdown(client_sock, SHUT_RD));
+	TST_EXP_EQ_LI(recv(client_sock, buff, MSGSIZE, 0), 0);

Interesting, I would expect failure ("If how is SHUT_RD, further receptions will be disallowed.")

And maybe use SAFE_RECV()?

testcases/kernel/syscalls/shutdown/shutdown01.c line 73

Quoted 1 line
testcases/kernel/syscalls/shutdown/shutdown01.c new file +1 -0
+	TST_EXP_EQ_LI(send(client_sock, buff, MSGSIZE, 0), MSGSIZE);

And SAFE_SEND() here?

testcases/kernel/syscalls/shutdown/shutdown01.c line 77

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+
+	SAFE_CLOSE(client_sock);
+	TST_CHECKPOINT_WAKE(0);
+}

nit: I would also use struct tcase and .tcnt, because all 3 tests are nearly identical.

Otherwise LGTM.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH 1/2] Add shutdown01 test

Hi!

Quoted 24 lines · Petr Vorel

Hi Andrea,

...

Quoted 6 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +0 -0
new file mode 100644
index 000000000..b68b14ae8

testcases/kernel/syscalls/shutdown/shutdown01.c line 9

Quoted 9 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +9 -0
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies the following shutdown() functionalities:

nit: here needs to be blank line to get list formatting.

testcases/kernel/syscalls/shutdown/shutdown01.c line 13

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+ * * SHUT_RD should enable send() ops but disable recv() ops
+ * * SHUT_WR should enable recv() ops but disable send() ops
+ * * SHUT_RDWR should disable both recv() and send() ops
+ */
Quoted 7 lines

...

testcases/kernel/syscalls/shutdown/shutdown01.c line 65

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+static void test_shutdown_recv(void)
+{
+	int client_sock;
+	char buff[MSGSIZE] = {0};

Wouldn't it be better to send some data?
Or is it not important, we use guarded buffers?

In this case, data is not really important because we need to test if send/recv are disabled after shutdown().

Quoted 22 lines

testcases/kernel/syscalls/shutdown/shutdown01.c line 72

Quoted 8 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +7 -0
+
+	client_sock = start_test();
+
+	tst_res(TINFO, "Testing SHUT_RD flag");
+
+	TST_EXP_PASS(shutdown(client_sock, SHUT_RD));
+	TST_EXP_EQ_LI(recv(client_sock, buff, MSGSIZE, 0), 0);

Interesting, I would expect failure ("If how is SHUT_RD, further receptions will be disallowed.")

And maybe use SAFE_RECV()?

testcases/kernel/syscalls/shutdown/shutdown01.c line 73

Quoted 1 line
testcases/kernel/syscalls/shutdown/shutdown01.c new file +1 -0
+	TST_EXP_EQ_LI(send(client_sock, buff, MSGSIZE, 0), MSGSIZE);

And SAFE_SEND() here?

testcases/kernel/syscalls/shutdown/shutdown01.c line 77

Quoted 4 lines
testcases/kernel/syscalls/shutdown/shutdown01.c new file +4 -0
+
+	SAFE_CLOSE(client_sock);
+	TST_CHECKPOINT_WAKE(0);
+}

nit: I would also use struct tcase and .tcnt, because all 3 tests are nearly identical.

Quoted 6 lines

Otherwise LGTM.

Kind regards,
Petr

I will fix the rest.

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH 2/2 Add shutdown02 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies the following shutdown() errors:
* EBADF sockfd is not a valid file descriptor
* EINVAL An invalid value was specified in how
* ENOTCONN The specified socket is not connected
* ENOTSOCK The file descriptor sockfd does not refer to a socket

---
 runtest/syscalls                                |  1 +
 testcases/kernel/syscalls/shutdown/.gitignore   |  1 +
 testcases/kernel/syscalls/shutdown/shutdown02.c | 75 +++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
runtest/syscalls +1 -0
index dc396415e..44a577db3 100644
@@ -1466,6 +1466,7 @@ shmget05 shmget05
 shmget06 shmget06
 
 shutdown01 shutdown01
+shutdown02 shutdown02
 
 sigaction01 sigaction01
 sigaction02 sigaction02
testcases/kernel/syscalls/shutdown/.gitignore +1 -0
index 2df24d1ab..fd1ed807d 100644
@@ -1 +1,2 @@
 shutdown01
+shutdown02
testcases/kernel/syscalls/shutdown/shutdown02.c new file +75 -0

75 lines not on this page · raw message

Signature · 5 lines
2.35.3


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