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