]> git.saurik.com Git - apple/xnu.git/blob - tests/task_policy.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / task_policy.c
1 #include <darwintest.h>
2 #include <signal.h>
3 #include <spawn.h>
4 #include <unistd.h>
5
6 #include <mach/mach.h>
7 #include <mach/mach_types.h>
8 #include <mach/task.h>
9 #include <mach/task_policy.h>
10
11 extern char **environ;
12
13 int task_inspect_for_pid(mach_port_name_t target_tport, int pid, mach_port_name_t *t);
14 int task_for_pid(mach_port_name_t target_tport, int pid, mach_port_name_t *t);
15 int task_name_for_pid(mach_port_name_t target_tport, int pid, mach_port_name_t *t);
16
17 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
18
19 #if defined(UNENTITLED)
20
21 T_DECL(task_policy_set_task_name, "task_policy_set with task name (not entitled)")
22 {
23 struct task_qos_policy qosinfo = {
24 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
25 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
26 };
27 task_name_t task_name = TASK_NAME_NULL;
28
29 T_SETUPBEGIN;
30 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), getpid(),
31 &task_name), NULL);
32 T_SETUPEND;
33
34 T_ASSERT_MACH_ERROR(task_policy_set(task_name,
35 TASK_BASE_QOS_POLICY,
36 (task_policy_t)&qosinfo,
37 TASK_QOS_POLICY_COUNT),
38 KERN_INVALID_ARGUMENT, NULL);
39 }
40
41 T_DECL(task_policy_set_task, "task_policy_set with task (not entitled)")
42 {
43 struct task_qos_policy qosinfo = {
44 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
45 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
46 };
47
48 T_ASSERT_MACH_SUCCESS(task_policy_set(mach_task_self(),
49 TASK_BASE_QOS_POLICY,
50 (task_policy_t)&qosinfo,
51 TASK_QOS_POLICY_COUNT),
52 NULL);
53 }
54
55 T_DECL(task_policy_set_inspect, "task_policy_set with task inspect (not entitled)")
56 {
57 struct task_qos_policy qosinfo = {
58 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
59 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
60 };
61 task_inspect_t task_inspect = TASK_INSPECT_NULL;
62
63 T_SETUPBEGIN;
64 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), getpid(),
65 &task_inspect), NULL);
66 T_SETUPEND;
67
68
69 T_ASSERT_MACH_ERROR(task_policy_set(task_inspect,
70 TASK_BASE_QOS_POLICY,
71 (task_policy_t)&qosinfo,
72 TASK_QOS_POLICY_COUNT),
73 KERN_INVALID_ARGUMENT, NULL);
74 }
75
76 T_DECL(task_policy_set_foreign_task, "task_policy_set for foreign task (not entitled)", T_META_ASROOT(true))
77 {
78 struct task_qos_policy qosinfo = {
79 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
80 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
81 };
82 task_t task = TASK_NULL;
83 kern_return_t ret = KERN_FAILURE;
84 char *args[] = { "sleep", "10", NULL };
85 pid_t pid = 0;
86
87 T_SETUPBEGIN;
88
89 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
90 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
91
92 T_ASSERT_MACH_SUCCESS(task_for_pid(mach_task_self(), pid,
93 &task), NULL);
94 T_SETUPEND;
95
96 T_ASSERT_MACH_SUCCESS(task_policy_set(task,
97 TASK_BASE_QOS_POLICY,
98 (task_policy_t)&qosinfo,
99 TASK_QOS_POLICY_COUNT),
100 NULL);
101
102 ret = kill(pid, SIGTERM);
103 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
104 }
105
106 T_DECL(task_policy_set_foreign_task_name, "task_policy_set for foreign task name (not entitled)", T_META_ASROOT(true))
107 {
108 struct task_qos_policy qosinfo = {
109 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
110 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
111 };
112 task_name_t task_name = TASK_NAME_NULL;
113 kern_return_t ret = KERN_FAILURE;
114 char *args[] = { "sleep", "10", NULL };
115 pid_t pid = 0;
116
117 T_SETUPBEGIN;
118
119 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
120 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
121
122 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), pid,
123 &task_name), NULL);
124 T_SETUPEND;
125
126 T_ASSERT_MACH_ERROR(task_policy_set(task_name,
127 TASK_BASE_QOS_POLICY,
128 (task_policy_t)&qosinfo,
129 TASK_QOS_POLICY_COUNT),
130 KERN_INVALID_ARGUMENT, NULL);
131
132 ret = kill(pid, SIGTERM);
133 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
134 }
135
136 T_DECL(task_policy_set_foreign_task_inspect, "task_policy_set for foreign task inspect (not entitled)", T_META_ASROOT(true))
137 {
138 struct task_qos_policy qosinfo = {
139 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
140 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
141 };
142 task_inspect_t task_inspect = TASK_INSPECT_NULL;
143 kern_return_t ret = KERN_FAILURE;
144 char *args[] = { "sleep", "10", NULL };
145 pid_t pid = 0;
146
147 T_SETUPBEGIN;
148
149 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
150 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
151
152 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), pid,
153 &task_inspect), NULL);
154 T_SETUPEND;
155
156 T_ASSERT_MACH_ERROR(task_policy_set(task_inspect,
157 TASK_BASE_QOS_POLICY,
158 (task_policy_t)&qosinfo,
159 TASK_QOS_POLICY_COUNT),
160 KERN_INVALID_ARGUMENT, NULL);
161
162 ret = kill(pid, SIGTERM);
163 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
164 }
165
166 T_DECL(task_policy_get_name, "task_policy_get with task name (not entitled)")
167 {
168 task_name_t task_name = TASK_NAME_NULL;
169 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
170 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
171 boolean_t get_default = FALSE;
172
173 T_SETUPBEGIN;
174 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), getpid(),
175 &task_name), NULL);
176 T_SETUPEND;
177
178 T_ASSERT_MACH_ERROR(task_policy_get(task_name,
179 TASK_CATEGORY_POLICY,
180 (task_policy_t)role,
181 &count,
182 &get_default),
183 KERN_INVALID_ARGUMENT, NULL);
184 }
185
186 T_DECL(task_policy_get_task, "task_policy_get with task (not entitled)")
187 {
188 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
189 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
190 boolean_t get_default = FALSE;
191
192 T_ASSERT_MACH_SUCCESS(task_policy_get(mach_task_self(),
193 TASK_CATEGORY_POLICY,
194 (task_policy_t)role,
195 &count,
196 &get_default),
197 NULL);
198 }
199
200 T_DECL(task_policy_get_inspect, "task_policy_get with task inspect (not entitled)")
201 {
202 task_inspect_t task_inspect = TASK_INSPECT_NULL;
203 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
204 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
205 boolean_t get_default = FALSE;
206
207 T_SETUPBEGIN;
208 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), getpid(),
209 &task_inspect), NULL);
210 T_SETUPEND;
211
212 T_ASSERT_MACH_SUCCESS(task_policy_get(task_inspect,
213 TASK_CATEGORY_POLICY,
214 (task_policy_t)role,
215 &count,
216 &get_default),
217 NULL);
218 }
219
220 T_DECL(task_policy_get_foreign_task_inspect, "task_policy_get for foreign task inspect (not entitled)", T_META_ASROOT(true))
221 {
222 task_inspect_t task_inspect = TASK_INSPECT_NULL;
223 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
224 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
225 boolean_t get_default = FALSE;
226 kern_return_t ret = KERN_FAILURE;
227 char *args[] = { "sleep", "10", NULL };
228 pid_t pid = 0;
229
230 T_SETUPBEGIN;
231
232 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
233 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
234
235 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), pid,
236 &task_inspect), NULL);
237 T_SETUPEND;
238
239 T_ASSERT_MACH_SUCCESS(task_policy_get(task_inspect,
240 TASK_CATEGORY_POLICY,
241 (task_policy_t)role,
242 &count,
243 &get_default),
244 NULL);
245
246 ret = kill(pid, SIGTERM);
247 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
248 }
249
250 T_DECL(task_policy_get_foreign_task, "task_policy_get for foreign task (not entitled)", T_META_ASROOT(true))
251 {
252 task_t task = TASK_NULL;
253 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
254 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
255 boolean_t get_default = FALSE;
256 kern_return_t ret = KERN_FAILURE;
257 char *args[] = { "sleep", "10", NULL };
258 pid_t pid = 0;
259
260 T_SETUPBEGIN;
261
262 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
263 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
264
265 T_ASSERT_MACH_SUCCESS(task_for_pid(mach_task_self(), pid,
266 &task), NULL);
267 T_SETUPEND;
268
269 T_ASSERT_MACH_SUCCESS(task_policy_get(task,
270 TASK_CATEGORY_POLICY,
271 (task_policy_t)role,
272 &count,
273 &get_default),
274 NULL);
275
276 ret = kill(pid, SIGTERM);
277 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
278 }
279
280 T_DECL(task_policy_get_foreign_task_name, "task_policy_get for foreign task name (not entitled)")
281 {
282 task_name_t task_name = TASK_NAME_NULL;
283 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
284 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
285 boolean_t get_default = FALSE;
286 kern_return_t ret = KERN_FAILURE;
287 char *args[] = { "sleep", "10", NULL };
288 pid_t pid = 0;
289
290 T_SETUPBEGIN;
291
292 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
293 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
294
295 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), pid,
296 &task_name), NULL);
297 T_SETUPEND;
298
299 T_ASSERT_MACH_ERROR(task_policy_get(task_name,
300 TASK_CATEGORY_POLICY,
301 (task_policy_t)role,
302 &count,
303 &get_default),
304 KERN_INVALID_ARGUMENT, NULL);
305
306 ret = kill(pid, SIGTERM);
307 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
308 }
309
310 #else /* ENTITLED */
311
312 T_DECL(task_policy_set_task_name_entitled, "task_policy_set with task name (entitled)", T_META_ASROOT(true), T_META_ASROOT(true))
313 {
314 struct task_qos_policy qosinfo = {
315 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
316 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
317 };
318 task_name_t task_name = TASK_NAME_NULL;
319
320 T_SETUPBEGIN;
321 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), getpid(),
322 &task_name), NULL);
323 T_SETUPEND;
324
325 T_ASSERT_MACH_SUCCESS(task_policy_set(task_name,
326 TASK_BASE_QOS_POLICY,
327 (task_policy_t)&qosinfo,
328 TASK_QOS_POLICY_COUNT),
329 NULL);
330 }
331
332 T_DECL(task_policy_set_task_entitled, "task_policy_set with task (entitled)")
333 {
334 struct task_qos_policy qosinfo = {
335 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
336 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
337 };
338
339 T_ASSERT_MACH_SUCCESS(task_policy_set(mach_task_self(),
340 TASK_BASE_QOS_POLICY,
341 (task_policy_t)&qosinfo,
342 TASK_QOS_POLICY_COUNT),
343 NULL);
344 }
345
346 T_DECL(task_policy_set_inspect_entitled, "task_policy_set with task inspect (entitled)")
347 {
348 struct task_qos_policy qosinfo = {
349 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
350 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
351 };
352 task_inspect_t task_inspect = TASK_INSPECT_NULL;
353
354 T_SETUPBEGIN;
355 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), getpid(),
356 &task_inspect), NULL);
357 T_SETUPEND;
358
359 T_ASSERT_MACH_SUCCESS(task_policy_set(task_inspect,
360 TASK_BASE_QOS_POLICY,
361 (task_policy_t)&qosinfo,
362 TASK_QOS_POLICY_COUNT),
363 NULL);
364 }
365
366 T_DECL(task_policy_set_foreign_task_entitled, "task_policy_set for foreign task (entitled)", T_META_ASROOT(true))
367 {
368 struct task_qos_policy qosinfo = {
369 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
370 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
371 };
372 task_t task = TASK_NULL;
373 kern_return_t ret = KERN_FAILURE;
374 char *args[] = { "sleep", "10", NULL };
375 pid_t pid = 0;
376
377 T_SETUPBEGIN;
378
379 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
380 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
381
382 T_ASSERT_MACH_SUCCESS(task_for_pid(mach_task_self(), pid,
383 &task), NULL);
384 T_SETUPEND;
385
386 T_ASSERT_MACH_SUCCESS(task_policy_set(task,
387 TASK_BASE_QOS_POLICY,
388 (task_policy_t)&qosinfo,
389 TASK_QOS_POLICY_COUNT),
390 NULL);
391
392 ret = kill(pid, SIGTERM);
393 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
394 }
395
396 T_DECL(task_policy_set_foreign_task_name_entitled, "task_policy_set for foreign task name (entitled)", T_META_ASROOT(true), T_META_ASROOT(true))
397 {
398 struct task_qos_policy qosinfo = {
399 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
400 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
401 };
402 task_name_t task_name = TASK_NAME_NULL;
403 kern_return_t ret = KERN_FAILURE;
404 char *args[] = { "sleep", "10", NULL };
405 pid_t pid = 0;
406
407 T_SETUPBEGIN;
408
409 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
410 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
411
412 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), pid,
413 &task_name), NULL);
414 T_SETUPEND;
415
416 T_ASSERT_MACH_SUCCESS(task_policy_set(task_name,
417 TASK_BASE_QOS_POLICY,
418 (task_policy_t)&qosinfo,
419 TASK_QOS_POLICY_COUNT),
420 NULL);
421
422 ret = kill(pid, SIGTERM);
423 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
424 }
425
426 T_DECL(task_policy_set_foreign_task_inspect_entitled, "task_policy_set for foreign task inspect (entitled)", T_META_ASROOT(true))
427 {
428 struct task_qos_policy qosinfo = {
429 .task_latency_qos_tier = LATENCY_QOS_TIER_0,
430 .task_throughput_qos_tier = THROUGHPUT_QOS_TIER_0,
431 };
432 task_inspect_t task_inspect = TASK_INSPECT_NULL;
433 kern_return_t ret = KERN_FAILURE;
434 char *args[] = { "sleep", "10", NULL };
435 pid_t pid = 0;
436
437 T_SETUPBEGIN;
438
439 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
440 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
441
442 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), pid,
443 &task_inspect), NULL);
444 T_SETUPEND;
445
446 T_ASSERT_MACH_SUCCESS(task_policy_set(task_inspect,
447 TASK_BASE_QOS_POLICY,
448 (task_policy_t)&qosinfo,
449 TASK_QOS_POLICY_COUNT),
450 NULL);
451
452 ret = kill(pid, SIGTERM);
453 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
454 }
455
456 T_DECL(task_policy_get_name_entitled, "task_policy_get with task name (entitled)", T_META_ASROOT(true))
457 {
458 task_name_t task_name = TASK_NAME_NULL;
459 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
460 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
461 boolean_t get_default = FALSE;
462
463 T_SETUPBEGIN;
464 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), getpid(),
465 &task_name), NULL);
466 T_SETUPEND;
467
468 T_ASSERT_MACH_SUCCESS(task_policy_get(task_name,
469 TASK_CATEGORY_POLICY,
470 (task_policy_t)role,
471 &count,
472 &get_default),
473 NULL);
474 }
475
476 T_DECL(task_policy_get_task_entitled, "task_policy_get with task (entitled)")
477 {
478 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
479 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
480 boolean_t get_default = FALSE;
481
482 T_ASSERT_MACH_SUCCESS(task_policy_get(mach_task_self(),
483 TASK_CATEGORY_POLICY,
484 (task_policy_t)role,
485 &count,
486 &get_default),
487 NULL);
488 }
489
490 T_DECL(task_policy_get_inspect_entitled, "task_policy_get with task inspect (entitled)")
491 {
492 task_inspect_t task_inspect = TASK_INSPECT_NULL;
493 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
494 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
495 boolean_t get_default = FALSE;
496
497 T_SETUPBEGIN;
498 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), getpid(),
499 &task_inspect), NULL);
500 T_SETUPEND;
501
502 T_ASSERT_MACH_SUCCESS(task_policy_get(task_inspect,
503 TASK_CATEGORY_POLICY,
504 (task_policy_t)role,
505 &count,
506 &get_default),
507 NULL);
508 }
509
510 T_DECL(task_policy_get_foreign_task_inspect_entitled, "task_policy_get for foreign task inspect (entitled)", T_META_ASROOT(true))
511 {
512 task_inspect_t task_inspect = TASK_INSPECT_NULL;
513 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
514 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
515 boolean_t get_default = FALSE;
516 kern_return_t ret = KERN_FAILURE;
517 char *args[] = { "sleep", "10", NULL };
518 pid_t pid = 0;
519
520 T_SETUPBEGIN;
521
522 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
523 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
524
525 T_ASSERT_MACH_SUCCESS(task_inspect_for_pid(mach_task_self(), pid,
526 &task_inspect), NULL);
527 T_SETUPEND;
528
529 T_ASSERT_MACH_SUCCESS(task_policy_get(task_inspect,
530 TASK_CATEGORY_POLICY,
531 (task_policy_t)role,
532 &count,
533 &get_default),
534 NULL);
535
536 ret = kill(pid, SIGTERM);
537 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
538 }
539
540 T_DECL(task_policy_get_foreign_task_entitled, "task_policy_get for foreign task (entitled)", T_META_ASROOT(true))
541 {
542 task_t task = TASK_NULL;
543 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
544 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
545 boolean_t get_default = FALSE;
546 kern_return_t ret = KERN_FAILURE;
547 char *args[] = { "sleep", "10", NULL };
548 pid_t pid = 0;
549
550 T_SETUPBEGIN;
551
552 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
553 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
554
555 T_ASSERT_MACH_SUCCESS(task_for_pid(mach_task_self(), pid,
556 &task), NULL);
557 T_SETUPEND;
558
559 T_ASSERT_MACH_SUCCESS(task_policy_get(task,
560 TASK_CATEGORY_POLICY,
561 (task_policy_t)role,
562 &count,
563 &get_default),
564 NULL);
565
566 ret = kill(pid, SIGTERM);
567 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
568 }
569
570 T_DECL(task_policy_get_foreign_task_name_entitled, "task_policy_get for foreign task name (entitled)", T_META_ASROOT(true))
571 {
572 task_name_t task_name = TASK_NAME_NULL;
573 struct task_category_policy role[TASK_CATEGORY_POLICY_COUNT];
574 mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
575 boolean_t get_default = FALSE;
576 kern_return_t ret = KERN_FAILURE;
577 char *args[] = { "sleep", "10", NULL };
578 pid_t pid = 0;
579
580 T_SETUPBEGIN;
581
582 ret = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
583 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "spawning sleep 10");
584
585 T_ASSERT_MACH_SUCCESS(task_name_for_pid(mach_task_self(), pid,
586 &task_name), NULL);
587 T_SETUPEND;
588
589 T_ASSERT_MACH_SUCCESS(task_policy_get(task_name,
590 TASK_CATEGORY_POLICY,
591 (task_policy_t)role,
592 &count,
593 &get_default),
594 NULL);
595
596 ret = kill(pid, SIGTERM);
597 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "killing sleep");
598 }
599
600 #endif /* UNENTITLED */