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