int run_ipc_send_recv_helper(uv_loop_t* loop, int inprocess) { int r; is_in_process = inprocess; memset(&ctx2, 0, sizeof(ctx2)); r = uv_pipe_init(loop, &ctx2.listen, 0); ASSERT(r == 0); r = uv_pipe_init(loop, &ctx2.channel, 1); ASSERT(r == 0); if (inprocess) { r = uv_pipe_bind(&ctx2.listen, TEST_PIPENAME_3); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&ctx2.listen, SOMAXCONN, listen_cb); ASSERT(r == 0); } else { uv_os_fd_t stdin_handle = uv_convert_fd_to_handle(0); r = uv_pipe_open(&ctx2.channel, stdin_handle); ASSERT(r == 0); send_recv_start(); } notify_parent_process(); r = uv_run(loop, UV_RUN_DEFAULT); ASSERT(r == 0); return 0; }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) { return ipc_helper_heavy_traffic_deadlock_bug(); } if (strcmp(argv[1], "ipc_send_recv_helper") == 0) { return ipc_send_recv_helper(); } if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) { return ipc_helper_tcp_connection(); } if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) { return ipc_helper_closed_handle(); } if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) { return ipc_helper_bind_twice(); } if (strcmp(argv[1], "ipc_helper_send_zero") == 0) { return ipc_helper_send_zero(); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { notify_parent_process(); return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { notify_parent_process(); printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) { notify_parent_process(); return spawn_tcp_server_helper(); } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; notify_parent_process(); ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { notify_parent_process(); /* Never surrender, never return! */ while (1) uv_sleep(10000); } if (strcmp(argv[1], "spawn_helper5") == 0) { const char out[] = "fourth stdio!\n"; notify_parent_process(); { #ifdef _WIN32 DWORD bytes; WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL); #else ssize_t r; do r = write(3, out, sizeof(out) - 1); while (r == -1 && errno == EINTR); fsync(3); #endif } return 1; } if (strcmp(argv[1], "spawn_helper6") == 0) { int r; notify_parent_process(); r = fprintf(stdout, "hello world\n"); ASSERT(r > 0); r = fprintf(stderr, "hello errworld\n"); ASSERT(r > 0); return 1; } if (strcmp(argv[1], "spawn_helper7") == 0) { int r; char *test; notify_parent_process(); /* Test if the test value from the parent is still set */ test = getenv("ENV_TEST"); ASSERT(test != NULL); r = fprintf(stdout, "%s", test); ASSERT(r > 0); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper8") == 0) { int fd; notify_parent_process(); ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd))); ASSERT(fd > 2); ASSERT(-1 == write(fd, "x", 1)); return 1; } #endif /* !_WIN32 */ if (strcmp(argv[1], "spawn_helper9") == 0) { notify_parent_process(); spawn_stdin_stdout(); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) { uv_uid_t uid = atoi(argv[2]); uv_gid_t gid = atoi(argv[3]); ASSERT(uid == getuid()); ASSERT(gid == getgid()); notify_parent_process(); return 1; } #endif /* !_WIN32 */ return run_test(argv[1], 0, 1); }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) { return ipc_helper_heavy_traffic_deadlock_bug(); } if (strcmp(argv[1], "ipc_send_recv_helper") == 0) { return ipc_send_recv_helper(); } if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) { return ipc_helper_tcp_connection(); } if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) { return ipc_helper_closed_handle(); } if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) { return ipc_helper_bind_twice(); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { notify_parent_process(); return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { notify_parent_process(); printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) { notify_parent_process(); return spawn_tcp_server_helper(); } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; notify_parent_process(); ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { notify_parent_process(); /* Never surrender, never return! */ while (1) uv_sleep(10000); } if (strcmp(argv[1], "spawn_helper5") == 0) { const char out[] = "fourth stdio!\n"; notify_parent_process(); #ifdef _WIN32 DWORD bytes; WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL); #else { ssize_t r; do r = write(3, out, sizeof(out) - 1); while (r == -1 && errno == EINTR); fsync(3); } #endif return 1; } if (strcmp(argv[1], "spawn_helper6") == 0) { int r; notify_parent_process(); r = fprintf(stdout, "hello world\n"); ASSERT(r > 0); r = fprintf(stderr, "hello errworld\n"); ASSERT(r > 0); return 1; } if (strcmp(argv[1], "spawn_helper7") == 0) { int r; char *test; notify_parent_process(); /* Test if the test value from the parent is still set */ test = getenv("ENV_TEST"); ASSERT(test != NULL); r = fprintf(stdout, "%s", test); ASSERT(r > 0); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper8") == 0) { int fd; notify_parent_process(); ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd))); ASSERT(fd > 2); ASSERT(-1 == write(fd, "x", 1)); return 1; } #endif /* !_WIN32 */ if (strcmp(argv[1], "spawn_helper9") == 0) { notify_parent_process(); return spawn_stdin_stdout(); } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) { uv_uid_t uid = atoi(argv[2]); uv_gid_t gid = atoi(argv[3]); ASSERT(uid == getuid()); ASSERT(gid == getgid()); notify_parent_process(); return 1; } #endif /* !_WIN32 */ #if !defined(NO_CPU_AFFINITY) if (strcmp(argv[1], "spawn_helper_affinity") == 0) { int i; int r; int cpu; int cpumask_size; #ifdef _WIN32 DWORD_PTR procmask; DWORD_PTR sysmask; #elif defined(__linux__) cpu_set_t cpuset; #else cpuset_t cpuset; #endif cpumask_size = uv_cpumask_size(); ASSERT(cpumask_size > 0); cpu = atoi(argv[2]); ASSERT(cpu >= 0); ASSERT(cpu < cpumask_size); /* verify the mask has the cpu we expect */ #ifdef _WIN32 r = GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask); ASSERT(r != 0); for (i = 0; i < cpumask_size; ++i) { ASSERT(((procmask & (((DWORD_PTR)1) << i)) != 0) == (i == cpu)); } #else CPU_ZERO(&cpuset); r = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); ASSERT(r == 0); for (i = 0; i < cpumask_size; ++i) { ASSERT(CPU_ISSET(i, &cpuset) == (i == cpu)); } #endif return 1; } #endif return run_test(argv[1], 0, 1); }