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