xref: /xnu-8796.101.5/tests/shared_cache_tests.c (revision aca3beaa3dfbd42498b42c5e5ce20a938e6554e5) !
1*aca3beaaSApple OSS Distributions #include <darwintest.h>
2*aca3beaaSApple OSS Distributions #include <darwintest_utils.h>
3*aca3beaaSApple OSS Distributions #include <mach-o/dyld.h>
4*aca3beaaSApple OSS Distributions #include <mach-o/dyld_priv.h>
5*aca3beaaSApple OSS Distributions #include <TargetConditionals.h>
6*aca3beaaSApple OSS Distributions 
7*aca3beaaSApple OSS Distributions T_GLOBAL_META(T_META_NAMESPACE("xnu.shared_cache"));
8*aca3beaaSApple OSS Distributions 
9*aca3beaaSApple OSS Distributions // Give the test up to two minutes because in the failure case we want to invoke update_dyld_shared_cache, which
10*aca3beaaSApple OSS Distributions // might take a bit to do.
11*aca3beaaSApple OSS Distributions T_DECL(present, "tests that the device is running with a shared cache", T_META_ASROOT(true), T_META_TIMEOUT(120))
12*aca3beaaSApple OSS Distributions {
13*aca3beaaSApple OSS Distributions 	size_t shared_cache_len = 0;
14*aca3beaaSApple OSS Distributions 	const void *cache_header = _dyld_get_shared_cache_range(&shared_cache_len);
15*aca3beaaSApple OSS Distributions 
16*aca3beaaSApple OSS Distributions #if TARGET_OS_OSX
17*aca3beaaSApple OSS Distributions 	T_SKIP("shared cache testing support incomplete (57267667)");
18*aca3beaaSApple OSS Distributions #endif /* TARGET_OS_OSX */
19*aca3beaaSApple OSS Distributions 
20*aca3beaaSApple OSS Distributions 	if ((cache_header == NULL) || (shared_cache_len == 0)) {
21*aca3beaaSApple OSS Distributions #if TARGET_OS_OSX
22*aca3beaaSApple OSS Distributions 		char *tmp_dir = (char *) dt_tmpdir();
23*aca3beaaSApple OSS Distributions 		T_QUIET; T_ASSERT_NOTNULL(tmp_dir, "darwintest created tmp dir");
24*aca3beaaSApple OSS Distributions 		// Try to invoke update_dyld_shared_cache to gather information on why we're not running with a shared cache
25*aca3beaaSApple OSS Distributions 		char *shared_cache_update_cmd[] = { "/usr/bin/update_dyld_shared_cache", "-debug", "-cache_dir", tmp_dir, NULL };
26*aca3beaaSApple OSS Distributions 		pid_t child1 = dt_launch_tool_pipe(shared_cache_update_cmd, false, NULL, ^bool (char *data, __unused size_t data_size, __unused dt_pipe_data_handler_context_t *context) {
27*aca3beaaSApple OSS Distributions 			T_LOG("%s", data);
28*aca3beaaSApple OSS Distributions 			return false;
29*aca3beaaSApple OSS Distributions 		}, ^bool (__unused char *data, __unused size_t data_size, __unused dt_pipe_data_handler_context_t *context) {
30*aca3beaaSApple OSS Distributions 			T_LOG("%s", data);
31*aca3beaaSApple OSS Distributions 			return false;
32*aca3beaaSApple OSS Distributions 		}, BUFFER_PATTERN_LINE, NULL);
33*aca3beaaSApple OSS Distributions 
34*aca3beaaSApple OSS Distributions 		int status = 0;
35*aca3beaaSApple OSS Distributions 		dt_waitpid(child1, &status, NULL, 0);
36*aca3beaaSApple OSS Distributions 
37*aca3beaaSApple OSS Distributions 		T_LOG("waitpid for %d returned with status %d", child1, WEXITSTATUS(status));
38*aca3beaaSApple OSS Distributions #endif // TARGET_OS_OSX
39*aca3beaaSApple OSS Distributions 		T_ASSERT_NOTNULL(cache_header, "shared cache present");
40*aca3beaaSApple OSS Distributions 		T_ASSERT_GT((int) shared_cache_len, 0, "shared cache has non-zero length");
41*aca3beaaSApple OSS Distributions 	}
42*aca3beaaSApple OSS Distributions 
43*aca3beaaSApple OSS Distributions 	T_PASS("shared cache appears to be present and valid");
44*aca3beaaSApple OSS Distributions }
45