|
| 1 | +// |
| 2 | +// At a high level, this test is designed to verify that use of declarations |
| 3 | +// annotated with @_backDeploy behave as expected when running a client binary |
| 4 | +// on an older OS that does not have the back deployed APIs. The |
| 5 | +// BackDeployHelper framework has a number of APIs that are available in the |
| 6 | +// OSes identified by the "BackDeploy 1.0" availability macro and are back |
| 7 | +// deployed before OSes identified "BackDeploy 2.0". Verification is performed |
| 8 | +// the following way: |
| 9 | +// |
| 10 | +// 1. Build the helper framework with both BackDeploy 1.0 defined to an |
| 11 | +// OS version before Swift ABI stability and 2.0 defined to an OS version |
| 12 | +// after Swift ABI stability. Note that stradling ABI stability is not |
| 13 | +// a necessary requirement of this test; it's just convenient to use OS |
| 14 | +// versions that correspond to existing lit substitutions. |
| 15 | +// 2. Build the client executable with a deployment target set to the same |
| 16 | +// OS version as BackDeploy 2.0. |
| 17 | +// 3. Run the client executable, verifying that the copies of the functions in |
| 18 | +// the framework are used (verified by runtime logic using #dsohandle). |
| 19 | +// 4. Build a new copy of the helper framework, this time with BackDeploy 2.0 |
| 20 | +// set to a distant future OS version. |
| 21 | +// 5. Build a new copy of the client executable using the new framework and |
| 22 | +// the deployment target set to the same OS version as BackDeploy 1.0. |
| 23 | +// 6. Run the new executable, verifying with #dsohandle that client copies of |
| 24 | +// the APIs are used. |
| 25 | +// 7. Re-build the framework in place, this time stripping the definitions of |
| 26 | +// the back deployed APIs entirely. |
| 27 | +// 8. Re-run the unmodified executable, with the same expectations as in (6). |
| 28 | +// However, this time we're also verifying that the executable can run even |
| 29 | +// without the original API symbols present in the linked dylib. |
| 30 | +// |
| 31 | + |
| 32 | +// REQUIRES: executable_test |
| 33 | +// REQUIRES: VENDOR=apple |
| 34 | + |
| 35 | +// ---- (0) Prepare SDK |
| 36 | +// RUN: %empty-directory(%t) |
| 37 | +// RUN: %empty-directory(%t/SDK_ABI) |
| 38 | +// RUN: %empty-directory(%t/SDK_BD) |
| 39 | + |
| 40 | +// ---- (1) Build famework with BackDeploy 2.0 in the past |
| 41 | +// RUN: mkdir -p %t/SDK_ABI/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule |
| 42 | +// RUN: %target-build-swift-dylib(%t/SDK_ABI/Frameworks/BackDeployHelper.framework/BackDeployHelper) \ |
| 43 | +// RUN: -emit-module-path %t/SDK_ABI/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule/%module-target-triple.swiftmodule \ |
| 44 | +// RUN: -module-name BackDeployHelper -emit-module %S/Inputs/BackDeployHelper.swift \ |
| 45 | +// RUN: -Xfrontend -target -Xfrontend %target-next-stable-abi-triple \ |
| 46 | +// RUN: -Xfrontend -define-availability \ |
| 47 | +// RUN: -Xfrontend 'BackDeploy 1.0:macOS 10.14.3, iOS 12.1, tvOS 12.1, watchOS 5.1' \ |
| 48 | +// RUN: -Xfrontend -define-availability \ |
| 49 | +// RUN: -Xfrontend 'BackDeploy 2.0:macOS 10.15, iOS 13, tvOS 13, watchOS 6' \ |
| 50 | +// RUN: -Xlinker -install_name -Xlinker @rpath/BackDeployHelper.framework/BackDeployHelper \ |
| 51 | +// RUN: -enable-library-evolution |
| 52 | + |
| 53 | +// ---- (2) Build executable |
| 54 | +// RUN: %target-build-swift -emit-executable %s -g -o %t/test_ABI \ |
| 55 | +// RUN: -Xfrontend -target -Xfrontend %target-pre-stable-abi-triple \ |
| 56 | +// RUN: -Xfrontend -define-availability \ |
| 57 | +// RUN: -Xfrontend 'BackDeploy 1.0:macOS 10.14.3, iOS 12.1, tvOS 12.1, watchOS 5.1' \ |
| 58 | +// RUN: -Xfrontend -define-availability \ |
| 59 | +// RUN: -Xfrontend 'BackDeploy 2.0:macOS 10.15, iOS 13, tvOS 13, watchOS 6' \ |
| 60 | +// RUN: -F %t/SDK_ABI/Frameworks/ -framework BackDeployHelper \ |
| 61 | +// RUN: %target-rpath(@executable_path/SDK_ABI/Frameworks) |
| 62 | + |
| 63 | +// ---- (3) Run executable |
| 64 | +// RUN: %target-codesign %t/test_ABI |
| 65 | +// RUN: %target-run %t/test_ABI %t/SDK_ABI/Frameworks/BackDeployHelper.framework/BackDeployHelper | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-ABI %s |
| 66 | + |
| 67 | +// ---- (4) Build famework with BackDeploy 2.0 in the future |
| 68 | +// RUN: mkdir -p %t/SDK_BD/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule |
| 69 | +// RUN: %target-build-swift-dylib(%t/SDK_BD/Frameworks/BackDeployHelper.framework/BackDeployHelper) \ |
| 70 | +// RUN: -emit-module-path %t/SDK_BD/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule/%module-target-triple.swiftmodule \ |
| 71 | +// RUN: -module-name BackDeployHelper -emit-module %S/Inputs/BackDeployHelper.swift \ |
| 72 | +// RUN: -Xfrontend -target -Xfrontend %target-next-stable-abi-triple \ |
| 73 | +// RUN: -Xfrontend -define-availability \ |
| 74 | +// RUN: -Xfrontend 'BackDeploy 1.0:macOS 10.14.3, iOS 12.1, tvOS 12.1, watchOS 5.1' \ |
| 75 | +// RUN: -Xfrontend -define-availability \ |
| 76 | +// RUN: -Xfrontend 'BackDeploy 2.0:macOS 999.0, iOS 999.0, watchOS 999.0, tvOS 999.0' \ |
| 77 | +// RUN: -Xlinker -install_name -Xlinker @rpath/BackDeployHelper.framework/BackDeployHelper \ |
| 78 | +// RUN: -enable-library-evolution |
| 79 | + |
| 80 | +// ---- (5) Build executable |
| 81 | +// RUN: %target-build-swift -emit-executable %s -g -o %t/test_BD \ |
| 82 | +// RUN: -Xfrontend -target -Xfrontend %target-next-stable-abi-triple \ |
| 83 | +// RUN: -Xfrontend -define-availability \ |
| 84 | +// RUN: -Xfrontend 'BackDeploy 1.0:macOS 10.14.3, iOS 12.1, tvOS 12.1, watchOS 5.1' \ |
| 85 | +// RUN: -Xfrontend -define-availability \ |
| 86 | +// RUN: -Xfrontend 'BackDeploy 2.0:macOS 999.0, iOS 999.0, watchOS 999.0, tvOS 999.0' \ |
| 87 | +// RUN: -F %t/SDK_BD/Frameworks/ -framework BackDeployHelper \ |
| 88 | +// RUN: %target-rpath(@executable_path/SDK_BD/Frameworks) |
| 89 | + |
| 90 | +// ---- (6) Run executable |
| 91 | +// RUN: %target-codesign %t/test_BD |
| 92 | +// RUN: %target-run %t/test_BD %t/SDK_BD/Frameworks/BackDeployHelper.framework/BackDeployHelper | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-BD %s |
| 93 | + |
| 94 | +// ---- (7) Re-build famework with the back deployed APIs stripped |
| 95 | +// RUN: mkdir -p %t/SDK_BD/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule |
| 96 | +// RUN: %target-build-swift-dylib(%t/SDK_BD/Frameworks/BackDeployHelper.framework/BackDeployHelper) \ |
| 97 | +// RUN: -emit-module-path %t/SDK_BD/Frameworks/BackDeployHelper.framework/Modules/BackDeployHelper.swiftmodule/%module-target-triple.swiftmodule \ |
| 98 | +// RUN: -module-name BackDeployHelper -emit-module %S/Inputs/BackDeployHelper.swift \ |
| 99 | +// RUN: -Xfrontend -target -Xfrontend %target-next-stable-abi-triple \ |
| 100 | +// RUN: -Xfrontend -define-availability \ |
| 101 | +// RUN: -Xfrontend 'BackDeploy 1.0:macOS 10.14.3, iOS 12.1, tvOS 12.1, watchOS 5.1' \ |
| 102 | +// RUN: -Xfrontend -define-availability \ |
| 103 | +// RUN: -Xfrontend 'BackDeploy 2.0:macOS 999.0, iOS 999.0, watchOS 999.0, tvOS 999.0' \ |
| 104 | +// RUN: -Xlinker -install_name -Xlinker @rpath/BackDeployHelper.framework/BackDeployHelper \ |
| 105 | +// RUN: -enable-library-evolution -DSTRIP_V2_APIS |
| 106 | + |
| 107 | +// ---- (8) Re-run executable |
| 108 | +// RUN: %target-codesign %t/test_BD |
| 109 | +// RUN: %target-run %t/test_BD %t/SDK_BD/Frameworks/BackDeployHelper.framework/BackDeployHelper | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-BD %s |
| 110 | + |
| 111 | +import BackDeployHelper |
| 112 | + |
| 113 | +// CHECK: client: check |
| 114 | +testPrint(handle: #dsohandle, "check") |
| 115 | +// CHECK: library: check |
| 116 | +testPrint(handle: libraryHandle(), "check") |
| 117 | + |
| 118 | +if isV2OrLater() { |
| 119 | + assert(!v2APIsAreStripped()) |
| 120 | +} |
| 121 | + |
| 122 | +// CHECK-ABI: library: trivial |
| 123 | +// CHECK-BD: client: trivial |
| 124 | +trivial() |
| 125 | + |
| 126 | +assert(try! pleaseThrow(false)) |
| 127 | +do { |
| 128 | + _ = try pleaseThrow(true) |
| 129 | + fatalError("Should have thrown") |
| 130 | +} catch { |
| 131 | + assert(error as? BadError == BadError.bad) |
| 132 | +} |
| 133 | + |
| 134 | +do { |
| 135 | + let zero = MutableInt.zero |
| 136 | + assert(zero.value == 0) |
| 137 | + |
| 138 | + var int = MutableInt(5) |
| 139 | + |
| 140 | + // CHECK-ABI: library: 5 |
| 141 | + // CHECK-BD: client: 5 |
| 142 | + int.print() |
| 143 | + |
| 144 | + assert(int.increment(by: 2) == 7) |
| 145 | + assert(genericIncrement(&int, by: 3) == 10) |
| 146 | + assert(int.decrement(by: 1) == 9) |
| 147 | + |
| 148 | + var incrementable: any Incrementable = int.toIncrementable() |
| 149 | + |
| 150 | + // CHECK-ABI: library: 10 |
| 151 | + // CHECK-BD: client: 10 |
| 152 | + existentialIncrementByOne(&incrementable) |
| 153 | + |
| 154 | + let int2 = MutableInt(0x7BB7914B) |
| 155 | + for (i, expectedByte) in [0x4B, 0x91, 0xB7, 0x7B].enumerated() { |
| 156 | + assert(int2[byteAt: i] == expectedByte) |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +do { |
| 161 | + let zero = ReferenceInt.zero |
| 162 | + assert(zero.value == 0) |
| 163 | + |
| 164 | + var int = ReferenceInt(42) |
| 165 | + |
| 166 | + // CHECK-ABI: library: 42 |
| 167 | + // CHECK-BD: client: 42 |
| 168 | + int.print() |
| 169 | + |
| 170 | + do { |
| 171 | + let copy = int.copy() |
| 172 | + assert(int !== copy) |
| 173 | + assert(copy.value == 42) |
| 174 | + } |
| 175 | + |
| 176 | + assert(int.increment(by: 2) == 44) |
| 177 | + assert(genericIncrement(&int, by: 3) == 47) |
| 178 | + assert(int.decrement(by: 46) == 1) |
| 179 | + |
| 180 | + var incrementable: any Incrementable = int.toIncrementable() |
| 181 | + |
| 182 | + // CHECK-ABI: library: 2 |
| 183 | + // CHECK-BD: client: 2 |
| 184 | + existentialIncrementByOne(&incrementable) |
| 185 | + |
| 186 | + let int2 = MutableInt(0x08AFAB76) |
| 187 | + for (i, expectedByte) in [0x76, 0xAB, 0xAF, 0x08].enumerated() { |
| 188 | + assert(int2[byteAt: i] == expectedByte) |
| 189 | + } |
| 190 | +} |
0 commit comments