xref: /xnu-10002.81.5/tests/task_info.c (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions #include <darwintest.h>
2*5e3eaea3SApple OSS Distributions #include <darwintest_utils.h>
3*5e3eaea3SApple OSS Distributions #include <errno.h>
4*5e3eaea3SApple OSS Distributions #include <mach/mach.h>
5*5e3eaea3SApple OSS Distributions #include <mach/mach_error.h>
6*5e3eaea3SApple OSS Distributions #include <mach/policy.h>
7*5e3eaea3SApple OSS Distributions #include <mach/task_info.h>
8*5e3eaea3SApple OSS Distributions #include <mach/thread_info.h>
9*5e3eaea3SApple OSS Distributions #include <signal.h>
10*5e3eaea3SApple OSS Distributions #include <stdio.h>
11*5e3eaea3SApple OSS Distributions #include <stdlib.h>
12*5e3eaea3SApple OSS Distributions #include <sys/mman.h>
13*5e3eaea3SApple OSS Distributions #include <sys/sysctl.h>
14*5e3eaea3SApple OSS Distributions #include <unistd.h>
15*5e3eaea3SApple OSS Distributions 
16*5e3eaea3SApple OSS Distributions #include "test_utils.h"
17*5e3eaea3SApple OSS Distributions 
18*5e3eaea3SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
19*5e3eaea3SApple OSS Distributions 
20*5e3eaea3SApple OSS Distributions /* *************************************************************************************
21*5e3eaea3SApple OSS Distributions  * Test the task_info API.
22*5e3eaea3SApple OSS Distributions  *
23*5e3eaea3SApple OSS Distributions  * This is a functional test of the following APIs:
24*5e3eaea3SApple OSS Distributions  * TASK_BASIC_INFO_32
25*5e3eaea3SApple OSS Distributions  * TASK_BASIC2_INFO_32
26*5e3eaea3SApple OSS Distributions  * TASK_BASIC_INFO_64
27*5e3eaea3SApple OSS Distributions  * TASK_BASIC_INFO_64_2
28*5e3eaea3SApple OSS Distributions  * TASK_POWER_INFO_V2
29*5e3eaea3SApple OSS Distributions  * TASK_FLAGS_INFO
30*5e3eaea3SApple OSS Distributions  * TASK_AFFINITY_TAG_INFO
31*5e3eaea3SApple OSS Distributions  * TASK_THREAD_TIMES_INFO
32*5e3eaea3SApple OSS Distributions  * TASK_ABSOLUTE_TIME_INFO
33*5e3eaea3SApple OSS Distributions  * <rdar://problem/22242021> Add tests to increase code coverage for the task_info API
34*5e3eaea3SApple OSS Distributions  * *************************************************************************************
35*5e3eaea3SApple OSS Distributions  */
36*5e3eaea3SApple OSS Distributions #define TESTPHYSFOOTPRINTVAL 5
37*5e3eaea3SApple OSS Distributions #define CANARY 0x0f0f0f0f0f0f0f0fULL
38*5e3eaea3SApple OSS Distributions #if !defined(CONFIG_EMBEDDED)
39*5e3eaea3SApple OSS Distributions #define ABSOLUTE_MIN_USER_TIME_DIFF 150
40*5e3eaea3SApple OSS Distributions #define ABSOLUTE_MIN_SYSTEM_TIME_DIFF 300
41*5e3eaea3SApple OSS Distributions #endif
42*5e3eaea3SApple OSS Distributions 
43*5e3eaea3SApple OSS Distributions enum info_kind { INFO_32, INFO_64, INFO_32_2, INFO_64_2, INFO_MACH, INFO_MAX };
44*5e3eaea3SApple OSS Distributions 
45*5e3eaea3SApple OSS Distributions enum info_get { GET_SUSPEND_COUNT, GET_RESIDENT_SIZE, GET_VIRTUAL_SIZE, GET_USER_TIME, GET_SYS_TIME, GET_POLICY, GET_MAX_RES };
46*5e3eaea3SApple OSS Distributions 
47*5e3eaea3SApple OSS Distributions /*
48*5e3eaea3SApple OSS Distributions  * This function uses CPU cycles by doing a factorial computation.
49*5e3eaea3SApple OSS Distributions  */
50*5e3eaea3SApple OSS Distributions static void do_factorial_task(void);
51*5e3eaea3SApple OSS Distributions 
52*5e3eaea3SApple OSS Distributions void test_task_basic_info_32(void);
53*5e3eaea3SApple OSS Distributions void test_task_basic_info_64(void);
54*5e3eaea3SApple OSS Distributions void task_basic_info_32_debug(void);
55*5e3eaea3SApple OSS Distributions void task_basic2_info_32_warmup(void);
56*5e3eaea3SApple OSS Distributions void test_task_basic_info(enum info_kind kind);
57*5e3eaea3SApple OSS Distributions uint64_t info_get(enum info_kind kind, enum info_get get, void * data);
58*5e3eaea3SApple OSS Distributions 
59*5e3eaea3SApple OSS Distributions T_DECL(task_vm_info, "tests task vm info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
60*5e3eaea3SApple OSS Distributions {
61*5e3eaea3SApple OSS Distributions 	kern_return_t err;
62*5e3eaea3SApple OSS Distributions 	task_vm_info_data_t vm_info;
63*5e3eaea3SApple OSS Distributions 
64*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
65*5e3eaea3SApple OSS Distributions 
66*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info, &count);
67*5e3eaea3SApple OSS Distributions 
68*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
69*5e3eaea3SApple OSS Distributions 
70*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.virtual_size, 0ULL, "task_info return value !=0 for virtual_size\n");
71*5e3eaea3SApple OSS Distributions 
72*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.phys_footprint, 0ULL, "task_info return value !=0 for phys_footprint\n");
73*5e3eaea3SApple OSS Distributions 
74*5e3eaea3SApple OSS Distributions 	/*
75*5e3eaea3SApple OSS Distributions 	 * Test the REV0 version of TASK_VM_INFO. It should not change the value of phys_footprint.
76*5e3eaea3SApple OSS Distributions 	 */
77*5e3eaea3SApple OSS Distributions 
78*5e3eaea3SApple OSS Distributions 	count                  = TASK_VM_INFO_REV0_COUNT;
79*5e3eaea3SApple OSS Distributions 	vm_info.phys_footprint = TESTPHYSFOOTPRINTVAL;
80*5e3eaea3SApple OSS Distributions 	vm_info.min_address    = CANARY;
81*5e3eaea3SApple OSS Distributions 	vm_info.max_address    = CANARY;
82*5e3eaea3SApple OSS Distributions 
83*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info, &count);
84*5e3eaea3SApple OSS Distributions 
85*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
86*5e3eaea3SApple OSS Distributions 
87*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(count, TASK_VM_INFO_REV0_COUNT, "task_info count(%d) is equal to TASK_VM_INFO_REV0_COUNT", count);
88*5e3eaea3SApple OSS Distributions 
89*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.virtual_size, 0ULL, "task_info --rev0 call does not return 0 for virtual_size");
90*5e3eaea3SApple OSS Distributions 
91*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(vm_info.phys_footprint, (unsigned long long)TESTPHYSFOOTPRINTVAL,
92*5e3eaea3SApple OSS Distributions 	    "task_info --rev0 call returned value %llu for vm_info.phys_footprint.  Expected %u since this value should not be "
93*5e3eaea3SApple OSS Distributions 	    "modified by rev0",
94*5e3eaea3SApple OSS Distributions 	    vm_info.phys_footprint, TESTPHYSFOOTPRINTVAL);
95*5e3eaea3SApple OSS Distributions 
96*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(vm_info.min_address, CANARY,
97*5e3eaea3SApple OSS Distributions 	    "task_info --rev0 call returned value 0x%llx for vm_info.min_address. Expected 0x%llx since this value should not "
98*5e3eaea3SApple OSS Distributions 	    "be modified by rev0",
99*5e3eaea3SApple OSS Distributions 	    vm_info.min_address, CANARY);
100*5e3eaea3SApple OSS Distributions 
101*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(vm_info.max_address, CANARY,
102*5e3eaea3SApple OSS Distributions 	    "task_info --rev0 call returned value 0x%llx for vm_info.max_address. Expected 0x%llx since this value should not "
103*5e3eaea3SApple OSS Distributions 	    "be modified by rev0",
104*5e3eaea3SApple OSS Distributions 	    vm_info.max_address, CANARY);
105*5e3eaea3SApple OSS Distributions 
106*5e3eaea3SApple OSS Distributions 	/*
107*5e3eaea3SApple OSS Distributions 	 * Test the REV1 version of TASK_VM_INFO.
108*5e3eaea3SApple OSS Distributions 	 */
109*5e3eaea3SApple OSS Distributions 
110*5e3eaea3SApple OSS Distributions 	count                  = TASK_VM_INFO_REV1_COUNT;
111*5e3eaea3SApple OSS Distributions 	vm_info.phys_footprint = TESTPHYSFOOTPRINTVAL;
112*5e3eaea3SApple OSS Distributions 	vm_info.min_address    = CANARY;
113*5e3eaea3SApple OSS Distributions 	vm_info.max_address    = CANARY;
114*5e3eaea3SApple OSS Distributions 
115*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info, &count);
116*5e3eaea3SApple OSS Distributions 
117*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
118*5e3eaea3SApple OSS Distributions 
119*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(count, TASK_VM_INFO_REV1_COUNT, "task_info count(%d) is equal to TASK_VM_INFO_REV1_COUNT", count);
120*5e3eaea3SApple OSS Distributions 
121*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.virtual_size, 0ULL, "task_info --rev1 call does not return 0 for virtual_size");
122*5e3eaea3SApple OSS Distributions 
123*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.phys_footprint, (unsigned long long)TESTPHYSFOOTPRINTVAL,
124*5e3eaea3SApple OSS Distributions 	    "task_info --rev1 call returned value %llu for vm_info.phys_footprint.  Expected value is anything other than %u "
125*5e3eaea3SApple OSS Distributions 	    "since this value should not be modified by rev1",
126*5e3eaea3SApple OSS Distributions 	    vm_info.phys_footprint, TESTPHYSFOOTPRINTVAL);
127*5e3eaea3SApple OSS Distributions 
128*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(vm_info.min_address, CANARY,
129*5e3eaea3SApple OSS Distributions 	    "task_info --rev1 call returned value 0x%llx for vm_info.min_address. Expected 0x%llx since this value should not "
130*5e3eaea3SApple OSS Distributions 	    "be modified by rev1",
131*5e3eaea3SApple OSS Distributions 	    vm_info.min_address, CANARY);
132*5e3eaea3SApple OSS Distributions 
133*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(vm_info.max_address, CANARY,
134*5e3eaea3SApple OSS Distributions 	    "task_info --rev1 call returned value 0x%llx for vm_info.max_address. Expected 0x%llx since this value should not "
135*5e3eaea3SApple OSS Distributions 	    "be modified by rev1",
136*5e3eaea3SApple OSS Distributions 	    vm_info.max_address, CANARY);
137*5e3eaea3SApple OSS Distributions 
138*5e3eaea3SApple OSS Distributions 	/*
139*5e3eaea3SApple OSS Distributions 	 * Test the REV2 version of TASK_VM_INFO.
140*5e3eaea3SApple OSS Distributions 	 */
141*5e3eaea3SApple OSS Distributions 
142*5e3eaea3SApple OSS Distributions 	count                  = TASK_VM_INFO_REV2_COUNT;
143*5e3eaea3SApple OSS Distributions 	vm_info.phys_footprint = TESTPHYSFOOTPRINTVAL;
144*5e3eaea3SApple OSS Distributions 	vm_info.min_address    = CANARY;
145*5e3eaea3SApple OSS Distributions 	vm_info.max_address    = CANARY;
146*5e3eaea3SApple OSS Distributions 
147*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info, &count);
148*5e3eaea3SApple OSS Distributions 
149*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
150*5e3eaea3SApple OSS Distributions 
151*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(count, TASK_VM_INFO_REV2_COUNT, "task_info count(%d) is equal to TASK_VM_INFO_REV2_COUNT\n", count);
152*5e3eaea3SApple OSS Distributions 
153*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.virtual_size, 0ULL, "task_info --rev2 call does not return 0 for virtual_size\n");
154*5e3eaea3SApple OSS Distributions 
155*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.phys_footprint, (unsigned long long)TESTPHYSFOOTPRINTVAL,
156*5e3eaea3SApple OSS Distributions 	    "task_info --rev2 call returned value %llu for vm_info.phys_footprint.  Expected anything other than %u since this "
157*5e3eaea3SApple OSS Distributions 	    "value should be modified by rev2",
158*5e3eaea3SApple OSS Distributions 	    vm_info.phys_footprint, TESTPHYSFOOTPRINTVAL);
159*5e3eaea3SApple OSS Distributions 
160*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.min_address, CANARY,
161*5e3eaea3SApple OSS Distributions 	    "task_info --rev2 call returned value 0x%llx for vm_info.min_address. Expected anything other than 0x%llx since "
162*5e3eaea3SApple OSS Distributions 	    "this value should be modified by rev2",
163*5e3eaea3SApple OSS Distributions 	    vm_info.min_address, CANARY);
164*5e3eaea3SApple OSS Distributions 
165*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.max_address, CANARY,
166*5e3eaea3SApple OSS Distributions 	    "task_info --rev2 call returned value 0x%llx for vm_info.max_address. Expected anything other than 0x%llx since "
167*5e3eaea3SApple OSS Distributions 	    "this value should be modified by rev2",
168*5e3eaea3SApple OSS Distributions 	    vm_info.max_address, CANARY);
169*5e3eaea3SApple OSS Distributions 
170*5e3eaea3SApple OSS Distributions 	/*
171*5e3eaea3SApple OSS Distributions 	 * Test the REV4 version of TASK_VM_INFO.
172*5e3eaea3SApple OSS Distributions 	 */
173*5e3eaea3SApple OSS Distributions 
174*5e3eaea3SApple OSS Distributions 	count                         = TASK_VM_INFO_REV4_COUNT;
175*5e3eaea3SApple OSS Distributions 	vm_info.phys_footprint        = TESTPHYSFOOTPRINTVAL;
176*5e3eaea3SApple OSS Distributions 	vm_info.min_address           = CANARY;
177*5e3eaea3SApple OSS Distributions 	vm_info.max_address           = CANARY;
178*5e3eaea3SApple OSS Distributions 	vm_info.limit_bytes_remaining = CANARY;
179*5e3eaea3SApple OSS Distributions 
180*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info, &count);
181*5e3eaea3SApple OSS Distributions 
182*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
183*5e3eaea3SApple OSS Distributions 
184*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(count, TASK_VM_INFO_REV4_COUNT, "task_info count(%d) is equal to TASK_VM_INFO_REV4_COUNT\n", count);
185*5e3eaea3SApple OSS Distributions 
186*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.phys_footprint, (unsigned long long)TESTPHYSFOOTPRINTVAL,
187*5e3eaea3SApple OSS Distributions 	    "task_info --rev4 call returned value %llu for vm_info.phys_footprint.  Expected anything other than %u since this "
188*5e3eaea3SApple OSS Distributions 	    "value should be modified by rev4",
189*5e3eaea3SApple OSS Distributions 	    vm_info.phys_footprint, TESTPHYSFOOTPRINTVAL);
190*5e3eaea3SApple OSS Distributions 
191*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.min_address, CANARY,
192*5e3eaea3SApple OSS Distributions 	    "task_info --rev4 call returned value 0x%llx for vm_info.min_address. Expected anything other than 0x%llx since "
193*5e3eaea3SApple OSS Distributions 	    "this value should be modified by rev4",
194*5e3eaea3SApple OSS Distributions 	    vm_info.min_address, CANARY);
195*5e3eaea3SApple OSS Distributions 
196*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.max_address, CANARY,
197*5e3eaea3SApple OSS Distributions 	    "task_info --rev4 call returned value 0x%llx for vm_info.max_address. Expected anything other than 0x%llx since "
198*5e3eaea3SApple OSS Distributions 	    "this value should be modified by rev4",
199*5e3eaea3SApple OSS Distributions 	    vm_info.max_address, CANARY);
200*5e3eaea3SApple OSS Distributions 
201*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(vm_info.limit_bytes_remaining, CANARY,
202*5e3eaea3SApple OSS Distributions 	    "task_info --rev4 call returned value 0x%llx for vm_info.limit_bytes_remaining. Expected anything other than 0x%llx since "
203*5e3eaea3SApple OSS Distributions 	    "this value should be modified by rev4",
204*5e3eaea3SApple OSS Distributions 	    vm_info.limit_bytes_remaining, CANARY);
205*5e3eaea3SApple OSS Distributions }
206*5e3eaea3SApple OSS Distributions 
207*5e3eaea3SApple OSS Distributions T_DECL(host_debug_info, "tests host debug info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
208*5e3eaea3SApple OSS Distributions {
209*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
210*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
211*5e3eaea3SApple OSS Distributions 	T_QUIET;
212*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
213*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
214*5e3eaea3SApple OSS Distributions 
215*5e3eaea3SApple OSS Distributions 	kern_return_t err;
216*5e3eaea3SApple OSS Distributions 	mach_port_t host;
217*5e3eaea3SApple OSS Distributions 	host_debug_info_internal_data_t debug_info;
218*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = HOST_DEBUG_INFO_INTERNAL_COUNT;
219*5e3eaea3SApple OSS Distributions 	host                         = mach_host_self();
220*5e3eaea3SApple OSS Distributions 	err                          = host_info(host, HOST_DEBUG_INFO_INTERNAL, (host_info_t)&debug_info, &count);
221*5e3eaea3SApple OSS Distributions 
222*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify host_info call succeeded");
223*5e3eaea3SApple OSS Distributions }
224*5e3eaea3SApple OSS Distributions 
225*5e3eaea3SApple OSS Distributions T_DECL(task_debug_info, "tests task debug info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
226*5e3eaea3SApple OSS Distributions {
227*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
228*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
229*5e3eaea3SApple OSS Distributions 	T_QUIET;
230*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
231*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
232*5e3eaea3SApple OSS Distributions 
233*5e3eaea3SApple OSS Distributions 	kern_return_t err;
234*5e3eaea3SApple OSS Distributions 	task_debug_info_internal_data_t debug_info;
235*5e3eaea3SApple OSS Distributions 
236*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_DEBUG_INFO_INTERNAL_COUNT;
237*5e3eaea3SApple OSS Distributions 
238*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_DEBUG_INFO_INTERNAL, (task_info_t)&debug_info, &count);
239*5e3eaea3SApple OSS Distributions 
240*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
241*5e3eaea3SApple OSS Distributions }
242*5e3eaea3SApple OSS Distributions 
243*5e3eaea3SApple OSS Distributions T_DECL(thread_debug_info, "tests thread debug info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
244*5e3eaea3SApple OSS Distributions {
245*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
246*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
247*5e3eaea3SApple OSS Distributions 	T_QUIET;
248*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
249*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
250*5e3eaea3SApple OSS Distributions 
251*5e3eaea3SApple OSS Distributions 	kern_return_t err;
252*5e3eaea3SApple OSS Distributions 	thread_debug_info_internal_data_t debug_info;
253*5e3eaea3SApple OSS Distributions 
254*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = THREAD_DEBUG_INFO_INTERNAL_COUNT;
255*5e3eaea3SApple OSS Distributions 
256*5e3eaea3SApple OSS Distributions 	err = thread_info(mach_thread_self(), THREAD_DEBUG_INFO_INTERNAL, (thread_info_t)&debug_info, &count);
257*5e3eaea3SApple OSS Distributions 
258*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
259*5e3eaea3SApple OSS Distributions }
260*5e3eaea3SApple OSS Distributions 
261*5e3eaea3SApple OSS Distributions static void
do_factorial_task()262*5e3eaea3SApple OSS Distributions do_factorial_task()
263*5e3eaea3SApple OSS Distributions {
264*5e3eaea3SApple OSS Distributions 	int number    = 20;
265*5e3eaea3SApple OSS Distributions 	int factorial = 1;
266*5e3eaea3SApple OSS Distributions 	int i;
267*5e3eaea3SApple OSS Distributions 	for (i = 1; i <= number; i++) {
268*5e3eaea3SApple OSS Distributions 		factorial *= i;
269*5e3eaea3SApple OSS Distributions 	}
270*5e3eaea3SApple OSS Distributions 
271*5e3eaea3SApple OSS Distributions 	return;
272*5e3eaea3SApple OSS Distributions }
273*5e3eaea3SApple OSS Distributions 
274*5e3eaea3SApple OSS Distributions T_DECL(task_thread_times_info, "tests task thread times info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
275*5e3eaea3SApple OSS Distributions {
276*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
277*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
278*5e3eaea3SApple OSS Distributions 	T_QUIET;
279*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
280*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
281*5e3eaea3SApple OSS Distributions 
282*5e3eaea3SApple OSS Distributions 	kern_return_t err;
283*5e3eaea3SApple OSS Distributions 	task_thread_times_info_data_t thread_times_info_data;
284*5e3eaea3SApple OSS Distributions 	task_thread_times_info_data_t thread_times_info_data_new;
285*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_THREAD_TIMES_INFO_COUNT;
286*5e3eaea3SApple OSS Distributions 
287*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t)&thread_times_info_data, &count);
288*5e3eaea3SApple OSS Distributions 
289*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
290*5e3eaea3SApple OSS Distributions 
291*5e3eaea3SApple OSS Distributions 	do_factorial_task();
292*5e3eaea3SApple OSS Distributions 
293*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t)&thread_times_info_data_new, &count);
294*5e3eaea3SApple OSS Distributions 
295*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
296*5e3eaea3SApple OSS Distributions 
297*5e3eaea3SApple OSS Distributions 	/*
298*5e3eaea3SApple OSS Distributions 	 * The difference is observed to be less than 30 microseconds for user_time
299*5e3eaea3SApple OSS Distributions 	 * and less than 50 microseconds for system_time. This observation was done for over
300*5e3eaea3SApple OSS Distributions 	 * 1000 runs.
301*5e3eaea3SApple OSS Distributions 	 */
302*5e3eaea3SApple OSS Distributions 
303*5e3eaea3SApple OSS Distributions 	T_EXPECT_FALSE((thread_times_info_data_new.user_time.seconds - thread_times_info_data.user_time.seconds) != 0 ||
304*5e3eaea3SApple OSS Distributions 	    (thread_times_info_data_new.system_time.seconds - thread_times_info_data.system_time.seconds) != 0,
305*5e3eaea3SApple OSS Distributions 	    "Tests whether the difference between thread times is greater than the allowed limit");
306*5e3eaea3SApple OSS Distributions 
307*5e3eaea3SApple OSS Distributions 	/*
308*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
309*5e3eaea3SApple OSS Distributions 	 */
310*5e3eaea3SApple OSS Distributions 
311*5e3eaea3SApple OSS Distributions 	count--;
312*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t)&thread_times_info_data, &count);
313*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(err, KERN_INVALID_ARGUMENT,
314*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API.");
315*5e3eaea3SApple OSS Distributions }
316*5e3eaea3SApple OSS Distributions 
317*5e3eaea3SApple OSS Distributions T_DECL(task_absolutetime_info, "tests task absolute time info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
318*5e3eaea3SApple OSS Distributions {
319*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
320*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
321*5e3eaea3SApple OSS Distributions 	T_QUIET;
322*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
323*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
324*5e3eaea3SApple OSS Distributions 
325*5e3eaea3SApple OSS Distributions 	kern_return_t err;
326*5e3eaea3SApple OSS Distributions 	uint64_t user_time_diff, system_time_diff;
327*5e3eaea3SApple OSS Distributions 	task_absolutetime_info_data_t absolute_time_info_data;
328*5e3eaea3SApple OSS Distributions 	task_absolutetime_info_data_t absolute_time_info_data_new;
329*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_ABSOLUTETIME_INFO_COUNT;
330*5e3eaea3SApple OSS Distributions 
331*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_ABSOLUTETIME_INFO, (task_info_t)&absolute_time_info_data, &count);
332*5e3eaea3SApple OSS Distributions 
333*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
334*5e3eaea3SApple OSS Distributions 
335*5e3eaea3SApple OSS Distributions 	do_factorial_task();
336*5e3eaea3SApple OSS Distributions 
337*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_ABSOLUTETIME_INFO, (task_info_t)&absolute_time_info_data_new, &count);
338*5e3eaea3SApple OSS Distributions 
339*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
340*5e3eaea3SApple OSS Distributions 
341*5e3eaea3SApple OSS Distributions 	user_time_diff   = absolute_time_info_data_new.total_user - absolute_time_info_data.total_user;
342*5e3eaea3SApple OSS Distributions 	system_time_diff = absolute_time_info_data_new.total_system - absolute_time_info_data.total_system;
343*5e3eaea3SApple OSS Distributions 
344*5e3eaea3SApple OSS Distributions #if !defined(__arm64__)
345*5e3eaea3SApple OSS Distributions 	/*
346*5e3eaea3SApple OSS Distributions 	 * On embedded devices the difference is always zero.
347*5e3eaea3SApple OSS Distributions 	 * On non-embedded devices the difference occurs in this range. This was observed over ~10000 runs.
348*5e3eaea3SApple OSS Distributions 	 */
349*5e3eaea3SApple OSS Distributions 
350*5e3eaea3SApple OSS Distributions 	T_EXPECT_FALSE(user_time_diff < ABSOLUTE_MIN_USER_TIME_DIFF || system_time_diff < ABSOLUTE_MIN_SYSTEM_TIME_DIFF,
351*5e3eaea3SApple OSS Distributions 	    "Tests whether the difference between thread times is greater than the expected range");
352*5e3eaea3SApple OSS Distributions #endif
353*5e3eaea3SApple OSS Distributions 
354*5e3eaea3SApple OSS Distributions 	if (absolute_time_info_data.threads_user <= 0) {
355*5e3eaea3SApple OSS Distributions 		int precise_time_val = 0;
356*5e3eaea3SApple OSS Distributions 		size_t len           = sizeof(size_t);
357*5e3eaea3SApple OSS Distributions 
358*5e3eaea3SApple OSS Distributions 		T_LOG("User threads time is zero. This should only happen rarely and when precise_user_time is off");
359*5e3eaea3SApple OSS Distributions 
360*5e3eaea3SApple OSS Distributions 		err = sysctlbyname("kern.precise_user_kernel_time", &precise_time_val, &len, NULL, 0);
361*5e3eaea3SApple OSS Distributions 
362*5e3eaea3SApple OSS Distributions 		T_EXPECT_POSIX_SUCCESS(err, "performing sysctl to check precise_user_time");
363*5e3eaea3SApple OSS Distributions 
364*5e3eaea3SApple OSS Distributions 		T_LOG("kern.precise_user_kernel_time val = %d", precise_time_val);
365*5e3eaea3SApple OSS Distributions 
366*5e3eaea3SApple OSS Distributions 		T_EXPECT_FALSE(precise_time_val, "user thread time should only be zero when precise_user_kernel_time is disabled");
367*5e3eaea3SApple OSS Distributions 	} else {
368*5e3eaea3SApple OSS Distributions 		T_PASS("task_info should return non-zero value for user threads time = %llu", absolute_time_info_data.threads_user);
369*5e3eaea3SApple OSS Distributions 	}
370*5e3eaea3SApple OSS Distributions 
371*5e3eaea3SApple OSS Distributions #if !defined(__arm64__)
372*5e3eaea3SApple OSS Distributions 	/*
373*5e3eaea3SApple OSS Distributions 	 * On iOS, system threads are always zero. On OS X this value can be some large positive number.
374*5e3eaea3SApple OSS Distributions 	 * There is no real way to estimate the exact amount.
375*5e3eaea3SApple OSS Distributions 	 */
376*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(absolute_time_info_data.threads_system, 0ULL,
377*5e3eaea3SApple OSS Distributions 	    "task_info should return non-zero value for system threads time = %llu", absolute_time_info_data.threads_system);
378*5e3eaea3SApple OSS Distributions #endif
379*5e3eaea3SApple OSS Distributions 
380*5e3eaea3SApple OSS Distributions 	/*
381*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
382*5e3eaea3SApple OSS Distributions 	 */
383*5e3eaea3SApple OSS Distributions 	count--;
384*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_ABSOLUTETIME_INFO, (task_info_t)&absolute_time_info_data_new, &count);
385*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(err, KERN_INVALID_ARGUMENT,
386*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API.");
387*5e3eaea3SApple OSS Distributions }
388*5e3eaea3SApple OSS Distributions 
389*5e3eaea3SApple OSS Distributions T_DECL(task_affinity_tag_info, "tests task_affinity_tag_info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
390*5e3eaea3SApple OSS Distributions {
391*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
392*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
393*5e3eaea3SApple OSS Distributions 	T_QUIET;
394*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
395*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
396*5e3eaea3SApple OSS Distributions 
397*5e3eaea3SApple OSS Distributions 	kern_return_t err;
398*5e3eaea3SApple OSS Distributions 	task_affinity_tag_info_data_t affinity_tag_info_data;
399*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_AFFINITY_TAG_INFO_COUNT;
400*5e3eaea3SApple OSS Distributions 
401*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_AFFINITY_TAG_INFO, (task_info_t)&affinity_tag_info_data, &count);
402*5e3eaea3SApple OSS Distributions 
403*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
404*5e3eaea3SApple OSS Distributions 
405*5e3eaea3SApple OSS Distributions 	/*
406*5e3eaea3SApple OSS Distributions 	 * The affinity is not set by default, hence expecting a zero value.
407*5e3eaea3SApple OSS Distributions 	 */
408*5e3eaea3SApple OSS Distributions 	T_ASSERT_FALSE(affinity_tag_info_data.min != 0 || affinity_tag_info_data.max != 0,
409*5e3eaea3SApple OSS Distributions 	    "task_info call returns non-zero min or max value");
410*5e3eaea3SApple OSS Distributions 
411*5e3eaea3SApple OSS Distributions 	/*
412*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
413*5e3eaea3SApple OSS Distributions 	 */
414*5e3eaea3SApple OSS Distributions 	count--;
415*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_AFFINITY_TAG_INFO, (task_info_t)&affinity_tag_info_data, &count);
416*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(err, KERN_INVALID_ARGUMENT,
417*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API.");
418*5e3eaea3SApple OSS Distributions }
419*5e3eaea3SApple OSS Distributions 
420*5e3eaea3SApple OSS Distributions T_DECL(task_flags_info, "tests task_flags_info", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
421*5e3eaea3SApple OSS Distributions {
422*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
423*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
424*5e3eaea3SApple OSS Distributions 	T_QUIET;
425*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
426*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
427*5e3eaea3SApple OSS Distributions 
428*5e3eaea3SApple OSS Distributions 	kern_return_t err;
429*5e3eaea3SApple OSS Distributions 	task_flags_info_data_t flags_info_data;
430*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_FLAGS_INFO_COUNT;
431*5e3eaea3SApple OSS Distributions 
432*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_FLAGS_INFO, (task_info_t)&flags_info_data, &count);
433*5e3eaea3SApple OSS Distributions 
434*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
435*5e3eaea3SApple OSS Distributions 
436*5e3eaea3SApple OSS Distributions 	/* Change for 32-bit arch possibility?*/
437*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ((flags_info_data.flags & (unsigned int)(~(TF_LP64 | TF_64B_DATA))), 0U,
438*5e3eaea3SApple OSS Distributions 	    "task_info should only give out 64-bit addr/data flags");
439*5e3eaea3SApple OSS Distributions 
440*5e3eaea3SApple OSS Distributions 	/*
441*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
442*5e3eaea3SApple OSS Distributions 	 */
443*5e3eaea3SApple OSS Distributions 
444*5e3eaea3SApple OSS Distributions 	count--;
445*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_FLAGS_INFO, (task_info_t)&flags_info_data, &count);
446*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(err, KERN_INVALID_ARGUMENT,
447*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API.");
448*5e3eaea3SApple OSS Distributions }
449*5e3eaea3SApple OSS Distributions 
450*5e3eaea3SApple OSS Distributions T_DECL(task_power_info_v2, "tests task_power_info_v2", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
451*5e3eaea3SApple OSS Distributions {
452*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
453*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
454*5e3eaea3SApple OSS Distributions 	T_QUIET;
455*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
456*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
457*5e3eaea3SApple OSS Distributions 
458*5e3eaea3SApple OSS Distributions 	kern_return_t err;
459*5e3eaea3SApple OSS Distributions 	task_power_info_v2_data_t power_info_data_v2;
460*5e3eaea3SApple OSS Distributions 	task_power_info_v2_data_t power_info_data_v2_new;
461*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = TASK_POWER_INFO_V2_COUNT;
462*5e3eaea3SApple OSS Distributions 
463*5e3eaea3SApple OSS Distributions 	sleep(1);
464*5e3eaea3SApple OSS Distributions 
465*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_POWER_INFO_V2, (task_info_t)&power_info_data_v2, &count);
466*5e3eaea3SApple OSS Distributions 
467*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
468*5e3eaea3SApple OSS Distributions 
469*5e3eaea3SApple OSS Distributions 	T_ASSERT_LE(power_info_data_v2.gpu_energy.task_gpu_utilisation, 0ULL,
470*5e3eaea3SApple OSS Distributions 	    "verified task_info call shows zero GPU utilization for non-GPU task");
471*5e3eaea3SApple OSS Distributions 
472*5e3eaea3SApple OSS Distributions 	do_factorial_task();
473*5e3eaea3SApple OSS Distributions 
474*5e3eaea3SApple OSS Distributions 	/*
475*5e3eaea3SApple OSS Distributions 	 * Verify the cpu_energy parameters.
476*5e3eaea3SApple OSS Distributions 	 */
477*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_POWER_INFO_V2, (task_info_t)&power_info_data_v2_new, &count);
478*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
479*5e3eaea3SApple OSS Distributions 
480*5e3eaea3SApple OSS Distributions #if !defined(__arm64__)
481*5e3eaea3SApple OSS Distributions 	/*
482*5e3eaea3SApple OSS Distributions 	 * iOS does not have system_time.
483*5e3eaea3SApple OSS Distributions 	 */
484*5e3eaea3SApple OSS Distributions 	T_ASSERT_GT(power_info_data_v2_new.cpu_energy.total_user, power_info_data_v2.cpu_energy.total_user,
485*5e3eaea3SApple OSS Distributions 	    "task_info call returns valid user time");
486*5e3eaea3SApple OSS Distributions 	T_ASSERT_GT(power_info_data_v2_new.cpu_energy.total_system, power_info_data_v2.cpu_energy.total_system,
487*5e3eaea3SApple OSS Distributions 	    "task_info call returns valid system time");
488*5e3eaea3SApple OSS Distributions #endif
489*5e3eaea3SApple OSS Distributions 
490*5e3eaea3SApple OSS Distributions 	T_ASSERT_GE(power_info_data_v2.cpu_energy.task_interrupt_wakeups, 1ULL,
491*5e3eaea3SApple OSS Distributions 	    "verify task_info call returns non-zero value for interrupt_wakeup (ret value = %llu)",
492*5e3eaea3SApple OSS Distributions 	    power_info_data_v2.cpu_energy.task_interrupt_wakeups);
493*5e3eaea3SApple OSS Distributions 
494*5e3eaea3SApple OSS Distributions #if !defined(__arm64__)
495*5e3eaea3SApple OSS Distributions 	if (power_info_data_v2.cpu_energy.task_platform_idle_wakeups != 0) {
496*5e3eaea3SApple OSS Distributions 		T_LOG("task_info call returned %llu for platform_idle_wakeup", power_info_data_v2.cpu_energy.task_platform_idle_wakeups);
497*5e3eaea3SApple OSS Distributions 	}
498*5e3eaea3SApple OSS Distributions #endif
499*5e3eaea3SApple OSS Distributions 
500*5e3eaea3SApple OSS Distributions 	count = TASK_POWER_INFO_V2_COUNT_OLD;
501*5e3eaea3SApple OSS Distributions 	err   = task_info(mach_task_self(), TASK_POWER_INFO_V2, (task_info_t)&power_info_data_v2, &count);
502*5e3eaea3SApple OSS Distributions 
503*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(err, "verify task_info call succeeded");
504*5e3eaea3SApple OSS Distributions 
505*5e3eaea3SApple OSS Distributions 	/*
506*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
507*5e3eaea3SApple OSS Distributions 	 */
508*5e3eaea3SApple OSS Distributions 	count--;
509*5e3eaea3SApple OSS Distributions 	err = task_info(mach_task_self(), TASK_POWER_INFO_V2, (task_info_t)&power_info_data_v2, &count);
510*5e3eaea3SApple OSS Distributions 
511*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(err, KERN_INVALID_ARGUMENT,
512*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API. Call "
513*5e3eaea3SApple OSS Distributions 	    "returns errno %d:%s",
514*5e3eaea3SApple OSS Distributions 	    err, mach_error_string(err));
515*5e3eaea3SApple OSS Distributions }
516*5e3eaea3SApple OSS Distributions 
517*5e3eaea3SApple OSS Distributions T_DECL(test_task_basic_info_32, "tests TASK_BASIC_INFO_32", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
518*5e3eaea3SApple OSS Distributions {
519*5e3eaea3SApple OSS Distributions 	test_task_basic_info(INFO_32);
520*5e3eaea3SApple OSS Distributions }
521*5e3eaea3SApple OSS Distributions 
522*5e3eaea3SApple OSS Distributions T_DECL(test_task_basic_info_32_2, "tests TASK_BASIC_INFO_32_2", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
523*5e3eaea3SApple OSS Distributions {
524*5e3eaea3SApple OSS Distributions 	test_task_basic_info(INFO_32_2);
525*5e3eaea3SApple OSS Distributions }
526*5e3eaea3SApple OSS Distributions 
527*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
528*5e3eaea3SApple OSS Distributions T_DECL(test_task_basic_info_64i_2, "tests TASK_BASIC_INFO_64_2", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
529*5e3eaea3SApple OSS Distributions {
530*5e3eaea3SApple OSS Distributions 	test_task_basic_info(INFO_64_2);
531*5e3eaea3SApple OSS Distributions }
532*5e3eaea3SApple OSS Distributions #else
533*5e3eaea3SApple OSS Distributions T_DECL(test_task_basic_info_64, "tests TASK_BASIC_INFO_64", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
534*5e3eaea3SApple OSS Distributions {
535*5e3eaea3SApple OSS Distributions 	test_task_basic_info(INFO_64);
536*5e3eaea3SApple OSS Distributions }
537*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
538*5e3eaea3SApple OSS Distributions 
539*5e3eaea3SApple OSS Distributions T_DECL(test_mach_task_basic_info, "tests MACH_TASK_BASIC_INFO", T_META_ASROOT(true), T_META_LTEPHASE(LTE_POSTINIT))
540*5e3eaea3SApple OSS Distributions {
541*5e3eaea3SApple OSS Distributions 	test_task_basic_info(INFO_MACH);
542*5e3eaea3SApple OSS Distributions }
543*5e3eaea3SApple OSS Distributions 
544*5e3eaea3SApple OSS Distributions void
test_task_basic_info(enum info_kind kind)545*5e3eaea3SApple OSS Distributions test_task_basic_info(enum info_kind kind)
546*5e3eaea3SApple OSS Distributions {
547*5e3eaea3SApple OSS Distributions #define BEFORE 0
548*5e3eaea3SApple OSS Distributions #define AFTER 1
549*5e3eaea3SApple OSS Distributions 
550*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
551*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
552*5e3eaea3SApple OSS Distributions 	T_QUIET;
553*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
554*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
555*5e3eaea3SApple OSS Distributions 
556*5e3eaea3SApple OSS Distributions 	task_info_t info_data[2];
557*5e3eaea3SApple OSS Distributions 	task_basic_info_32_data_t basic_info_32_data[2];
558*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
559*5e3eaea3SApple OSS Distributions 	task_basic_info_64_2_data_t basic_info_64_2_data[2];
560*5e3eaea3SApple OSS Distributions #else
561*5e3eaea3SApple OSS Distributions 	task_basic_info_64_data_t basic_info_64_data[2];
562*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
563*5e3eaea3SApple OSS Distributions 	mach_task_basic_info_data_t mach_basic_info_data[2];
564*5e3eaea3SApple OSS Distributions 
565*5e3eaea3SApple OSS Distributions 	kern_return_t kr;
566*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count;
567*5e3eaea3SApple OSS Distributions 	task_flavor_t flavor = 0;
568*5e3eaea3SApple OSS Distributions 	integer_t suspend_count;
569*5e3eaea3SApple OSS Distributions 	uint64_t resident_size_diff;
570*5e3eaea3SApple OSS Distributions 	uint64_t virtual_size_diff;
571*5e3eaea3SApple OSS Distributions 
572*5e3eaea3SApple OSS Distributions 	void * tmp_map = NULL;
573*5e3eaea3SApple OSS Distributions 	pid_t child_pid;
574*5e3eaea3SApple OSS Distributions 	mach_port_name_t child_task;
575*5e3eaea3SApple OSS Distributions 	/*for dt_waitpid*/
576*5e3eaea3SApple OSS Distributions 	int timeout     = 10; // change to max timeout
577*5e3eaea3SApple OSS Distributions 	int exit_status = 0;
578*5e3eaea3SApple OSS Distributions 
579*5e3eaea3SApple OSS Distributions 	switch (kind) {
580*5e3eaea3SApple OSS Distributions 	case INFO_32:
581*5e3eaea3SApple OSS Distributions 	case INFO_32_2:
582*5e3eaea3SApple OSS Distributions 		info_data[BEFORE] = (task_info_t)&basic_info_32_data[BEFORE];
583*5e3eaea3SApple OSS Distributions 		info_data[AFTER]  = (task_info_t)&basic_info_32_data[AFTER];
584*5e3eaea3SApple OSS Distributions 		count             = TASK_BASIC_INFO_32_COUNT;
585*5e3eaea3SApple OSS Distributions 		flavor            = TASK_BASIC_INFO_32;
586*5e3eaea3SApple OSS Distributions 
587*5e3eaea3SApple OSS Distributions 		if (kind == INFO_32_2) {
588*5e3eaea3SApple OSS Distributions 			flavor = TASK_BASIC2_INFO_32;
589*5e3eaea3SApple OSS Distributions 		}
590*5e3eaea3SApple OSS Distributions 
591*5e3eaea3SApple OSS Distributions 		break;
592*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
593*5e3eaea3SApple OSS Distributions 	case INFO_64:
594*5e3eaea3SApple OSS Distributions 		T_ASSERT_FAIL("invalid basic info kind");
595*5e3eaea3SApple OSS Distributions 		break;
596*5e3eaea3SApple OSS Distributions 
597*5e3eaea3SApple OSS Distributions 	case INFO_64_2:
598*5e3eaea3SApple OSS Distributions 		info_data[BEFORE] = (task_info_t)&basic_info_64_2_data[BEFORE];
599*5e3eaea3SApple OSS Distributions 		info_data[AFTER]  = (task_info_t)&basic_info_64_2_data[AFTER];
600*5e3eaea3SApple OSS Distributions 		count             = TASK_BASIC_INFO_64_2_COUNT;
601*5e3eaea3SApple OSS Distributions 		flavor            = TASK_BASIC_INFO_64_2;
602*5e3eaea3SApple OSS Distributions 		break;
603*5e3eaea3SApple OSS Distributions 
604*5e3eaea3SApple OSS Distributions #else
605*5e3eaea3SApple OSS Distributions 	case INFO_64:
606*5e3eaea3SApple OSS Distributions 		info_data[BEFORE] = (task_info_t)&basic_info_64_data[BEFORE];
607*5e3eaea3SApple OSS Distributions 		info_data[AFTER]  = (task_info_t)&basic_info_64_data[AFTER];
608*5e3eaea3SApple OSS Distributions 		count             = TASK_BASIC_INFO_64_COUNT;
609*5e3eaea3SApple OSS Distributions 		flavor            = TASK_BASIC_INFO_64;
610*5e3eaea3SApple OSS Distributions 		break;
611*5e3eaea3SApple OSS Distributions 
612*5e3eaea3SApple OSS Distributions 	case INFO_64_2:
613*5e3eaea3SApple OSS Distributions 		T_ASSERT_FAIL("invalid basic info kind");
614*5e3eaea3SApple OSS Distributions 		break;
615*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
616*5e3eaea3SApple OSS Distributions 	case INFO_MACH:
617*5e3eaea3SApple OSS Distributions 		info_data[BEFORE] = (task_info_t)&mach_basic_info_data[BEFORE];
618*5e3eaea3SApple OSS Distributions 		info_data[AFTER]  = (task_info_t)&mach_basic_info_data[AFTER];
619*5e3eaea3SApple OSS Distributions 		count             = MACH_TASK_BASIC_INFO_COUNT;
620*5e3eaea3SApple OSS Distributions 		flavor            = MACH_TASK_BASIC_INFO;
621*5e3eaea3SApple OSS Distributions 		break;
622*5e3eaea3SApple OSS Distributions 	case INFO_MAX:
623*5e3eaea3SApple OSS Distributions 	default:
624*5e3eaea3SApple OSS Distributions 		T_ASSERT_FAIL("invalid basic info kind");
625*5e3eaea3SApple OSS Distributions 		break;
626*5e3eaea3SApple OSS Distributions 	}
627*5e3eaea3SApple OSS Distributions 
628*5e3eaea3SApple OSS Distributions 	kr = task_info(mach_task_self(), flavor, info_data[BEFORE], &count);
629*5e3eaea3SApple OSS Distributions 
630*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info succeeded");
631*5e3eaea3SApple OSS Distributions 
632*5e3eaea3SApple OSS Distributions 	do_factorial_task();
633*5e3eaea3SApple OSS Distributions 
634*5e3eaea3SApple OSS Distributions 	/*
635*5e3eaea3SApple OSS Distributions 	 * Allocate virtual and resident memory.
636*5e3eaea3SApple OSS Distributions 	 */
637*5e3eaea3SApple OSS Distributions 	tmp_map = mmap(0, PAGE_SIZE, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
638*5e3eaea3SApple OSS Distributions 
639*5e3eaea3SApple OSS Distributions 	T_WITH_ERRNO;
640*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(tmp_map, MAP_FAILED, "verify mmap call is successful");
641*5e3eaea3SApple OSS Distributions 
642*5e3eaea3SApple OSS Distributions 	memset(tmp_map, 'm', PAGE_SIZE);
643*5e3eaea3SApple OSS Distributions 
644*5e3eaea3SApple OSS Distributions 	child_pid = fork();
645*5e3eaea3SApple OSS Distributions 
646*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(child_pid, "verify process can be forked");
647*5e3eaea3SApple OSS Distributions 
648*5e3eaea3SApple OSS Distributions 	if (child_pid == 0) {
649*5e3eaea3SApple OSS Distributions 		/*
650*5e3eaea3SApple OSS Distributions 		 * This will suspend the child process.
651*5e3eaea3SApple OSS Distributions 		 */
652*5e3eaea3SApple OSS Distributions 		kr = task_suspend(mach_task_self());
653*5e3eaea3SApple OSS Distributions 		exit(kr);
654*5e3eaea3SApple OSS Distributions 	}
655*5e3eaea3SApple OSS Distributions 
656*5e3eaea3SApple OSS Distributions 	/*
657*5e3eaea3SApple OSS Distributions 	 * Wait for the child process to suspend itself.
658*5e3eaea3SApple OSS Distributions 	 */
659*5e3eaea3SApple OSS Distributions 	sleep(1);
660*5e3eaea3SApple OSS Distributions 
661*5e3eaea3SApple OSS Distributions 	kr = task_for_pid(mach_task_self(), child_pid, &child_task);
662*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_for_pid succeeded.  check sudo if failed");
663*5e3eaea3SApple OSS Distributions 
664*5e3eaea3SApple OSS Distributions 	/*
665*5e3eaea3SApple OSS Distributions 	 * Verify the suspend_count for child and resume it.
666*5e3eaea3SApple OSS Distributions 	 */
667*5e3eaea3SApple OSS Distributions 
668*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, flavor, info_data[AFTER], &count);
669*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
670*5e3eaea3SApple OSS Distributions 
671*5e3eaea3SApple OSS Distributions 	suspend_count = (integer_t)(info_get(kind, GET_SUSPEND_COUNT, info_data[AFTER]));
672*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(suspend_count, 1, "verify task_info shows correct suspend_count");
673*5e3eaea3SApple OSS Distributions 
674*5e3eaea3SApple OSS Distributions 	kr = task_resume(child_task);
675*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_resume succeeded");
676*5e3eaea3SApple OSS Distributions 
677*5e3eaea3SApple OSS Distributions 	/*
678*5e3eaea3SApple OSS Distributions 	 * reap kr from task_suspend call in child
679*5e3eaea3SApple OSS Distributions 	 */
680*5e3eaea3SApple OSS Distributions 	if (dt_waitpid(child_pid, &exit_status, NULL, timeout)) {
681*5e3eaea3SApple OSS Distributions 		T_ASSERT_MACH_SUCCESS(exit_status, "verify child task_suspend is successful");
682*5e3eaea3SApple OSS Distributions 	} else {
683*5e3eaea3SApple OSS Distributions 		T_FAIL("dt_waitpid failed");
684*5e3eaea3SApple OSS Distributions 	}
685*5e3eaea3SApple OSS Distributions 
686*5e3eaea3SApple OSS Distributions 	kr = task_info(mach_task_self(), flavor, info_data[AFTER], &count);
687*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
688*5e3eaea3SApple OSS Distributions 
689*5e3eaea3SApple OSS Distributions 	resident_size_diff = info_get(kind, GET_RESIDENT_SIZE, info_data[AFTER]) - info_get(kind, GET_RESIDENT_SIZE, info_data[BEFORE]);
690*5e3eaea3SApple OSS Distributions 	virtual_size_diff  = info_get(kind, GET_VIRTUAL_SIZE, info_data[AFTER]) - info_get(kind, GET_VIRTUAL_SIZE, info_data[BEFORE]);
691*5e3eaea3SApple OSS Distributions 
692*5e3eaea3SApple OSS Distributions 	/*
693*5e3eaea3SApple OSS Distributions 	 * INFO_32_2 gets the max resident size instead of the current resident size
694*5e3eaea3SApple OSS Distributions 	 * 32 KB tolerance built into test.  The returned value is generally between 0 and 16384
695*5e3eaea3SApple OSS Distributions 	 *
696*5e3eaea3SApple OSS Distributions 	 * max resident size is a discrete field in INFO_MACH, so it's handled differently
697*5e3eaea3SApple OSS Distributions 	 */
698*5e3eaea3SApple OSS Distributions 	if (kind == INFO_32_2) {
699*5e3eaea3SApple OSS Distributions 		T_EXPECT_EQ(resident_size_diff % 4096, 0ULL, "verify task_info returns valid max resident_size");
700*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(resident_size_diff, 0ULL, "verify task_info returns non-negative max resident_size");
701*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(virtual_size_diff, (unsigned long long)PAGE_SIZE, "verify task_info returns valid virtual_size");
702*5e3eaea3SApple OSS Distributions 	} else {
703*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(resident_size_diff, (unsigned long long)PAGE_SIZE, "task_info returns valid resident_size");
704*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(virtual_size_diff, (unsigned long long)PAGE_SIZE, "task_info returns valid virtual_size");
705*5e3eaea3SApple OSS Distributions 	}
706*5e3eaea3SApple OSS Distributions 
707*5e3eaea3SApple OSS Distributions 	if (kind == INFO_MACH) {
708*5e3eaea3SApple OSS Distributions 		resident_size_diff = info_get(kind, GET_MAX_RES, info_data[AFTER]) - info_get(kind, GET_MAX_RES, info_data[BEFORE]);
709*5e3eaea3SApple OSS Distributions 		T_EXPECT_EQ(resident_size_diff % 4096, 0ULL, "verify task_info returns valid max resident_size");
710*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(resident_size_diff, 0ULL, "verify task_info returns non-negative max resident_size");
711*5e3eaea3SApple OSS Distributions 		T_EXPECT_GE(info_get(kind, GET_MAX_RES, info_data[AFTER]), info_get(kind, GET_RESIDENT_SIZE, info_data[AFTER]),
712*5e3eaea3SApple OSS Distributions 		    "verify max resident size is greater than or equal to curr resident size");
713*5e3eaea3SApple OSS Distributions 	}
714*5e3eaea3SApple OSS Distributions 
715*5e3eaea3SApple OSS Distributions 	do_factorial_task();
716*5e3eaea3SApple OSS Distributions 
717*5e3eaea3SApple OSS Distributions 	/*
718*5e3eaea3SApple OSS Distributions 	 * These counters give time for threads that have terminated. We dont have any, so checking for zero.
719*5e3eaea3SApple OSS Distributions 	 */
720*5e3eaea3SApple OSS Distributions 
721*5e3eaea3SApple OSS Distributions 	time_value_t * user_tv = (time_value_t *)(info_get(kind, GET_USER_TIME, info_data[BEFORE]));
722*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ((user_tv->seconds + user_tv->microseconds / 1000000), 0, "verify task_info shows valid user time");
723*5e3eaea3SApple OSS Distributions 
724*5e3eaea3SApple OSS Distributions 	time_value_t * sys_tv = (time_value_t *)(info_get(kind, GET_SYS_TIME, info_data[BEFORE]));
725*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(sys_tv->seconds + (sys_tv->microseconds / 1000000), 0, "verify task_info shows valid system time");
726*5e3eaea3SApple OSS Distributions 
727*5e3eaea3SApple OSS Distributions 	/*
728*5e3eaea3SApple OSS Distributions 	 * The default value for non-kernel tasks is TIMESHARE.
729*5e3eaea3SApple OSS Distributions 	 */
730*5e3eaea3SApple OSS Distributions 
731*5e3eaea3SApple OSS Distributions 	policy_t pt = (policy_t)info_get(kind, GET_POLICY, info_data[BEFORE]);
732*5e3eaea3SApple OSS Distributions 
733*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(pt, POLICY_TIMESHARE, "verify task_info shows valid policy");
734*5e3eaea3SApple OSS Distributions 
735*5e3eaea3SApple OSS Distributions 	/*
736*5e3eaea3SApple OSS Distributions 	 * This is a negative case.
737*5e3eaea3SApple OSS Distributions 	 */
738*5e3eaea3SApple OSS Distributions 
739*5e3eaea3SApple OSS Distributions 	count--;
740*5e3eaea3SApple OSS Distributions 	kr = task_info(mach_task_self(), flavor, info_data[AFTER], &count);
741*5e3eaea3SApple OSS Distributions 
742*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_ERROR(kr, KERN_INVALID_ARGUMENT,
743*5e3eaea3SApple OSS Distributions 	    "Negative test case: task_info should verify that count is at least equal to what is defined in API");
744*5e3eaea3SApple OSS Distributions 
745*5e3eaea3SApple OSS Distributions 	/*
746*5e3eaea3SApple OSS Distributions 	 * deallocate memory
747*5e3eaea3SApple OSS Distributions 	 */
748*5e3eaea3SApple OSS Distributions 	munmap(tmp_map, PAGE_SIZE);
749*5e3eaea3SApple OSS Distributions 
750*5e3eaea3SApple OSS Distributions 	return;
751*5e3eaea3SApple OSS Distributions 
752*5e3eaea3SApple OSS Distributions #undef BEFORE
753*5e3eaea3SApple OSS Distributions #undef AFTER
754*5e3eaea3SApple OSS Distributions }
755*5e3eaea3SApple OSS Distributions 
756*5e3eaea3SApple OSS Distributions T_DECL(test_sigcont_task_suspend_resume,
757*5e3eaea3SApple OSS Distributions     "test to verify that SIGCONT on task_suspend()-ed process works",
758*5e3eaea3SApple OSS Distributions     T_META_ASROOT(true),
759*5e3eaea3SApple OSS Distributions     T_META_LTEPHASE(LTE_POSTINIT))
760*5e3eaea3SApple OSS Distributions {
761*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
762*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
763*5e3eaea3SApple OSS Distributions 	T_QUIET;
764*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
765*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
766*5e3eaea3SApple OSS Distributions 
767*5e3eaea3SApple OSS Distributions 	mach_task_basic_info_data_t mach_basic_info_data;
768*5e3eaea3SApple OSS Distributions 	task_info_t info_data = (task_info_t)&mach_basic_info_data;
769*5e3eaea3SApple OSS Distributions 
770*5e3eaea3SApple OSS Distributions 	task_debug_info_internal_data_t debug_info;
771*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t debug_count = TASK_DEBUG_INFO_INTERNAL_COUNT;
772*5e3eaea3SApple OSS Distributions 
773*5e3eaea3SApple OSS Distributions 	kern_return_t kr;
774*5e3eaea3SApple OSS Distributions 	int posix_ret;
775*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
776*5e3eaea3SApple OSS Distributions 	task_flavor_t flavor         = MACH_TASK_BASIC_INFO;
777*5e3eaea3SApple OSS Distributions 	integer_t suspend_count;
778*5e3eaea3SApple OSS Distributions 	integer_t debug_suspend_count;
779*5e3eaea3SApple OSS Distributions 	pid_t child_pid = 0;
780*5e3eaea3SApple OSS Distributions 	mach_port_name_t child_task;
781*5e3eaea3SApple OSS Distributions 	/*for dt_waitpid*/
782*5e3eaea3SApple OSS Distributions 	int timeout     = 5;
783*5e3eaea3SApple OSS Distributions 	int exit_status = 0;
784*5e3eaea3SApple OSS Distributions 	int signal_no   = 0;
785*5e3eaea3SApple OSS Distributions 
786*5e3eaea3SApple OSS Distributions 	child_pid = fork();
787*5e3eaea3SApple OSS Distributions 
788*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(child_pid, "verify process can be forked");
789*5e3eaea3SApple OSS Distributions 
790*5e3eaea3SApple OSS Distributions 	if (child_pid == 0) {
791*5e3eaea3SApple OSS Distributions 		/*
792*5e3eaea3SApple OSS Distributions 		 * This will suspend the child process.
793*5e3eaea3SApple OSS Distributions 		 */
794*5e3eaea3SApple OSS Distributions 		kr = task_suspend(mach_task_self());
795*5e3eaea3SApple OSS Distributions 
796*5e3eaea3SApple OSS Distributions 		/*
797*5e3eaea3SApple OSS Distributions 		 * When child resumes, it exits immediately
798*5e3eaea3SApple OSS Distributions 		 */
799*5e3eaea3SApple OSS Distributions 
800*5e3eaea3SApple OSS Distributions 		exit(kr);
801*5e3eaea3SApple OSS Distributions 	}
802*5e3eaea3SApple OSS Distributions 
803*5e3eaea3SApple OSS Distributions 	/*
804*5e3eaea3SApple OSS Distributions 	 * Wait for the child process to suspend itself.
805*5e3eaea3SApple OSS Distributions 	 */
806*5e3eaea3SApple OSS Distributions 	sleep(1);
807*5e3eaea3SApple OSS Distributions 
808*5e3eaea3SApple OSS Distributions 	kr = task_for_pid(mach_task_self(), child_pid, &child_task);
809*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_for_pid succeeded.  check sudo if failed");
810*5e3eaea3SApple OSS Distributions 
811*5e3eaea3SApple OSS Distributions 	/*
812*5e3eaea3SApple OSS Distributions 	 * Verify the suspend_count for child and resume it.
813*5e3eaea3SApple OSS Distributions 	 */
814*5e3eaea3SApple OSS Distributions 
815*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, flavor, info_data, &count);
816*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
817*5e3eaea3SApple OSS Distributions 
818*5e3eaea3SApple OSS Distributions 	suspend_count = (integer_t)(info_get(INFO_MACH, GET_SUSPEND_COUNT, info_data));
819*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(suspend_count, 1, "verify task_info shows correct suspend_count (1) (actually user stop count) ");
820*5e3eaea3SApple OSS Distributions 
821*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, TASK_DEBUG_INFO_INTERNAL, (task_info_t)&debug_info, &debug_count);
822*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
823*5e3eaea3SApple OSS Distributions 
824*5e3eaea3SApple OSS Distributions 	debug_suspend_count = debug_info.suspend_count;
825*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(debug_info.suspend_count, 1, "verify debug_info shows correct suspend_count(1)");
826*5e3eaea3SApple OSS Distributions 
827*5e3eaea3SApple OSS Distributions 	posix_ret = kill(child_pid, SIGCONT);
828*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_ret, "verify signal call succeeded");
829*5e3eaea3SApple OSS Distributions 
830*5e3eaea3SApple OSS Distributions 	/*
831*5e3eaea3SApple OSS Distributions 	 * reap kr from task_suspend call in child
832*5e3eaea3SApple OSS Distributions 	 */
833*5e3eaea3SApple OSS Distributions 	dt_waitpid(child_pid, &exit_status, &signal_no, timeout);
834*5e3eaea3SApple OSS Distributions 
835*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(signal_no, 0, "child should be resumed and exit without signal");
836*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(exit_status, 0, "child should exit with 0");
837*5e3eaea3SApple OSS Distributions }
838*5e3eaea3SApple OSS Distributions 
839*5e3eaea3SApple OSS Distributions T_DECL(test_sigcont_task_suspend2_resume,
840*5e3eaea3SApple OSS Distributions     "test to verify that SIGCONT on task_suspend2()-ed process doesn't work",
841*5e3eaea3SApple OSS Distributions     T_META_ASROOT(true),
842*5e3eaea3SApple OSS Distributions     T_META_LTEPHASE(LTE_POSTINIT))
843*5e3eaea3SApple OSS Distributions {
844*5e3eaea3SApple OSS Distributions 	T_SETUPBEGIN;
845*5e3eaea3SApple OSS Distributions 	int is_dev = is_development_kernel();
846*5e3eaea3SApple OSS Distributions 	T_QUIET;
847*5e3eaea3SApple OSS Distributions 	T_ASSERT_TRUE(is_dev, "verify development kernel is running");
848*5e3eaea3SApple OSS Distributions 	T_SETUPEND;
849*5e3eaea3SApple OSS Distributions 
850*5e3eaea3SApple OSS Distributions 	mach_task_basic_info_data_t mach_basic_info_data;
851*5e3eaea3SApple OSS Distributions 	task_info_t info_data = (task_info_t)&mach_basic_info_data;
852*5e3eaea3SApple OSS Distributions 
853*5e3eaea3SApple OSS Distributions 	task_debug_info_internal_data_t debug_info;
854*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t debug_count = TASK_DEBUG_INFO_INTERNAL_COUNT;
855*5e3eaea3SApple OSS Distributions 
856*5e3eaea3SApple OSS Distributions 	kern_return_t kr;
857*5e3eaea3SApple OSS Distributions 	int posix_ret;
858*5e3eaea3SApple OSS Distributions 	mach_msg_type_number_t count  = MACH_TASK_BASIC_INFO_COUNT;
859*5e3eaea3SApple OSS Distributions 	task_flavor_t flavor          = MACH_TASK_BASIC_INFO;
860*5e3eaea3SApple OSS Distributions 	integer_t suspend_count       = 0;
861*5e3eaea3SApple OSS Distributions 	integer_t debug_suspend_count = 0;
862*5e3eaea3SApple OSS Distributions 	pid_t child_pid               = 0;
863*5e3eaea3SApple OSS Distributions 	mach_port_name_t child_task;
864*5e3eaea3SApple OSS Distributions 	task_suspension_token_t child_token = 0xFFFFF;
865*5e3eaea3SApple OSS Distributions 
866*5e3eaea3SApple OSS Distributions 	/*
867*5e3eaea3SApple OSS Distributions 	 * for dt_waitpid
868*5e3eaea3SApple OSS Distributions 	 * We expect the test to fail right now, so I've set timeout to
869*5e3eaea3SApple OSS Distributions 	 * be shorter than we may want it to be when the issue is fixed
870*5e3eaea3SApple OSS Distributions 	 */
871*5e3eaea3SApple OSS Distributions 	int timeout     = 1;
872*5e3eaea3SApple OSS Distributions 	int exit_status = 0;
873*5e3eaea3SApple OSS Distributions 	int signal_no   = 0;
874*5e3eaea3SApple OSS Distributions 
875*5e3eaea3SApple OSS Distributions 	/* for pipe */
876*5e3eaea3SApple OSS Distributions 	int fd[2];
877*5e3eaea3SApple OSS Distributions 	pipe(fd);
878*5e3eaea3SApple OSS Distributions 	int pipe_msg = 0;
879*5e3eaea3SApple OSS Distributions 
880*5e3eaea3SApple OSS Distributions 	child_pid = fork();
881*5e3eaea3SApple OSS Distributions 
882*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(child_pid, "verify process can be forked %d", child_pid);
883*5e3eaea3SApple OSS Distributions 
884*5e3eaea3SApple OSS Distributions 	if (child_pid == 0) {
885*5e3eaea3SApple OSS Distributions 		close(fd[1]);
886*5e3eaea3SApple OSS Distributions 		T_LOG("Waiting to read from parent...");
887*5e3eaea3SApple OSS Distributions 		read(fd[0], &pipe_msg, sizeof(pipe_msg));
888*5e3eaea3SApple OSS Distributions 		T_LOG("Done reading from parent, about to exit...");
889*5e3eaea3SApple OSS Distributions 		exit(0);
890*5e3eaea3SApple OSS Distributions 	}
891*5e3eaea3SApple OSS Distributions 	/*
892*5e3eaea3SApple OSS Distributions 	 * Wait for child to fork and block on read
893*5e3eaea3SApple OSS Distributions 	 */
894*5e3eaea3SApple OSS Distributions 	sleep(1);
895*5e3eaea3SApple OSS Distributions 
896*5e3eaea3SApple OSS Distributions 	close(fd[0]);
897*5e3eaea3SApple OSS Distributions 
898*5e3eaea3SApple OSS Distributions 	kr = task_for_pid(mach_task_self(), child_pid, &child_task);
899*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_for_pid succeeded.  check sudo if failed");
900*5e3eaea3SApple OSS Distributions 
901*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, TASK_DEBUG_INFO_INTERNAL, (task_info_t)&debug_info, &debug_count);
902*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
903*5e3eaea3SApple OSS Distributions 
904*5e3eaea3SApple OSS Distributions 	debug_suspend_count = debug_info.suspend_count;
905*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(debug_suspend_count, 0, "verify debug_info shows correct (true) suspend_count(0)");
906*5e3eaea3SApple OSS Distributions 
907*5e3eaea3SApple OSS Distributions 	kr = task_suspend2(child_task, &child_token);
908*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_suspend2 call succeeded");
909*5e3eaea3SApple OSS Distributions 
910*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, TASK_DEBUG_INFO_INTERNAL, (task_info_t)&debug_info, &debug_count);
911*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
912*5e3eaea3SApple OSS Distributions 
913*5e3eaea3SApple OSS Distributions 	debug_suspend_count = debug_info.suspend_count;
914*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(debug_suspend_count, 1, "verify debug_info shows correct (true) suspend_count(1)");
915*5e3eaea3SApple OSS Distributions 
916*5e3eaea3SApple OSS Distributions 	/*
917*5e3eaea3SApple OSS Distributions 	 * Verify the suspend_count for child and resume it.
918*5e3eaea3SApple OSS Distributions 	 */
919*5e3eaea3SApple OSS Distributions 
920*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, flavor, info_data, &count);
921*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_info call succeeded");
922*5e3eaea3SApple OSS Distributions 
923*5e3eaea3SApple OSS Distributions 	suspend_count = (integer_t)(info_get(INFO_MACH, GET_SUSPEND_COUNT, info_data));
924*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(suspend_count, 1, "verify task_info shows correct (user_stop_count) suspend_count (1)");
925*5e3eaea3SApple OSS Distributions 
926*5e3eaea3SApple OSS Distributions 	posix_ret = kill(child_pid, SIGCONT);
927*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_ret, "verify signal call succeeded");
928*5e3eaea3SApple OSS Distributions 
929*5e3eaea3SApple OSS Distributions 	kr = task_info(child_task, TASK_DEBUG_INFO_INTERNAL, (task_info_t)&debug_info, &debug_count);
930*5e3eaea3SApple OSS Distributions 	T_EXPECT_MACH_SUCCESS(kr, "verify task_info call succeeded");
931*5e3eaea3SApple OSS Distributions 
932*5e3eaea3SApple OSS Distributions 	debug_suspend_count = debug_info.suspend_count;
933*5e3eaea3SApple OSS Distributions 	T_EXPECTFAIL_WITH_RADAR(33166654);
934*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ(debug_suspend_count, 1, "verify debug_info shows correct (true) suspend_count (1)");
935*5e3eaea3SApple OSS Distributions 
936*5e3eaea3SApple OSS Distributions 	suspend_count = (integer_t)(info_get(INFO_MACH, GET_SUSPEND_COUNT, info_data));
937*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(suspend_count, 1, "verify task_info shows correct (user_stop_count) suspend_count (1) after SIG_CONT");
938*5e3eaea3SApple OSS Distributions 
939*5e3eaea3SApple OSS Distributions 	kr = task_resume(child_task);
940*5e3eaea3SApple OSS Distributions 	T_EXPECTFAIL_WITH_RADAR(33166654);
941*5e3eaea3SApple OSS Distributions 	T_EXPECT_MACH_SUCCESS(kr, "verify task_resume succeeded");
942*5e3eaea3SApple OSS Distributions 
943*5e3eaea3SApple OSS Distributions 	/*
944*5e3eaea3SApple OSS Distributions 	 * reap kr from task_suspend call in child
945*5e3eaea3SApple OSS Distributions 	 */
946*5e3eaea3SApple OSS Distributions 
947*5e3eaea3SApple OSS Distributions 	dt_waitpid(child_pid, &exit_status, &signal_no, timeout);
948*5e3eaea3SApple OSS Distributions 
949*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(signal_no, SIG_DT_TIMEOUT, "dt_waitpid timed out as expected");
950*5e3eaea3SApple OSS Distributions 
951*5e3eaea3SApple OSS Distributions 	// Resume properly using token and then wait
952*5e3eaea3SApple OSS Distributions 
953*5e3eaea3SApple OSS Distributions 	kr = task_resume2(child_token);
954*5e3eaea3SApple OSS Distributions 	T_EXPECTFAIL_WITH_RADAR(33166654);
955*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(kr, "verify task_resume2 succeeded");
956*5e3eaea3SApple OSS Distributions 
957*5e3eaea3SApple OSS Distributions 	write(fd[1], &pipe_msg, sizeof(pipe_msg));
958*5e3eaea3SApple OSS Distributions 
959*5e3eaea3SApple OSS Distributions 	/*
960*5e3eaea3SApple OSS Distributions 	 * reap kr from task_suspend call in child
961*5e3eaea3SApple OSS Distributions 	 */
962*5e3eaea3SApple OSS Distributions 	dt_waitpid(child_pid, &exit_status, &signal_no, timeout);
963*5e3eaea3SApple OSS Distributions 
964*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(signal_no, 0, "child should be resumed and no signal should be returned");
965*5e3eaea3SApple OSS Distributions 	T_ASSERT_EQ(exit_status, 0, "child should exit with 0");
966*5e3eaea3SApple OSS Distributions }
967*5e3eaea3SApple OSS Distributions 
968*5e3eaea3SApple OSS Distributions uint64_t
info_get(enum info_kind kind,enum info_get get,void * data)969*5e3eaea3SApple OSS Distributions info_get(enum info_kind kind, enum info_get get, void * data)
970*5e3eaea3SApple OSS Distributions {
971*5e3eaea3SApple OSS Distributions 	switch (get) {
972*5e3eaea3SApple OSS Distributions 	case GET_SUSPEND_COUNT:
973*5e3eaea3SApple OSS Distributions 		switch (kind) {
974*5e3eaea3SApple OSS Distributions 		case INFO_32:
975*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
976*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_32_t)data)->suspend_count);
977*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
978*5e3eaea3SApple OSS Distributions 		case INFO_64:
979*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
980*5e3eaea3SApple OSS Distributions 			break;
981*5e3eaea3SApple OSS Distributions 
982*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
983*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_2_t)data)->suspend_count);
984*5e3eaea3SApple OSS Distributions #else
985*5e3eaea3SApple OSS Distributions 		case INFO_64:
986*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_t)data)->suspend_count);
987*5e3eaea3SApple OSS Distributions 
988*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
989*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
990*5e3eaea3SApple OSS Distributions 			break;
991*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
992*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
993*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((mach_task_basic_info_t)data)->suspend_count);
994*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
995*5e3eaea3SApple OSS Distributions 		default:
996*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
997*5e3eaea3SApple OSS Distributions 		}
998*5e3eaea3SApple OSS Distributions 	case GET_RESIDENT_SIZE:
999*5e3eaea3SApple OSS Distributions 		switch (kind) {
1000*5e3eaea3SApple OSS Distributions 		case INFO_32:
1001*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1002*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_32_t)data)->resident_size);
1003*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
1004*5e3eaea3SApple OSS Distributions 		case INFO_64:
1005*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1006*5e3eaea3SApple OSS Distributions 			break;
1007*5e3eaea3SApple OSS Distributions 
1008*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1009*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_2_t)data)->resident_size);
1010*5e3eaea3SApple OSS Distributions #else
1011*5e3eaea3SApple OSS Distributions 		case INFO_64:
1012*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_t)data)->resident_size);
1013*5e3eaea3SApple OSS Distributions 
1014*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1015*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1016*5e3eaea3SApple OSS Distributions 			break;
1017*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
1018*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1019*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((mach_task_basic_info_t)data)->resident_size);
1020*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1021*5e3eaea3SApple OSS Distributions 		default:
1022*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1023*5e3eaea3SApple OSS Distributions 		}
1024*5e3eaea3SApple OSS Distributions 	case GET_VIRTUAL_SIZE:
1025*5e3eaea3SApple OSS Distributions 		switch (kind) {
1026*5e3eaea3SApple OSS Distributions 		case INFO_32:
1027*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1028*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_32_t)data)->virtual_size);
1029*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
1030*5e3eaea3SApple OSS Distributions 		case INFO_64:
1031*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1032*5e3eaea3SApple OSS Distributions 			break;
1033*5e3eaea3SApple OSS Distributions 
1034*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1035*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_2_t)data)->virtual_size);
1036*5e3eaea3SApple OSS Distributions #else
1037*5e3eaea3SApple OSS Distributions 		case INFO_64:
1038*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_t)data)->virtual_size);
1039*5e3eaea3SApple OSS Distributions 
1040*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1041*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1042*5e3eaea3SApple OSS Distributions 			break;
1043*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
1044*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1045*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((mach_task_basic_info_t)data)->virtual_size);
1046*5e3eaea3SApple OSS Distributions 
1047*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1048*5e3eaea3SApple OSS Distributions 		default:
1049*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1050*5e3eaea3SApple OSS Distributions 		}
1051*5e3eaea3SApple OSS Distributions 	case GET_USER_TIME:
1052*5e3eaea3SApple OSS Distributions 		switch (kind) {
1053*5e3eaea3SApple OSS Distributions 		case INFO_32:
1054*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1055*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_32_t)data)->user_time);
1056*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
1057*5e3eaea3SApple OSS Distributions 		case INFO_64:
1058*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1059*5e3eaea3SApple OSS Distributions 			break;
1060*5e3eaea3SApple OSS Distributions 
1061*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1062*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_64_2_t)data)->user_time);
1063*5e3eaea3SApple OSS Distributions #else
1064*5e3eaea3SApple OSS Distributions 		case INFO_64:
1065*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_64_t)data)->user_time);
1066*5e3eaea3SApple OSS Distributions 
1067*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1068*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1069*5e3eaea3SApple OSS Distributions 			break;
1070*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
1071*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1072*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((mach_task_basic_info_t)data)->user_time);
1073*5e3eaea3SApple OSS Distributions 
1074*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1075*5e3eaea3SApple OSS Distributions 		default:
1076*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1077*5e3eaea3SApple OSS Distributions 		}
1078*5e3eaea3SApple OSS Distributions 	case GET_SYS_TIME:
1079*5e3eaea3SApple OSS Distributions 		switch (kind) {
1080*5e3eaea3SApple OSS Distributions 		case INFO_32:
1081*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1082*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_32_t)data)->system_time);
1083*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
1084*5e3eaea3SApple OSS Distributions 		case INFO_64:
1085*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1086*5e3eaea3SApple OSS Distributions 			break;
1087*5e3eaea3SApple OSS Distributions 
1088*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1089*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_64_2_t)data)->system_time);
1090*5e3eaea3SApple OSS Distributions #else
1091*5e3eaea3SApple OSS Distributions 		case INFO_64:
1092*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((task_basic_info_64_t)data)->system_time);
1093*5e3eaea3SApple OSS Distributions 
1094*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1095*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1096*5e3eaea3SApple OSS Distributions 			break;
1097*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
1098*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1099*5e3eaea3SApple OSS Distributions 			return (uint64_t) &(((mach_task_basic_info_t)data)->user_time);
1100*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1101*5e3eaea3SApple OSS Distributions 		default:
1102*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1103*5e3eaea3SApple OSS Distributions 		}
1104*5e3eaea3SApple OSS Distributions 	case GET_POLICY:
1105*5e3eaea3SApple OSS Distributions 		switch (kind) {
1106*5e3eaea3SApple OSS Distributions 		case INFO_32:
1107*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1108*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_32_t)data)->policy);
1109*5e3eaea3SApple OSS Distributions #if defined(__arm64__)
1110*5e3eaea3SApple OSS Distributions 		case INFO_64:
1111*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1112*5e3eaea3SApple OSS Distributions 			break;
1113*5e3eaea3SApple OSS Distributions 
1114*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1115*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_2_t)data)->policy);
1116*5e3eaea3SApple OSS Distributions #else
1117*5e3eaea3SApple OSS Distributions 		case INFO_64:
1118*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((task_basic_info_64_t)data)->policy);
1119*5e3eaea3SApple OSS Distributions 
1120*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1121*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1122*5e3eaea3SApple OSS Distributions 			break;
1123*5e3eaea3SApple OSS Distributions #endif /* defined(__arm64__) */
1124*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1125*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((mach_task_basic_info_t)data)->policy);
1126*5e3eaea3SApple OSS Distributions 
1127*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1128*5e3eaea3SApple OSS Distributions 		default:
1129*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1130*5e3eaea3SApple OSS Distributions 		}
1131*5e3eaea3SApple OSS Distributions 	case GET_MAX_RES:
1132*5e3eaea3SApple OSS Distributions 		switch (kind) {
1133*5e3eaea3SApple OSS Distributions 		case INFO_32:
1134*5e3eaea3SApple OSS Distributions 		case INFO_32_2:
1135*5e3eaea3SApple OSS Distributions 		case INFO_64:
1136*5e3eaea3SApple OSS Distributions 		case INFO_64_2:
1137*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("illegal info_get %d %d", kind, get);
1138*5e3eaea3SApple OSS Distributions 		case INFO_MACH:
1139*5e3eaea3SApple OSS Distributions 			return (uint64_t)(((mach_task_basic_info_t)data)->resident_size_max);
1140*5e3eaea3SApple OSS Distributions 		case INFO_MAX:
1141*5e3eaea3SApple OSS Distributions 		default:
1142*5e3eaea3SApple OSS Distributions 			T_ASSERT_FAIL("unhandled info_get %d %d", kind, get);
1143*5e3eaea3SApple OSS Distributions 		}
1144*5e3eaea3SApple OSS Distributions 	}
1145*5e3eaea3SApple OSS Distributions 
1146*5e3eaea3SApple OSS Distributions 	__builtin_unreachable();
1147*5e3eaea3SApple OSS Distributions }
1148