test: test for uv_spawn with stdio_count == 3
This commit is contained in:
parent
f5b5127db0
commit
dc7a62d114
@ -104,5 +104,17 @@ static int maybe_run_test(int argc, char **argv) {
|
||||
while (1) uv_sleep(10000);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "spawn_helper5") == 0) {
|
||||
const char* out = "fourth stdio!\n\0";
|
||||
#ifdef _WIN32
|
||||
DWORD bytes;
|
||||
WriteFile((HANDLE) _get_osfhandle(3), out, strlen(out), &bytes, NULL);
|
||||
#else
|
||||
write(3, out, strlen(out));
|
||||
fsync(3);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
return run_test(argv[1], TEST_TIMEOUT, 0);
|
||||
}
|
||||
|
||||
@ -119,6 +119,7 @@ TEST_DECLARE (pass_always)
|
||||
TEST_DECLARE (spawn_exit_code)
|
||||
TEST_DECLARE (spawn_stdout)
|
||||
TEST_DECLARE (spawn_stdin)
|
||||
TEST_DECLARE (spawn_stdio_greater_than_3)
|
||||
TEST_DECLARE (spawn_and_kill)
|
||||
TEST_DECLARE (spawn_detached)
|
||||
TEST_DECLARE (spawn_and_kill_with_std)
|
||||
@ -333,6 +334,7 @@ TASK_LIST_START
|
||||
TEST_ENTRY (spawn_exit_code)
|
||||
TEST_ENTRY (spawn_stdout)
|
||||
TEST_ENTRY (spawn_stdin)
|
||||
TEST_ENTRY (spawn_stdio_greater_than_3)
|
||||
TEST_ENTRY (spawn_and_kill)
|
||||
TEST_ENTRY (spawn_detached)
|
||||
TEST_ENTRY (spawn_and_kill_with_std)
|
||||
|
||||
@ -295,6 +295,40 @@ TEST_IMPL(spawn_stdin) {
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(spawn_stdio_greater_than_3) {
|
||||
int r;
|
||||
uv_pipe_t pipe;
|
||||
uv_stdio_container_t stdio[4];
|
||||
|
||||
init_process_options("spawn_helper5", exit_cb);
|
||||
|
||||
uv_pipe_init(uv_default_loop(), &pipe, 0);
|
||||
options.stdio = stdio;
|
||||
options.stdio[0].flags = UV_IGNORE;
|
||||
options.stdio[1].flags = UV_IGNORE;
|
||||
options.stdio[2].flags = UV_IGNORE;
|
||||
options.stdio[3].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
|
||||
options.stdio[3].data.stream = (uv_stream_t*)&pipe;
|
||||
options.stdio_count = 4;
|
||||
|
||||
r = uv_spawn(uv_default_loop(), &process, options);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_read_start((uv_stream_t*) &pipe, on_alloc, on_read);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_run(uv_default_loop());
|
||||
ASSERT(r == 0);
|
||||
|
||||
ASSERT(exit_cb_called == 1);
|
||||
ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
|
||||
printf("output from stdio[3] is: %s", output);
|
||||
ASSERT(strcmp("fourth stdio!\n", output) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(spawn_and_kill) {
|
||||
int r;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user