xref: /xnu-8796.121.2/tests/proc_info_44873309.c (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions #include <darwintest.h>
2*c54f35caSApple OSS Distributions #include <mach/mach.h>
3*c54f35caSApple OSS Distributions #include <mach/mach_types.h>
4*c54f35caSApple OSS Distributions #include <unistd.h>
5*c54f35caSApple OSS Distributions #include <sys/types.h>
6*c54f35caSApple OSS Distributions #include <sys/wait.h>
7*c54f35caSApple OSS Distributions #include <stdlib.h>
8*c54f35caSApple OSS Distributions 
9*c54f35caSApple OSS Distributions #include <stdio.h>
10*c54f35caSApple OSS Distributions #include <assert.h>
11*c54f35caSApple OSS Distributions #include <err.h>
12*c54f35caSApple OSS Distributions #include <libproc.h>
13*c54f35caSApple OSS Distributions 
14*c54f35caSApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
15*c54f35caSApple OSS Distributions 
16*c54f35caSApple OSS Distributions T_DECL(proc_info_44873309, "ensure new proc_pidinfo flavor returns correct table sizes",
17*c54f35caSApple OSS Distributions     T_META_CHECK_LEAKS(false), T_META_ASROOT(true))
18*c54f35caSApple OSS Distributions {
19*c54f35caSApple OSS Distributions 	mach_port_t port;
20*c54f35caSApple OSS Distributions 	int retval;
21*c54f35caSApple OSS Distributions 
22*c54f35caSApple OSS Distributions 	pid_t pid = getpid();
23*c54f35caSApple OSS Distributions 	struct proc_ipctableinfo table_info = {};
24*c54f35caSApple OSS Distributions 	retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info, (uint32_t)sizeof(table_info));
25*c54f35caSApple OSS Distributions 	T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval);
26*c54f35caSApple OSS Distributions 	T_EXPECT_EQ(retval, (int)sizeof(table_info), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size = %u, table_free = %u",
27*c54f35caSApple OSS Distributions 	    table_info.table_size, table_info.table_free);
28*c54f35caSApple OSS Distributions 
29*c54f35caSApple OSS Distributions 	kern_return_t ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port);
30*c54f35caSApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE");
31*c54f35caSApple OSS Distributions 
32*c54f35caSApple OSS Distributions 	struct proc_ipctableinfo table_info2 = {};
33*c54f35caSApple OSS Distributions 	retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info2, (uint32_t)sizeof(table_info2));
34*c54f35caSApple OSS Distributions 	T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval);
35*c54f35caSApple OSS Distributions 	T_EXPECT_EQ(retval, (int)sizeof(table_info2), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size2 = %u, table_free2 = %u",
36*c54f35caSApple OSS Distributions 	    table_info2.table_size, table_info2.table_free);
37*c54f35caSApple OSS Distributions 
38*c54f35caSApple OSS Distributions 	T_EXPECT_EQ(table_info.table_free, table_info2.table_free + 1, "Comparing the table_free values");
39*c54f35caSApple OSS Distributions }
40