diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2019-06-22 15:18:17 +0200 |
---|---|---|
committer | Saúl Ibarra Corretgé <s@saghul.net> | 2019-09-18 08:09:14 +0200 |
commit | 4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6 (patch) | |
tree | ce6b8b3282f3ac65d6bbeba5cec36463b68f06e5 /test/test-threadpool-cancel.c | |
parent | fd1502f5630591bf8ce79502df9b5d76868dfd3b (diff) | |
download | libuv-4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6.tar.gz libuv-4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6.zip |
unix,win: add uv_random()
Add an API for obtaining cryptographically strong random data from the
system PRNG.
Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
Refs: https://github.com/libuv/libuv/pull/1055
PR-URL: https://github.com/libuv/libuv/pull/2347
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Diffstat (limited to 'test/test-threadpool-cancel.c')
-rw-r--r-- | test/test-threadpool-cancel.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test-threadpool-cancel.c b/test/test-threadpool-cancel.c index dd13d8ae..be252c6f 100644 --- a/test/test-threadpool-cancel.c +++ b/test/test-threadpool-cancel.c @@ -37,6 +37,11 @@ struct cancel_info { uv_timer_t timer_handle; }; +struct random_info { + uv_random_t random_req; + char buf[1]; +}; + static unsigned fs_cb_called; static unsigned done_cb_called; static unsigned done2_cb_called; @@ -143,6 +148,19 @@ static void nop_done_cb(uv_work_t* req, int status) { } +static void nop_random_cb(uv_random_t* req, int status, void* buf, size_t len) { + struct random_info* ri; + + ri = container_of(req, struct random_info, random_req); + + ASSERT(status == UV_ECANCELED); + ASSERT(buf == (void*) ri->buf); + ASSERT(len == sizeof(ri->buf)); + + done_cb_called++; +} + + TEST_IMPL(threadpool_cancel_getaddrinfo) { uv_getaddrinfo_t reqs[4]; struct cancel_info ci; @@ -212,6 +230,29 @@ TEST_IMPL(threadpool_cancel_getnameinfo) { } +TEST_IMPL(threadpool_cancel_random) { + struct random_info req; + uv_loop_t* loop; + + saturate_threadpool(); + loop = uv_default_loop(); + ASSERT(0 == uv_random(loop, + &req.random_req, + &req.buf, + sizeof(req.buf), + 0, + nop_random_cb)); + ASSERT(0 == uv_cancel((uv_req_t*) &req)); + ASSERT(0 == done_cb_called); + unblock_threadpool(); + ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); + ASSERT(1 == done_cb_called); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + + TEST_IMPL(threadpool_cancel_work) { struct cancel_info ci; uv_work_t reqs[16]; |