1 #include <os/variant_private.h>
3 #include <darwintest.h>
6 * Most of these are MAYFAIL because the test might sometimes run on non-internal devices.
9 T_DECL(os_variant_basic
, "Just calls all the APIs")
12 T_EXPECT_TRUE(os_variant_has_internal_content("com.apple.Libc.tests"), NULL
);
15 T_EXPECT_TRUE(os_variant_has_internal_diagnostics("com.apple.Libc.tests"), NULL
);
18 T_EXPECT_TRUE(os_variant_has_internal_ui("com.apple.Libc.tests"), NULL
);
21 T_EXPECT_TRUE(os_variant_allows_internal_security_policies("com.apple.Libc.tests"), NULL
);
24 #define VARIANT_SKIP_EXPORTED
26 #include "../libdarwin/variant.c"
28 T_DECL(os_variant_detailed
, "Looks at individual checks")
31 T_EXPECT_FALSE(_check_disabled(VP_ALL
), NULL
);
34 T_EXPECT_FALSE(_check_disabled(VP_CONTENT
), NULL
);
37 T_EXPECT_FALSE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
40 T_EXPECT_FALSE(_check_disabled(VP_UI
), NULL
);
43 T_EXPECT_FALSE(_check_disabled(VP_SECURITY
), NULL
);
45 #if !TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
47 T_EXPECT_TRUE(_check_internal_content(), NULL
);
52 T_EXPECT_TRUE(_check_internal_release_type(), NULL
);
55 T_EXPECT_FALSE(_check_internal_diags_profile(), NULL
);
59 T_EXPECT_TRUE(_check_can_has_debugger(), NULL
);
62 T_DECL(os_variant_override_parse
, "Checks the parsing of the override file")
64 // Warm up the dispatch_once
65 _check_disabled(VP_ALL
);
67 T_LOG("Override: NULL"); // Live system
68 _parse_disabled_status(NULL
);
69 T_MAYFAIL
; T_EXPECT_FALSE(_check_disabled(VP_CONTENT
), NULL
);
70 T_MAYFAIL
; T_EXPECT_FALSE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
71 T_MAYFAIL
; T_EXPECT_FALSE(_check_disabled(VP_UI
), NULL
);
72 T_MAYFAIL
; T_EXPECT_FALSE(_check_disabled(VP_SECURITY
), NULL
);
74 T_LOG("Override: \"content\"");
75 _parse_disabled_status("content");
76 T_EXPECT_TRUE(_check_disabled(VP_CONTENT
), NULL
);
77 T_EXPECT_FALSE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
78 T_EXPECT_FALSE(_check_disabled(VP_UI
), NULL
);
79 T_EXPECT_FALSE(_check_disabled(VP_SECURITY
), NULL
);
81 T_LOG("Override: \"ui\"");
82 _parse_disabled_status("ui");
83 T_EXPECT_FALSE(_check_disabled(VP_CONTENT
), NULL
);
84 T_EXPECT_FALSE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
85 T_EXPECT_TRUE(_check_disabled(VP_UI
), NULL
);
86 T_EXPECT_FALSE(_check_disabled(VP_SECURITY
), NULL
);
88 T_LOG("Override: \"security,diagnostics\"");
89 _parse_disabled_status("security,diagnostics");
90 T_EXPECT_FALSE(_check_disabled(VP_CONTENT
), NULL
);
91 T_EXPECT_TRUE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
92 T_EXPECT_FALSE(_check_disabled(VP_UI
), NULL
);
93 T_EXPECT_TRUE(_check_disabled(VP_SECURITY
), NULL
);
95 T_LOG("Override: \"content,diagnostics,ui,security\"");
96 _parse_disabled_status("content,diagnostics,ui,security");
97 T_EXPECT_TRUE(_check_disabled(VP_CONTENT
), NULL
);
98 T_EXPECT_TRUE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
99 T_EXPECT_TRUE(_check_disabled(VP_UI
), NULL
);
100 T_EXPECT_TRUE(_check_disabled(VP_SECURITY
), NULL
);
102 T_LOG("Override: \"diagnostics\\n"); // Now check newline-handling.
103 _parse_disabled_status("diagnostics\n");
104 T_EXPECT_FALSE(_check_disabled(VP_CONTENT
), NULL
);
105 T_EXPECT_TRUE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
106 T_EXPECT_FALSE(_check_disabled(VP_UI
), NULL
);
107 T_EXPECT_FALSE(_check_disabled(VP_SECURITY
), NULL
);
109 T_LOG("Override: \"content,diagnostics\\nui,security\\n\"");
110 _parse_disabled_status("content,diagnostics\nui,security\n");
111 T_EXPECT_TRUE(_check_disabled(VP_CONTENT
), NULL
);
112 T_EXPECT_TRUE(_check_disabled(VP_DIAGNOSTICS
), NULL
);
113 T_EXPECT_TRUE(_check_disabled(VP_UI
), NULL
);
114 T_EXPECT_TRUE(_check_disabled(VP_SECURITY
), NULL
);
117 T_DECL(os_status_cache
, "Checks saving and restoring of state")
120 size_t status_size
= sizeof(status
);
121 int ret
= sysctlbyname(CACHE_SYSCTL_NAME
, &status
, &status_size
, NULL
, 0);
122 T_EXPECT_POSIX_ZERO(ret
, "sysctlbyname(kern.osvariant_status)");
123 T_EXPECT_GT(status
, 0ULL, "Kernel's status has bits set");
124 T_EXPECT_EQ(status
& STATUS_INITIAL_BITS
, STATUS_INITIAL_BITS
, "Kernel's status has initial bits set");
127 T_EXPECT_TRUE(_check_can_has_debugger(), NULL
);
129 status
= _get_cached_check_status();
130 T_LOG("Cached status: %llx", status
);
132 T_EXPECT_EQ(status
& STATUS_INITIAL_BITS
, STATUS_INITIAL_BITS
, "Our status has initial bits set");
134 _restore_cached_check_status(status
);
137 T_EXPECT_TRUE(os_variant_allows_internal_security_policies(NULL
), NULL
);
139 status
= STATUS_INITIAL_BITS
|
140 (S_NO
<< (SFP_CAN_HAS_DEBUGGER
* STATUS_BIT_WIDTH
));
141 T_LOG("Restoring status without can_has_debugger: %llx", status
);
142 _restore_cached_check_status(status
);
144 T_EXPECT_FALSE(_check_can_has_debugger(), NULL
);
146 // Trigger dispatch_once internally with known state
147 _check_disabled(VP_SECURITY
);
149 status
= STATUS_INITIAL_BITS
|
150 (0x1ULL
<< (VP_SECURITY
+ 32));
151 T_LOG("Restoring status with override: %llx", status
);
152 _restore_cached_check_status(status
);
154 T_EXPECT_TRUE(_check_disabled(VP_SECURITY
), NULL
);