xref: /netbsd-src/external/mit/libuv/dist/test/test-ref.c (revision 5f2f42719cd62ff11fd913b40b7ce19f07c4fd25)
10e552da7Schristos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
20e552da7Schristos  *
30e552da7Schristos  * Permission is hereby granted, free of charge, to any person obtaining a copy
40e552da7Schristos  * of this software and associated documentation files (the "Software"), to
50e552da7Schristos  * deal in the Software without restriction, including without limitation the
60e552da7Schristos  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70e552da7Schristos  * sell copies of the Software, and to permit persons to whom the Software is
80e552da7Schristos  * furnished to do so, subject to the following conditions:
90e552da7Schristos  *
100e552da7Schristos  * The above copyright notice and this permission notice shall be included in
110e552da7Schristos  * all copies or substantial portions of the Software.
120e552da7Schristos  *
130e552da7Schristos  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140e552da7Schristos  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150e552da7Schristos  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160e552da7Schristos  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
170e552da7Schristos  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
180e552da7Schristos  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
190e552da7Schristos  * IN THE SOFTWARE.
200e552da7Schristos  */
210e552da7Schristos 
220e552da7Schristos #include "uv.h"
230e552da7Schristos #include "task.h"
240e552da7Schristos 
250e552da7Schristos #include <stdlib.h>
260e552da7Schristos #include <string.h>
270e552da7Schristos 
280e552da7Schristos 
290e552da7Schristos static uv_write_t write_req;
300e552da7Schristos static uv_shutdown_t shutdown_req;
310e552da7Schristos static uv_connect_t connect_req;
320e552da7Schristos 
330e552da7Schristos static char buffer[32767];
340e552da7Schristos 
350e552da7Schristos static int req_cb_called;
360e552da7Schristos static int connect_cb_called;
370e552da7Schristos static int write_cb_called;
380e552da7Schristos static int shutdown_cb_called;
390e552da7Schristos static int close_cb_called;
400e552da7Schristos 
410e552da7Schristos 
close_cb(uv_handle_t * handle)420e552da7Schristos static void close_cb(uv_handle_t* handle) {
430e552da7Schristos   close_cb_called++;
440e552da7Schristos }
450e552da7Schristos 
460e552da7Schristos 
do_close(void * handle)470e552da7Schristos static void do_close(void* handle) {
480e552da7Schristos   close_cb_called = 0;
490e552da7Schristos   uv_close((uv_handle_t*)handle, close_cb);
500e552da7Schristos   ASSERT(close_cb_called == 0);
510e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
520e552da7Schristos   ASSERT(close_cb_called == 1);
530e552da7Schristos }
540e552da7Schristos 
550e552da7Schristos 
fail_cb(void)560e552da7Schristos static void fail_cb(void) {
570e552da7Schristos   FATAL("fail_cb should not have been called");
580e552da7Schristos }
590e552da7Schristos 
600e552da7Schristos 
fail_cb2(void)610e552da7Schristos static void fail_cb2(void) {
620e552da7Schristos   ASSERT(0 && "fail_cb2 should not have been called");
630e552da7Schristos }
640e552da7Schristos 
650e552da7Schristos 
req_cb(uv_handle_t * req,int status)660e552da7Schristos static void req_cb(uv_handle_t* req, int status) {
670e552da7Schristos   req_cb_called++;
680e552da7Schristos }
690e552da7Schristos 
700e552da7Schristos 
shutdown_cb(uv_shutdown_t * req,int status)710e552da7Schristos static void shutdown_cb(uv_shutdown_t* req, int status) {
720e552da7Schristos   ASSERT(req == &shutdown_req);
730e552da7Schristos   shutdown_cb_called++;
740e552da7Schristos }
750e552da7Schristos 
760e552da7Schristos 
write_cb(uv_write_t * req,int status)770e552da7Schristos static void write_cb(uv_write_t* req, int status) {
780e552da7Schristos   ASSERT(req == &write_req);
790e552da7Schristos   uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
800e552da7Schristos   write_cb_called++;
810e552da7Schristos }
820e552da7Schristos 
830e552da7Schristos 
connect_and_write(uv_connect_t * req,int status)840e552da7Schristos static void connect_and_write(uv_connect_t* req, int status) {
850e552da7Schristos   uv_buf_t buf = uv_buf_init(buffer, sizeof buffer);
860e552da7Schristos   ASSERT(req == &connect_req);
870e552da7Schristos   ASSERT(status == 0);
880e552da7Schristos   uv_write(&write_req, req->handle, &buf, 1, write_cb);
890e552da7Schristos   connect_cb_called++;
900e552da7Schristos }
910e552da7Schristos 
920e552da7Schristos 
930e552da7Schristos 
connect_and_shutdown(uv_connect_t * req,int status)940e552da7Schristos static void connect_and_shutdown(uv_connect_t* req, int status) {
950e552da7Schristos   ASSERT(req == &connect_req);
960e552da7Schristos   ASSERT(status == 0);
970e552da7Schristos   uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
980e552da7Schristos   connect_cb_called++;
990e552da7Schristos }
1000e552da7Schristos 
1010e552da7Schristos 
TEST_IMPL(ref)1020e552da7Schristos TEST_IMPL(ref) {
1030e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1040e552da7Schristos   MAKE_VALGRIND_HAPPY();
1050e552da7Schristos   return 0;
1060e552da7Schristos }
1070e552da7Schristos 
1080e552da7Schristos 
TEST_IMPL(idle_ref)1090e552da7Schristos TEST_IMPL(idle_ref) {
1100e552da7Schristos   uv_idle_t h;
1110e552da7Schristos   uv_idle_init(uv_default_loop(), &h);
1120e552da7Schristos   uv_idle_start(&h, (uv_idle_cb) fail_cb2);
1130e552da7Schristos   uv_unref((uv_handle_t*)&h);
1140e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1150e552da7Schristos   do_close(&h);
1160e552da7Schristos   MAKE_VALGRIND_HAPPY();
1170e552da7Schristos   return 0;
1180e552da7Schristos }
1190e552da7Schristos 
1200e552da7Schristos 
TEST_IMPL(async_ref)1210e552da7Schristos TEST_IMPL(async_ref) {
1220e552da7Schristos   uv_async_t h;
1230e552da7Schristos   uv_async_init(uv_default_loop(), &h, NULL);
1240e552da7Schristos   uv_unref((uv_handle_t*)&h);
1250e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1260e552da7Schristos   do_close(&h);
1270e552da7Schristos   MAKE_VALGRIND_HAPPY();
1280e552da7Schristos   return 0;
1290e552da7Schristos }
1300e552da7Schristos 
1310e552da7Schristos 
TEST_IMPL(prepare_ref)1320e552da7Schristos TEST_IMPL(prepare_ref) {
1330e552da7Schristos   uv_prepare_t h;
1340e552da7Schristos   uv_prepare_init(uv_default_loop(), &h);
1350e552da7Schristos   uv_prepare_start(&h, (uv_prepare_cb) fail_cb2);
1360e552da7Schristos   uv_unref((uv_handle_t*)&h);
1370e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1380e552da7Schristos   do_close(&h);
1390e552da7Schristos   MAKE_VALGRIND_HAPPY();
1400e552da7Schristos   return 0;
1410e552da7Schristos }
1420e552da7Schristos 
1430e552da7Schristos 
TEST_IMPL(check_ref)1440e552da7Schristos TEST_IMPL(check_ref) {
1450e552da7Schristos   uv_check_t h;
1460e552da7Schristos   uv_check_init(uv_default_loop(), &h);
1470e552da7Schristos   uv_check_start(&h, (uv_check_cb) fail_cb2);
1480e552da7Schristos   uv_unref((uv_handle_t*)&h);
1490e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1500e552da7Schristos   do_close(&h);
1510e552da7Schristos   MAKE_VALGRIND_HAPPY();
1520e552da7Schristos   return 0;
1530e552da7Schristos }
1540e552da7Schristos 
1550e552da7Schristos 
prepare_cb(uv_prepare_t * h)1560e552da7Schristos static void prepare_cb(uv_prepare_t* h) {
157*5f2f4271Schristos   ASSERT_NOT_NULL(h);
1580e552da7Schristos   uv_unref((uv_handle_t*)h);
1590e552da7Schristos }
1600e552da7Schristos 
1610e552da7Schristos 
TEST_IMPL(unref_in_prepare_cb)1620e552da7Schristos TEST_IMPL(unref_in_prepare_cb) {
1630e552da7Schristos   uv_prepare_t h;
1640e552da7Schristos   uv_prepare_init(uv_default_loop(), &h);
1650e552da7Schristos   uv_prepare_start(&h, prepare_cb);
1660e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1670e552da7Schristos   do_close(&h);
1680e552da7Schristos   MAKE_VALGRIND_HAPPY();
1690e552da7Schristos   return 0;
1700e552da7Schristos }
1710e552da7Schristos 
1720e552da7Schristos 
TEST_IMPL(timer_ref)1730e552da7Schristos TEST_IMPL(timer_ref) {
1740e552da7Schristos   uv_timer_t h;
1750e552da7Schristos   uv_timer_init(uv_default_loop(), &h);
1760e552da7Schristos   uv_unref((uv_handle_t*)&h);
1770e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1780e552da7Schristos   do_close(&h);
1790e552da7Schristos   MAKE_VALGRIND_HAPPY();
1800e552da7Schristos   return 0;
1810e552da7Schristos }
1820e552da7Schristos 
1830e552da7Schristos 
TEST_IMPL(timer_ref2)1840e552da7Schristos TEST_IMPL(timer_ref2) {
1850e552da7Schristos   uv_timer_t h;
1860e552da7Schristos   uv_timer_init(uv_default_loop(), &h);
1870e552da7Schristos   uv_timer_start(&h, (uv_timer_cb)fail_cb, 42, 42);
1880e552da7Schristos   uv_unref((uv_handle_t*)&h);
1890e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
1900e552da7Schristos   do_close(&h);
1910e552da7Schristos   MAKE_VALGRIND_HAPPY();
1920e552da7Schristos   return 0;
1930e552da7Schristos }
1940e552da7Schristos 
1950e552da7Schristos 
TEST_IMPL(fs_event_ref)1960e552da7Schristos TEST_IMPL(fs_event_ref) {
1970e552da7Schristos #if defined(NO_FS_EVENTS)
1980e552da7Schristos   RETURN_SKIP(NO_FS_EVENTS);
1990e552da7Schristos #endif
2000e552da7Schristos   uv_fs_event_t h;
2010e552da7Schristos   uv_fs_event_init(uv_default_loop(), &h);
2020e552da7Schristos   uv_fs_event_start(&h, (uv_fs_event_cb)fail_cb, ".", 0);
2030e552da7Schristos   uv_unref((uv_handle_t*)&h);
2040e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2050e552da7Schristos   do_close(&h);
2060e552da7Schristos   MAKE_VALGRIND_HAPPY();
2070e552da7Schristos   return 0;
2080e552da7Schristos }
2090e552da7Schristos 
2100e552da7Schristos 
TEST_IMPL(fs_poll_ref)2110e552da7Schristos TEST_IMPL(fs_poll_ref) {
2120e552da7Schristos   uv_fs_poll_t h;
2130e552da7Schristos   uv_fs_poll_init(uv_default_loop(), &h);
2140e552da7Schristos   uv_fs_poll_start(&h, NULL, ".", 999);
2150e552da7Schristos   uv_unref((uv_handle_t*)&h);
2160e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2170e552da7Schristos   do_close(&h);
2180e552da7Schristos   MAKE_VALGRIND_HAPPY();
2190e552da7Schristos   return 0;
2200e552da7Schristos }
2210e552da7Schristos 
2220e552da7Schristos 
TEST_IMPL(tcp_ref)2230e552da7Schristos TEST_IMPL(tcp_ref) {
2240e552da7Schristos   uv_tcp_t h;
2250e552da7Schristos   uv_tcp_init(uv_default_loop(), &h);
2260e552da7Schristos   uv_unref((uv_handle_t*)&h);
2270e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2280e552da7Schristos   do_close(&h);
2290e552da7Schristos   MAKE_VALGRIND_HAPPY();
2300e552da7Schristos   return 0;
2310e552da7Schristos }
2320e552da7Schristos 
2330e552da7Schristos 
TEST_IMPL(tcp_ref2)2340e552da7Schristos TEST_IMPL(tcp_ref2) {
2350e552da7Schristos   uv_tcp_t h;
2360e552da7Schristos   uv_tcp_init(uv_default_loop(), &h);
2370e552da7Schristos   uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb);
2380e552da7Schristos   uv_unref((uv_handle_t*)&h);
2390e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2400e552da7Schristos   do_close(&h);
2410e552da7Schristos   MAKE_VALGRIND_HAPPY();
2420e552da7Schristos   return 0;
2430e552da7Schristos }
2440e552da7Schristos 
2450e552da7Schristos 
TEST_IMPL(tcp_ref2b)2460e552da7Schristos TEST_IMPL(tcp_ref2b) {
2470e552da7Schristos   uv_tcp_t h;
2480e552da7Schristos   uv_tcp_init(uv_default_loop(), &h);
2490e552da7Schristos   uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb);
2500e552da7Schristos   uv_unref((uv_handle_t*)&h);
2510e552da7Schristos   uv_close((uv_handle_t*)&h, close_cb);
2520e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2530e552da7Schristos   ASSERT(close_cb_called == 1);
2540e552da7Schristos   MAKE_VALGRIND_HAPPY();
2550e552da7Schristos   return 0;
2560e552da7Schristos }
2570e552da7Schristos 
2580e552da7Schristos 
TEST_IMPL(tcp_ref3)2590e552da7Schristos TEST_IMPL(tcp_ref3) {
2600e552da7Schristos   struct sockaddr_in addr;
2610e552da7Schristos   uv_tcp_t h;
2620e552da7Schristos   ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
2630e552da7Schristos   uv_tcp_init(uv_default_loop(), &h);
2640e552da7Schristos   uv_tcp_connect(&connect_req,
2650e552da7Schristos                  &h,
2660e552da7Schristos                  (const struct sockaddr*) &addr,
2670e552da7Schristos                  connect_and_shutdown);
2680e552da7Schristos   uv_unref((uv_handle_t*)&h);
2690e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2700e552da7Schristos   ASSERT(connect_cb_called == 1);
2710e552da7Schristos   ASSERT(shutdown_cb_called == 1);
2720e552da7Schristos   do_close(&h);
2730e552da7Schristos   MAKE_VALGRIND_HAPPY();
2740e552da7Schristos   return 0;
2750e552da7Schristos }
2760e552da7Schristos 
2770e552da7Schristos 
TEST_IMPL(tcp_ref4)2780e552da7Schristos TEST_IMPL(tcp_ref4) {
2790e552da7Schristos   struct sockaddr_in addr;
2800e552da7Schristos   uv_tcp_t h;
2810e552da7Schristos   ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
2820e552da7Schristos   uv_tcp_init(uv_default_loop(), &h);
2830e552da7Schristos   uv_tcp_connect(&connect_req,
2840e552da7Schristos                  &h,
2850e552da7Schristos                  (const struct sockaddr*) &addr,
2860e552da7Schristos                  connect_and_write);
2870e552da7Schristos   uv_unref((uv_handle_t*)&h);
2880e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
2890e552da7Schristos   ASSERT(connect_cb_called == 1);
2900e552da7Schristos   ASSERT(write_cb_called == 1);
2910e552da7Schristos   ASSERT(shutdown_cb_called == 1);
2920e552da7Schristos   do_close(&h);
2930e552da7Schristos   MAKE_VALGRIND_HAPPY();
2940e552da7Schristos   return 0;
2950e552da7Schristos }
2960e552da7Schristos 
2970e552da7Schristos 
TEST_IMPL(udp_ref)2980e552da7Schristos TEST_IMPL(udp_ref) {
2990e552da7Schristos   uv_udp_t h;
3000e552da7Schristos   uv_udp_init(uv_default_loop(), &h);
3010e552da7Schristos   uv_unref((uv_handle_t*)&h);
3020e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3030e552da7Schristos   do_close(&h);
3040e552da7Schristos   MAKE_VALGRIND_HAPPY();
3050e552da7Schristos   return 0;
3060e552da7Schristos }
3070e552da7Schristos 
3080e552da7Schristos 
TEST_IMPL(udp_ref2)3090e552da7Schristos TEST_IMPL(udp_ref2) {
3100e552da7Schristos   struct sockaddr_in addr;
3110e552da7Schristos   uv_udp_t h;
3120e552da7Schristos   ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
3130e552da7Schristos   uv_udp_init(uv_default_loop(), &h);
3140e552da7Schristos   uv_udp_bind(&h, (const struct sockaddr*) &addr, 0);
3150e552da7Schristos   uv_udp_recv_start(&h, (uv_alloc_cb)fail_cb, (uv_udp_recv_cb)fail_cb);
3160e552da7Schristos   uv_unref((uv_handle_t*)&h);
3170e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3180e552da7Schristos   do_close(&h);
3190e552da7Schristos   MAKE_VALGRIND_HAPPY();
3200e552da7Schristos   return 0;
3210e552da7Schristos }
3220e552da7Schristos 
3230e552da7Schristos 
TEST_IMPL(udp_ref3)3240e552da7Schristos TEST_IMPL(udp_ref3) {
3250e552da7Schristos   struct sockaddr_in addr;
3260e552da7Schristos   uv_buf_t buf = uv_buf_init("PING", 4);
3270e552da7Schristos   uv_udp_send_t req;
3280e552da7Schristos   uv_udp_t h;
3290e552da7Schristos 
3300e552da7Schristos   ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
3310e552da7Schristos   uv_udp_init(uv_default_loop(), &h);
3320e552da7Schristos   uv_udp_send(&req,
3330e552da7Schristos               &h,
3340e552da7Schristos               &buf,
3350e552da7Schristos               1,
3360e552da7Schristos               (const struct sockaddr*) &addr,
3370e552da7Schristos               (uv_udp_send_cb) req_cb);
3380e552da7Schristos   uv_unref((uv_handle_t*)&h);
3390e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3400e552da7Schristos   ASSERT(req_cb_called == 1);
3410e552da7Schristos   do_close(&h);
3420e552da7Schristos 
3430e552da7Schristos   MAKE_VALGRIND_HAPPY();
3440e552da7Schristos   return 0;
3450e552da7Schristos }
3460e552da7Schristos 
3470e552da7Schristos 
TEST_IMPL(pipe_ref)3480e552da7Schristos TEST_IMPL(pipe_ref) {
3490e552da7Schristos   uv_pipe_t h;
3500e552da7Schristos   uv_pipe_init(uv_default_loop(), &h, 0);
3510e552da7Schristos   uv_unref((uv_handle_t*)&h);
3520e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3530e552da7Schristos   do_close(&h);
3540e552da7Schristos   MAKE_VALGRIND_HAPPY();
3550e552da7Schristos   return 0;
3560e552da7Schristos }
3570e552da7Schristos 
3580e552da7Schristos 
TEST_IMPL(pipe_ref2)3590e552da7Schristos TEST_IMPL(pipe_ref2) {
3600e552da7Schristos   uv_pipe_t h;
3610e552da7Schristos   uv_pipe_init(uv_default_loop(), &h, 0);
3620e552da7Schristos   uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb);
3630e552da7Schristos   uv_unref((uv_handle_t*)&h);
3640e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3650e552da7Schristos   do_close(&h);
3660e552da7Schristos   MAKE_VALGRIND_HAPPY();
3670e552da7Schristos   return 0;
3680e552da7Schristos }
3690e552da7Schristos 
3700e552da7Schristos 
TEST_IMPL(pipe_ref3)3710e552da7Schristos TEST_IMPL(pipe_ref3) {
3720e552da7Schristos   uv_pipe_t h;
3730e552da7Schristos   uv_pipe_init(uv_default_loop(), &h, 0);
3740e552da7Schristos   uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_and_shutdown);
3750e552da7Schristos   uv_unref((uv_handle_t*)&h);
3760e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3770e552da7Schristos   ASSERT(connect_cb_called == 1);
3780e552da7Schristos   ASSERT(shutdown_cb_called == 1);
3790e552da7Schristos   do_close(&h);
3800e552da7Schristos   MAKE_VALGRIND_HAPPY();
3810e552da7Schristos   return 0;
3820e552da7Schristos }
3830e552da7Schristos 
3840e552da7Schristos 
TEST_IMPL(pipe_ref4)3850e552da7Schristos TEST_IMPL(pipe_ref4) {
3860e552da7Schristos   uv_pipe_t h;
3870e552da7Schristos   uv_pipe_init(uv_default_loop(), &h, 0);
3880e552da7Schristos   uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_and_write);
3890e552da7Schristos   uv_unref((uv_handle_t*)&h);
3900e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
3910e552da7Schristos   ASSERT(connect_cb_called == 1);
3920e552da7Schristos   ASSERT(write_cb_called == 1);
3930e552da7Schristos   ASSERT(shutdown_cb_called == 1);
3940e552da7Schristos   do_close(&h);
3950e552da7Schristos   MAKE_VALGRIND_HAPPY();
3960e552da7Schristos   return 0;
3970e552da7Schristos }
3980e552da7Schristos 
3990e552da7Schristos 
TEST_IMPL(process_ref)4000e552da7Schristos TEST_IMPL(process_ref) {
4010e552da7Schristos   /* spawn_helper4 blocks indefinitely. */
4020e552da7Schristos   char *argv[] = { NULL, "spawn_helper4", NULL };
4030e552da7Schristos   uv_process_options_t options;
4040e552da7Schristos   size_t exepath_size;
4050e552da7Schristos   char exepath[256];
4060e552da7Schristos   uv_process_t h;
4070e552da7Schristos   int r;
4080e552da7Schristos 
4090e552da7Schristos   memset(&options, 0, sizeof(options));
4100e552da7Schristos   exepath_size = sizeof(exepath);
4110e552da7Schristos 
4120e552da7Schristos   r = uv_exepath(exepath, &exepath_size);
4130e552da7Schristos   ASSERT(r == 0);
4140e552da7Schristos 
4150e552da7Schristos   argv[0] = exepath;
4160e552da7Schristos   options.file = exepath;
4170e552da7Schristos   options.args = argv;
4180e552da7Schristos   options.exit_cb = NULL;
4190e552da7Schristos 
4200e552da7Schristos   r = uv_spawn(uv_default_loop(), &h, &options);
4210e552da7Schristos   ASSERT(r == 0);
4220e552da7Schristos 
4230e552da7Schristos   uv_unref((uv_handle_t*)&h);
4240e552da7Schristos   uv_run(uv_default_loop(), UV_RUN_DEFAULT);
4250e552da7Schristos 
4260e552da7Schristos   r = uv_process_kill(&h, /* SIGTERM */ 15);
4270e552da7Schristos   ASSERT(r == 0);
4280e552da7Schristos 
4290e552da7Schristos   do_close(&h);
4300e552da7Schristos 
4310e552da7Schristos   MAKE_VALGRIND_HAPPY();
4320e552da7Schristos   return 0;
4330e552da7Schristos }
4340e552da7Schristos 
4350e552da7Schristos 
TEST_IMPL(has_ref)4360e552da7Schristos TEST_IMPL(has_ref) {
4370e552da7Schristos   uv_idle_t h;
4380e552da7Schristos   uv_idle_init(uv_default_loop(), &h);
4390e552da7Schristos   uv_ref((uv_handle_t*)&h);
4400e552da7Schristos   ASSERT(uv_has_ref((uv_handle_t*)&h) == 1);
4410e552da7Schristos   uv_unref((uv_handle_t*)&h);
4420e552da7Schristos   ASSERT(uv_has_ref((uv_handle_t*)&h) == 0);
4430e552da7Schristos   MAKE_VALGRIND_HAPPY();
4440e552da7Schristos   return 0;
4450e552da7Schristos }
446