1 #include <darwintest.h> 2 #include <mach/mach.h> 3 #include <stdlib.h> 4 #include <sys/sysctl.h> 5 #include <unistd.h> 6 #include <darwintest_multiprocess.h> 7 #include <spawn.h> 8 #include <spawn_private.h> 9 #include <libproc_internal.h> 10 #include <signal.h> 11 12 T_GLOBAL_META( 13 T_META_NAMESPACE("xnu.ipc"), 14 T_META_RUN_CONCURRENTLY(TRUE), 15 T_META_RADAR_COMPONENT_NAME("xnu"), 16 T_META_RADAR_COMPONENT_VERSION("IPC")); 17 18 #define MAX_ARGV 2 19 20 extern char **environ; 21 22 T_DECL(port_exhaustion_test_max_ports, "Allocate maximum ipc ports possible", T_META_IGNORECRASHES(".*port_exhaustion_client.*"), T_META_CHECK_LEAKS(false)) 23 { 24 char *test_prog_name = "./port_exhaustion_client"; 25 char *child_args[MAX_ARGV]; 26 int child_pid; 27 posix_spawnattr_t attrs; 28 int err; 29 30 /* Initialize posix_spawn attributes */ 31 posix_spawnattr_init(&attrs); 32 33 child_args[0] = test_prog_name; 34 child_args[1] = NULL; 35 36 err = posix_spawn(&child_pid, child_args[0], NULL, &attrs, &child_args[0], environ); 37 T_EXPECT_POSIX_SUCCESS(err, "posix_spawn port_exhaustion_client"); 38 39 int child_status; 40 /* Wait for child and check for exception */ 41 if (-1 == waitpid(child_pid, &child_status, 0)) { 42 T_FAIL("waitpid: child mia"); 43 } 44 45 T_ASSERT_EQ(WIFEXITED(child_status), 0, "Child did not exit normally"); 46 47 if (WIFSIGNALED(child_status)) { 48 T_ASSERT_EQ(child_status, 9, "Child exited with status = %x", child_status); 49 } 50 } 51