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