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