Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
2b2a6b8090
!19 调整spec中补丁位置
From: @licihua 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2023-01-29 06:47:37 +00:00
licihua
e9d4c5acf4 modify the pathes location 2023-01-28 15:41:59 +08:00
openeuler-ci-bot
49e8bfc4c7
!15 [sync] PR-14: 修复t-socket测试用例失败
From: @openeuler-sync-bot 
Reviewed-by: @SuperSix173 
Signed-off-by: @SuperSix173
2022-11-23 06:22:31 +00:00
yaowenbin
c3ef424080 fix t-socket test case fail
Signed-off-by: yaowenbin <yaowenbin1@huawei.com>
(cherry picked from commit 5361f26c273f8eb4a123314bf3014dcbd93bd7b3)
2022-09-26 14:37:56 +08:00
openeuler-ci-bot
8ce50b5704
!12 posix: Add npth_poll/npth_ppoll.
From: @euleroswander 
Reviewed-by: @wangbin224 
Signed-off-by: @wangbin224
2022-03-14 08:30:40 +00:00
EulerOSWander
4a30b2e5ed posix: Add npth_poll/npth_ppoll
posix: Add npth_poll/npth_ppoll

Signed-off-by: EulerOSWander <314264452@qq.com>
2022-03-13 11:46:09 +08:00
openeuler-ci-bot
8784a74280
!11 add testcases
From: @yaowenbin1 
Reviewed-by: @SuperSix173 
Signed-off-by: @SuperSix173
2022-03-02 07:00:39 +00:00
yaowenbin
ea2faf11fe npth: add test cases
reason:Add the following test cases to cover more interfaces of npth:
t-condlock.c    test npth condlock interfaces
t-fork-enhance.c    test npth fork interfaces
t-rwlock.c    test npth rwlock interfaces
t-signal.c    test npth signal interfaces
t-socket.c    test npth socket interfaces

Signed-off-by: yaowenbin <yaowenbin1@huawei.com>
2022-03-01 13:24:16 +00:00
openeuler-ci-bot
dda4db2564 !8 npth delete -Sgit from %autosetup, and delete BuildRequires git
From: @chenyanpanHW
Reviewed-by: @liqingqing_1229
Signed-off-by: @liqingqing_1229
2021-08-12 07:30:00 +00:00
chenyanpanHW
f25028c1a9
delete -Sgit from %autosetup, and delete BuildRequires git 2021-07-30 23:09:22 +08:00
3 changed files with 966 additions and 5 deletions

784
add-test-cases.patch Normal file
View File

