Paul Duffin | a80fdec | 2019-12-03 15:25:00 +0000 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package sdk |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/cc" |
| 21 | ) |
| 22 | |
| 23 | // Contains tests for SDK members provided by the cc package. |
| 24 | |
| 25 | func TestSdkIsCompileMultilibBoth(t *testing.T) { |
| 26 | result := testSdk(t, ` |
| 27 | sdk { |
| 28 | name: "mysdk", |
| 29 | native_shared_libs: ["sdkmember"], |
| 30 | } |
| 31 | |
| 32 | cc_library_shared { |
| 33 | name: "sdkmember", |
| 34 | srcs: ["Test.cpp"], |
| 35 | system_shared_libs: [], |
| 36 | stl: "none", |
| 37 | } |
| 38 | `) |
| 39 | |
| 40 | armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_core_shared").(*cc.Module).OutputFile() |
| 41 | arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_core_shared").(*cc.Module).OutputFile() |
| 42 | |
| 43 | var inputs []string |
| 44 | buildParams := result.Module("mysdk", "android_common").BuildParamsForTests() |
| 45 | for _, bp := range buildParams { |
| 46 | if bp.Input != nil { |
| 47 | inputs = append(inputs, bp.Input.String()) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // ensure that both 32/64 outputs are inputs of the sdk snapshot |
| 52 | ensureListContains(t, inputs, armOutput.String()) |
| 53 | ensureListContains(t, inputs, arm64Output.String()) |
| 54 | } |
| 55 | |
| 56 | func TestBasicSdkWithCc(t *testing.T) { |
| 57 | result := testSdk(t, ` |
| 58 | sdk { |
| 59 | name: "mysdk", |
| 60 | native_shared_libs: ["sdkmember"], |
| 61 | } |
| 62 | |
| 63 | sdk_snapshot { |
| 64 | name: "mysdk@1", |
| 65 | native_shared_libs: ["sdkmember_mysdk_1"], |
| 66 | } |
| 67 | |
| 68 | sdk_snapshot { |
| 69 | name: "mysdk@2", |
| 70 | native_shared_libs: ["sdkmember_mysdk_2"], |
| 71 | } |
| 72 | |
| 73 | cc_prebuilt_library_shared { |
| 74 | name: "sdkmember", |
| 75 | srcs: ["libfoo.so"], |
| 76 | prefer: false, |
| 77 | system_shared_libs: [], |
| 78 | stl: "none", |
| 79 | } |
| 80 | |
| 81 | cc_prebuilt_library_shared { |
| 82 | name: "sdkmember_mysdk_1", |
| 83 | sdk_member_name: "sdkmember", |
| 84 | srcs: ["libfoo.so"], |
| 85 | system_shared_libs: [], |
| 86 | stl: "none", |
| 87 | } |
| 88 | |
| 89 | cc_prebuilt_library_shared { |
| 90 | name: "sdkmember_mysdk_2", |
| 91 | sdk_member_name: "sdkmember", |
| 92 | srcs: ["libfoo.so"], |
| 93 | system_shared_libs: [], |
| 94 | stl: "none", |
| 95 | } |
| 96 | |
| 97 | cc_library_shared { |
| 98 | name: "mycpplib", |
| 99 | srcs: ["Test.cpp"], |
| 100 | shared_libs: ["sdkmember"], |
| 101 | system_shared_libs: [], |
| 102 | stl: "none", |
| 103 | } |
| 104 | |
| 105 | apex { |
| 106 | name: "myapex", |
| 107 | native_shared_libs: ["mycpplib"], |
| 108 | uses_sdks: ["mysdk@1"], |
| 109 | key: "myapex.key", |
| 110 | certificate: ":myapex.cert", |
| 111 | } |
| 112 | |
| 113 | apex { |
| 114 | name: "myapex2", |
| 115 | native_shared_libs: ["mycpplib"], |
| 116 | uses_sdks: ["mysdk@2"], |
| 117 | key: "myapex.key", |
| 118 | certificate: ":myapex.cert", |
| 119 | } |
| 120 | `) |
| 121 | |
| 122 | sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_core_shared_myapex").Rule("toc").Output |
| 123 | sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_core_shared_myapex2").Rule("toc").Output |
| 124 | |
| 125 | cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex") |
| 126 | cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex2") |
| 127 | |
| 128 | // Depending on the uses_sdks value, different libs are linked |
| 129 | ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String()) |
| 130 | ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String()) |
| 131 | } |
| 132 | |
| 133 | func TestSnapshotWithCcShared(t *testing.T) { |
| 134 | result := testSdk(t, ` |
| 135 | sdk { |
| 136 | name: "mysdk", |
| 137 | native_shared_libs: ["mynativelib"], |
| 138 | } |
| 139 | |
| 140 | cc_library_shared { |
| 141 | name: "mynativelib", |
| 142 | srcs: [ |
| 143 | "Test.cpp", |
| 144 | "aidl/foo/bar/Test.aidl", |
| 145 | ], |
| 146 | export_include_dirs: ["include"], |
| 147 | aidl: { |
| 148 | export_aidl_headers: true, |
| 149 | }, |
| 150 | system_shared_libs: [], |
| 151 | stl: "none", |
| 152 | } |
| 153 | `) |
| 154 | |
| 155 | result.CheckSnapshot("mysdk", "android_common", |
| 156 | checkAndroidBpContents(` |
| 157 | // This is auto-generated. DO NOT EDIT. |
| 158 | |
| 159 | cc_prebuilt_library_shared { |
| 160 | name: "mysdk_mynativelib@current", |
| 161 | sdk_member_name: "mynativelib", |
| 162 | arch: { |
| 163 | arm64: { |
| 164 | srcs: ["arm64/lib/mynativelib.so"], |
| 165 | export_include_dirs: [ |
| 166 | "arm64/include/include", |
| 167 | "arm64/include_gen/mynativelib", |
| 168 | ], |
| 169 | }, |
| 170 | arm: { |
| 171 | srcs: ["arm/lib/mynativelib.so"], |
| 172 | export_include_dirs: [ |
| 173 | "arm/include/include", |
| 174 | "arm/include_gen/mynativelib", |
| 175 | ], |
| 176 | }, |
| 177 | }, |
| 178 | stl: "none", |
| 179 | system_shared_libs: [], |
| 180 | } |
| 181 | |
| 182 | cc_prebuilt_library_shared { |
| 183 | name: "mynativelib", |
| 184 | prefer: false, |
| 185 | arch: { |
| 186 | arm64: { |
| 187 | srcs: ["arm64/lib/mynativelib.so"], |
| 188 | export_include_dirs: [ |
| 189 | "arm64/include/include", |
| 190 | "arm64/include_gen/mynativelib", |
| 191 | ], |
| 192 | }, |
| 193 | arm: { |
| 194 | srcs: ["arm/lib/mynativelib.so"], |
| 195 | export_include_dirs: [ |
| 196 | "arm/include/include", |
| 197 | "arm/include_gen/mynativelib", |
| 198 | ], |
| 199 | }, |
| 200 | }, |
| 201 | stl: "none", |
| 202 | system_shared_libs: [], |
| 203 | } |
| 204 | |
| 205 | sdk_snapshot { |
| 206 | name: "mysdk@current", |
| 207 | native_shared_libs: ["mysdk_mynativelib@current"], |
| 208 | } |
| 209 | `), |
| 210 | checkAllCopyRules(` |
| 211 | .intermediates/mynativelib/android_arm64_armv8-a_core_shared/mynativelib.so -> arm64/lib/mynativelib.so |
| 212 | include/Test.h -> arm64/include/include/Test.h |
| 213 | .intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h |
| 214 | .intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h |
| 215 | .intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h |
| 216 | .intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/mynativelib.so -> arm/lib/mynativelib.so |
| 217 | include/Test.h -> arm/include/include/Test.h |
| 218 | .intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h |
| 219 | .intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h |
| 220 | .intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h |
| 221 | `), |
| 222 | ) |
| 223 | } |
| 224 | |
| 225 | func TestHostSnapshotWithCcShared(t *testing.T) { |
| 226 | // b/145598135 - Generating host snapshots for anything other than linux is not supported. |
| 227 | SkipIfNotLinux(t) |
| 228 | |
| 229 | result := testSdk(t, ` |
| 230 | sdk { |
| 231 | name: "mysdk", |
| 232 | device_supported: false, |
| 233 | host_supported: true, |
| 234 | native_shared_libs: ["mynativelib"], |
| 235 | } |
| 236 | |
| 237 | cc_library_shared { |
| 238 | name: "mynativelib", |
| 239 | device_supported: false, |
| 240 | host_supported: true, |
| 241 | srcs: [ |
| 242 | "Test.cpp", |
| 243 | "aidl/foo/bar/Test.aidl", |
| 244 | ], |
| 245 | export_include_dirs: ["include"], |
| 246 | aidl: { |
| 247 | export_aidl_headers: true, |
| 248 | }, |
| 249 | system_shared_libs: [], |
| 250 | stl: "none", |
| 251 | } |
| 252 | `) |
| 253 | |
| 254 | result.CheckSnapshot("mysdk", "linux_glibc_common", |
| 255 | checkAndroidBpContents(` |
| 256 | // This is auto-generated. DO NOT EDIT. |
| 257 | |
| 258 | cc_prebuilt_library_shared { |
| 259 | name: "mysdk_mynativelib@current", |
| 260 | sdk_member_name: "mynativelib", |
| 261 | device_supported: false, |
| 262 | host_supported: true, |
| 263 | arch: { |
| 264 | x86_64: { |
| 265 | srcs: ["x86_64/lib/mynativelib.so"], |
| 266 | export_include_dirs: [ |
| 267 | "x86_64/include/include", |
| 268 | "x86_64/include_gen/mynativelib", |
| 269 | ], |
| 270 | }, |
| 271 | x86: { |
| 272 | srcs: ["x86/lib/mynativelib.so"], |
| 273 | export_include_dirs: [ |
| 274 | "x86/include/include", |
| 275 | "x86/include_gen/mynativelib", |
| 276 | ], |
| 277 | }, |
| 278 | }, |
| 279 | stl: "none", |
| 280 | system_shared_libs: [], |
| 281 | } |
| 282 | |
| 283 | cc_prebuilt_library_shared { |
| 284 | name: "mynativelib", |
| 285 | prefer: false, |
| 286 | device_supported: false, |
| 287 | host_supported: true, |
| 288 | arch: { |
| 289 | x86_64: { |
| 290 | srcs: ["x86_64/lib/mynativelib.so"], |
| 291 | export_include_dirs: [ |
| 292 | "x86_64/include/include", |
| 293 | "x86_64/include_gen/mynativelib", |
| 294 | ], |
| 295 | }, |
| 296 | x86: { |
| 297 | srcs: ["x86/lib/mynativelib.so"], |
| 298 | export_include_dirs: [ |
| 299 | "x86/include/include", |
| 300 | "x86/include_gen/mynativelib", |
| 301 | ], |
| 302 | }, |
| 303 | }, |
| 304 | stl: "none", |
| 305 | system_shared_libs: [], |
| 306 | } |
| 307 | |
| 308 | sdk_snapshot { |
| 309 | name: "mysdk@current", |
| 310 | device_supported: false, |
| 311 | host_supported: true, |
| 312 | native_shared_libs: ["mysdk_mynativelib@current"], |
| 313 | } |
| 314 | `), |
| 315 | checkAllCopyRules(` |
| 316 | .intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so |
| 317 | include/Test.h -> x86_64/include/include/Test.h |
| 318 | .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h |
| 319 | .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h |
| 320 | .intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h |
| 321 | .intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so |
| 322 | include/Test.h -> x86/include/include/Test.h |
| 323 | .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h |
| 324 | .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h |
| 325 | .intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h |
| 326 | `), |
| 327 | ) |
| 328 | } |