diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-25 19:35:52 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-29 16:05:23 -0700 |
| commit | 33dc5d611f578ace9833a80dc006a34b09da18af (patch) | |
| tree | 2351fd7d197530493dbd27034ae9e1546c2e299c /tests/platform.c | |
| parent | fe5336ec1f9f27045f2c27ac253285c8447aa653 (diff) | |
| download | nng-33dc5d611f578ace9833a80dc006a34b09da18af.tar.gz nng-33dc5d611f578ace9833a80dc006a34b09da18af.tar.bz2 nng-33dc5d611f578ace9833a80dc006a34b09da18af.zip | |
fixes #484 crashes in websocket transport
fixes #490 posix_epdesc use-after-free bug
fixes #489 Sanitizer based testing would help
fixes #492 Numerous memory leaks found with sanitizer
This introduces support for compiler-based sanitizers when using
clang or gcc (and not on Windows). See NNG_SANITIZER for possible
settings such as "thread" or "address".
Furthermore, we have fixed the issues we found with both the
thread and address sanitizers. We believe that the thread issues
pointed to a low frequency use-after-free responsible for rare
crashes in some of the tests.
The tests generally have their timeouts doubled when running under
a sanitizer, to account for the extra long times that the sanitizer
can cause these to take.
While here, we also changed the compat_ws test to avoid a particularly
painful and time consuming DNS lookup, and we made the nngcat_unlimited
test a bit more robust by waiting before sending traffic.
Diffstat (limited to 'tests/platform.c')
| -rw-r--r-- | tests/platform.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/tests/platform.c b/tests/platform.c index 168f7879..51dc41fc 100644 --- a/tests/platform.c +++ b/tests/platform.c @@ -15,35 +15,24 @@ #include "stubs.h" -// Add is for testing threads. -void -add(void *arg) -{ - *(int *) arg += 1; -} - -// Notify tests for verifying condvars. -struct notifyarg { - int did; - nng_duration when; - nng_mtx * mx; - nng_cv * cv; +struct addarg { + int cnt; + nng_mtx *mx; + nng_cv * cv; }; void -notifyafter(void *arg) +add(void *arg) { - struct notifyarg *na = arg; + struct addarg *aa = arg; - nng_msleep(na->when); - nng_mtx_lock(na->mx); - na->did = 1; - nng_cv_wake(na->cv); - nng_mtx_unlock(na->mx); + nng_mtx_lock(aa->mx); + aa->cnt++; + nng_cv_wake(aa->cv); + nng_mtx_unlock(aa->mx); } TestMain("Platform Operations", { - // This is required for anything else to work Convey("The clock works", { uint64_t now = getms(); @@ -79,35 +68,46 @@ TestMain("Platform Operations", { So(nng_mtx_alloc(&mx) == 0); Reset({ nng_mtx_free(mx); }); - Convey("We can lock a mutex", { + Convey("We can lock and unlock mutex", { nng_mtx_lock(mx); So(1); - Convey("And we can unlock it", { + nng_mtx_unlock(mx); + So(1); + Convey("And then lock it again", { + nng_mtx_lock(mx); + So(1); nng_mtx_unlock(mx); So(1); - Convey("And then lock it again", { - nng_mtx_lock(mx); - So(1); - nng_mtx_unlock(mx); - So(1); - }); }); }); }); Convey("Threads work", { static nng_thread *thr; - int val = 0; int rv; + struct addarg aa; + + So(nng_mtx_alloc(&aa.mx) == 0); + So(nng_cv_alloc(&aa.cv, aa.mx) == 0); + Reset({ + nng_mtx_free(aa.mx); + nng_cv_free(aa.cv); + }); + aa.cnt = 0; Convey("We can create threads", { - rv = nng_thread_create(&thr, add, &val); + rv = nng_thread_create(&thr, add, &aa); So(rv == 0); Reset({ nng_thread_destroy(thr); }); Convey("It ran", { - nng_msleep(50); // for context switch + int val; + nng_mtx_lock(aa.mx); + while ((val = aa.cnt) == 0) { + nng_cv_wait(aa.cv); + } + nng_mtx_unlock(aa.mx); So(val == 1); }); }); |
