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