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