6 Star 0 Fork 9

src-openEuler/npth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
add-test-cases.patch 19.37 KB
一键复制 编辑 原始数据 按行查看 历史
yaowenbin 提交于 2022-09-24 15:18 . fix t-socket test case fail
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/npth.git
git@gitee.com:src-openeuler/npth.git
src-openeuler
npth
npth
master

搜索帮助