fix t-socket test case fail

Signed-off-by: yaowenbin <yaowenbin1@huawei.com>
(cherry picked from commit 5361f26c273f8eb4a123314bf3014dcbd93bd7b3)
This commit is contained in:
yaowenbin 2022-09-24 15:18:33 +08:00 committed by openeuler-sync-bot
parent 8ce50b5704
commit c3ef424080
2 changed files with 40 additions and 23 deletions

View File

@ -1,7 +1,7 @@
From d5ff2e1a5f4df3b3545fde4249be6a9f69401b4d Mon Sep 17 00:00:00 2001
From 9ce3797bb45fc360bf0d38a0d28911b1c1ada585 Mon Sep 17 00:00:00 2001
From: yaowenbin <yaowenbin1@huawei.com>
Date: Tue, 1 Mar 2022 08:30:38 +0000
Subject: [PATCH] add test cases
Subject: [PATCH 1/1] add test cases
The following test cases are added to test more interfaces of npth:
t-condlock.c test npth condlock interfaces
@ -13,12 +13,12 @@ t-socket.c test npth socket interfaces
Signed-off-by: yaowenbin <yaowenbin1@huawei.com>
---
tests/Makefile.am | 3 +-
tests/t-condlock.c | 106 ++++++++++++++++
tests/t-fork-enhance.c | 68 +++++++++++
tests/t-rwlock.c | 196 ++++++++++++++++++++++++++++++
tests/t-signal.c | 49 ++++++++
tests/t-socket.c | 270 +++++++++++++++++++++++++++++++++++++++++
6 files changed, 691 insertions(+), 1 deletion(-)
tests/t-condlock.c | 106 +++++++++++++++
tests/t-fork-enhance.c | 68 ++++++++++
tests/t-rwlock.c | 196 ++++++++++++++++++++++++++++
tests/t-signal.c | 49 +++++++
tests/t-socket.c | 284 +++++++++++++++++++++++++++++++++++++++++
6 files changed, 705 insertions(+), 1 deletion(-)
create mode 100644 tests/t-condlock.c
create mode 100644 tests/t-fork-enhance.c
create mode 100644 tests/t-rwlock.c
@ -491,10 +491,10 @@ index 0000000..45c7c97
+}
diff --git a/tests/t-socket.c b/tests/t-socket.c
new file mode 100644
index 0000000..c7bfc15
index 0000000..94ad0bb
--- /dev/null
+++ b/tests/t-socket.c
@@ -0,0 +1,270 @@
@@ -0,0 +1,284 @@
+/* t-socket.c
+ *
+ * This file is free software; as a special exception the author gives
@ -518,6 +518,9 @@ index 0000000..c7bfc15
+#define NAME "Socket"
+#define DATA "Hello, little Baby . . ."
+
+static int server1Ready;
+static int server2Ready;
+
+static void *
+thread_one (void *arg)
+{
@ -536,16 +539,17 @@ index 0000000..c7bfc15
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ exit(1);
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
+ if (bind(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un))) {
+ perror("binding stream socket");
+ exit(1);
+ goto end;
+ }
+ printf("Socket has name %s\n", server.sun_path);
+ listen(sock, 5);
+ server1Ready = 1;
+ msgsock = npth_accept(sock, 0, 0);
+ if (msgsock == -1)
+ perror("accept");
@ -565,7 +569,7 @@ index 0000000..c7bfc15
+ close(sock);
+ unlink(NAME);
+ info_msg ("thread-one terminated");
+
+end:
+ return (void*)4711;
+}
+
@ -579,10 +583,14 @@ index 0000000..c7bfc15
+ char buf[1024];
+
+ info_msg ("thread-two started");
+ if (!server1Ready) {
+ info_msg ("server1 not ready");
+ goto end;
+ }
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ exit(1);
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
@ -590,7 +598,7 @@ index 0000000..c7bfc15
+ if (npth_connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
+ close(sock);
+ perror("connecting stream socket");
+ exit(1);
+ goto end;
+ }
+ if (npth_write(sock, DATA, sizeof(DATA)) < 0)
+ perror("writing on stream socket");
@ -598,6 +606,7 @@ index 0000000..c7bfc15
+
+ info_msg ("thread-two terminated");
+
+end:
+ return (void*)4722;
+}
+
@ -621,16 +630,17 @@ index 0000000..c7bfc15
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ exit(1);
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
+ if (bind(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un))) {
+ perror("binding stream socket");
+ exit(1);
+ goto end;
+ }
+ printf("Socket has name %s\n", server.sun_path);
+ listen(sock, 5);
+ server2Ready = 1;
+ msgsock = npth_accept(sock, 0, 0);
+ if (msgsock == -1)
+ perror("accept");
@ -646,7 +656,7 @@ index 0000000..c7bfc15
+ close(sock);
+ unlink(NAME);
+ info_msg ("thread-three terminated");
+
+end:
+ return (void*)4711;
+}
+
@ -668,10 +678,14 @@ index 0000000..c7bfc15
+ msg.msg_iovlen = 1;
+
+ info_msg ("thread-four started");
+ if (!server2Ready) {
+ info_msg ("server2 not ready");
+ goto end;
+ }
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ exit(1);
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
@ -679,13 +693,13 @@ index 0000000..c7bfc15
+ if (npth_connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
+ close(sock);
+ perror("connecting stream socket");
+ exit(1);
+ goto end;
+ }
+ npth_sendmsg(sock, &msg, 0);
+ close(sock);
+
+ info_msg ("thread-four terminated");
+
+end:
+ return (void*)4722;
+}
+
@ -766,5 +780,5 @@ index 0000000..c7bfc15
+ return 0;
+}
--
2.23.0
2.27.0

View File

@ -1,6 +1,6 @@
Name: npth
Version: 1.6
Release: 5
Release: 6
Summary: The New GNU Portable Threads library
License: LGPLv2+
URL: http://git.gnupg.org/cgi-bin/gitweb.cgi?p=npth.git
@ -62,6 +62,9 @@ make check
%{_datadir}/aclocal/%{name}.m4
%changelog
* Sat Sep 24 2022 yaowenbin1 <yaowenbin1@huawei.com> - 1.6-6
- DESC: fix t-socket test case fail
* Thu Mar 10 2022 EulerOSWander <314264452@qq.com> - 1.6-5
- DESC: posix: Add npth_poll/npth_ppoll