]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dyld_version_spis.dtest/version_set.c
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / dyld_version_spis.dtest / version_set.c
1 // FIXME: -Wl,-platform_version triggers linker warnings, we need to find a way to stop clang from emitting -platform_version
2 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,10.14,10.14 -o $BUILD_DIR/version_set_10.14.exe
3 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,10.14.9,10.14.9 -o $BUILD_DIR/version_set_10.14.9.exe
4 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,10.15,10.15 -o $BUILD_DIR/version_set_10.15.exe
5 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,10.15.1,10.15.1 -o $BUILD_DIR/version_set_10.15.1.exe
6 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,10.16,10.16 -o $BUILD_DIR/version_set_10.16.exe
7 // BUILD(macos): $CC version_set.c -Wl,-platform_version,macos,11.0,11.0 -o $BUILD_DIR/version_set_11.exe
8 // RUN(macos): ./version_set_10.14.exe
9 // RUN(macos): ./version_set_10.14.9.exe
10 // RUN(macos): ./version_set_10.15.exe
11 // RUN(macos): ./version_set_10.15.1.exe
12 // RUN(macos): ./version_set_10.16.exe
13 // RUN(macos): ./version_set_11.exe
14
15 // BUILD(tvos): $CC version_set.c -Wl,-platform_version,tvos,12.0,12.0 -o $BUILD_DIR/version_set_12.exe
16 // BUILD(tvos): $CC version_set.c -Wl,-platform_version,tvos,12.9,12.9 -o $BUILD_DIR/version_set_12.9.exe
17 // BUILD(tvos): $CC version_set.c -Wl,-platform_version,tvos,13.0,13.0 -o $BUILD_DIR/version_set_13.exe
18 // BUILD(tvos): $CC version_set.c -Wl,-platform_version,tvos,13.1,13.1 -o $BUILD_DIR/version_set_13.1.exe
19 // BUILD(tvos): $CC version_set.c -Wl,-platform_version,tvos,14.0,14.0 -o $BUILD_DIR/version_set_14.exe
20 // RUN(tvos): ./version_set_12.exe
21 // RUN(tvos): ./version_set_12.9.exe
22 // RUN(tvos): ./version_set_13.exe
23 // RUN(tvos): ./version_set_13.1.exe
24 // RUN(tvos): ./version_set_14.exe
25
26 // BUILD(ios): $CC version_set.c -Wl,-platform_version,ios,12.0,12.0 -o $BUILD_DIR/version_set_12.exe
27 // BUILD(ios): $CC version_set.c -Wl,-platform_version,ios,12.9,12.9 -o $BUILD_DIR/version_set_12.9.exe
28 // BUILD(ios): $CC version_set.c -Wl,-platform_version,ios,13.0,13.0 -o $BUILD_DIR/version_set_13.exe
29 // BUILD(ios): $CC version_set.c -Wl,-platform_version,ios,13.1,13.1 -o $BUILD_DIR/version_set_13.1.exe
30 // BUILD(ios): $CC version_set.c -Wl,-platform_version,ios,14.0,14.0 -o $BUILD_DIR/version_set_14.exe
31 // RUN(ios): ./version_set_12.exe
32 // RUN(ios): ./version_set_12.9.exe
33 // RUN(ios): ./version_set_13.exe
34 // RUN(ios): ./version_set_13.1.exe
35 // RUN(ios): ./version_set_14.exe
36
37 // BUILD(watchos): $CC version_set.c -Wl,-platform_version,watchos,5.0,5.0 -o $BUILD_DIR/version_set_5.exe
38 // BUILD(watchos): $CC version_set.c -Wl,-platform_version,watchos,5.9,5.9 -o $BUILD_DIR/version_set_5.9.exe
39 // BUILD(watchos): $CC version_set.c -Wl,-platform_version,watchos,6.0,6.0 -o $BUILD_DIR/version_set_6.exe
40 // BUILD(watchos): $CC version_set.c -Wl,-platform_version,watchos,6.1,6.1 -o $BUILD_DIR/version_set_6.1.exe
41 // BUILD(watchos): $CC version_set.c -Wl,-platform_version,watchos,7.0,7.0 -o $BUILD_DIR/version_set_7.exe
42 // RUN(watchos): ./version_set_5.exe
43 // RUN(watchos): ./version_set_5.9.exe
44 // RUN(watchos): ./version_set_6.exe
45 // RUN(watchos): ./version_set_6.1.exe
46 // RUN(watchos): ./version_set_7.exe
47
48 // BUILD(bridgeos):
49
50 #include <stdio.h>
51 #include <string.h>
52 #include <mach-o/dyld_priv.h>
53 #include <dyld/for_dyld_priv.inc>
54
55 #include "test_support.h"
56
57 extern struct mach_header __dso_handle;
58
59 #if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 101400)
60 #define FALL_2018 true
61 #define FALL_2019 false
62 #define FALL_2020 false
63 #define VERSION_NAME "macOS 10.14"
64 #elif (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 101409)
65 #define FALL_2018 true
66 #define FALL_2019 false
67 #define FALL_2020 false
68 #define VERSION_NAME "macOS 10.14.9"
69 #elif (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 101500)
70 #define FALL_2018 true
71 #define FALL_2019 true
72 #define FALL_2020 false
73 #define VERSION_NAME "macOS 10.15"
74 #elif (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 101501)
75 #define FALL_2018 true
76 #define FALL_2019 true
77 #define FALL_2020 false
78 #define VERSION_NAME "macOS 10.15.1"
79 #elif (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 101600)
80 #define FALL_2018 true
81 #define FALL_2019 true
82 #define FALL_2020 true
83 #define VERSION_NAME "macOS 10.16"
84 #elif (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ == 110000)
85 #define FALL_2018 true
86 #define FALL_2019 true
87 #define FALL_2020 true
88 #define VERSION_NAME "macOS 11"
89 #elif (__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ == 120000)
90 #define FALL_2018 true
91 #define FALL_2019 false
92 #define FALL_2020 false
93 #define VERSION_NAME "tvOS 12"
94 #elif (__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ == 120900)
95 #define FALL_2018 true
96 #define FALL_2019 false
97 #define FALL_2020 false
98 #define VERSION_NAME "tvOS 12.9"
99 #elif (__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ == 130000)
100 #define FALL_2018 true
101 #define FALL_2019 true
102 #define FALL_2020 false
103 #define VERSION_NAME "tvOS 13"
104 #elif (__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ == 130100)
105 #define FALL_2018 true
106 #define FALL_2019 true
107 #define FALL_2020 false
108 #define VERSION_NAME "tvOS 13.1"
109 #elif (__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ == 140000)
110 #define FALL_2018 true
111 #define FALL_2019 true
112 #define FALL_2020 true
113 #define VERSION_NAME "tvOS 14"
114 #elif (__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ == 120000)
115 #define FALL_2018 true
116 #define FALL_2019 false
117 #define FALL_2020 false
118 #define VERSION_NAME "iOS 12"
119 #elif (__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ == 120900)
120 #define FALL_2018 true
121 #define FALL_2019 false
122 #define FALL_2020 false
123 #define VERSION_NAME "iOS 12.9"
124 #elif (__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ == 130000)
125 #define FALL_2018 true
126 #define FALL_2019 true
127 #define FALL_2020 false
128 #define VERSION_NAME "iOS 13"
129 #elif (__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ == 130100)
130 #define FALL_2018 true
131 #define FALL_2019 true
132 #define FALL_2020 false
133 #define VERSION_NAME "iOS 13.1"
134 #elif (__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ == 140000)
135 #define FALL_2018 true
136 #define FALL_2019 true
137 #define FALL_2020 true
138 #define VERSION_NAME "iOS 14"
139 #elif (__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ == 50000)
140 #define FALL_2018 true
141 #define FALL_2019 false
142 #define FALL_2020 false
143 #define VERSION_NAME "watchOS 5"
144 #elif (__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ == 50900)
145 #define FALL_2018 true
146 #define FALL_2019 false
147 #define FALL_2020 false
148 #define VERSION_NAME "watchOS 5.9"
149 #elif (__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ == 60000)
150 #define FALL_2018 true
151 #define FALL_2019 true
152 #define FALL_2020 false
153 #define VERSION_NAME "watchOS 6"
154 #elif (__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ == 60100)
155 #define FALL_2018 true
156 #define FALL_2019 true
157 #define FALL_2020 false
158 #define VERSION_NAME "watchOS 6.1"
159 #elif (__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ == 70000)
160 #define FALL_2018 true
161 #define FALL_2019 true
162 #define FALL_2020 true
163 #define VERSION_NAME "watchOS 7"
164 #else
165 #error Unknown version
166 #endif
167
168 void testVersionChecks(const char* versionName, dyld_build_version_t testVersion, bool expected) {
169 if (expected != dyld_minos_at_least(&__dso_handle, testVersion)) {
170 FAIL(VERSION_NAME "should be %s than %s for dyld_minos_at_least()", versionName, expected ? "newer" : "older");
171 }
172 if (expected != dyld_sdk_at_least(&__dso_handle, testVersion)) {
173 FAIL(VERSION_NAME "should be %s than %s for dyld_sdk_at_least()", versionName, expected ? "newer" : "older");
174 }
175 if (expected != dyld_program_minos_at_least(testVersion)) {
176 FAIL(VERSION_NAME "should be %s than %s for dyld_program_minos_at_least()", versionName, expected ? "newer" : "older");
177 }
178 if (expected != dyld_program_sdk_at_least(testVersion)) {
179 FAIL(VERSION_NAME "should be %s than %s for dyld_program_sdk_at_least()", versionName, expected ? "newer" : "older");
180 }
181 }
182
183 int main(void) {
184 testVersionChecks("dyld_fall_2018_os_versions", dyld_fall_2018_os_versions, FALL_2018);
185 testVersionChecks("dyld_fall_2019_os_versions", dyld_fall_2019_os_versions, FALL_2019);
186 testVersionChecks("dyld_fall_2020_os_versions", dyld_fall_2020_os_versions, FALL_2020);
187
188 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
189 testVersionChecks("dyld_platform_version_macOS_10_14", dyld_platform_version_macOS_10_14, FALL_2018);
190 testVersionChecks("dyld_platform_version_macOS_10_15", dyld_platform_version_macOS_10_15, FALL_2019);
191 testVersionChecks("dyld_platform_version_macOS_10_16", dyld_platform_version_macOS_10_16, FALL_2020);
192 #elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
193 testVersionChecks("dyld_platform_version_tvOS_12_0", dyld_platform_version_tvOS_12_0, FALL_2018);
194 testVersionChecks("dyld_platform_version_tvOS_13_0", dyld_platform_version_tvOS_13_0, FALL_2019);
195 testVersionChecks("dyld_platform_version_tvOS_14_0", dyld_platform_version_tvOS_14_0, FALL_2020);
196 #elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
197 testVersionChecks("dyld_platform_version_iOS_12_0", dyld_platform_version_iOS_12_0, FALL_2018);
198 testVersionChecks("dyld_platform_version_iOS_13_0", dyld_platform_version_iOS_13_0, FALL_2019);
199 testVersionChecks("dyld_platform_version_iOS_14_0", dyld_platform_version_iOS_14_0, FALL_2020);
200 #elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
201 testVersionChecks("dyld_platform_version_watchOS_5_0", dyld_platform_version_watchOS_5_0, FALL_2018);
202 testVersionChecks("dyld_platform_version_watchOS_6_0", dyld_platform_version_watchOS_6_0, FALL_2019);
203 testVersionChecks("dyld_platform_version_watchOS_7_0", dyld_platform_version_watchOS_7_0, FALL_2020);
204 #endif
205
206 PASS("Success");
207 };