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