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