aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-02-20 19:41:55 -0800
committerGarrett D'Amore <garrett@damore.org>2018-02-20 19:41:55 -0800
commitfd871e6ce9de54f81f00918d4c7e3f3f4336b6d3 (patch)
treef7758c6430a696f797763d21d5a3d53ea950b561 /tests
parent03b9fab6cbf8374aca5f5daa2b5b030bcc4cbb85 (diff)
downloadnng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.tar.gz
nng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.tar.bz2
nng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.zip
Introduce 'porting layer' Public API.
This introduces portable primitives for time, random numbers, synchronization primitives, and threading. These are somewhat primitive (least common denominiators), but they can help with writing portable applications, especially our own demo apps.
Diffstat (limited to 'tests')
-rw-r--r--tests/device.c7
-rw-r--r--tests/multistress.c7
-rw-r--r--tests/pipeline.c5
-rw-r--r--tests/platform.c102
-rw-r--r--tests/pollfd.c5
-rw-r--r--tests/pubsub.c5
-rw-r--r--tests/reconnect.c7
-rw-r--r--tests/scalability.c3
-rw-r--r--tests/sock.c7
-rw-r--r--tests/synch.c195
-rw-r--r--tests/trantest.h3
11 files changed, 151 insertions, 195 deletions
diff --git a/tests/device.c b/tests/device.c
index 56ad2cb5..535371e6 100644
--- a/tests/device.c
+++ b/tests/device.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -11,6 +11,7 @@
#include "convey.h"
#include "nng.h"
#include "protocol/pair1/pair.h"
+#include "supplemental/util/platform.h"
#include "stubs.h"
#include <string.h>
@@ -48,7 +49,7 @@ Main({
nng_socket end2;
nng_duration tmo;
nng_msg * msg;
- void * thr;
+ nng_thread * thr;
So(nng_pair1_open(&dev1) == 0);
So(nng_pair1_open(&dev2) == 0);
diff --git a/tests/multistress.c b/tests/multistress.c
index 6a41a551..556718fa 100644
--- a/tests/multistress.c
+++ b/tests/multistress.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -22,6 +22,7 @@
#include "protocol/reqrep0/req.h"
#include "protocol/survey0/respond.h"
#include "protocol/survey0/survey.h"
+#include "supplemental/util/platform.h"
#include "transport/inproc/inproc.h"
#include "transport/ipc/ipc.h"
#include "transport/tcp/tcp.h"
@@ -69,7 +70,7 @@ int allocaddrs;
typedef struct test_case {
nng_socket socket;
const char *name;
- void * thr;
+ nng_thread *thr;
int nrecv;
int nsend;
int nfail;
diff --git a/tests/pipeline.c b/tests/pipeline.c
index 96ae3d17..2b61d99a 100644
--- a/tests/pipeline.c
+++ b/tests/pipeline.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -13,6 +13,7 @@
#include "protocol/pipeline0/pull.h"
#include "protocol/pipeline0/push.h"
#include "stubs.h"
+#include "supplemental/util/platform.h"
#include <string.h>
diff --git a/tests/platform.c b/tests/platform.c
index 10278e7d..168f7879 100644
--- a/tests/platform.c
+++ b/tests/platform.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -9,8 +9,10 @@
//
#include "convey.h"
-#include "core/nng_impl.h"
+
#include "nng.h"
+#include "supplemental/util/platform.h"
+
#include "stubs.h"
// Add is for testing threads.
@@ -24,8 +26,8 @@ add(void *arg)
struct notifyarg {
int did;
nng_duration when;
- nni_mtx mx;
- nni_cv cv;
+ nng_mtx * mx;
+ nng_cv * cv;
};
void
@@ -34,16 +36,14 @@ notifyafter(void *arg)
struct notifyarg *na = arg;
nng_msleep(na->when);
- nni_mtx_lock(&na->mx);
+ nng_mtx_lock(na->mx);
na->did = 1;
- nni_cv_wake(&na->cv);
- nni_mtx_unlock(&na->mx);
+ nng_cv_wake(na->cv);
+ nng_mtx_unlock(na->mx);
}
TestMain("Platform Operations", {
- nni_init();
-
// This is required for anything else to work
Convey("The clock works", {
uint64_t now = getms();
@@ -58,10 +58,10 @@ TestMain("Platform Operations", {
uint64_t msend;
int usdelta;
int msdelta;
- nni_time usend;
- nni_time usnow = nni_clock();
+ nng_time usend;
+ nng_time usnow = nng_clock();
nng_msleep(200);
- usend = nni_clock();
+ usend = nng_clock();
msend = getms();
So(usend > usnow);
@@ -74,38 +74,37 @@ TestMain("Platform Operations", {
});
});
Convey("Mutexes work", {
- static nni_mtx mx;
+ static nng_mtx *mx;
- nni_mtx_init(&mx);
+ So(nng_mtx_alloc(&mx) == 0);
+ Reset({ nng_mtx_free(mx); });
Convey("We can lock a mutex", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
Convey("And we can unlock it", {
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
Convey("And then lock it again", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
});
});
});
- Convey("We can finalize it", { nni_mtx_fini(&mx); });
});
Convey("Threads work", {
- static nni_thr thr;
- int val = 0;
- int rv;
+ static nng_thread *thr;
+ int val = 0;
+ int rv;
Convey("We can create threads", {
- rv = nni_thr_init(&thr, add, &val);
+ rv = nng_thread_create(&thr, add, &val);
So(rv == 0);
- nni_thr_run(&thr);
- Reset({ nni_thr_fini(&thr); });
+ Reset({ nng_thread_destroy(thr); });
Convey("It ran", {
nng_msleep(50); // for context switch
@@ -113,55 +112,4 @@ TestMain("Platform Operations", {
});
});
});
- Convey("Condition variables work", {
- static struct notifyarg arg;
- static nni_thr thr;
-
- nni_mtx_init(&arg.mx);
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
-
- Reset({
- nni_cv_fini(&arg.cv);
- nni_mtx_fini(&arg.mx);
- nni_thr_fini(&thr);
- });
-
- Convey("Notification works", {
- arg.did = 0;
- arg.when = 10;
- nni_thr_run(&thr);
-
- nni_mtx_lock(&arg.mx);
- if (!arg.did) {
- nni_cv_wait(&arg.cv);
- }
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
- So(arg.did == 1);
- });
-
- Convey("Timeout works", {
- arg.did = 0;
- arg.when = 200;
- nni_thr_run(&thr);
- nni_mtx_lock(&arg.mx);
- if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
- }
- So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
- });
- Convey("Not running works", {
- arg.did = 0;
- arg.when = 1;
- nni_mtx_lock(&arg.mx);
- if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
- }
- So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
- });
- });
})
diff --git a/tests/pollfd.c b/tests/pollfd.c
index 8526c705..7a87fe9b 100644
--- a/tests/pollfd.c
+++ b/tests/pollfd.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -35,6 +35,7 @@
#include "protocol/pipeline0/pull.h"
#include "protocol/pipeline0/push.h"
#include "stubs.h"
+#include "supplemental/util/platform.h"
TestMain("Poll FDs", {
diff --git a/tests/pubsub.c b/tests/pubsub.c
index 796d951e..3fd95b42 100644
--- a/tests/pubsub.c
+++ b/tests/pubsub.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -13,6 +13,7 @@
#include "protocol/pubsub0/pub.h"
#include "protocol/pubsub0/sub.h"
#include "stubs.h"
+#include "supplemental/util/platform.h"
#include <string.h>
diff --git a/tests/reconnect.c b/tests/reconnect.c
index e191f70a..6e7ab79f 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -12,8 +12,9 @@
#include "nng.h"
#include "protocol/pipeline0/pull.h"
#include "protocol/pipeline0/push.h"
-#include "stubs.h"
+#include "supplemental/util/platform.h"
+#include "stubs.h"
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
diff --git a/tests/scalability.c b/tests/scalability.c
index 9695c53c..84395f9d 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -13,6 +13,7 @@
#include "protocol/reqrep0/rep.h"
#include "protocol/reqrep0/req.h"
+#include "supplemental/util/platform.h"
#include "stubs.h"
#include <string.h>
@@ -21,7 +22,7 @@ static int nclients = 200;
static char *addr = "inproc:///atscale";
nng_socket rep;
-void * server;
+nng_thread *server;
void
serve(void *arg)
diff --git a/tests/sock.c b/tests/sock.c
index 404e160b..1f7567f8 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -15,6 +15,9 @@
#include "protocol/pubsub0/sub.h"
#include "protocol/pair1/pair.h"
+
+#include "supplemental/util/platform.h"
+
#include "stubs.h"
#include <string.h>
diff --git a/tests/synch.c b/tests/synch.c
index c9de3deb..de0d7e16 100644
--- a/tests/synch.c
+++ b/tests/synch.c
@@ -9,15 +9,16 @@
//
#include "convey.h"
-#include "core/nng_impl.h"
+//#include "core/nng_impl.h"
#include "nng.h"
+#include "supplemental/util/platform.h"
// Notify tests for verifying condvars.
struct notifyarg {
int did;
nng_duration when;
- nni_mtx mx;
- nni_cv cv;
+ nng_mtx * mx;
+ nng_cv * cv;
};
#ifdef NNG_PLATFORM_POSIX
@@ -31,118 +32,116 @@ notifyafter(void *arg)
{
struct notifyarg *na = arg;
- nni_msleep(na->when);
- nni_mtx_lock(&na->mx);
+ nng_msleep(na->when);
+ nng_mtx_lock(na->mx);
na->did = 1;
- nni_cv_wake(&na->cv);
- nni_mtx_unlock(&na->mx);
+ nng_cv_wake(na->cv);
+ nng_mtx_unlock(na->mx);
}
struct notifyarg arg;
-nni_thr thr;
+nng_thread * thr;
static void
test_sync(void)
{
Convey("Mutexes work", {
- nni_mtx mx;
+ nng_mtx *mx;
- nni_mtx_init(&mx);
+ So(nng_mtx_alloc(&mx) == 0);
+ Reset({ nng_mtx_free(mx); });
Convey("We can lock a mutex", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
Convey("And we can unlock it", {
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
Convey("And then lock it again", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
});
});
Convey("Things block properly", {
- nni_mtx_init(&arg.mx);
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
+ So(nng_mtx_alloc(&arg.mx) == 0);
+ So(nng_cv_alloc(&arg.cv, arg.mx) == 0);
arg.did = 0;
arg.when = 0;
- nni_mtx_lock(&arg.mx);
- nni_thr_run(&thr);
+ nng_mtx_lock(arg.mx);
+ So(nng_thread_create(
+ &thr, notifyafter, &arg) == 0);
nng_msleep(10);
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_unlock(arg.mx);
nng_msleep(10);
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
while (!arg.did) {
- nni_cv_wait(&arg.cv);
+ nng_cv_wait(arg.cv);
}
So(arg.did != 0);
- nni_mtx_unlock(&arg.mx);
- nni_thr_fini(&thr);
- nni_cv_fini(&arg.cv);
- nni_mtx_fini(&arg.mx);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
+ nng_cv_free(arg.cv);
+ nng_mtx_free(arg.mx);
})
});
- Convey("We can finalize it", { nni_mtx_fini(&mx); });
});
Convey("Condition variables work", {
- nni_mtx_init(&arg.mx);
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
+ So(nng_mtx_alloc(&arg.mx) == 0);
+ So(nng_cv_alloc(&arg.cv, arg.mx) == 0);
Reset({
- nni_cv_fini(&arg.cv);
- nni_mtx_fini(&arg.mx);
- nni_thr_fini(&thr);
+ nng_cv_free(arg.cv);
+ nng_mtx_free(arg.mx);
});
Convey("Notification works", {
arg.did = 0;
arg.when = 10;
- nni_thr_run(&thr);
+ So(nng_thread_create(&thr, notifyafter, &arg) == 0);
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_wait(&arg.cv);
+ nng_cv_wait(arg.cv);
}
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
So(arg.did == 1);
});
Convey("Timeout works", {
arg.did = 0;
arg.when = 200;
- nni_thr_run(&thr);
- nni_mtx_lock(&arg.mx);
+ So(nng_thread_create(&thr, notifyafter, &arg) == 0);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
+ nng_cv_until(arg.cv, nng_clock() + 10);
}
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
});
Convey("Empty timeout is EAGAIN", {
- nni_mtx_lock(&arg.mx);
- So(nni_cv_until(&arg.cv, 0) == NNG_EAGAIN);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_lock(arg.mx);
+ So(nng_cv_until(arg.cv, 0) == NNG_EAGAIN);
+ nng_mtx_unlock(arg.mx);
});
Convey("Not running works", {
arg.did = 0;
arg.when = 1;
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
+ nng_cv_until(arg.cv, nng_clock() + 10);
}
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_unlock(arg.mx);
});
});
}
@@ -157,104 +156,102 @@ test_sync_fallback(void)
{
nni_plat_sync_fallback = 1;
Convey("Mutexes work", {
- nni_mtx mx;
+ nng_mtx *mx;
- nni_mtx_init(&mx);
+ So(nng_mtx_alloc(&mx) == 0);
+ Reset({ nng_mtx_free(mx); });
Convey("We can lock a mutex", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
Convey("And we can unlock it", {
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
Convey("And then lock it again", {
- nni_mtx_lock(&mx);
+ nng_mtx_lock(mx);
So(1);
- nni_mtx_unlock(&mx);
+ nng_mtx_unlock(mx);
So(1);
});
});
Convey("Things block properly", {
- nni_mtx_init(&arg.mx);
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
+ So(nng_mtx_alloc(&arg.mx) == 0);
+ So(nng_cv_alloc(&arg.cv, arg.mx) == 0);
arg.did = 0;
arg.when = 0;
- nni_mtx_lock(&arg.mx);
- nni_thr_run(&thr);
+ nng_mtx_lock(arg.mx);
+ So(nng_thread_create(
+ &thr, notifyafter, &arg) == 0);
nng_msleep(10);
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_unlock(arg.mx);
nng_msleep(10);
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
while (!arg.did) {
- nni_cv_wait(&arg.cv);
+ nng_cv_wait(arg.cv);
}
So(arg.did != 0);
- nni_mtx_unlock(&arg.mx);
- nni_thr_fini(&thr);
- nni_cv_fini(&arg.cv);
- nni_mtx_fini(&arg.mx);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
+ nng_cv_free(arg.cv);
+ nng_mtx_free(arg.mx);
})
});
- Convey("We can finalize it", { nni_mtx_fini(&mx); });
});
Convey("Condition variables work", {
- nni_mtx_init(&arg.mx);
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
+ So(nng_mtx_alloc(&arg.mx) == 0);
+ So(nng_cv_alloc(&arg.cv, arg.mx) == 0);
Reset({
- nni_cv_fini(&arg.cv);
- nni_mtx_fini(&arg.mx);
- nni_thr_fini(&thr);
+ nng_cv_free(arg.cv);
+ nng_mtx_free(arg.mx);
});
Convey("Notification works", {
arg.did = 0;
arg.when = 10;
- nni_thr_run(&thr);
+ So(nng_thread_create(&thr, notifyafter, &arg) == 0);
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_wait(&arg.cv);
+ nng_cv_wait(arg.cv);
}
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
So(arg.did == 1);
});
Convey("Timeout works", {
arg.did = 0;
arg.when = 200;
- nni_thr_run(&thr);
- nni_mtx_lock(&arg.mx);
+ So(nng_thread_create(&thr, notifyafter, &arg) == 0);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
+ nng_cv_until(arg.cv, nng_clock() + 10);
}
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
});
Convey("Empty timeout is EAGAIN", {
- nni_mtx_lock(&arg.mx);
- So(nni_cv_until(&arg.cv, 0) == NNG_EAGAIN);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_lock(arg.mx);
+ So(nng_cv_until(arg.cv, 0) == NNG_EAGAIN);
+ nng_mtx_unlock(arg.mx);
});
Convey("Not running works", {
arg.did = 0;
arg.when = 1;
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_until(&arg.cv, nni_clock() + 10);
+ nng_cv_until(arg.cv, nng_clock() + 10);
}
So(arg.did == 0);
- nni_mtx_unlock(&arg.mx);
+ nng_mtx_unlock(arg.mx);
});
});
}
@@ -263,7 +260,6 @@ test_sync_fallback(void)
#endif
TestMain("Synchronization", {
- nni_init();
Convey("Synchronization works", { test_sync(); });
@@ -271,21 +267,22 @@ TestMain("Synchronization", {
ConveyFB("Transform works", {
nni_plat_sync_fallback = 0;
- nni_mtx_init(&arg.mx);
+ So(nng_mtx_alloc(&arg.mx) == 0);
nni_plat_sync_fallback = 1;
- nni_cv_init(&arg.cv, &arg.mx);
- So(nni_thr_init(&thr, notifyafter, &arg) == 0);
+ So(nng_cv_alloc(&arg.cv, arg.mx) == 0);
arg.did = 0;
arg.when = 10;
- nni_thr_run(&thr);
+ So(nng_thread_create(&thr, notifyafter, &arg) == 0);
- nni_mtx_lock(&arg.mx);
+ nng_mtx_lock(arg.mx);
if (!arg.did) {
- nni_cv_wait(&arg.cv);
+ nng_cv_wait(arg.cv);
}
- nni_mtx_unlock(&arg.mx);
- nni_thr_wait(&thr);
+ nng_mtx_unlock(arg.mx);
+ nng_thread_destroy(thr);
So(arg.did == 1);
+ nng_cv_free(arg.cv);
+ nng_mtx_free(arg.mx);
});
})
diff --git a/tests/trantest.h b/tests/trantest.h
index 13445eaf..feb34be8 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -1,6 +1,6 @@
//
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -13,6 +13,7 @@
#include "nng.h"
#include "protocol/reqrep0/rep.h"
#include "protocol/reqrep0/req.h"
+#include "supplemental/util/platform.h"
#include <stdlib.h>
#include <string.h>