dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / env-DYLD_FORCE_PLATFORM.dtest / main.c
1 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_FORCE_PLATFORM.exe -DENABLE_ALT_PLATFORMS=1
2 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_FORCE_PLATFORM-fail.exe
3 // BUILD(macos): $TASK_FOR_PID_ENABLE $BUILD_DIR/env-DYLD_FORCE_PLATFORM.exe
4 // BUILD(macos): $TASK_FOR_PID_ENABLE $BUILD_DIR/env-DYLD_FORCE_PLATFORM-fail.exe
5
6 // BUILD(ios,tvos,watchos,bridgeos):
7
8 // RUN: DYLD_FORCE_PLATFORM=6 ./env-DYLD_FORCE_PLATFORM.exe
9 // RUN: DYLD_FORCE_PLATFORM=6 ./env-DYLD_FORCE_PLATFORM-fail.exe
10
11 #include <mach-o/dyld_priv.h>
12 #include <dlfcn.h>
13
14 #include "test_support.h"
15
16 #if ENABLE_ALT_PLATFORMS
17 __attribute__((section("__DATA,__allow_alt_plat"))) uint64_t dummy;
18
19 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
20 dyld_build_version_t ios12 = { .platform = PLATFORM_IOS, .version = 0x000c0000 };
21 if (dyld_get_active_platform() != PLATFORM_MACCATALYST) { FAIL("dyld_get_active_platform() should return PLATFORM_MACCATALYST"); }
22 // libswiftUIKit.dylib exists in /System/iOSSupport/usr/lib/swift
23 // We should be able to dlopen it only if we are correctly prepending the /System/iOSSupport root path
24 #if 0
25 // FIXME: We don't want to bring in such large dylib graphs. We can repurpose root testing support for this
26 if (!dlopen_preflight("/usr/lib/swift/libswiftUIKit.dylib")) { FAIL("Should be able to dlopen libswiftUIKit but %s", dlerror()); }
27 #endif
28 if (!dyld_program_minos_at_least(ios12)) { FAIL("DYLD_FORCE_PLATFORM should synthesize an iOS min version greater than 12.0"); }
29 if (!dyld_program_sdk_at_least(ios12)) { FAIL("DYLD_FORCE_PLATFORM should synthesize an iOS sdk versio greater than 12.0"); }
30 PASS("Success");
31 }
32 #else
33 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
34 if (dyld_get_active_platform() != PLATFORM_MACOS) { FAIL("dyld_get_active_platform() should return PLATFORM_MACOS"); }
35
36 // libswiftUIKit.dylib exists in /System/iOSSupport/usr/lib/swift
37 // We should not be able to dlopen this as we don't expect to find it in a macOS location. If it starts
38 // being in a macOS location then we should update this test
39 if(dlopen_preflight("/usr/lib/swift/libswiftUIKit.dylib")) { FAIL("Should not be able to dlopen libswiftUIKit"); }
40 PASS("Success");
41 }
42 #endif