Colin Cross | d00350c | 2017-11-17 10:55:38 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 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 | |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 15 | package cc |
| 16 | |
| 17 | import ( |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 18 | "android/soong/android" |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 19 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 20 | "fmt" |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 21 | "io/ioutil" |
| 22 | "os" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 23 | "reflect" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 24 | "sort" |
| 25 | "strings" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 26 | "testing" |
| 27 | ) |
| 28 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 29 | var buildDir string |
| 30 | |
| 31 | func setUp() { |
| 32 | var err error |
| 33 | buildDir, err = ioutil.TempDir("", "soong_cc_test") |
| 34 | if err != nil { |
| 35 | panic(err) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func tearDown() { |
| 40 | os.RemoveAll(buildDir) |
| 41 | } |
| 42 | |
| 43 | func TestMain(m *testing.M) { |
| 44 | run := func() int { |
| 45 | setUp() |
| 46 | defer tearDown() |
| 47 | |
| 48 | return m.Run() |
| 49 | } |
| 50 | |
| 51 | os.Exit(run()) |
| 52 | } |
| 53 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 54 | func createTestContext(t *testing.T, config android.Config, bp string) *android.TestContext { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 55 | ctx := android.NewTestArchContext() |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 56 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 57 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory)) |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 58 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory)) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 59 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory)) |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 60 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory)) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 61 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory)) |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 62 | ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory)) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 63 | ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory)) |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 64 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory)) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 65 | ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 66 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 67 | ctx.BottomUp("image", ImageMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 68 | ctx.BottomUp("link", LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 69 | ctx.BottomUp("vndk", VndkMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 70 | ctx.BottomUp("version", VersionMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 71 | ctx.BottomUp("begin", BeginMutator).Parallel() |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 72 | }) |
| 73 | ctx.Register() |
| 74 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 75 | // add some modules that are required by the compiler and/or linker |
| 76 | bp = bp + ` |
| 77 | toolchain_library { |
| 78 | name: "libatomic", |
| 79 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 80 | recovery_available: true, |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 81 | src: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | toolchain_library { |
| 85 | name: "libcompiler_rt-extras", |
| 86 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 87 | recovery_available: true, |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 88 | src: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | toolchain_library { |
Yi Kong | 7df0f30 | 2018-10-08 22:10:12 +0000 | [diff] [blame] | 92 | name: "libclang_rt.builtins-arm-android", |
| 93 | vendor_available: true, |
| 94 | recovery_available: true, |
| 95 | src: "", |
| 96 | } |
| 97 | |
| 98 | toolchain_library { |
| 99 | name: "libclang_rt.builtins-aarch64-android", |
| 100 | vendor_available: true, |
| 101 | recovery_available: true, |
| 102 | src: "", |
| 103 | } |
| 104 | |
| 105 | toolchain_library { |
| 106 | name: "libclang_rt.builtins-i686-android", |
| 107 | vendor_available: true, |
| 108 | recovery_available: true, |
| 109 | src: "", |
| 110 | } |
| 111 | |
| 112 | toolchain_library { |
| 113 | name: "libclang_rt.builtins-x86_64-android", |
| 114 | vendor_available: true, |
| 115 | recovery_available: true, |
| 116 | src: "", |
| 117 | } |
| 118 | |
| 119 | toolchain_library { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 120 | name: "libgcc", |
| 121 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 122 | recovery_available: true, |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 123 | src: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | cc_library { |
| 127 | name: "libc", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 128 | no_libgcc: true, |
| 129 | nocrt: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 130 | system_shared_libs: [], |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 131 | recovery_available: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 132 | } |
| 133 | llndk_library { |
| 134 | name: "libc", |
| 135 | symbol_file: "", |
| 136 | } |
| 137 | cc_library { |
| 138 | name: "libm", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 139 | no_libgcc: true, |
| 140 | nocrt: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 141 | system_shared_libs: [], |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 142 | recovery_available: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 143 | } |
| 144 | llndk_library { |
| 145 | name: "libm", |
| 146 | symbol_file: "", |
| 147 | } |
| 148 | cc_library { |
| 149 | name: "libdl", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 150 | no_libgcc: true, |
| 151 | nocrt: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 152 | system_shared_libs: [], |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 153 | recovery_available: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 154 | } |
| 155 | llndk_library { |
| 156 | name: "libdl", |
| 157 | symbol_file: "", |
| 158 | } |
Jaewoong Jung | 3e6b1fb | 2018-11-02 22:56:30 +0000 | [diff] [blame] | 159 | cc_library { |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 160 | name: "libc++_static", |
| 161 | no_libgcc: true, |
| 162 | nocrt: true, |
| 163 | system_shared_libs: [], |
| 164 | stl: "none", |
| 165 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 166 | recovery_available: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 167 | } |
| 168 | cc_library { |
| 169 | name: "libc++", |
| 170 | no_libgcc: true, |
| 171 | nocrt: true, |
| 172 | system_shared_libs: [], |
| 173 | stl: "none", |
| 174 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 175 | recovery_available: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 176 | vndk: { |
| 177 | enabled: true, |
| 178 | support_system_process: true, |
| 179 | }, |
| 180 | } |
| 181 | cc_library { |
| 182 | name: "libunwind_llvm", |
| 183 | no_libgcc: true, |
| 184 | nocrt: true, |
| 185 | system_shared_libs: [], |
| 186 | stl: "none", |
| 187 | vendor_available: true, |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 188 | recovery_available: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 189 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 190 | |
| 191 | cc_object { |
| 192 | name: "crtbegin_so", |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 193 | recovery_available: true, |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 194 | vendor_available: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | cc_object { |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 198 | name: "crtbegin_static", |
| 199 | recovery_available: true, |
| 200 | vendor_available: true, |
| 201 | } |
| 202 | |
| 203 | cc_object { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 204 | name: "crtend_so", |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 205 | recovery_available: true, |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 206 | vendor_available: true, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 209 | cc_object { |
| 210 | name: "crtend_android", |
| 211 | recovery_available: true, |
| 212 | vendor_available: true, |
| 213 | } |
| 214 | |
Colin Cross | ad59e75 | 2017-11-16 14:29:11 -0800 | [diff] [blame] | 215 | cc_library { |
| 216 | name: "libprotobuf-cpp-lite", |
| 217 | } |
| 218 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 219 | ` |
| 220 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 221 | ctx.MockFileSystem(map[string][]byte{ |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 222 | "Android.bp": []byte(bp), |
| 223 | "foo.c": nil, |
| 224 | "bar.c": nil, |
| 225 | "a.proto": nil, |
| 226 | "b.aidl": nil, |
| 227 | "my_include": nil, |
| 228 | "foo.map.txt": nil, |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 229 | }) |
| 230 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 231 | return ctx |
| 232 | } |
| 233 | |
| 234 | func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 235 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 236 | ctx := createTestContext(t, config, bp) |
| 237 | |
Jeff Gaston | d3e141d | 2017-08-08 17:46:01 -0700 | [diff] [blame] | 238 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 239 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 240 | _, errs = ctx.PrepareBuildActions(config) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 241 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 242 | |
| 243 | return ctx |
| 244 | } |
| 245 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 246 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 247 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 248 | config := android.TestArchConfig(buildDir, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 249 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 250 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 251 | |
| 252 | return testCcWithConfig(t, bp, config) |
| 253 | } |
| 254 | |
| 255 | func testCcNoVndk(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 256 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 257 | config := android.TestArchConfig(buildDir, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 258 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 259 | |
| 260 | return testCcWithConfig(t, bp, config) |
| 261 | } |
| 262 | |
| 263 | func testCcError(t *testing.T, pattern string, bp string) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 264 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 265 | config := android.TestArchConfig(buildDir, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 266 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 267 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 268 | |
| 269 | ctx := createTestContext(t, config, bp) |
| 270 | |
| 271 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 272 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 273 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 274 | return |
| 275 | } |
| 276 | |
| 277 | _, errs = ctx.PrepareBuildActions(config) |
| 278 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 279 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 280 | return |
| 281 | } |
| 282 | |
| 283 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 284 | } |
| 285 | |
| 286 | const ( |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 287 | coreVariant = "android_arm64_armv8-a_core_shared" |
| 288 | vendorVariant = "android_arm64_armv8-a_vendor_shared" |
| 289 | recoveryVariant = "android_arm64_armv8-a_recovery_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 290 | ) |
| 291 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 292 | func TestVendorSrc(t *testing.T) { |
| 293 | ctx := testCc(t, ` |
| 294 | cc_library { |
| 295 | name: "libTest", |
| 296 | srcs: ["foo.c"], |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 297 | no_libgcc: true, |
| 298 | nocrt: true, |
| 299 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 300 | vendor_available: true, |
| 301 | target: { |
| 302 | vendor: { |
| 303 | srcs: ["bar.c"], |
| 304 | }, |
| 305 | }, |
| 306 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 307 | `) |
| 308 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 309 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 310 | var objs []string |
| 311 | for _, o := range ld.Inputs { |
| 312 | objs = append(objs, o.Base()) |
| 313 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 314 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 315 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 316 | } |
| 317 | } |
| 318 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 319 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
| 320 | isVndkSp bool, extends string) { |
| 321 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 322 | t.Helper() |
| 323 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 324 | mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module) |
| 325 | if !mod.hasVendorVariant() { |
Colin Cross | f46e37f | 2018-03-21 16:25:58 -0700 | [diff] [blame] | 326 | t.Errorf("%q must have vendor variant", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | // Check library properties. |
| 330 | lib, ok := mod.compiler.(*libraryDecorator) |
| 331 | if !ok { |
| 332 | t.Errorf("%q must have libraryDecorator", name) |
| 333 | } else if lib.baseInstaller.subDir != subDir { |
| 334 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 335 | lib.baseInstaller.subDir) |
| 336 | } |
| 337 | |
| 338 | // Check VNDK properties. |
| 339 | if mod.vndkdep == nil { |
| 340 | t.Fatalf("%q must have `vndkdep`", name) |
| 341 | } |
| 342 | if !mod.isVndk() { |
| 343 | t.Errorf("%q isVndk() must equal to true", name) |
| 344 | } |
| 345 | if mod.isVndkSp() != isVndkSp { |
| 346 | t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp) |
| 347 | } |
| 348 | |
| 349 | // Check VNDK extension properties. |
| 350 | isVndkExt := extends != "" |
| 351 | if mod.isVndkExt() != isVndkExt { |
| 352 | t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt) |
| 353 | } |
| 354 | |
| 355 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 356 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | func TestVndk(t *testing.T) { |
| 361 | ctx := testCc(t, ` |
| 362 | cc_library { |
| 363 | name: "libvndk", |
| 364 | vendor_available: true, |
| 365 | vndk: { |
| 366 | enabled: true, |
| 367 | }, |
| 368 | nocrt: true, |
| 369 | } |
| 370 | |
| 371 | cc_library { |
| 372 | name: "libvndk_private", |
| 373 | vendor_available: false, |
| 374 | vndk: { |
| 375 | enabled: true, |
| 376 | }, |
| 377 | nocrt: true, |
| 378 | } |
| 379 | |
| 380 | cc_library { |
| 381 | name: "libvndk_sp", |
| 382 | vendor_available: true, |
| 383 | vndk: { |
| 384 | enabled: true, |
| 385 | support_system_process: true, |
| 386 | }, |
| 387 | nocrt: true, |
| 388 | } |
| 389 | |
| 390 | cc_library { |
| 391 | name: "libvndk_sp_private", |
| 392 | vendor_available: false, |
| 393 | vndk: { |
| 394 | enabled: true, |
| 395 | support_system_process: true, |
| 396 | }, |
| 397 | nocrt: true, |
| 398 | } |
| 399 | `) |
| 400 | |
| 401 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "") |
| 402 | checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "") |
| 403 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "") |
| 404 | checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "") |
| 405 | } |
| 406 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 407 | func TestVndkDepError(t *testing.T) { |
| 408 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 409 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 410 | cc_library { |
| 411 | name: "libvndk", |
| 412 | vendor_available: true, |
| 413 | vndk: { |
| 414 | enabled: true, |
| 415 | }, |
| 416 | shared_libs: ["libfwk"], // Cause error |
| 417 | nocrt: true, |
| 418 | } |
| 419 | |
| 420 | cc_library { |
| 421 | name: "libfwk", |
| 422 | nocrt: true, |
| 423 | } |
| 424 | `) |
| 425 | |
| 426 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 427 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 428 | cc_library { |
| 429 | name: "libvndk", |
| 430 | vendor_available: true, |
| 431 | vndk: { |
| 432 | enabled: true, |
| 433 | }, |
| 434 | shared_libs: ["libvendor"], // Cause error |
| 435 | nocrt: true, |
| 436 | } |
| 437 | |
| 438 | cc_library { |
| 439 | name: "libvendor", |
| 440 | vendor: true, |
| 441 | nocrt: true, |
| 442 | } |
| 443 | `) |
| 444 | |
| 445 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 446 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 447 | cc_library { |
| 448 | name: "libvndk_sp", |
| 449 | vendor_available: true, |
| 450 | vndk: { |
| 451 | enabled: true, |
| 452 | support_system_process: true, |
| 453 | }, |
| 454 | shared_libs: ["libfwk"], // Cause error |
| 455 | nocrt: true, |
| 456 | } |
| 457 | |
| 458 | cc_library { |
| 459 | name: "libfwk", |
| 460 | nocrt: true, |
| 461 | } |
| 462 | `) |
| 463 | |
| 464 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 465 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 466 | cc_library { |
| 467 | name: "libvndk_sp", |
| 468 | vendor_available: true, |
| 469 | vndk: { |
| 470 | enabled: true, |
| 471 | support_system_process: true, |
| 472 | }, |
| 473 | shared_libs: ["libvendor"], // Cause error |
| 474 | nocrt: true, |
| 475 | } |
| 476 | |
| 477 | cc_library { |
| 478 | name: "libvendor", |
| 479 | vendor: true, |
| 480 | nocrt: true, |
| 481 | } |
| 482 | `) |
| 483 | |
| 484 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 485 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 486 | cc_library { |
| 487 | name: "libvndk_sp", |
| 488 | vendor_available: true, |
| 489 | vndk: { |
| 490 | enabled: true, |
| 491 | support_system_process: true, |
| 492 | }, |
| 493 | shared_libs: ["libvndk"], // Cause error |
| 494 | nocrt: true, |
| 495 | } |
| 496 | |
| 497 | cc_library { |
| 498 | name: "libvndk", |
| 499 | vendor_available: true, |
| 500 | vndk: { |
| 501 | enabled: true, |
| 502 | }, |
| 503 | nocrt: true, |
| 504 | } |
| 505 | `) |
| 506 | } |
| 507 | |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 508 | func TestVndkMustNotBeProductSpecific(t *testing.T) { |
| 509 | // Check whether an error is emitted when a vndk lib has 'product_specific: true'. |
| 510 | testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", ` |
| 511 | cc_library { |
| 512 | name: "libvndk", |
| 513 | product_specific: true, // Cause error |
| 514 | vendor_available: true, |
| 515 | vndk: { |
| 516 | enabled: true, |
| 517 | }, |
| 518 | nocrt: true, |
| 519 | } |
| 520 | `) |
| 521 | } |
| 522 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 523 | func TestVndkExt(t *testing.T) { |
| 524 | // This test checks the VNDK-Ext properties. |
| 525 | ctx := testCc(t, ` |
| 526 | cc_library { |
| 527 | name: "libvndk", |
| 528 | vendor_available: true, |
| 529 | vndk: { |
| 530 | enabled: true, |
| 531 | }, |
| 532 | nocrt: true, |
| 533 | } |
| 534 | |
| 535 | cc_library { |
| 536 | name: "libvndk_ext", |
| 537 | vendor: true, |
| 538 | vndk: { |
| 539 | enabled: true, |
| 540 | extends: "libvndk", |
| 541 | }, |
| 542 | nocrt: true, |
| 543 | } |
| 544 | `) |
| 545 | |
| 546 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk") |
| 547 | } |
| 548 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 549 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 550 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 551 | ctx := testCcNoVndk(t, ` |
| 552 | cc_library { |
| 553 | name: "libvndk", |
| 554 | vendor_available: true, |
| 555 | vndk: { |
| 556 | enabled: true, |
| 557 | }, |
| 558 | nocrt: true, |
| 559 | } |
| 560 | |
| 561 | cc_library { |
| 562 | name: "libvndk_ext", |
| 563 | vendor: true, |
| 564 | vndk: { |
| 565 | enabled: true, |
| 566 | extends: "libvndk", |
| 567 | }, |
| 568 | nocrt: true, |
| 569 | } |
| 570 | `) |
| 571 | |
| 572 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 573 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 574 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 575 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | func TestVndkExtError(t *testing.T) { |
| 580 | // This test ensures an error is emitted in ill-formed vndk-ext definition. |
| 581 | testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", ` |
| 582 | cc_library { |
| 583 | name: "libvndk", |
| 584 | vendor_available: true, |
| 585 | vndk: { |
| 586 | enabled: true, |
| 587 | }, |
| 588 | nocrt: true, |
| 589 | } |
| 590 | |
| 591 | cc_library { |
| 592 | name: "libvndk_ext", |
| 593 | vndk: { |
| 594 | enabled: true, |
| 595 | extends: "libvndk", |
| 596 | }, |
| 597 | nocrt: true, |
| 598 | } |
| 599 | `) |
| 600 | |
| 601 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 602 | cc_library { |
| 603 | name: "libvndk", |
| 604 | vendor_available: true, |
| 605 | vndk: { |
| 606 | enabled: true, |
| 607 | }, |
| 608 | nocrt: true, |
| 609 | } |
| 610 | |
| 611 | cc_library { |
| 612 | name: "libvndk_ext", |
| 613 | vendor: true, |
| 614 | vndk: { |
| 615 | enabled: true, |
| 616 | }, |
| 617 | nocrt: true, |
| 618 | } |
| 619 | `) |
| 620 | } |
| 621 | |
| 622 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 623 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 624 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 625 | cc_library { |
| 626 | name: "libvndk", |
| 627 | vendor_available: true, |
| 628 | vndk: { |
| 629 | enabled: true, |
| 630 | }, |
| 631 | nocrt: true, |
| 632 | } |
| 633 | |
| 634 | cc_library { |
| 635 | name: "libvndk_sp_ext", |
| 636 | vendor: true, |
| 637 | vndk: { |
| 638 | enabled: true, |
| 639 | extends: "libvndk", |
| 640 | support_system_process: true, |
| 641 | }, |
| 642 | nocrt: true, |
| 643 | } |
| 644 | `) |
| 645 | |
| 646 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 647 | cc_library { |
| 648 | name: "libvndk_sp", |
| 649 | vendor_available: true, |
| 650 | vndk: { |
| 651 | enabled: true, |
| 652 | support_system_process: true, |
| 653 | }, |
| 654 | nocrt: true, |
| 655 | } |
| 656 | |
| 657 | cc_library { |
| 658 | name: "libvndk_ext", |
| 659 | vendor: true, |
| 660 | vndk: { |
| 661 | enabled: true, |
| 662 | extends: "libvndk_sp", |
| 663 | }, |
| 664 | nocrt: true, |
| 665 | } |
| 666 | `) |
| 667 | } |
| 668 | |
| 669 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 670 | // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 671 | // with `vendor_available: false`. |
| 672 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 673 | cc_library { |
| 674 | name: "libvndk", |
| 675 | vendor_available: false, |
| 676 | vndk: { |
| 677 | enabled: true, |
| 678 | }, |
| 679 | nocrt: true, |
| 680 | } |
| 681 | |
| 682 | cc_library { |
| 683 | name: "libvndk_ext", |
| 684 | vendor: true, |
| 685 | vndk: { |
| 686 | enabled: true, |
| 687 | extends: "libvndk", |
| 688 | }, |
| 689 | nocrt: true, |
| 690 | } |
| 691 | `) |
| 692 | } |
| 693 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 694 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 695 | // This test ensures a vendor module can depend on a VNDK-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 696 | testCc(t, ` |
| 697 | cc_library { |
| 698 | name: "libvndk", |
| 699 | vendor_available: true, |
| 700 | vndk: { |
| 701 | enabled: true, |
| 702 | }, |
| 703 | nocrt: true, |
| 704 | } |
| 705 | |
| 706 | cc_library { |
| 707 | name: "libvndk_ext", |
| 708 | vendor: true, |
| 709 | vndk: { |
| 710 | enabled: true, |
| 711 | extends: "libvndk", |
| 712 | }, |
| 713 | nocrt: true, |
| 714 | } |
| 715 | |
| 716 | cc_library { |
| 717 | |
| 718 | name: "libvndk_sp", |
| 719 | vendor_available: true, |
| 720 | vndk: { |
| 721 | enabled: true, |
| 722 | support_system_process: true, |
| 723 | }, |
| 724 | nocrt: true, |
| 725 | } |
| 726 | |
| 727 | cc_library { |
| 728 | name: "libvndk_sp_ext", |
| 729 | vendor: true, |
| 730 | vndk: { |
| 731 | enabled: true, |
| 732 | extends: "libvndk_sp", |
| 733 | support_system_process: true, |
| 734 | }, |
| 735 | nocrt: true, |
| 736 | } |
| 737 | |
| 738 | cc_library { |
| 739 | name: "libvendor", |
| 740 | vendor: true, |
| 741 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 742 | nocrt: true, |
| 743 | } |
| 744 | `) |
| 745 | } |
| 746 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 747 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 748 | // This test ensures a VNDK-Ext library can depend on a vendor library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 749 | testCc(t, ` |
| 750 | cc_library { |
| 751 | name: "libvndk", |
| 752 | vendor_available: true, |
| 753 | vndk: { |
| 754 | enabled: true, |
| 755 | }, |
| 756 | nocrt: true, |
| 757 | } |
| 758 | |
| 759 | cc_library { |
| 760 | name: "libvndk_ext", |
| 761 | vendor: true, |
| 762 | vndk: { |
| 763 | enabled: true, |
| 764 | extends: "libvndk", |
| 765 | }, |
| 766 | shared_libs: ["libvendor"], |
| 767 | nocrt: true, |
| 768 | } |
| 769 | |
| 770 | cc_library { |
| 771 | name: "libvendor", |
| 772 | vendor: true, |
| 773 | nocrt: true, |
| 774 | } |
| 775 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 776 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 777 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 778 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 779 | cc_library { |
| 780 | name: "libvndk_sp", |
| 781 | vendor_available: true, |
| 782 | vndk: { |
| 783 | enabled: true, |
| 784 | support_system_process: true, |
| 785 | }, |
| 786 | nocrt: true, |
| 787 | } |
| 788 | |
| 789 | cc_library { |
| 790 | name: "libvndk_sp_ext", |
| 791 | vendor: true, |
| 792 | vndk: { |
| 793 | enabled: true, |
| 794 | extends: "libvndk_sp", |
| 795 | support_system_process: true, |
| 796 | }, |
| 797 | shared_libs: ["libvendor"], // Cause an error |
| 798 | nocrt: true, |
| 799 | } |
| 800 | |
| 801 | cc_library { |
| 802 | name: "libvendor", |
| 803 | vendor: true, |
| 804 | nocrt: true, |
| 805 | } |
| 806 | `) |
| 807 | } |
| 808 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 809 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 810 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 811 | // library. |
| 812 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 813 | cc_library { |
| 814 | name: "libvndk", |
| 815 | vendor_available: true, |
| 816 | vndk: { |
| 817 | enabled: true, |
| 818 | }, |
| 819 | nocrt: true, |
| 820 | } |
| 821 | |
| 822 | cc_library { |
| 823 | name: "libvndk_sp", |
| 824 | vendor_available: true, |
| 825 | vndk: { |
| 826 | enabled: true, |
| 827 | support_system_process: true, |
| 828 | }, |
| 829 | nocrt: true, |
| 830 | } |
| 831 | |
| 832 | cc_library { |
| 833 | name: "libvndk_sp_ext", |
| 834 | vendor: true, |
| 835 | vndk: { |
| 836 | enabled: true, |
| 837 | extends: "libvndk_sp", |
| 838 | support_system_process: true, |
| 839 | }, |
| 840 | shared_libs: ["libvndk"], // Cause an error |
| 841 | nocrt: true, |
| 842 | } |
| 843 | `) |
| 844 | |
| 845 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 846 | // library. |
| 847 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 848 | cc_library { |
| 849 | name: "libvndk", |
| 850 | vendor_available: true, |
| 851 | vndk: { |
| 852 | enabled: true, |
| 853 | }, |
| 854 | nocrt: true, |
| 855 | } |
| 856 | |
| 857 | cc_library { |
| 858 | name: "libvndk_ext", |
| 859 | vendor: true, |
| 860 | vndk: { |
| 861 | enabled: true, |
| 862 | extends: "libvndk", |
| 863 | }, |
| 864 | nocrt: true, |
| 865 | } |
| 866 | |
| 867 | cc_library { |
| 868 | name: "libvndk_sp", |
| 869 | vendor_available: true, |
| 870 | vndk: { |
| 871 | enabled: true, |
| 872 | support_system_process: true, |
| 873 | }, |
| 874 | nocrt: true, |
| 875 | } |
| 876 | |
| 877 | cc_library { |
| 878 | name: "libvndk_sp_ext", |
| 879 | vendor: true, |
| 880 | vndk: { |
| 881 | enabled: true, |
| 882 | extends: "libvndk_sp", |
| 883 | support_system_process: true, |
| 884 | }, |
| 885 | shared_libs: ["libvndk_ext"], // Cause an error |
| 886 | nocrt: true, |
| 887 | } |
| 888 | `) |
| 889 | } |
| 890 | |
| 891 | func TestVndkUseVndkExtError(t *testing.T) { |
| 892 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 893 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 894 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 895 | cc_library { |
| 896 | name: "libvndk", |
| 897 | vendor_available: true, |
| 898 | vndk: { |
| 899 | enabled: true, |
| 900 | }, |
| 901 | nocrt: true, |
| 902 | } |
| 903 | |
| 904 | cc_library { |
| 905 | name: "libvndk_ext", |
| 906 | vendor: true, |
| 907 | vndk: { |
| 908 | enabled: true, |
| 909 | extends: "libvndk", |
| 910 | }, |
| 911 | nocrt: true, |
| 912 | } |
| 913 | |
| 914 | cc_library { |
| 915 | name: "libvndk2", |
| 916 | vendor_available: true, |
| 917 | vndk: { |
| 918 | enabled: true, |
| 919 | }, |
| 920 | shared_libs: ["libvndk_ext"], |
| 921 | nocrt: true, |
| 922 | } |
| 923 | `) |
| 924 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 925 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 926 | cc_library { |
| 927 | name: "libvndk", |
| 928 | vendor_available: true, |
| 929 | vndk: { |
| 930 | enabled: true, |
| 931 | }, |
| 932 | nocrt: true, |
| 933 | } |
| 934 | |
| 935 | cc_library { |
| 936 | name: "libvndk_ext", |
| 937 | vendor: true, |
| 938 | vndk: { |
| 939 | enabled: true, |
| 940 | extends: "libvndk", |
| 941 | }, |
| 942 | nocrt: true, |
| 943 | } |
| 944 | |
| 945 | cc_library { |
| 946 | name: "libvndk2", |
| 947 | vendor_available: true, |
| 948 | vndk: { |
| 949 | enabled: true, |
| 950 | }, |
| 951 | target: { |
| 952 | vendor: { |
| 953 | shared_libs: ["libvndk_ext"], |
| 954 | }, |
| 955 | }, |
| 956 | nocrt: true, |
| 957 | } |
| 958 | `) |
| 959 | |
| 960 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 961 | cc_library { |
| 962 | name: "libvndk_sp", |
| 963 | vendor_available: true, |
| 964 | vndk: { |
| 965 | enabled: true, |
| 966 | support_system_process: true, |
| 967 | }, |
| 968 | nocrt: true, |
| 969 | } |
| 970 | |
| 971 | cc_library { |
| 972 | name: "libvndk_sp_ext", |
| 973 | vendor: true, |
| 974 | vndk: { |
| 975 | enabled: true, |
| 976 | extends: "libvndk_sp", |
| 977 | support_system_process: true, |
| 978 | }, |
| 979 | nocrt: true, |
| 980 | } |
| 981 | |
| 982 | cc_library { |
| 983 | name: "libvndk_sp_2", |
| 984 | vendor_available: true, |
| 985 | vndk: { |
| 986 | enabled: true, |
| 987 | support_system_process: true, |
| 988 | }, |
| 989 | shared_libs: ["libvndk_sp_ext"], |
| 990 | nocrt: true, |
| 991 | } |
| 992 | `) |
| 993 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 994 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 995 | cc_library { |
| 996 | name: "libvndk_sp", |
| 997 | vendor_available: true, |
| 998 | vndk: { |
| 999 | enabled: true, |
| 1000 | }, |
| 1001 | nocrt: true, |
| 1002 | } |
| 1003 | |
| 1004 | cc_library { |
| 1005 | name: "libvndk_sp_ext", |
| 1006 | vendor: true, |
| 1007 | vndk: { |
| 1008 | enabled: true, |
| 1009 | extends: "libvndk_sp", |
| 1010 | }, |
| 1011 | nocrt: true, |
| 1012 | } |
| 1013 | |
| 1014 | cc_library { |
| 1015 | name: "libvndk_sp2", |
| 1016 | vendor_available: true, |
| 1017 | vndk: { |
| 1018 | enabled: true, |
| 1019 | }, |
| 1020 | target: { |
| 1021 | vendor: { |
| 1022 | shared_libs: ["libvndk_sp_ext"], |
| 1023 | }, |
| 1024 | }, |
| 1025 | nocrt: true, |
| 1026 | } |
| 1027 | `) |
| 1028 | } |
| 1029 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1030 | var ( |
| 1031 | str11 = "01234567891" |
| 1032 | str10 = str11[:10] |
| 1033 | str9 = str11[:9] |
| 1034 | str5 = str11[:5] |
| 1035 | str4 = str11[:4] |
| 1036 | ) |
| 1037 | |
| 1038 | var splitListForSizeTestCases = []struct { |
| 1039 | in []string |
| 1040 | out [][]string |
| 1041 | size int |
| 1042 | }{ |
| 1043 | { |
| 1044 | in: []string{str10}, |
| 1045 | out: [][]string{{str10}}, |
| 1046 | size: 10, |
| 1047 | }, |
| 1048 | { |
| 1049 | in: []string{str9}, |
| 1050 | out: [][]string{{str9}}, |
| 1051 | size: 10, |
| 1052 | }, |
| 1053 | { |
| 1054 | in: []string{str5}, |
| 1055 | out: [][]string{{str5}}, |
| 1056 | size: 10, |
| 1057 | }, |
| 1058 | { |
| 1059 | in: []string{str11}, |
| 1060 | out: nil, |
| 1061 | size: 10, |
| 1062 | }, |
| 1063 | { |
| 1064 | in: []string{str10, str10}, |
| 1065 | out: [][]string{{str10}, {str10}}, |
| 1066 | size: 10, |
| 1067 | }, |
| 1068 | { |
| 1069 | in: []string{str9, str10}, |
| 1070 | out: [][]string{{str9}, {str10}}, |
| 1071 | size: 10, |
| 1072 | }, |
| 1073 | { |
| 1074 | in: []string{str10, str9}, |
| 1075 | out: [][]string{{str10}, {str9}}, |
| 1076 | size: 10, |
| 1077 | }, |
| 1078 | { |
| 1079 | in: []string{str5, str4}, |
| 1080 | out: [][]string{{str5, str4}}, |
| 1081 | size: 10, |
| 1082 | }, |
| 1083 | { |
| 1084 | in: []string{str5, str4, str5}, |
| 1085 | out: [][]string{{str5, str4}, {str5}}, |
| 1086 | size: 10, |
| 1087 | }, |
| 1088 | { |
| 1089 | in: []string{str5, str4, str5, str4}, |
| 1090 | out: [][]string{{str5, str4}, {str5, str4}}, |
| 1091 | size: 10, |
| 1092 | }, |
| 1093 | { |
| 1094 | in: []string{str5, str4, str5, str5}, |
| 1095 | out: [][]string{{str5, str4}, {str5}, {str5}}, |
| 1096 | size: 10, |
| 1097 | }, |
| 1098 | { |
| 1099 | in: []string{str5, str5, str5, str4}, |
| 1100 | out: [][]string{{str5}, {str5}, {str5, str4}}, |
| 1101 | size: 10, |
| 1102 | }, |
| 1103 | { |
| 1104 | in: []string{str9, str11}, |
| 1105 | out: nil, |
| 1106 | size: 10, |
| 1107 | }, |
| 1108 | { |
| 1109 | in: []string{str11, str9}, |
| 1110 | out: nil, |
| 1111 | size: 10, |
| 1112 | }, |
| 1113 | } |
| 1114 | |
| 1115 | func TestSplitListForSize(t *testing.T) { |
| 1116 | for _, testCase := range splitListForSizeTestCases { |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 1117 | out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size) |
| 1118 | |
| 1119 | var outStrings [][]string |
| 1120 | |
| 1121 | if len(out) > 0 { |
| 1122 | outStrings = make([][]string, len(out)) |
| 1123 | for i, o := range out { |
| 1124 | outStrings[i] = o.Strings() |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | if !reflect.DeepEqual(outStrings, testCase.out) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1129 | t.Errorf("incorrect output:") |
| 1130 | t.Errorf(" input: %#v", testCase.in) |
| 1131 | t.Errorf(" size: %d", testCase.size) |
| 1132 | t.Errorf(" expected: %#v", testCase.out) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 1133 | t.Errorf(" got: %#v", outStrings) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1137 | |
| 1138 | var staticLinkDepOrderTestCases = []struct { |
| 1139 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 1140 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1141 | inStatic string |
| 1142 | |
| 1143 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 1144 | // It models the dependencies declared in an Android.bp file. |
| 1145 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1146 | |
| 1147 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 1148 | // The keys of allOrdered specify which modules we would like to check. |
| 1149 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 1150 | // dependencies) for each module to test |
| 1151 | allOrdered string |
| 1152 | |
| 1153 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 1154 | // The keys of outOrdered specify which modules we would like to check. |
| 1155 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 1156 | // for each module to test. |
| 1157 | outOrdered string |
| 1158 | }{ |
| 1159 | // Simple tests |
| 1160 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1161 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1162 | outOrdered: "", |
| 1163 | }, |
| 1164 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1165 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1166 | outOrdered: "a:", |
| 1167 | }, |
| 1168 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1169 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1170 | outOrdered: "a:b; b:", |
| 1171 | }, |
| 1172 | // Tests of reordering |
| 1173 | { |
| 1174 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1175 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1176 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 1177 | }, |
| 1178 | { |
| 1179 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1180 | inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1181 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 1182 | }, |
| 1183 | { |
| 1184 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1185 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1186 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 1187 | }, |
| 1188 | { |
| 1189 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1190 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1191 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 1192 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 1193 | }, |
| 1194 | { |
| 1195 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1196 | inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1197 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 1198 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 1199 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1200 | // shared dependencies |
| 1201 | { |
| 1202 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 1203 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 1204 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 1205 | // a shared dependency on b, that that shows up in allOrdered. |
| 1206 | inShared: "c:b", |
| 1207 | allOrdered: "c:b", |
| 1208 | outOrdered: "c:", |
| 1209 | }, |
| 1210 | { |
| 1211 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 1212 | // the second phase of the above test would look like |
| 1213 | inStatic: "a:b,c; c:b", |
| 1214 | allOrdered: "a:c,b; c:b", |
| 1215 | outOrdered: "a:c,b; c:b", |
| 1216 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1217 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 1218 | // to dictate an order |
| 1219 | { |
| 1220 | // if the tie is between two modules at the end of a's deps, then a's order wins |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1221 | inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1222 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 1223 | }, |
| 1224 | { |
| 1225 | // if the tie is between two modules at the start of a's deps, then c's order is used |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1226 | inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1227 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 1228 | }, |
| 1229 | // Tests involving duplicate dependencies |
| 1230 | { |
| 1231 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1232 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1233 | outOrdered: "a:c,b", |
| 1234 | }, |
| 1235 | { |
| 1236 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1237 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1238 | outOrdered: "a:d,c,b", |
| 1239 | }, |
| 1240 | // Tests to confirm the nonexistence of infinite loops. |
| 1241 | // These cases should never happen, so as long as the test terminates and the |
| 1242 | // result is deterministic then that should be fine. |
| 1243 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1244 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1245 | outOrdered: "a:a", |
| 1246 | }, |
| 1247 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1248 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1249 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 1250 | outOrdered: "a:b; b:c; c:a", |
| 1251 | }, |
| 1252 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1253 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1254 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 1255 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 1256 | }, |
| 1257 | } |
| 1258 | |
| 1259 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 1260 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 1261 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 1262 | strippedText := strings.Replace(text, " ", "", -1) |
| 1263 | if len(strippedText) < 1 { |
| 1264 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 1265 | } |
| 1266 | allDeps = make(map[android.Path][]android.Path, 0) |
| 1267 | |
| 1268 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 1269 | moduleTexts := strings.Split(strippedText, ";") |
| 1270 | |
| 1271 | outputForModuleName := func(moduleName string) android.Path { |
| 1272 | return android.PathForTesting(moduleName) |
| 1273 | } |
| 1274 | |
| 1275 | for _, moduleText := range moduleTexts { |
| 1276 | // convert from "a:b,c" to ["a", "b,c"] |
| 1277 | components := strings.Split(moduleText, ":") |
| 1278 | if len(components) != 2 { |
| 1279 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 1280 | } |
| 1281 | moduleName := components[0] |
| 1282 | moduleOutput := outputForModuleName(moduleName) |
| 1283 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 1284 | |
| 1285 | depString := components[1] |
| 1286 | // convert from "b,c" to ["b", "c"] |
| 1287 | depNames := strings.Split(depString, ",") |
| 1288 | if len(depString) < 1 { |
| 1289 | depNames = []string{} |
| 1290 | } |
| 1291 | var deps []android.Path |
| 1292 | for _, depName := range depNames { |
| 1293 | deps = append(deps, outputForModuleName(depName)) |
| 1294 | } |
| 1295 | allDeps[moduleOutput] = deps |
| 1296 | } |
| 1297 | return modulesInOrder, allDeps |
| 1298 | } |
| 1299 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1300 | func TestLinkReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1301 | for _, testCase := range staticLinkDepOrderTestCases { |
| 1302 | errs := []string{} |
| 1303 | |
| 1304 | // parse testcase |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1305 | _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1306 | expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered) |
| 1307 | if testCase.allOrdered == "" { |
| 1308 | // allow the test case to skip specifying allOrdered |
| 1309 | testCase.allOrdered = testCase.outOrdered |
| 1310 | } |
| 1311 | _, expectedAllDeps := parseModuleDeps(testCase.allOrdered) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1312 | _, givenAllSharedDeps := parseModuleDeps(testCase.inShared) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1313 | |
| 1314 | // For each module whose post-reordered dependencies were specified, validate that |
| 1315 | // reordering the inputs produces the expected outputs. |
| 1316 | for _, moduleName := range expectedModuleNames { |
| 1317 | moduleDeps := givenTransitiveDeps[moduleName] |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1318 | givenSharedDeps := givenAllSharedDeps[moduleName] |
| 1319 | orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1320 | |
| 1321 | correctAllOrdered := expectedAllDeps[moduleName] |
| 1322 | if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) { |
| 1323 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+ |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1324 | "\nin static:%q"+ |
| 1325 | "\nin shared:%q"+ |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1326 | "\nmodule: %v"+ |
| 1327 | "\nexpected: %s"+ |
| 1328 | "\nactual: %s", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1329 | testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | correctOutputDeps := expectedTransitiveDeps[moduleName] |
| 1333 | if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) { |
| 1334 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+ |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1335 | "\nin static:%q"+ |
| 1336 | "\nin shared:%q"+ |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1337 | "\nmodule: %v"+ |
| 1338 | "\nexpected: %s"+ |
| 1339 | "\nactual: %s", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1340 | testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | if len(errs) > 0 { |
| 1345 | sort.Strings(errs) |
| 1346 | for _, err := range errs { |
| 1347 | t.Error(err) |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1352 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1353 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 1354 | for _, moduleName := range moduleNames { |
| 1355 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 1356 | output := module.outputFile.Path() |
| 1357 | paths = append(paths, output) |
| 1358 | } |
| 1359 | return paths |
| 1360 | } |
| 1361 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1362 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1363 | ctx := testCc(t, ` |
| 1364 | cc_library { |
| 1365 | name: "a", |
| 1366 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1367 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1368 | } |
| 1369 | cc_library { |
| 1370 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1371 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1372 | } |
| 1373 | cc_library { |
| 1374 | name: "c", |
| 1375 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1376 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1377 | } |
| 1378 | cc_library { |
| 1379 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1380 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | `) |
| 1384 | |
| 1385 | variant := "android_arm64_armv8-a_core_static" |
| 1386 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1387 | actual := moduleA.depsInLinkOrder |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1388 | expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"}) |
| 1389 | |
| 1390 | if !reflect.DeepEqual(actual, expected) { |
| 1391 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 1392 | "\nactual: %v"+ |
| 1393 | "\nexpected: %v", |
| 1394 | actual, |
| 1395 | expected, |
| 1396 | ) |
| 1397 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 1398 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1399 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1400 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 1401 | ctx := testCc(t, ` |
| 1402 | cc_library { |
| 1403 | name: "a", |
| 1404 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1405 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1406 | } |
| 1407 | cc_library { |
| 1408 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1409 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1410 | } |
| 1411 | cc_library { |
| 1412 | name: "c", |
| 1413 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1414 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | `) |
| 1418 | |
| 1419 | variant := "android_arm64_armv8-a_core_static" |
| 1420 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
| 1421 | actual := moduleA.depsInLinkOrder |
| 1422 | expected := getOutputPaths(ctx, variant, []string{"c", "b"}) |
| 1423 | |
| 1424 | if !reflect.DeepEqual(actual, expected) { |
| 1425 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 1426 | "\nactual: %v"+ |
| 1427 | "\nexpected: %v", |
| 1428 | actual, |
| 1429 | expected, |
| 1430 | ) |
| 1431 | } |
| 1432 | } |
| 1433 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 1434 | func TestLlndkHeaders(t *testing.T) { |
| 1435 | ctx := testCc(t, ` |
| 1436 | llndk_headers { |
| 1437 | name: "libllndk_headers", |
| 1438 | export_include_dirs: ["my_include"], |
| 1439 | } |
| 1440 | llndk_library { |
| 1441 | name: "libllndk", |
| 1442 | export_llndk_headers: ["libllndk_headers"], |
| 1443 | } |
| 1444 | cc_library { |
| 1445 | name: "libvendor", |
| 1446 | shared_libs: ["libllndk"], |
| 1447 | vendor: true, |
| 1448 | srcs: ["foo.c"], |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1449 | no_libgcc: true, |
| 1450 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 1451 | } |
| 1452 | `) |
| 1453 | |
| 1454 | // _static variant is used since _shared reuses *.o from the static variant |
| 1455 | cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor_static").Rule("cc") |
| 1456 | cflags := cc.Args["cFlags"] |
| 1457 | if !strings.Contains(cflags, "-Imy_include") { |
| 1458 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 1459 | } |
| 1460 | } |
| 1461 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1462 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 1463 | actual := module.Properties.AndroidMkRuntimeLibs |
| 1464 | if !reflect.DeepEqual(actual, expected) { |
| 1465 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 1466 | "\nactual: %v"+ |
| 1467 | "\nexpected: %v", |
| 1468 | actual, |
| 1469 | expected, |
| 1470 | ) |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | const runtimeLibAndroidBp = ` |
| 1475 | cc_library { |
| 1476 | name: "libvendor_available1", |
| 1477 | vendor_available: true, |
| 1478 | no_libgcc : true, |
| 1479 | nocrt : true, |
| 1480 | system_shared_libs : [], |
| 1481 | } |
| 1482 | cc_library { |
| 1483 | name: "libvendor_available2", |
| 1484 | vendor_available: true, |
| 1485 | runtime_libs: ["libvendor_available1"], |
| 1486 | no_libgcc : true, |
| 1487 | nocrt : true, |
| 1488 | system_shared_libs : [], |
| 1489 | } |
| 1490 | cc_library { |
| 1491 | name: "libvendor_available3", |
| 1492 | vendor_available: true, |
| 1493 | runtime_libs: ["libvendor_available1"], |
| 1494 | target: { |
| 1495 | vendor: { |
| 1496 | exclude_runtime_libs: ["libvendor_available1"], |
| 1497 | } |
| 1498 | }, |
| 1499 | no_libgcc : true, |
| 1500 | nocrt : true, |
| 1501 | system_shared_libs : [], |
| 1502 | } |
| 1503 | cc_library { |
| 1504 | name: "libcore", |
| 1505 | runtime_libs: ["libvendor_available1"], |
| 1506 | no_libgcc : true, |
| 1507 | nocrt : true, |
| 1508 | system_shared_libs : [], |
| 1509 | } |
| 1510 | cc_library { |
| 1511 | name: "libvendor1", |
| 1512 | vendor: true, |
| 1513 | no_libgcc : true, |
| 1514 | nocrt : true, |
| 1515 | system_shared_libs : [], |
| 1516 | } |
| 1517 | cc_library { |
| 1518 | name: "libvendor2", |
| 1519 | vendor: true, |
| 1520 | runtime_libs: ["libvendor_available1", "libvendor1"], |
| 1521 | no_libgcc : true, |
| 1522 | nocrt : true, |
| 1523 | system_shared_libs : [], |
| 1524 | } |
| 1525 | ` |
| 1526 | |
| 1527 | func TestRuntimeLibs(t *testing.T) { |
| 1528 | ctx := testCc(t, runtimeLibAndroidBp) |
| 1529 | |
| 1530 | // runtime_libs for core variants use the module names without suffixes. |
| 1531 | variant := "android_arm64_armv8-a_core_shared" |
| 1532 | |
| 1533 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 1534 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 1535 | |
| 1536 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
| 1537 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 1538 | |
| 1539 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 1540 | // and vendor variants. |
| 1541 | variant = "android_arm64_armv8-a_vendor_shared" |
| 1542 | |
| 1543 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 1544 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) |
| 1545 | |
| 1546 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 1547 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) |
| 1548 | } |
| 1549 | |
| 1550 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 1551 | ctx := testCc(t, runtimeLibAndroidBp) |
| 1552 | |
| 1553 | variant := "android_arm64_armv8-a_core_shared" |
| 1554 | module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 1555 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 1556 | |
| 1557 | variant = "android_arm64_armv8-a_vendor_shared" |
| 1558 | module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 1559 | checkRuntimeLibs(t, nil, module) |
| 1560 | } |
| 1561 | |
| 1562 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 1563 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 1564 | |
| 1565 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 1566 | |
| 1567 | variant := "android_arm64_armv8-a_core_shared" |
| 1568 | |
| 1569 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 1570 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 1571 | |
| 1572 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 1573 | checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) |
| 1574 | } |
| 1575 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1576 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
| 1577 | actual := module.Properties.AndroidMkStaticLibs |
| 1578 | if !reflect.DeepEqual(actual, expected) { |
| 1579 | t.Errorf("incorrect static_libs"+ |
| 1580 | "\nactual: %v"+ |
| 1581 | "\nexpected: %v", |
| 1582 | actual, |
| 1583 | expected, |
| 1584 | ) |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | const staticLibAndroidBp = ` |
| 1589 | cc_library { |
| 1590 | name: "lib1", |
| 1591 | } |
| 1592 | cc_library { |
| 1593 | name: "lib2", |
| 1594 | static_libs: ["lib1"], |
| 1595 | } |
| 1596 | ` |
| 1597 | |
| 1598 | func TestStaticLibDepExport(t *testing.T) { |
| 1599 | ctx := testCc(t, staticLibAndroidBp) |
| 1600 | |
| 1601 | // Check the shared version of lib2. |
| 1602 | variant := "android_arm64_armv8-a_core_shared" |
| 1603 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 1604 | checkStaticLibs(t, []string{"lib1", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module) |
| 1605 | |
| 1606 | // Check the static version of lib2. |
| 1607 | variant = "android_arm64_armv8-a_core_static" |
| 1608 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 1609 | // libc++_static is linked additionally. |
| 1610 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module) |
| 1611 | } |
| 1612 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 1613 | var compilerFlagsTestCases = []struct { |
| 1614 | in string |
| 1615 | out bool |
| 1616 | }{ |
| 1617 | { |
| 1618 | in: "a", |
| 1619 | out: false, |
| 1620 | }, |
| 1621 | { |
| 1622 | in: "-a", |
| 1623 | out: true, |
| 1624 | }, |
| 1625 | { |
| 1626 | in: "-Ipath/to/something", |
| 1627 | out: false, |
| 1628 | }, |
| 1629 | { |
| 1630 | in: "-isystempath/to/something", |
| 1631 | out: false, |
| 1632 | }, |
| 1633 | { |
| 1634 | in: "--coverage", |
| 1635 | out: false, |
| 1636 | }, |
| 1637 | { |
| 1638 | in: "-include a/b", |
| 1639 | out: true, |
| 1640 | }, |
| 1641 | { |
| 1642 | in: "-include a/b c/d", |
| 1643 | out: false, |
| 1644 | }, |
| 1645 | { |
| 1646 | in: "-DMACRO", |
| 1647 | out: true, |
| 1648 | }, |
| 1649 | { |
| 1650 | in: "-DMAC RO", |
| 1651 | out: false, |
| 1652 | }, |
| 1653 | { |
| 1654 | in: "-a -b", |
| 1655 | out: false, |
| 1656 | }, |
| 1657 | { |
| 1658 | in: "-DMACRO=definition", |
| 1659 | out: true, |
| 1660 | }, |
| 1661 | { |
| 1662 | in: "-DMACRO=defi nition", |
| 1663 | out: true, // TODO(jiyong): this should be false |
| 1664 | }, |
| 1665 | { |
| 1666 | in: "-DMACRO(x)=x + 1", |
| 1667 | out: true, |
| 1668 | }, |
| 1669 | { |
| 1670 | in: "-DMACRO=\"defi nition\"", |
| 1671 | out: true, |
| 1672 | }, |
| 1673 | } |
| 1674 | |
| 1675 | type mockContext struct { |
| 1676 | BaseModuleContext |
| 1677 | result bool |
| 1678 | } |
| 1679 | |
| 1680 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 1681 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 1682 | ctx.result = false |
| 1683 | } |
| 1684 | |
| 1685 | func TestCompilerFlags(t *testing.T) { |
| 1686 | for _, testCase := range compilerFlagsTestCases { |
| 1687 | ctx := &mockContext{result: true} |
| 1688 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 1689 | if ctx.result != testCase.out { |
| 1690 | t.Errorf("incorrect output:") |
| 1691 | t.Errorf(" input: %#v", testCase.in) |
| 1692 | t.Errorf(" expected: %#v", testCase.out) |
| 1693 | t.Errorf(" got: %#v", ctx.result) |
| 1694 | } |
| 1695 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1696 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1697 | |
| 1698 | func TestVendorPublicLibraries(t *testing.T) { |
| 1699 | ctx := testCc(t, ` |
| 1700 | cc_library_headers { |
| 1701 | name: "libvendorpublic_headers", |
| 1702 | export_include_dirs: ["my_include"], |
| 1703 | } |
| 1704 | vendor_public_library { |
| 1705 | name: "libvendorpublic", |
| 1706 | symbol_file: "", |
| 1707 | export_public_headers: ["libvendorpublic_headers"], |
| 1708 | } |
| 1709 | cc_library { |
| 1710 | name: "libvendorpublic", |
| 1711 | srcs: ["foo.c"], |
| 1712 | vendor: true, |
| 1713 | no_libgcc: true, |
| 1714 | nocrt: true, |
| 1715 | } |
| 1716 | |
| 1717 | cc_library { |
| 1718 | name: "libsystem", |
| 1719 | shared_libs: ["libvendorpublic"], |
| 1720 | vendor: false, |
| 1721 | srcs: ["foo.c"], |
| 1722 | no_libgcc: true, |
| 1723 | nocrt: true, |
| 1724 | } |
| 1725 | cc_library { |
| 1726 | name: "libvendor", |
| 1727 | shared_libs: ["libvendorpublic"], |
| 1728 | vendor: true, |
| 1729 | srcs: ["foo.c"], |
| 1730 | no_libgcc: true, |
| 1731 | nocrt: true, |
| 1732 | } |
| 1733 | `) |
| 1734 | |
| 1735 | variant := "android_arm64_armv8-a_core_shared" |
| 1736 | |
| 1737 | // test if header search paths are correctly added |
| 1738 | // _static variant is used since _shared reuses *.o from the static variant |
| 1739 | cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc") |
| 1740 | cflags := cc.Args["cFlags"] |
| 1741 | if !strings.Contains(cflags, "-Imy_include") { |
| 1742 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 1743 | } |
| 1744 | |
| 1745 | // test if libsystem is linked to the stub |
| 1746 | ld := ctx.ModuleForTests("libsystem", variant).Rule("ld") |
| 1747 | libflags := ld.Args["libFlags"] |
| 1748 | stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
| 1749 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 1750 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 1751 | } |
| 1752 | |
| 1753 | // test if libvendor is linked to the real shared lib |
| 1754 | ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor", 1)).Rule("ld") |
| 1755 | libflags = ld.Args["libFlags"] |
| 1756 | stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor", 1), []string{"libvendorpublic"}) |
| 1757 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 1758 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 1759 | } |
| 1760 | |
| 1761 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 1762 | |
| 1763 | func TestRecovery(t *testing.T) { |
| 1764 | ctx := testCc(t, ` |
| 1765 | cc_library_shared { |
| 1766 | name: "librecovery", |
| 1767 | recovery: true, |
| 1768 | } |
| 1769 | cc_library_shared { |
| 1770 | name: "librecovery32", |
| 1771 | recovery: true, |
| 1772 | compile_multilib:"32", |
| 1773 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 1774 | cc_library_shared { |
| 1775 | name: "libHalInRecovery", |
| 1776 | recovery_available: true, |
| 1777 | vendor: true, |
| 1778 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 1779 | `) |
| 1780 | |
| 1781 | variants := ctx.ModuleVariantsForTests("librecovery") |
| 1782 | const arm64 = "android_arm64_armv8-a_recovery_shared" |
| 1783 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 1784 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 1785 | } |
| 1786 | |
| 1787 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 1788 | if android.InList(arm64, variants) { |
| 1789 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 1790 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 1791 | |
| 1792 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 1793 | if !recoveryModule.Platform() { |
| 1794 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 1795 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1796 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 1797 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1798 | func TestVersionedStubs(t *testing.T) { |
| 1799 | ctx := testCc(t, ` |
| 1800 | cc_library_shared { |
| 1801 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 1802 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1803 | stubs: { |
| 1804 | symbol_file: "foo.map.txt", |
| 1805 | versions: ["1", "2", "3"], |
| 1806 | }, |
| 1807 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 1808 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1809 | cc_library_shared { |
| 1810 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 1811 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1812 | shared_libs: ["libFoo#1"], |
| 1813 | }`) |
| 1814 | |
| 1815 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 1816 | expectedVariants := []string{ |
| 1817 | "android_arm64_armv8-a_core_shared", |
| 1818 | "android_arm64_armv8-a_core_shared_1", |
| 1819 | "android_arm64_armv8-a_core_shared_2", |
| 1820 | "android_arm64_armv8-a_core_shared_3", |
| 1821 | "android_arm_armv7-a-neon_core_shared", |
| 1822 | "android_arm_armv7-a-neon_core_shared_1", |
| 1823 | "android_arm_armv7-a-neon_core_shared_2", |
| 1824 | "android_arm_armv7-a-neon_core_shared_3", |
| 1825 | } |
| 1826 | variantsMismatch := false |
| 1827 | if len(variants) != len(expectedVariants) { |
| 1828 | variantsMismatch = true |
| 1829 | } else { |
| 1830 | for _, v := range expectedVariants { |
| 1831 | if !inList(v, variants) { |
| 1832 | variantsMismatch = false |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | if variantsMismatch { |
| 1837 | t.Errorf("variants of libFoo expected:\n") |
| 1838 | for _, v := range expectedVariants { |
| 1839 | t.Errorf("%q\n", v) |
| 1840 | } |
| 1841 | t.Errorf(", but got:\n") |
| 1842 | for _, v := range variants { |
| 1843 | t.Errorf("%q\n", v) |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld") |
| 1848 | libFlags := libBarLinkRule.Args["libFlags"] |
| 1849 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so" |
| 1850 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 1851 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 1852 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 1853 | |
| 1854 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc") |
| 1855 | cFlags := libBarCompileRule.Args["cFlags"] |
| 1856 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 1857 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 1858 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 1859 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 1860 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 1861 | |
| 1862 | func TestStaticExecutable(t *testing.T) { |
| 1863 | ctx := testCc(t, ` |
| 1864 | cc_binary { |
| 1865 | name: "static_test", |
| 1866 | srcs: ["foo.c"], |
| 1867 | static_executable: true, |
| 1868 | }`) |
| 1869 | |
| 1870 | variant := "android_arm64_armv8-a_core" |
| 1871 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 1872 | libFlags := binModuleRule.Args["libFlags"] |
| 1873 | systemStaticLibs := []string{"libc.a", "libm.a", "libdl.a"} |
| 1874 | for _, lib := range systemStaticLibs { |
| 1875 | if !strings.Contains(libFlags, lib) { |
| 1876 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 1877 | } |
| 1878 | } |
| 1879 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 1880 | for _, lib := range systemSharedLibs { |
| 1881 | if strings.Contains(libFlags, lib) { |
| 1882 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 1883 | } |
| 1884 | } |
| 1885 | } |