1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34 static int close_cb_called;
35 static int exit_cb_called;
36 static uv_process_t process;
37 static uv_timer_t timer;
38 static uv_process_options_t options;
39 static char exepath[1024];
40 static size_t exepath_size = 1024;
42 static int no_term_signal;
44 #define OUTPUT_SIZE 1024
45 static char output[OUTPUT_SIZE];
46 static int output_used;
49 static void close_cb(uv_handle_t* handle) {
54 static void exit_cb(uv_process_t* process,
59 ASSERT(exit_status == 1);
60 ASSERT(term_signal == 0);
61 uv_close((uv_handle_t*)process, close_cb);
65 static void fail_cb(uv_process_t* process,
68 ASSERT(0 && "fail_cb called");
72 static void kill_cb(uv_process_t* process,
80 ASSERT(exit_status == 1);
82 ASSERT(exit_status == 0);
84 ASSERT(no_term_signal || term_signal == 15);
85 uv_close((uv_handle_t*)process, close_cb);
88 * Sending signum == 0 should check if the
89 * child process is still alive, not kill it.
90 * This process should be dead.
92 err = uv_kill(process->pid, 0);
93 ASSERT(err == UV_ESRCH);
96 static void detach_failure_cb(uv_process_t* process,
99 printf("detach_cb\n");
103 static void on_alloc(uv_handle_t* handle,
104 size_t suggested_size,
106 buf->base = output + output_used;
107 buf->len = OUTPUT_SIZE - output_used;
111 static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
113 output_used += nread;
114 } else if (nread < 0) {
115 ASSERT(nread == UV_EOF);
116 uv_close((uv_handle_t*)tcp, close_cb);
121 static void write_cb(uv_write_t* req, int status) {
123 uv_close((uv_handle_t*)req->handle, close_cb);
127 static void init_process_options(char* test, uv_exit_cb exit_cb) {
128 /* Note spawn_helper1 defined in test/run-tests.c */
129 int r = uv_exepath(exepath, &exepath_size);
131 exepath[exepath_size] = '\0';
135 options.file = exepath;
137 options.exit_cb = exit_cb;
142 static void timer_cb(uv_timer_t* handle, int status) {
143 uv_process_kill(&process, /* SIGTERM */ 15);
144 uv_close((uv_handle_t*)handle, close_cb);
148 TEST_IMPL(spawn_fails) {
151 init_process_options("", fail_cb);
152 options.file = options.args[0] = "program-that-had-better-not-exist";
154 r = uv_spawn(uv_default_loop(), &process, &options);
155 ASSERT(r == UV_ENOENT || r == UV_EACCES);
156 ASSERT(0 == uv_is_active((uv_handle_t*) &process));
157 ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
159 MAKE_VALGRIND_HAPPY();
164 TEST_IMPL(spawn_exit_code) {
167 init_process_options("spawn_helper1", exit_cb);
169 r = uv_spawn(uv_default_loop(), &process, &options);
172 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
175 ASSERT(exit_cb_called == 1);
176 ASSERT(close_cb_called == 1);
178 MAKE_VALGRIND_HAPPY();
183 TEST_IMPL(spawn_stdout) {
186 uv_stdio_container_t stdio[2];
188 init_process_options("spawn_helper2", exit_cb);
190 uv_pipe_init(uv_default_loop(), &out, 0);
191 options.stdio = stdio;
192 options.stdio[0].flags = UV_IGNORE;
193 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
194 options.stdio[1].data.stream = (uv_stream_t*)&out;
195 options.stdio_count = 2;
197 r = uv_spawn(uv_default_loop(), &process, &options);
200 r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
203 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
206 ASSERT(exit_cb_called == 1);
207 ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
208 printf("output is: %s", output);
209 ASSERT(strcmp("hello world\n", output) == 0);
211 MAKE_VALGRIND_HAPPY();
216 TEST_IMPL(spawn_stdout_to_file) {
220 uv_stdio_container_t stdio[2];
223 unlink("stdout_file");
225 init_process_options("spawn_helper2", exit_cb);
227 r = uv_fs_open(uv_default_loop(), &fs_req, "stdout_file", O_CREAT | O_RDWR,
228 S_IRUSR | S_IWUSR, NULL);
230 uv_fs_req_cleanup(&fs_req);
234 options.stdio = stdio;
235 options.stdio[0].flags = UV_IGNORE;
236 options.stdio[1].flags = UV_INHERIT_FD;
237 options.stdio[1].data.fd = file;
238 options.stdio_count = 2;
240 r = uv_spawn(uv_default_loop(), &process, &options);
243 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
246 ASSERT(exit_cb_called == 1);
247 ASSERT(close_cb_called == 1);
249 r = uv_fs_read(uv_default_loop(), &fs_req, file, output, sizeof(output),
252 uv_fs_req_cleanup(&fs_req);
254 r = uv_fs_close(uv_default_loop(), &fs_req, file, NULL);
256 uv_fs_req_cleanup(&fs_req);
258 printf("output is: %s", output);
259 ASSERT(strcmp("hello world\n", output) == 0);
262 unlink("stdout_file");
264 MAKE_VALGRIND_HAPPY();
269 TEST_IMPL(spawn_stdin) {
273 uv_write_t write_req;
275 uv_stdio_container_t stdio[2];
276 char buffer[] = "hello-from-spawn_stdin";
278 init_process_options("spawn_helper3", exit_cb);
280 uv_pipe_init(uv_default_loop(), &out, 0);
281 uv_pipe_init(uv_default_loop(), &in, 0);
282 options.stdio = stdio;
283 options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
284 options.stdio[0].data.stream = (uv_stream_t*)∈
285 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
286 options.stdio[1].data.stream = (uv_stream_t*)&out;
287 options.stdio_count = 2;
289 r = uv_spawn(uv_default_loop(), &process, &options);
293 buf.len = sizeof(buffer);
294 r = uv_write(&write_req, (uv_stream_t*)&in, &buf, 1, write_cb);
297 r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
300 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
303 ASSERT(exit_cb_called == 1);
304 ASSERT(close_cb_called == 3); /* Once for process twice for the pipe. */
305 ASSERT(strcmp(buffer, output) == 0);
307 MAKE_VALGRIND_HAPPY();
312 TEST_IMPL(spawn_stdio_greater_than_3) {
315 uv_stdio_container_t stdio[4];
317 init_process_options("spawn_helper5", exit_cb);
319 uv_pipe_init(uv_default_loop(), &pipe, 0);
320 options.stdio = stdio;
321 options.stdio[0].flags = UV_IGNORE;
322 options.stdio[1].flags = UV_IGNORE;
323 options.stdio[2].flags = UV_IGNORE;
324 options.stdio[3].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
325 options.stdio[3].data.stream = (uv_stream_t*)&pipe;
326 options.stdio_count = 4;
328 r = uv_spawn(uv_default_loop(), &process, &options);
331 r = uv_read_start((uv_stream_t*) &pipe, on_alloc, on_read);
334 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
337 ASSERT(exit_cb_called == 1);
338 ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
339 printf("output from stdio[3] is: %s", output);
340 ASSERT(strcmp("fourth stdio!\n", output) == 0);
342 MAKE_VALGRIND_HAPPY();
347 TEST_IMPL(spawn_ignored_stdio) {
350 init_process_options("spawn_helper6", exit_cb);
352 options.stdio = NULL;
353 options.stdio_count = 0;
355 r = uv_spawn(uv_default_loop(), &process, &options);
358 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
361 ASSERT(exit_cb_called == 1);
362 ASSERT(close_cb_called == 1);
364 MAKE_VALGRIND_HAPPY();
369 TEST_IMPL(spawn_and_kill) {
372 init_process_options("spawn_helper4", kill_cb);
374 r = uv_spawn(uv_default_loop(), &process, &options);
377 r = uv_timer_init(uv_default_loop(), &timer);
380 r = uv_timer_start(&timer, timer_cb, 500, 0);
383 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
386 ASSERT(exit_cb_called == 1);
387 ASSERT(close_cb_called == 2); /* Once for process and once for timer. */
389 MAKE_VALGRIND_HAPPY();
394 TEST_IMPL(spawn_preserve_env) {
397 uv_stdio_container_t stdio[2];
399 init_process_options("spawn_helper7", exit_cb);
401 uv_pipe_init(uv_default_loop(), &out, 0);
402 options.stdio = stdio;
403 options.stdio[0].flags = UV_IGNORE;
404 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
405 options.stdio[1].data.stream = (uv_stream_t*) &out;
406 options.stdio_count = 2;
408 r = putenv("ENV_TEST=testval");
411 /* Explicitly set options.env to NULL to test for env clobbering. */
414 r = uv_spawn(uv_default_loop(), &process, &options);
417 r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
420 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
423 ASSERT(exit_cb_called == 1);
424 ASSERT(close_cb_called == 2);
426 printf("output is: %s", output);
427 ASSERT(strcmp("testval", output) == 0);
429 MAKE_VALGRIND_HAPPY();
434 TEST_IMPL(spawn_detached) {
437 init_process_options("spawn_helper4", detach_failure_cb);
439 options.flags |= UV_PROCESS_DETACHED;
441 r = uv_spawn(uv_default_loop(), &process, &options);
444 uv_unref((uv_handle_t*)&process);
446 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
449 ASSERT(exit_cb_called == 0);
451 r = uv_kill(process.pid, 0);
454 r = uv_kill(process.pid, 15);
457 MAKE_VALGRIND_HAPPY();
461 TEST_IMPL(spawn_and_kill_with_std) {
463 uv_pipe_t in, out, err;
465 char message[] = "Nancy's joining me because the message this evening is "
466 "not my message but ours.";
468 uv_stdio_container_t stdio[3];
470 init_process_options("spawn_helper4", kill_cb);
472 r = uv_pipe_init(uv_default_loop(), &in, 0);
475 r = uv_pipe_init(uv_default_loop(), &out, 0);
478 r = uv_pipe_init(uv_default_loop(), &err, 0);
481 options.stdio = stdio;
482 options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
483 options.stdio[0].data.stream = (uv_stream_t*)∈
484 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
485 options.stdio[1].data.stream = (uv_stream_t*)&out;
486 options.stdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
487 options.stdio[2].data.stream = (uv_stream_t*)&err;
488 options.stdio_count = 3;
490 r = uv_spawn(uv_default_loop(), &process, &options);
493 buf = uv_buf_init(message, sizeof message);
494 r = uv_write(&write, (uv_stream_t*) &in, &buf, 1, write_cb);
497 r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
500 r = uv_read_start((uv_stream_t*) &err, on_alloc, on_read);
503 r = uv_timer_init(uv_default_loop(), &timer);
506 r = uv_timer_start(&timer, timer_cb, 500, 0);
509 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
512 ASSERT(exit_cb_called == 1);
513 ASSERT(close_cb_called == 5); /* process x 1, timer x 1, stdio x 3. */
515 MAKE_VALGRIND_HAPPY();
520 TEST_IMPL(spawn_and_ping) {
521 uv_write_t write_req;
524 uv_stdio_container_t stdio[2];
527 init_process_options("spawn_helper3", exit_cb);
528 buf = uv_buf_init("TEST", 4);
530 uv_pipe_init(uv_default_loop(), &out, 0);
531 uv_pipe_init(uv_default_loop(), &in, 0);
532 options.stdio = stdio;
533 options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
534 options.stdio[0].data.stream = (uv_stream_t*)∈
535 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
536 options.stdio[1].data.stream = (uv_stream_t*)&out;
537 options.stdio_count = 2;
539 r = uv_spawn(uv_default_loop(), &process, &options);
542 /* Sending signum == 0 should check if the
543 * child process is still alive, not kill it.
545 r = uv_process_kill(&process, 0);
548 r = uv_write(&write_req, (uv_stream_t*)&in, &buf, 1, write_cb);
551 r = uv_read_start((uv_stream_t*)&out, on_alloc, on_read);
554 ASSERT(exit_cb_called == 0);
556 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
559 ASSERT(exit_cb_called == 1);
560 ASSERT(strcmp(output, "TEST") == 0);
562 MAKE_VALGRIND_HAPPY();
574 init_process_options("spawn_helper4", kill_cb);
576 r = uv_spawn(uv_default_loop(), &process, &options);
579 /* Sending signum == 0 should check if the
580 * child process is still alive, not kill it.
582 r = uv_kill(process.pid, 0);
585 /* Kill the process. */
586 r = uv_kill(process.pid, /* SIGTERM */ 15);
589 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
592 ASSERT(exit_cb_called == 1);
593 ASSERT(close_cb_called == 1);
595 MAKE_VALGRIND_HAPPY();
601 TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) {
606 uv_stdio_container_t stdio[2];
608 init_process_options("spawn_helper2", exit_cb);
610 uv_pipe_init(uv_default_loop(), &out, 0);
611 options.stdio = stdio;
612 options.stdio[0].flags = UV_IGNORE;
613 options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
614 options.stdio[1].data.stream = (uv_stream_t*)&out;
615 options.stdio_count = 2;
617 /* Create a pipe that'll cause a collision. */
620 "\\\\.\\pipe\\uv\\%p-%d",
622 GetCurrentProcessId());
623 pipe_handle = CreateNamedPipeA(name,
624 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
625 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
631 ASSERT(pipe_handle != INVALID_HANDLE_VALUE);
633 r = uv_spawn(uv_default_loop(), &process, &options);
636 r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
639 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
642 ASSERT(exit_cb_called == 1);
643 ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
644 printf("output is: %s", output);
645 ASSERT(strcmp("hello world\n", output) == 0);
647 MAKE_VALGRIND_HAPPY();
652 int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr);
653 WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target);
655 TEST_IMPL(argument_escaping) {
656 const WCHAR* test_str[] = {
665 L"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\""
667 const int count = sizeof(test_str) / sizeof(*test_str);
671 size_t total_size = 0;
679 "c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"",
682 WCHAR* verbatim_output;
683 WCHAR* non_verbatim_output;
685 test_output = calloc(count, sizeof(WCHAR*));
686 for (i = 0; i < count; ++i) {
687 test_output[i] = calloc(2 * (wcslen(test_str[i]) + 2), sizeof(WCHAR));
688 quote_cmd_arg(test_str[i], test_output[i]);
689 wprintf(L"input : %s\n", test_str[i]);
690 wprintf(L"output: %s\n", test_output[i]);
691 total_size += wcslen(test_output[i]) + 1;
693 command_line = calloc(total_size + 1, sizeof(WCHAR));
694 for (i = 0; i < count; ++i) {
695 wcscat(command_line, test_output[i]);
696 wcscat(command_line, L" ");
698 command_line[total_size - 1] = L'\0';
700 wprintf(L"command_line: %s\n", command_line);
702 cracked = CommandLineToArgvW(command_line, &num_args);
703 for (i = 0; i < num_args; ++i) {
704 wprintf(L"%d: %s\t%s\n", i, test_str[i], cracked[i]);
705 ASSERT(wcscmp(test_str[i], cracked[i]) == 0);
709 for (i = 0; i < count; ++i) {
710 free(test_output[i]);
713 result = make_program_args(verbatim, 1, &verbatim_output);
715 result = make_program_args(verbatim, 0, &non_verbatim_output);
718 wprintf(L" verbatim_output: %s\n", verbatim_output);
719 wprintf(L"non_verbatim_output: %s\n", non_verbatim_output);
721 ASSERT(wcscmp(verbatim_output,
722 L"cmd.exe /c c:\\path\\to\\node.exe --eval "
723 L"\"require('c:\\\\path\\\\to\\\\test.js')\"") == 0);
724 ASSERT(wcscmp(non_verbatim_output,
725 L"cmd.exe /c \"c:\\path\\to\\node.exe --eval "
726 L"\\\"require('c:\\\\path\\\\to\\\\test.js')\\\"\"") == 0);
728 free(verbatim_output);
729 free(non_verbatim_output);
734 int make_program_env(char** env_block, WCHAR** dst_ptr);
736 TEST_IMPL(environment_creation) {
738 char* environment[] = {
740 "SYSTEM=ROOT", /* substring of a supplied var name */
741 "SYSTEMROOTED=OMG", /* supplied var name is a substring */
748 WCHAR* ptr = expected;
753 for (i = 0; i < sizeof(environment) / sizeof(environment[0]) - 1; i++) {
754 ptr += uv_utf8_to_utf16(environment[i],
756 expected + sizeof(expected) - ptr);
759 memcpy(ptr, L"SYSTEMROOT=", sizeof(L"SYSTEMROOT="));
760 ptr += sizeof(L"SYSTEMROOT=")/sizeof(WCHAR) - 1;
761 ptr += GetEnvironmentVariableW(L"SYSTEMROOT",
763 expected + sizeof(expected) - ptr);
766 memcpy(ptr, L"SYSTEMDRIVE=", sizeof(L"SYSTEMDRIVE="));
767 ptr += sizeof(L"SYSTEMDRIVE=")/sizeof(WCHAR) - 1;
768 ptr += GetEnvironmentVariableW(L"SYSTEMDRIVE",
770 expected + sizeof(expected) - ptr);
774 result = make_program_env(environment, &env);
777 for (str = env; *str; str += wcslen(str) + 1) {
778 wprintf(L"%s\n", str);
781 ASSERT(wcscmp(expected, env) == 0);
788 TEST_IMPL(spawn_setuid_setgid) {
791 /* if not root, then this will fail. */
792 uv_uid_t uid = getuid();
794 fprintf(stderr, "spawn_setuid_setgid skipped: not root\n");
798 init_process_options("spawn_helper1", exit_cb);
800 /* become the "nobody" user. */
802 pw = getpwnam("nobody");
804 options.uid = pw->pw_uid;
805 options.gid = pw->pw_gid;
806 options.flags = UV_PROCESS_SETUID | UV_PROCESS_SETGID;
808 r = uv_spawn(uv_default_loop(), &process, &options);
811 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
814 ASSERT(exit_cb_called == 1);
815 ASSERT(close_cb_called == 1);
817 MAKE_VALGRIND_HAPPY();
824 TEST_IMPL(spawn_setuid_fails) {
827 /* if root, become nobody. */
828 uv_uid_t uid = getuid();
831 pw = getpwnam("nobody");
833 ASSERT(0 == setgid(pw->pw_gid));
834 ASSERT(0 == setuid(pw->pw_uid));
837 init_process_options("spawn_helper1", fail_cb);
839 options.flags |= UV_PROCESS_SETUID;
842 r = uv_spawn(uv_default_loop(), &process, &options);
843 ASSERT(r == UV_EPERM);
845 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
848 ASSERT(close_cb_called == 0);
850 MAKE_VALGRIND_HAPPY();
855 TEST_IMPL(spawn_setgid_fails) {
858 /* if root, become nobody. */
859 uv_uid_t uid = getuid();
862 pw = getpwnam("nobody");
864 ASSERT(0 == setgid(pw->pw_gid));
865 ASSERT(0 == setuid(pw->pw_uid));
868 init_process_options("spawn_helper1", fail_cb);
870 options.flags |= UV_PROCESS_SETGID;
873 r = uv_spawn(uv_default_loop(), &process, &options);
874 ASSERT(r == UV_EPERM);
876 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
879 ASSERT(close_cb_called == 0);
881 MAKE_VALGRIND_HAPPY();
889 static void exit_cb_unexpected(uv_process_t* process,
892 ASSERT(0 && "should not have been called");
896 TEST_IMPL(spawn_setuid_fails) {
899 init_process_options("spawn_helper1", exit_cb_unexpected);
901 options.flags |= UV_PROCESS_SETUID;
902 options.uid = (uv_uid_t) -42424242;
904 r = uv_spawn(uv_default_loop(), &process, &options);
905 ASSERT(r == UV_ENOTSUP);
907 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
910 ASSERT(close_cb_called == 0);
912 MAKE_VALGRIND_HAPPY();
917 TEST_IMPL(spawn_setgid_fails) {
920 init_process_options("spawn_helper1", exit_cb_unexpected);
922 options.flags |= UV_PROCESS_SETGID;
923 options.gid = (uv_gid_t) -42424242;
925 r = uv_spawn(uv_default_loop(), &process, &options);
926 ASSERT(r == UV_ENOTSUP);
928 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
931 ASSERT(close_cb_called == 0);
933 MAKE_VALGRIND_HAPPY();
939 TEST_IMPL(spawn_auto_unref) {
940 init_process_options("spawn_helper1", NULL);
941 ASSERT(0 == uv_spawn(uv_default_loop(), &process, &options));
942 ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
943 ASSERT(0 == uv_is_closing((uv_handle_t*) &process));
944 uv_close((uv_handle_t*) &process, NULL);
945 ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
946 ASSERT(1 == uv_is_closing((uv_handle_t*) &process));
947 MAKE_VALGRIND_HAPPY();