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