@ -0,0 +1,784 @@
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 1/1] add test cases
The following test cases are added to test more interfaces of npth:
t-condlock.c test npth condlock interfaces
t-fork-enhance.c test npth fork interfaces
t-rwlock.c test npth rwlock interfaces
t-signal.c test npth signal interfaces
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 | 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
create mode 100644 tests/t-signal.c
create mode 100644 tests/t-socket.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8092a3c..f37e798 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,7 +18,7 @@
## Process this file with automake to produce Makefile.in
-TESTS = t-mutex t-thread
+TESTS = t-mutex t-thread t-condlock t-rwlock t-signal t-socket
# We explicitly require POSIX.1-2001 so that pthread_rwlock_t is
# available when build with c99.
@@ -31,6 +31,7 @@ AM_CPPFLAGS = -I../src -D_POSIX_C_SOURCE=200112L
AM_LDFLAGS =
LDADD = ../src/libnpth.la $(LIBSOCKET) $(LIB_CLOCK_GETTIME)
TESTS += t-fork
+TESTS += t-fork-enhance
endif
noinst_HEADERS = t-support.h
diff --git a/tests/t-condlock.c b/tests/t-condlock.c
new file mode 100644
index 0000000..ff7597b
--- /dev/null
+++ b/tests/t-condlock.c
@@ -0,0 +1,106 @@
+/* t-condlock.c
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "t-support.h"
+
+
+static int counter;
+static npth_mutex_t cond_mutex;
+static npth_cond_t cond = NPTH_COND_INITIALIZER;
+
+static void *
+thread_one (void *arg)
+{
+ int rc;
+ struct timespec tout;
+
+ rc = npth_mutex_lock (&cond_mutex);
+ fail_if_err (rc);
+ if (counter == 0)
+ npth_cond_wait(&cond, &cond_mutex);
+ counter--;
+ info_msg ("count dec");
+ clock_gettime(CLOCK_REALTIME, &tout);
+ tout.tv_sec += 1;
+ npth_cond_timedwait (&cond, &cond_mutex, &tout);
+ npth_mutex_unlock (&cond_mutex);
+ return (void*)4711;
+}
+
+static void *
+thread_two (void *arg)
+{
+ int rc;
+
+ rc = npth_mutex_lock (&cond_mutex);
+ fail_if_err (rc);
+ counter++;
+ info_msg ("count inc");
+ if (counter != 0)
+ npth_cond_signal(&cond);
+ npth_mutex_unlock (&cond_mutex);
+ return (void*)4722;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int rc;
+ npth_attr_t tattr;
+ int state;
+ npth_t tid1, tid2;
+ void *retval;
+
+ if (argc >= 2 && !strcmp (argv[1], "--verbose"))
+ opt_verbose = 1;
+
+ rc = npth_init ();
+ fail_if_err (rc);
+
+ rc = npth_mutex_init (&cond_mutex, NULL);
+ fail_if_err (rc);
+
+ rc = npth_attr_init (&tattr);
+ fail_if_err (rc);
+ rc = npth_attr_getdetachstate (&tattr, &state);
+ fail_if_err (rc);
+ if ( state != NPTH_CREATE_JOINABLE )
+ fail_msg ("new tattr is not joinable");
+
+ info_msg ("creating thread-one");
+ rc = npth_create (&tid1, &tattr, thread_one, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid1, "thread-one");
+
+ npth_usleep(100);
+
+ info_msg ("creating thread-two");
+ rc = npth_create (&tid2, &tattr, thread_two, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid2, "thread-two");
+
+ rc = npth_attr_destroy (&tattr);
+ fail_if_err (rc);
+
+ info_msg ("waiting for thread-one to terminate");
+ rc = npth_join (tid1, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4711)
+ fail_msg ("thread-one returned an unexpected value");
+
+ info_msg ("waiting for thread-two to terminate");
+ rc = npth_join (tid2, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4722)
+ fail_msg ("thread-two returned an unexpected value");
+
+ return 0;
+}
diff --git a/tests/t-fork-enhance.c b/tests/t-fork-enhance.c
new file mode 100644
index 0000000..0c0a957
--- /dev/null
+++ b/tests/t-fork-enhance.c
@@ -0,0 +1,68 @@
+/* t-fork-enhance.c
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "t-support.h"
+
+/* This is a test if nPth can allow daemon-like applications
+ initializing earlier.
+
+ For daemon-like applications, ideally, it is expected to call
+ npth_init after fork. This condition is not satisfied sometimes.
+
+ Failure of this test means nPth implementation doesn't allow
+ npth_init after fork. In such a case, application should be
+ modified.
+ */
+
+int
+main (int argc, const char *argv[])
+{
+ int rc;
+ pid_t pid;
+ struct timespec ts;
+
+ if (argc >= 2 && !strcmp (argv[1], "--verbose"))
+ opt_verbose = 1;
+
+ rc = npth_init ();
+ fail_if_err (rc);
+
+ rc = npth_system("pwd");
+ fail_if_err (rc);
+
+ npth_clock_gettime (&ts);
+
+ npth_unprotect ();
+ npth_protect ();
+ npth_is_protected ();
+
+ pid = fork ();
+ if (pid == (pid_t)-1)
+ fail_msg ("fork failed");
+ else if (pid)
+ {
+ int status;
+
+ info_msg ("forked");
+ npth_waitpid(pid, &status, 0);
+ fail_if_err (status);
+ }
+ else
+ {
+ info_msg ("child exit");
+ npth_usleep (1000); /* Let NPTH enter, sleep, and leave. */
+ }
+
+ return 0;
+}
diff --git a/tests/t-rwlock.c b/tests/t-rwlock.c
new file mode 100644
index 0000000..6b06e05
--- /dev/null
+++ b/tests/t-rwlock.c
@@ -0,0 +1,196 @@
+/* t-rwlock.c
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "t-support.h"
+
+#define BUFLEN 100
+
+static int counter;
+static npth_mutex_t counter_mutex;
+static int thread_twoone_ready;
+static npth_rwlock_t counter_rwlock;
+
+static void *
+thread_one (void *arg)
+{
+ int rc, i;
+ struct timespec tout;
+
+ clock_gettime(CLOCK_REALTIME, &tout);
+ tout.tv_sec += 1;
+ rc = npth_rwlock_timedrdlock (&counter_rwlock, &tout);
+ if (rc == 0)
+ npth_rwlock_unlock(&counter_rwlock);
+
+ clock_gettime(CLOCK_REALTIME, &tout);
+ tout.tv_sec += 1;
+ rc = npth_rwlock_timedwrlock (&counter_rwlock, &tout);
+ if (rc == 0)
+ npth_rwlock_unlock(&counter_rwlock);
+
+ info_msg ("thread-one started");
+ npth_usleep (10); /* Give the other thread some time to start. */
+ for (i=0; i < 10; i++)
+ {
+ /* We would not need the mutex here, but we use it to allow the
+ system to switch to another thread. */
+ rc = npth_mutex_lock (&counter_mutex);
+ fail_if_err (rc);
+
+ counter++;
+
+ rc = npth_mutex_unlock (&counter_mutex);
+ fail_if_err (rc);
+ }
+
+ info_msg ("thread-one terminated");
+
+ return (void*)4711;
+}
+
+
+static void *
+thread_twoone (void *arg)
+{
+ int rc, i;
+
+ npth_setname_np (npth_self (), "thread-twoone");
+ info_msg ("thread-twoone started");
+
+ rc = npth_detach (npth_self ());
+ fail_if_err (rc);
+
+ while (counter < 100)
+ {
+ npth_usleep (1000);
+ counter++;
+ }
+ info_msg ("thread-twoone terminated");
+ thread_twoone_ready = 1;
+
+ npth_exit (&rc);
+ return NULL;
+}
+
+
+static void *
+thread_two (void *arg)
+{
+ int rc, i;
+
+ info_msg ("thread-two started");
+
+ for (i=0; i < 10; i++)
+ {
+ rc = npth_mutex_lock (&counter_mutex);
+ fail_if_err (rc);
+
+ counter--;
+
+ if (i == 5)
+ {
+ npth_t tid;
+
+ info_msg ("creating thread-twoone");
+ rc = npth_create (&tid, NULL, thread_twoone, NULL);
+ fail_if_err (rc);
+ npth_usleep (10); /* Give new thread some time to start. */
+ }
+
+ rc = npth_mutex_unlock (&counter_mutex);
+ fail_if_err (rc);
+ }
+
+ info_msg ("busy waiting for thread twoone");
+ while (!thread_twoone_ready)
+ npth_sleep (0);
+
+ info_msg ("thread-two terminated");
+
+ return (void*)4722;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int rc;
+ npth_attr_t tattr;
+ int state;
+ npth_t tid1, tid2;
+ void *retval;
+ char bufname[BUFLEN];
+ struct timespec tout;
+
+ if (argc >= 2 && !strcmp (argv[1], "--verbose"))
+ opt_verbose = 1;
+
+ rc = npth_init ();
+ fail_if_err (rc);
+
+ rc = npth_mutex_init (&counter_mutex, NULL);
+ fail_if_err (rc);
+
+ clock_gettime(CLOCK_REALTIME, &tout);
+ tout.tv_sec += 1;
+ rc = npth_mutex_timedlock (&counter_mutex, &tout);
+ npth_mutex_unlock (&counter_mutex);
+
+ rc = npth_rwlock_init(&counter_rwlock, NULL);
+ fail_if_err (rc);
+
+ npth_rwlock_rdlock(&counter_rwlock);
+ npth_rwlock_unlock(&counter_rwlock);
+
+ npth_rwlock_wrlock(&counter_rwlock);
+ npth_rwlock_unlock(&counter_rwlock);
+
+ rc = npth_attr_init (&tattr);
+ fail_if_err (rc);
+ rc = npth_attr_getdetachstate (&tattr, &state);
+ fail_if_err (rc);
+ if ( state != NPTH_CREATE_JOINABLE )
+ fail_msg ("new tattr is not joinable");
+
+ info_msg ("creating thread-one");
+ rc = npth_create (&tid1, &tattr, thread_one, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid1, "thread-one");
+ npth_getname_np (tid1, bufname, BUFLEN);
+
+ npth_rwlock_wrlock(&counter_rwlock);
+ npth_sleep(5);
+ npth_rwlock_unlock(&counter_rwlock);
+
+ info_msg ("creating thread-two");
+ rc = npth_create (&tid2, &tattr, thread_two, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid2, "thread-two");
+
+ rc = npth_attr_destroy (&tattr);
+ fail_if_err (rc);
+
+ info_msg ("waiting for thread-one to terminate");
+ rc = npth_join (tid1, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4711)
+ fail_msg ("thread-one returned an unexpected value");
+
+ info_msg ("waiting for thread-two to terminate");
+ rc = npth_join (tid2, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4722)
+ fail_msg ("thread-two returned an unexpected value");
+
+ if (counter != 100)
+ fail_msg ("counter value not as expected");
+
+ return 0;
+}
diff --git a/tests/t-signal.c b/tests/t-signal.c
new file mode 100644
index 0000000..45c7c97
--- /dev/null
+++ b/tests/t-signal.c
@@ -0,0 +1,49 @@
+/* t-signal.c
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "t-support.h"
+
+/* This is a test if nPth can allow daemon-like applications
+ initializing earlier.
+
+ For daemon-like applications, ideally, it is expected to call
+ npth_init after fork. This condition is not satisfied sometimes.
+
+ Failure of this test means nPth implementation doesn't allow
+ npth_init after fork. In such a case, application should be
+ modified.
+ */
+
+int
+main (int argc, const char *argv[])
+{
+ int rc;
+ pid_t pid;
+ int r_signum;
+
+ if (argc >= 2 && !strcmp (argv[1], "--verbose"))
+ opt_verbose = 1;
+
+ rc = npth_init ();
+ fail_if_err (rc);
+
+ npth_sigev_init();
+ npth_sigev_add (5);
+ npth_sigev_add (7);
+ npth_sigev_fini ();
+ npth_sigev_sigmask ();
+ npth_sigev_get_pending (&r_signum);
+
+ return 0;
+}
diff --git a/tests/t-socket.c b/tests/t-socket.c
new file mode 100644
index 0000000..94ad0bb
--- /dev/null
+++ b/tests/t-socket.c
@@ -0,0 +1,284 @@
+/* t-socket.c
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "t-support.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+
+#define NAME "Socket"
+#define DATA "Hello, little Baby . . ."
+
+static int server1Ready;
+static int server2Ready;
+
+static void *
+thread_one (void *arg)
+{
+ int sock, msgsock, rval;
+ struct sockaddr_un server;
+ char buf[1024];
+ struct timeval tv;
+ struct timespec ts;
+
+ info_msg ("thread-one started");
+ tv.tv_sec = 0;
+ tv.tv_usec = 100;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000;
+
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ 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");
+ 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");
+ else do {
+ bzero(buf, sizeof(buf));
+ if ((rval = npth_read(msgsock, buf, 1024)) < 0)
+ perror("reading stream message");
+ else if (rval == 0)
+ printf("Ending connection\n");
+ else
+ printf("-->%s\n", buf);
+ } while (rval > 0);
+
+ npth_select(0, NULL, NULL, NULL, &tv);
+ npth_pselect(0, NULL, NULL, NULL, &ts, NULL);
+ close(msgsock);
+ close(sock);
+ unlink(NAME);
+ info_msg ("thread-one terminated");
+end:
+ return (void*)4711;
+}
+
+
+static void *
+thread_two (void *arg)
+{
+
+ int sock;
+ struct sockaddr_un server;
+ 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");
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
+
+ if (npth_connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
+ close(sock);
+ perror("connecting stream socket");
+ goto end;
+ }
+ if (npth_write(sock, DATA, sizeof(DATA)) < 0)
+ perror("writing on stream socket");
+ close(sock);
+
+ info_msg ("thread-two terminated");
+
+end:
+ return (void*)4722;
+}
+
+static void *
+thread_three (void *arg)
+{
+ int sock, msgsock, rval;
+ struct sockaddr_un server;
+ char buf[1024];
+ struct msghdr msg;
+ struct iovec io;
+
+ msg.msg_name = NULL;
+ io.iov_base = buf;
+ io.iov_len = 1024;
+ msg.msg_iov = &io;
+ msg.msg_iovlen = 1;
+
+ info_msg ("thread-three started");
+
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening stream socket");
+ 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");
+ 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");
+ else {
+ bzero(buf, sizeof(buf));
+ ssize_t recv_size = npth_recvmsg(msgsock, &msg, 0);
+ char * temp = msg.msg_iov[0].iov_base;
+ temp[recv_size] = '\0';
+ printf("get message:%s", temp);
+ };
+
+ close(msgsock);
+ close(sock);
+ unlink(NAME);
+ info_msg ("thread-three terminated");
+end:
+ return (void*)4711;
+}
+
+
+static void *
+thread_four (void *arg)
+{
+
+ int sock;
+ struct sockaddr_un server;
+ char buf[1024] = "test sendmsg and recvmsg\n";
+ struct msghdr msg;
+ struct iovec io;
+
+ msg.msg_name = NULL;
+ io.iov_base = buf;
+ io.iov_len = sizeof(buf);
+ msg.msg_iov = &io;
+ 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");
+ goto end;
+ }
+ server.sun_family = AF_UNIX;
+ strcpy(server.sun_path, NAME);
+
+ if (npth_connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
+ close(sock);
+ perror("connecting stream socket");
+ goto end;
+ }
+ npth_sendmsg(sock, &msg, 0);
+ close(sock);
+
+ info_msg ("thread-four terminated");
+end:
+ return (void*)4722;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int rc;
+ npth_attr_t tattr;
+ int state;
+ npth_t tid1, tid2;
+ npth_t tid3, tid4;
+ void *retval;
+
+ if (argc >= 2 && !strcmp (argv[1], "--verbose"))
+ opt_verbose = 1;
+
+ rc = npth_init ();
+ fail_if_err (rc);
+
+ rc = npth_attr_init (&tattr);
+ fail_if_err (rc);
+ rc = npth_attr_getdetachstate (&tattr, &state);
+ fail_if_err (rc);
+ if ( state != NPTH_CREATE_JOINABLE )
+ fail_msg ("new tattr is not joinable");
+
+ info_msg ("creating thread-one");
+ rc = npth_create (&tid1, &tattr, thread_one, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid1, "thread-one");
+
+ npth_usleep(100);
+
+ info_msg ("creating thread-two");
+ rc = npth_create (&tid2, &tattr, thread_two, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid2, "thread-two");
+
+ rc = npth_attr_destroy (&tattr);
+ fail_if_err (rc);
+
+ info_msg ("waiting for thread-one to terminate");
+ rc = npth_join (tid1, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4711)
+ fail_msg ("thread-one returned an unexpected value");
+
+ info_msg ("waiting for thread-two to terminate");
+ rc = npth_join (tid2, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4722)
+ fail_msg ("thread-two returned an unexpected value");
+
+ info_msg ("creating thread-three");
+ rc = npth_create (&tid3, NULL, thread_three, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid3, "thread-three");
+
+ npth_usleep(100);
+
+ info_msg ("creating thread-four");
+ rc = npth_create (&tid4, NULL, thread_four, NULL);
+ fail_if_err (rc);
+ npth_setname_np (tid4, "thread-two");
+
+ info_msg ("waiting for thread-three to terminate");
+ rc = npth_join (tid3, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4711)
+ fail_msg ("thread-three returned an unexpected value");
+
+ info_msg ("waiting for thread-four to terminate");
+ rc = npth_join (tid4, &retval);
+ fail_if_err (rc);
+ if (retval != (void*)4722)
+ fail_msg ("thread-four returned an unexpected value");
+
+ return 0;
+}
--
2.27.0

View File

@ -0,0 +1,157 @@
From b5ecd8d2c6fdb988f6139c5157c124ebea293bd7 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Wed, 22 Dec 2021 09:52:44 +0900
Subject: [PATCH 1/2] posix: Add npth_poll/npth_ppoll.
* configure.ac: Add checks for poll.h and ppoll.
--
GnuPG-bug-id: 5748
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Signed-off-by: EulerOSWander <314264452@qq.com>
---
configure.ac | 6 ++---
src/npth.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/npth.h.in | 5 +++++
3 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3d76661..cf8bb0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@
# Process this file with autoconf to produce a configure script.
-AC_PREREQ([2.67])
+AC_PREREQ([2.69])
min_automake_version="1.14"
# To build a release you need to create a tag with the version number
@@ -198,7 +198,7 @@ AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
#
# fixme: For what do we need the sys/socket test?
AC_CHECK_HEADERS([sys/socket.h sys/select.h unistd.h sys/time.h time.h \
- signal.h])
+ signal.h poll.h])
INSERT_SYS_SELECT_H=
if test x"$ac_cv_header_sys_select_h" = xyes; then
INSERT_SYS_SELECT_H="include <sys/select.h>"
@@ -277,7 +277,7 @@ if test "$have_w32_system" = no; then
fi
fi
-AC_CHECK_FUNCS([select pselect gettimeofday])
+AC_CHECK_FUNCS([select pselect gettimeofday ppoll])
npth_LIBSOCKET
config_libs="$config_libs $LIBSOCKET"
diff --git a/src/npth.c b/src/npth.c
index 45ca7ee..22314a6 100644
--- a/src/npth.c
+++ b/src/npth.c
@@ -71,6 +71,9 @@ sem_wait (sem_t *sem)
#ifndef HAVE_PSELECT
# include <signal.h>
#endif
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
#include "npth.h"
@@ -675,6 +678,73 @@ npth_pselect(int nfd, fd_set *rfds, fd_set *wfds, fd_set *efds,
}
+int
+npth_poll (struct pollfd *fds, unsigned long nfds, int timeout)
+{
+ int res;
+
+ ENTER();
+#ifdef HAVE_POLL_H
+ res = poll (fds, (nfds_t)nfds, timeout);
+#endif
+ LEAVE();
+ return res;
+}
+
+
+int
+npth_ppoll (struct pollfd *fds, unsigned long nfds,
+ const struct timespec *timeout, const sigset_t *sigmask)
+{
+ int res;
+
+ ENTER();
+#ifdef HAVE_POLL_H
+#ifdef HAVE_PPOLL
+ res = ppoll (fds, (nfds_t)nfds, timeout, sigmask);
+#else /*!HAVE_PPOLL*/
+ {
+# ifdef __GNUC__
+# warning Using a non race free ppoll emulation.
+# endif
+
+ int t;
+
+ if (!timeout)
+ t = -1;
+ else if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000)
+ t = timeout->tv_sec * 1000 + (timeout->tv_nsec + 999999) / 1000000;
+ else
+ {
+ errno = EINVAL;
+ res = -1;
+ goto leave;
+ }
+
+ if (sigmask)
+ {
+ int save_errno;
+ sigset_t savemask;
+
+ pthread_sigmask (SIG_SETMASK, sigmask, &savemask);
+ res = poll (fds, (nfds_t)nfds, timeout);
+ save_errno = errno;
+ pthread_sigmask (SIG_SETMASK, &savemask, NULL);
+ errno = save_errno;
+ }
+ else
+ res = poll (fds, (nfds_t)nfds, timeout);
+
+ leave:
+ ;
+ }
+#endif
+#endif
+ LEAVE();
+ return res;
+}
+
+
ssize_t
npth_read(int fd, void *buf, size_t nbytes)
{
diff --git a/src/npth.h.in b/src/npth.h.in
index 39dcf32..db57935 100644
--- a/src/npth.h.in
+++ b/src/npth.h.in
@@ -345,6 +345,11 @@ ssize_t npth_write(int fd, const void *buf, size_t nbytes);
int npth_recvmsg (int fd, struct msghdr *msg, int flags);
int npth_sendmsg (int fd, const struct msghdr *msg, int flags);
+struct pollfd;
+int npth_poll (struct pollfd *fds, unsigned long nfds, int timeout);
+int npth_ppoll (struct pollfd *fds, unsigned long nfds,
+ const struct timespec *timeout, const sigset_t *sigmask);
+
/* For anything not covered here, you can enter/leave manually at your
own risk. */
void npth_unprotect (void);
--
1.8.3.1

View File

@ -1,12 +1,16 @@
Name: npth
Version: 1.6
Release: 2
Release: 7
Summary: The New GNU Portable Threads library
License: LGPLv2+
URL: http://git.gnupg.org/cgi-bin/gitweb.cgi?p=npth.git
Source: https://gnupg.org/ftp/gcrypt/npth/%{name}-%{version}.tar.bz2
BuildRequires: make gcc git
Patch6000: backport-0001-w32-Use-cast-by-uintptr_t-for-thread-ID.patch
Patch6001: add-test-cases.patch
Patch6002: backport-0002-posix-Add-npth_poll-npth_ppoll.patch
BuildRequires: make gcc automake
%description
The NPth package contains a very portable POSIX/ANSI-C based
@ -19,8 +23,6 @@ stack, signal mask and errno variable.
%package devel
Summary: Development files for %{name}
Patch6000: backport-0001-w32-Use-cast-by-uintptr_t-for-thread-ID.patch
Requires: %{name}%{?_isa} = %{version}-%{release}
%description devel
@ -28,7 +30,10 @@ This package contains libraries and header files for
developing applications that use %{name}.
%prep
%autosetup -n %{name}-%{version} -p1 -Sgit
%autosetup -n %{name}-%{version} -p1
aclocal
automake
%build
%configure --disable-static
@ -57,6 +62,21 @@ make check
%{_datadir}/aclocal/%{name}.m4
%changelog
* Sat Jan 28 2023 licihua<licihua@huawei.com> - 1.6-7
- DESC: modify the patchs location
* 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
* Tue Mar 1 2022 yaowenbinHW <yaowenbin@huawei.com> - 1.6-4
- DESC: add test cases
* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 1.6-3
- DESC: delete -Sgit from %autosetup, and delete BuildRequires git
* Mon Sep 28 2020 EulerOSWander <314264452@qq.com> - 1.6-2
- Use cast by uintptr_t for thread ID.