2 // BUILD: $CC main.c -o $BUILD_DIR/versions.exe
8 #include <mach-o/dyld_priv.h>
10 #include "test_support.h"
12 extern struct mach_header __dso_handle
;
14 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
15 dyld_platform_t active
= dyld_get_active_platform();
16 dyld_platform_t base
= dyld_get_base_platform(active
);
17 dyld_build_version_t absoluteMin
= { .platform
= base
, .version
= 0 };
18 dyld_build_version_t absoluteMax
= { .platform
= base
, .version
= 0xffffffff };
19 // We choose high platform value that is unlikely to ever be used, and a non-zero version number
20 // If the platform number we choose here is ever used it will fail on that platform and this test will need to be fixed.
21 dyld_build_version_t bogusPlatformVersion
= { .platform
= 0xffff0000, .version
= 1 };
24 if ( base
!= PLATFORM_MACOS
) {
25 FAIL("base.platform %u incorrect for macOS", base
);
28 if ( base
!= PLATFORM_IOS
) {
29 FAIL("base.platform %u incorrect for iOS", base
);
32 if ( base
!= PLATFORM_TVOS
) {
33 FAIL("base.platform %u incorrect for tvOS", base
);
35 #elif TARGET_OS_BRIDGE
36 if ( base
!= PLATFORM_BRIDGEOS
) {
37 FAIL("base.platform %u incorrect for wacthOS", base
);
40 if ( base
!= PLATFORM_WATCHOS
) {
41 FAIL("base.platform %u incorrect for bridgeOn", base
);
44 FAIL("Running on unknown platform");
47 #if TARGET_OS_SIMULATOR
48 if (dyld_is_simulator_platform(active
) != true) {
49 FAIL("active platform %u should be a simulator", active
);
52 if (dyld_is_simulator_platform(active
) == true) {
53 FAIL("active platform %u should not be a simulator", active
);
57 if (dyld_is_simulator_platform(base
) == true) {
58 FAIL("base platform %u should not be a simulator", base
);
61 if (!dyld_sdk_at_least(&__dso_handle
, absoluteMin
)) {
62 FAIL("executable sdk version should not < 1.0.0");
65 if (dyld_sdk_at_least(&__dso_handle
, absoluteMax
)) {
66 FAIL("executable sdk version should not > 65536.0.0");
69 if (!dyld_minos_at_least(&__dso_handle
, absoluteMin
)) {
70 FAIL("executable min version should not < 1.0.0");
73 if (dyld_minos_at_least(&__dso_handle
, absoluteMax
)) {
74 FAIL("executable min version should not > 65536.0.0");
77 if (dyld_minos_at_least(&__dso_handle
, bogusPlatformVersion
)) {
78 FAIL("dyld_minos_at_least should be false for bogus platform");
81 if (dyld_program_minos_at_least(bogusPlatformVersion
)) {
82 FAIL("dyld_program_minos_at_least should be false for bogus platform");
85 if (dyld_sdk_at_least(&__dso_handle
, bogusPlatformVersion
)) {
86 FAIL("dyld_sdk_at_least should be false for bogus platform");
89 if (dyld_program_sdk_at_least(bogusPlatformVersion
)) {
90 FAIL("dyld_program_sdk_at_least should be false for bogus platform");