xref: /xnu-10002.41.9/tests/proc_uuid_policy_26567533.c (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions #include <darwintest.h>
2*699cd480SApple OSS Distributions #include <uuid/uuid.h>
3*699cd480SApple OSS Distributions #include <System/sys/proc_uuid_policy.h>
4*699cd480SApple OSS Distributions #include <stdint.h>
5*699cd480SApple OSS Distributions 
6*699cd480SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
7*699cd480SApple OSS Distributions 
8*699cd480SApple OSS Distributions #define NUM_PROC_UUID_POLICY_FLAGS 4
9*699cd480SApple OSS Distributions 
10*699cd480SApple OSS Distributions T_DECL(proc_uuid_policy_26567533, "Tests passing a NULL uuid in (uap->uuid).", T_META_LTEPHASE(LTE_POSTINIT))
11*699cd480SApple OSS Distributions {
12*699cd480SApple OSS Distributions 	int i, ret;
13*699cd480SApple OSS Distributions 	uuid_t null_uuid;
14*699cd480SApple OSS Distributions 	memset(null_uuid, 0, sizeof(uuid_t));
15*699cd480SApple OSS Distributions 
16*699cd480SApple OSS Distributions 	uint32_t policy_flags[] = {
17*699cd480SApple OSS Distributions 		PROC_UUID_POLICY_FLAGS_NONE,
18*699cd480SApple OSS Distributions 		PROC_UUID_NO_CELLULAR,
19*699cd480SApple OSS Distributions 		PROC_UUID_NECP_APP_POLICY,
20*699cd480SApple OSS Distributions 		PROC_UUID_ALT_DYLD_POLICY
21*699cd480SApple OSS Distributions 	};
22*699cd480SApple OSS Distributions 
23*699cd480SApple OSS Distributions 	for (i = 0; i < NUM_PROC_UUID_POLICY_FLAGS; i++) {
24*699cd480SApple OSS Distributions 		T_LOG("Testing policy add with flag value 0x%x", policy_flags[i]);
25*699cd480SApple OSS Distributions 
26*699cd480SApple OSS Distributions 		/* Since UUID is null, this call should fail with errno = EINVAL. */
27*699cd480SApple OSS Distributions 		ret = proc_uuid_policy(PROC_UUID_POLICY_OPERATION_ADD, null_uuid, sizeof(uuid_t), policy_flags[i]);
28*699cd480SApple OSS Distributions 
29*699cd480SApple OSS Distributions 		T_ASSERT_TRUE(ret == -1, "proc_uuid_policy returned %d", ret);
30*699cd480SApple OSS Distributions 		T_WITH_ERRNO;
31*699cd480SApple OSS Distributions 		T_ASSERT_TRUE(errno = EINVAL, "errno is %d", errno);
32*699cd480SApple OSS Distributions 	}
33*699cd480SApple OSS Distributions 
34*699cd480SApple OSS Distributions 	for (i = 0; i < NUM_PROC_UUID_POLICY_FLAGS; i++) {
35*699cd480SApple OSS Distributions 		T_LOG("Testing policy remove with flag value 0x%x", policy_flags[i]);
36*699cd480SApple OSS Distributions 
37*699cd480SApple OSS Distributions 		/* Since UUID is null, this call should fail with errno = EINVAL. */
38*699cd480SApple OSS Distributions 		ret = proc_uuid_policy(PROC_UUID_POLICY_OPERATION_REMOVE, null_uuid, sizeof(uuid_t), policy_flags[i]);
39*699cd480SApple OSS Distributions 
40*699cd480SApple OSS Distributions 		T_ASSERT_TRUE(ret == -1, "proc_uuid_policy returned %d", ret);
41*699cd480SApple OSS Distributions 		T_WITH_ERRNO;
42*699cd480SApple OSS Distributions 		T_ASSERT_TRUE(errno = EINVAL, "errno is %d", errno);
43*699cd480SApple OSS Distributions 	}
44*699cd480SApple OSS Distributions }
45