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 ( |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 18 | "fmt" |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 19 | "io/ioutil" |
| 20 | "os" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 21 | "path/filepath" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 22 | "reflect" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 23 | "strings" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 24 | "testing" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 25 | |
| 26 | "android/soong/android" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 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 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 54 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 55 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 56 | ctx := CreateTestContext() |
| 57 | ctx.Register(config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 58 | |
Jeff Gaston | d3e141d | 2017-08-08 17:46:01 -0700 | [diff] [blame] | 59 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 60 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 61 | _, errs = ctx.PrepareBuildActions(config) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 62 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 63 | |
| 64 | return ctx |
| 65 | } |
| 66 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 67 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 68 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 69 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 70 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 71 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 72 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 73 | return testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | func testCcNoVndk(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 77 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 78 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 79 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 80 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 81 | return testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 84 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 85 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 86 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 87 | ctx := CreateTestContext() |
| 88 | ctx.Register(config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 89 | |
| 90 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 91 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 92 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 93 | return |
| 94 | } |
| 95 | |
| 96 | _, errs = ctx.PrepareBuildActions(config) |
| 97 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 98 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 99 | return |
| 100 | } |
| 101 | |
| 102 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 103 | } |
| 104 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 105 | func testCcError(t *testing.T, pattern string, bp string) { |
| 106 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 107 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 108 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 109 | testCcErrorWithConfig(t, pattern, config) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { |
| 114 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 115 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 116 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 117 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 118 | testCcErrorWithConfig(t, pattern, config) |
| 119 | return |
| 120 | } |
| 121 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 122 | const ( |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 123 | coreVariant = "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 124 | vendorVariant = "android_vendor.VER_arm64_armv8-a_shared" |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 125 | productVariant = "android_product.VER_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 126 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 127 | ) |
| 128 | |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 129 | func TestFuchsiaDeps(t *testing.T) { |
| 130 | t.Helper() |
| 131 | |
| 132 | bp := ` |
| 133 | cc_library { |
| 134 | name: "libTest", |
| 135 | srcs: ["foo.c"], |
| 136 | target: { |
| 137 | fuchsia: { |
| 138 | srcs: ["bar.c"], |
| 139 | }, |
| 140 | }, |
| 141 | }` |
| 142 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 143 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) |
| 144 | ctx := testCcWithConfig(t, config) |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 145 | |
| 146 | rt := false |
| 147 | fb := false |
| 148 | |
| 149 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") |
| 150 | implicits := ld.Implicits |
| 151 | for _, lib := range implicits { |
| 152 | if strings.Contains(lib.Rel(), "libcompiler_rt") { |
| 153 | rt = true |
| 154 | } |
| 155 | |
| 156 | if strings.Contains(lib.Rel(), "libbioniccompat") { |
| 157 | fb = true |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if !rt || !fb { |
| 162 | t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat") |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | func TestFuchsiaTargetDecl(t *testing.T) { |
| 167 | t.Helper() |
| 168 | |
| 169 | bp := ` |
| 170 | cc_library { |
| 171 | name: "libTest", |
| 172 | srcs: ["foo.c"], |
| 173 | target: { |
| 174 | fuchsia: { |
| 175 | srcs: ["bar.c"], |
| 176 | }, |
| 177 | }, |
| 178 | }` |
| 179 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 180 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) |
| 181 | ctx := testCcWithConfig(t, config) |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 182 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") |
| 183 | var objs []string |
| 184 | for _, o := range ld.Inputs { |
| 185 | objs = append(objs, o.Base()) |
| 186 | } |
| 187 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
| 188 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 189 | } |
| 190 | } |
| 191 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 192 | func TestVendorSrc(t *testing.T) { |
| 193 | ctx := testCc(t, ` |
| 194 | cc_library { |
| 195 | name: "libTest", |
| 196 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 197 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 198 | nocrt: true, |
| 199 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 200 | vendor_available: true, |
| 201 | target: { |
| 202 | vendor: { |
| 203 | srcs: ["bar.c"], |
| 204 | }, |
| 205 | }, |
| 206 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 207 | `) |
| 208 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 209 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 210 | var objs []string |
| 211 | for _, o := range ld.Inputs { |
| 212 | objs = append(objs, o.Base()) |
| 213 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 214 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 215 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 216 | } |
| 217 | } |
| 218 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 219 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 220 | isVndkSp bool, extends string, variant string) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 221 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 222 | t.Helper() |
| 223 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 224 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 225 | if !mod.HasVendorVariant() { |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 226 | t.Errorf("%q must have variant %q", name, variant) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Check library properties. |
| 230 | lib, ok := mod.compiler.(*libraryDecorator) |
| 231 | if !ok { |
| 232 | t.Errorf("%q must have libraryDecorator", name) |
| 233 | } else if lib.baseInstaller.subDir != subDir { |
| 234 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 235 | lib.baseInstaller.subDir) |
| 236 | } |
| 237 | |
| 238 | // Check VNDK properties. |
| 239 | if mod.vndkdep == nil { |
| 240 | t.Fatalf("%q must have `vndkdep`", name) |
| 241 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 242 | if !mod.IsVndk() { |
| 243 | t.Errorf("%q IsVndk() must equal to true", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 244 | } |
| 245 | if mod.isVndkSp() != isVndkSp { |
| 246 | t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp) |
| 247 | } |
| 248 | |
| 249 | // Check VNDK extension properties. |
| 250 | isVndkExt := extends != "" |
| 251 | if mod.isVndkExt() != isVndkExt { |
| 252 | t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt) |
| 253 | } |
| 254 | |
| 255 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 256 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 257 | } |
| 258 | } |
| 259 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 260 | func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool) { |
| 261 | t.Helper() |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 262 | mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer) |
| 263 | if !ok { |
| 264 | t.Errorf("%q must have output\n", moduleName) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 265 | return |
| 266 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 267 | outputFiles, err := mod.OutputFiles("") |
| 268 | if err != nil || len(outputFiles) != 1 { |
| 269 | t.Errorf("%q must have single output\n", moduleName) |
| 270 | return |
| 271 | } |
| 272 | snapshotPath := filepath.Join(subDir, snapshotFilename) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 273 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 274 | if include { |
| 275 | out := singleton.Output(snapshotPath) |
| 276 | if out.Input.String() != outputFiles[0].String() { |
| 277 | t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0]) |
| 278 | } |
| 279 | } else { |
| 280 | out := singleton.MaybeOutput(snapshotPath) |
| 281 | if out.Rule != nil { |
| 282 | t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0]) |
| 283 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 287 | func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { |
| 288 | checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true) |
| 289 | } |
| 290 | |
| 291 | func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) { |
| 292 | checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false) |
| 293 | } |
| 294 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 295 | func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { |
| 296 | t.Helper() |
| 297 | assertString(t, params.Rule.String(), android.WriteFile.String()) |
| 298 | actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' }) |
| 299 | assertArrayString(t, actual, expected) |
| 300 | } |
| 301 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 302 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { |
| 303 | t.Helper() |
| 304 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 305 | checkWriteFileOutput(t, vndkSnapshot.Output(output), expected) |
| 306 | } |
| 307 | |
| 308 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { |
| 309 | t.Helper() |
| 310 | vndkLibraries := ctx.ModuleForTests(module, "") |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 311 | |
| 312 | var output string |
| 313 | if module != "vndkcorevariant.libraries.txt" { |
| 314 | output = insertVndkVersion(module, "VER") |
| 315 | } else { |
| 316 | output = module |
| 317 | } |
| 318 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 319 | checkWriteFileOutput(t, vndkLibraries.Output(output), expected) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 320 | } |
| 321 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 322 | func TestVndk(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 323 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 324 | cc_library { |
| 325 | name: "libvndk", |
| 326 | vendor_available: true, |
| 327 | vndk: { |
| 328 | enabled: true, |
| 329 | }, |
| 330 | nocrt: true, |
| 331 | } |
| 332 | |
| 333 | cc_library { |
| 334 | name: "libvndk_private", |
| 335 | vendor_available: false, |
| 336 | vndk: { |
| 337 | enabled: true, |
| 338 | }, |
| 339 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 340 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | cc_library { |
| 344 | name: "libvndk_sp", |
| 345 | vendor_available: true, |
| 346 | vndk: { |
| 347 | enabled: true, |
| 348 | support_system_process: true, |
| 349 | }, |
| 350 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 351 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | cc_library { |
| 355 | name: "libvndk_sp_private", |
| 356 | vendor_available: false, |
| 357 | vndk: { |
| 358 | enabled: true, |
| 359 | support_system_process: true, |
| 360 | }, |
| 361 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 362 | target: { |
| 363 | vendor: { |
| 364 | suffix: "-x", |
| 365 | }, |
| 366 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 367 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 368 | vndk_libraries_txt { |
| 369 | name: "llndk.libraries.txt", |
| 370 | } |
| 371 | vndk_libraries_txt { |
| 372 | name: "vndkcore.libraries.txt", |
| 373 | } |
| 374 | vndk_libraries_txt { |
| 375 | name: "vndksp.libraries.txt", |
| 376 | } |
| 377 | vndk_libraries_txt { |
| 378 | name: "vndkprivate.libraries.txt", |
| 379 | } |
| 380 | vndk_libraries_txt { |
| 381 | name: "vndkcorevariant.libraries.txt", |
| 382 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 383 | ` |
| 384 | |
| 385 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 386 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 387 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 388 | |
| 389 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 390 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 391 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", vendorVariant) |
| 392 | checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "", vendorVariant) |
| 393 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", vendorVariant) |
| 394 | checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "", vendorVariant) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 395 | |
| 396 | // Check VNDK snapshot output. |
| 397 | |
| 398 | snapshotDir := "vndk-snapshot" |
| 399 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 400 | |
| 401 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 402 | "arm64", "armv8-a")) |
| 403 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 404 | "arm", "armv7-a-neon")) |
| 405 | |
| 406 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 407 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
| 408 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 409 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
| 410 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 411 | variant := "android_vendor.VER_arm64_armv8-a_shared" |
| 412 | variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 413 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 414 | snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") |
| 415 | |
| 416 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 417 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
| 418 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 419 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 420 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 421 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 422 | checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") |
| 423 | checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") |
| 424 | checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") |
| 425 | checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 426 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 427 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 428 | "LLNDK: libc.so", |
| 429 | "LLNDK: libdl.so", |
| 430 | "LLNDK: libft2.so", |
| 431 | "LLNDK: libm.so", |
| 432 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 433 | "VNDK-SP: libvndk_sp-x.so", |
| 434 | "VNDK-SP: libvndk_sp_private-x.so", |
| 435 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 436 | "VNDK-core: libvndk.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 437 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 438 | "VNDK-private: libvndk-private.so", |
| 439 | "VNDK-private: libvndk_sp_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 440 | }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 441 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"}) |
| 442 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"}) |
| 443 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"}) |
| 444 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"}) |
| 445 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 446 | } |
| 447 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 448 | func TestVndkWithHostSupported(t *testing.T) { |
| 449 | ctx := testCc(t, ` |
| 450 | cc_library { |
| 451 | name: "libvndk_host_supported", |
| 452 | vendor_available: true, |
| 453 | vndk: { |
| 454 | enabled: true, |
| 455 | }, |
| 456 | host_supported: true, |
| 457 | } |
| 458 | |
| 459 | cc_library { |
| 460 | name: "libvndk_host_supported_but_disabled_on_device", |
| 461 | vendor_available: true, |
| 462 | vndk: { |
| 463 | enabled: true, |
| 464 | }, |
| 465 | host_supported: true, |
| 466 | enabled: false, |
| 467 | target: { |
| 468 | host: { |
| 469 | enabled: true, |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | vndk_libraries_txt { |
| 475 | name: "vndkcore.libraries.txt", |
| 476 | } |
| 477 | `) |
| 478 | |
| 479 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"}) |
| 480 | } |
| 481 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 482 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 483 | bp := ` |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 484 | vndk_libraries_txt { |
| 485 | name: "llndk.libraries.txt", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 486 | }` |
| 487 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 488 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 489 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 490 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 491 | |
| 492 | module := ctx.ModuleForTests("llndk.libraries.txt", "") |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 493 | entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0] |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 494 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | func TestVndkUsingCoreVariant(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 498 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 499 | cc_library { |
| 500 | name: "libvndk", |
| 501 | vendor_available: true, |
| 502 | vndk: { |
| 503 | enabled: true, |
| 504 | }, |
| 505 | nocrt: true, |
| 506 | } |
| 507 | |
| 508 | cc_library { |
| 509 | name: "libvndk_sp", |
| 510 | vendor_available: true, |
| 511 | vndk: { |
| 512 | enabled: true, |
| 513 | support_system_process: true, |
| 514 | }, |
| 515 | nocrt: true, |
| 516 | } |
| 517 | |
| 518 | cc_library { |
| 519 | name: "libvndk2", |
| 520 | vendor_available: false, |
| 521 | vndk: { |
| 522 | enabled: true, |
| 523 | }, |
| 524 | nocrt: true, |
| 525 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 526 | |
| 527 | vndk_libraries_txt { |
| 528 | name: "vndkcorevariant.libraries.txt", |
| 529 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 530 | ` |
| 531 | |
| 532 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 533 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 534 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 535 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 536 | |
| 537 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) |
| 538 | |
| 539 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 540 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 541 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 542 | } |
| 543 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 544 | func TestDataLibs(t *testing.T) { |
| 545 | bp := ` |
| 546 | cc_test_library { |
| 547 | name: "test_lib", |
| 548 | srcs: ["test_lib.cpp"], |
| 549 | gtest: false, |
| 550 | } |
| 551 | |
| 552 | cc_test { |
| 553 | name: "main_test", |
| 554 | data_libs: ["test_lib"], |
| 555 | gtest: false, |
| 556 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 557 | ` |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 558 | |
| 559 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 560 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 561 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 562 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 563 | |
| 564 | ctx := testCcWithConfig(t, config) |
| 565 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 566 | testBinary := module.(*Module).linker.(*testBinary) |
| 567 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 568 | if err != nil { |
| 569 | t.Errorf("Expected cc_test to produce output files, error: %s", err) |
| 570 | return |
| 571 | } |
| 572 | if len(outputFiles) != 1 { |
| 573 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 574 | return |
| 575 | } |
| 576 | if len(testBinary.dataPaths()) != 1 { |
| 577 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 578 | return |
| 579 | } |
| 580 | |
| 581 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 582 | testBinaryPath := testBinary.dataPaths()[0].SrcPath.String() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 583 | |
| 584 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 585 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 586 | return |
| 587 | } |
| 588 | if !strings.HasSuffix(testBinaryPath, "/test_lib.so") { |
| 589 | t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath) |
| 590 | return |
| 591 | } |
| 592 | } |
| 593 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 594 | func TestDataLibsRelativeInstallPath(t *testing.T) { |
| 595 | bp := ` |
| 596 | cc_test_library { |
| 597 | name: "test_lib", |
| 598 | srcs: ["test_lib.cpp"], |
| 599 | relative_install_path: "foo/bar/baz", |
| 600 | gtest: false, |
| 601 | } |
| 602 | |
| 603 | cc_test { |
| 604 | name: "main_test", |
| 605 | data_libs: ["test_lib"], |
| 606 | gtest: false, |
| 607 | } |
| 608 | ` |
| 609 | |
| 610 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 611 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 612 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 613 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 614 | |
| 615 | ctx := testCcWithConfig(t, config) |
| 616 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 617 | testBinary := module.(*Module).linker.(*testBinary) |
| 618 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 619 | if err != nil { |
| 620 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 621 | } |
| 622 | if len(outputFiles) != 1 { |
| 623 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 624 | } |
| 625 | if len(testBinary.dataPaths()) != 1 { |
| 626 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 627 | } |
| 628 | |
| 629 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 630 | |
| 631 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 632 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 633 | } |
| 634 | entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] |
| 635 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 636 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 637 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 641 | func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 642 | ctx := testCcNoVndk(t, ` |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 643 | cc_library { |
| 644 | name: "libvndk", |
| 645 | vendor_available: true, |
| 646 | vndk: { |
| 647 | enabled: true, |
| 648 | }, |
| 649 | nocrt: true, |
| 650 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 651 | `) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 652 | |
| 653 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 654 | "LLNDK: libc.so", |
| 655 | "LLNDK: libdl.so", |
| 656 | "LLNDK: libft2.so", |
| 657 | "LLNDK: libm.so", |
| 658 | "VNDK-SP: libc++.so", |
| 659 | "VNDK-core: libvndk.so", |
| 660 | "VNDK-private: libft2.so", |
| 661 | }) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 662 | } |
| 663 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 664 | func TestVndkDepError(t *testing.T) { |
| 665 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 666 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 667 | cc_library { |
| 668 | name: "libvndk", |
| 669 | vendor_available: true, |
| 670 | vndk: { |
| 671 | enabled: true, |
| 672 | }, |
| 673 | shared_libs: ["libfwk"], // Cause error |
| 674 | nocrt: true, |
| 675 | } |
| 676 | |
| 677 | cc_library { |
| 678 | name: "libfwk", |
| 679 | nocrt: true, |
| 680 | } |
| 681 | `) |
| 682 | |
| 683 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 684 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 685 | cc_library { |
| 686 | name: "libvndk", |
| 687 | vendor_available: true, |
| 688 | vndk: { |
| 689 | enabled: true, |
| 690 | }, |
| 691 | shared_libs: ["libvendor"], // Cause error |
| 692 | nocrt: true, |
| 693 | } |
| 694 | |
| 695 | cc_library { |
| 696 | name: "libvendor", |
| 697 | vendor: true, |
| 698 | nocrt: true, |
| 699 | } |
| 700 | `) |
| 701 | |
| 702 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 703 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 704 | cc_library { |
| 705 | name: "libvndk_sp", |
| 706 | vendor_available: true, |
| 707 | vndk: { |
| 708 | enabled: true, |
| 709 | support_system_process: true, |
| 710 | }, |
| 711 | shared_libs: ["libfwk"], // Cause error |
| 712 | nocrt: true, |
| 713 | } |
| 714 | |
| 715 | cc_library { |
| 716 | name: "libfwk", |
| 717 | nocrt: true, |
| 718 | } |
| 719 | `) |
| 720 | |
| 721 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 722 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 723 | cc_library { |
| 724 | name: "libvndk_sp", |
| 725 | vendor_available: true, |
| 726 | vndk: { |
| 727 | enabled: true, |
| 728 | support_system_process: true, |
| 729 | }, |
| 730 | shared_libs: ["libvendor"], // Cause error |
| 731 | nocrt: true, |
| 732 | } |
| 733 | |
| 734 | cc_library { |
| 735 | name: "libvendor", |
| 736 | vendor: true, |
| 737 | nocrt: true, |
| 738 | } |
| 739 | `) |
| 740 | |
| 741 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 742 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 743 | cc_library { |
| 744 | name: "libvndk_sp", |
| 745 | vendor_available: true, |
| 746 | vndk: { |
| 747 | enabled: true, |
| 748 | support_system_process: true, |
| 749 | }, |
| 750 | shared_libs: ["libvndk"], // Cause error |
| 751 | nocrt: true, |
| 752 | } |
| 753 | |
| 754 | cc_library { |
| 755 | name: "libvndk", |
| 756 | vendor_available: true, |
| 757 | vndk: { |
| 758 | enabled: true, |
| 759 | }, |
| 760 | nocrt: true, |
| 761 | } |
| 762 | `) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 763 | |
| 764 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. |
| 765 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 766 | cc_library { |
| 767 | name: "libvndk", |
| 768 | vendor_available: true, |
| 769 | vndk: { |
| 770 | enabled: true, |
| 771 | }, |
| 772 | shared_libs: ["libnonvndk"], |
| 773 | nocrt: true, |
| 774 | } |
| 775 | |
| 776 | cc_library { |
| 777 | name: "libnonvndk", |
| 778 | vendor_available: true, |
| 779 | nocrt: true, |
| 780 | } |
| 781 | `) |
| 782 | |
| 783 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. |
| 784 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 785 | cc_library { |
| 786 | name: "libvndkprivate", |
| 787 | vendor_available: false, |
| 788 | vndk: { |
| 789 | enabled: true, |
| 790 | }, |
| 791 | shared_libs: ["libnonvndk"], |
| 792 | nocrt: true, |
| 793 | } |
| 794 | |
| 795 | cc_library { |
| 796 | name: "libnonvndk", |
| 797 | vendor_available: true, |
| 798 | nocrt: true, |
| 799 | } |
| 800 | `) |
| 801 | |
| 802 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. |
| 803 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 804 | cc_library { |
| 805 | name: "libvndksp", |
| 806 | vendor_available: true, |
| 807 | vndk: { |
| 808 | enabled: true, |
| 809 | support_system_process: true, |
| 810 | }, |
| 811 | shared_libs: ["libnonvndk"], |
| 812 | nocrt: true, |
| 813 | } |
| 814 | |
| 815 | cc_library { |
| 816 | name: "libnonvndk", |
| 817 | vendor_available: true, |
| 818 | nocrt: true, |
| 819 | } |
| 820 | `) |
| 821 | |
| 822 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. |
| 823 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 824 | cc_library { |
| 825 | name: "libvndkspprivate", |
| 826 | vendor_available: false, |
| 827 | vndk: { |
| 828 | enabled: true, |
| 829 | support_system_process: true, |
| 830 | }, |
| 831 | shared_libs: ["libnonvndk"], |
| 832 | nocrt: true, |
| 833 | } |
| 834 | |
| 835 | cc_library { |
| 836 | name: "libnonvndk", |
| 837 | vendor_available: true, |
| 838 | nocrt: true, |
| 839 | } |
| 840 | `) |
| 841 | } |
| 842 | |
| 843 | func TestDoubleLoadbleDep(t *testing.T) { |
| 844 | // okay to link : LLNDK -> double_loadable VNDK |
| 845 | testCc(t, ` |
| 846 | cc_library { |
| 847 | name: "libllndk", |
| 848 | shared_libs: ["libdoubleloadable"], |
| 849 | } |
| 850 | |
| 851 | llndk_library { |
| 852 | name: "libllndk", |
| 853 | symbol_file: "", |
| 854 | } |
| 855 | |
| 856 | cc_library { |
| 857 | name: "libdoubleloadable", |
| 858 | vendor_available: true, |
| 859 | vndk: { |
| 860 | enabled: true, |
| 861 | }, |
| 862 | double_loadable: true, |
| 863 | } |
| 864 | `) |
| 865 | // okay to link : LLNDK -> VNDK-SP |
| 866 | testCc(t, ` |
| 867 | cc_library { |
| 868 | name: "libllndk", |
| 869 | shared_libs: ["libvndksp"], |
| 870 | } |
| 871 | |
| 872 | llndk_library { |
| 873 | name: "libllndk", |
| 874 | symbol_file: "", |
| 875 | } |
| 876 | |
| 877 | cc_library { |
| 878 | name: "libvndksp", |
| 879 | vendor_available: true, |
| 880 | vndk: { |
| 881 | enabled: true, |
| 882 | support_system_process: true, |
| 883 | }, |
| 884 | } |
| 885 | `) |
| 886 | // okay to link : double_loadable -> double_loadable |
| 887 | testCc(t, ` |
| 888 | cc_library { |
| 889 | name: "libdoubleloadable1", |
| 890 | shared_libs: ["libdoubleloadable2"], |
| 891 | vendor_available: true, |
| 892 | double_loadable: true, |
| 893 | } |
| 894 | |
| 895 | cc_library { |
| 896 | name: "libdoubleloadable2", |
| 897 | vendor_available: true, |
| 898 | double_loadable: true, |
| 899 | } |
| 900 | `) |
| 901 | // okay to link : double_loadable VNDK -> double_loadable VNDK private |
| 902 | testCc(t, ` |
| 903 | cc_library { |
| 904 | name: "libdoubleloadable", |
| 905 | vendor_available: true, |
| 906 | vndk: { |
| 907 | enabled: true, |
| 908 | }, |
| 909 | double_loadable: true, |
| 910 | shared_libs: ["libnondoubleloadable"], |
| 911 | } |
| 912 | |
| 913 | cc_library { |
| 914 | name: "libnondoubleloadable", |
| 915 | vendor_available: false, |
| 916 | vndk: { |
| 917 | enabled: true, |
| 918 | }, |
| 919 | double_loadable: true, |
| 920 | } |
| 921 | `) |
| 922 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable |
| 923 | testCc(t, ` |
| 924 | cc_library { |
| 925 | name: "libllndk", |
| 926 | shared_libs: ["libcoreonly"], |
| 927 | } |
| 928 | |
| 929 | llndk_library { |
| 930 | name: "libllndk", |
| 931 | symbol_file: "", |
| 932 | } |
| 933 | |
| 934 | cc_library { |
| 935 | name: "libcoreonly", |
| 936 | shared_libs: ["libvendoravailable"], |
| 937 | } |
| 938 | |
| 939 | // indirect dependency of LLNDK |
| 940 | cc_library { |
| 941 | name: "libvendoravailable", |
| 942 | vendor_available: true, |
| 943 | double_loadable: true, |
| 944 | } |
| 945 | `) |
| 946 | } |
| 947 | |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 948 | func TestVendorSnapshotCapture(t *testing.T) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 949 | bp := ` |
| 950 | cc_library { |
| 951 | name: "libvndk", |
| 952 | vendor_available: true, |
| 953 | vndk: { |
| 954 | enabled: true, |
| 955 | }, |
| 956 | nocrt: true, |
| 957 | } |
| 958 | |
| 959 | cc_library { |
| 960 | name: "libvendor", |
| 961 | vendor: true, |
| 962 | nocrt: true, |
| 963 | } |
| 964 | |
| 965 | cc_library { |
| 966 | name: "libvendor_available", |
| 967 | vendor_available: true, |
| 968 | nocrt: true, |
| 969 | } |
| 970 | |
| 971 | cc_library_headers { |
| 972 | name: "libvendor_headers", |
| 973 | vendor_available: true, |
| 974 | nocrt: true, |
| 975 | } |
| 976 | |
| 977 | cc_binary { |
| 978 | name: "vendor_bin", |
| 979 | vendor: true, |
| 980 | nocrt: true, |
| 981 | } |
| 982 | |
| 983 | cc_binary { |
| 984 | name: "vendor_available_bin", |
| 985 | vendor_available: true, |
| 986 | nocrt: true, |
| 987 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 988 | |
| 989 | toolchain_library { |
| 990 | name: "libb", |
| 991 | vendor_available: true, |
| 992 | src: "libb.a", |
| 993 | } |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 994 | |
| 995 | cc_object { |
| 996 | name: "obj", |
| 997 | vendor_available: true, |
| 998 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 999 | ` |
| 1000 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1001 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1002 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1003 | ctx := testCcWithConfig(t, config) |
| 1004 | |
| 1005 | // Check Vendor snapshot output. |
| 1006 | |
| 1007 | snapshotDir := "vendor-snapshot" |
| 1008 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1009 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1010 | |
| 1011 | var jsonFiles []string |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1012 | |
| 1013 | for _, arch := range [][]string{ |
| 1014 | []string{"arm64", "armv8-a"}, |
| 1015 | []string{"arm", "armv7-a-neon"}, |
| 1016 | } { |
| 1017 | archType := arch[0] |
| 1018 | archVariant := arch[1] |
| 1019 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1020 | |
| 1021 | // For shared libraries, only non-VNDK vendor_available modules are captured |
| 1022 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 1023 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1024 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1025 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) |
| 1026 | jsonFiles = append(jsonFiles, |
| 1027 | filepath.Join(sharedDir, "libvendor.so.json"), |
| 1028 | filepath.Join(sharedDir, "libvendor_available.so.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1029 | |
| 1030 | // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1031 | // Also cfi variants are captured, except for prebuilts like toolchain_library |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1032 | staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1033 | staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1034 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1035 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 1036 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1037 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1038 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1039 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1040 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1041 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1042 | jsonFiles = append(jsonFiles, |
| 1043 | filepath.Join(staticDir, "libb.a.json"), |
| 1044 | filepath.Join(staticDir, "libvndk.a.json"), |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1045 | filepath.Join(staticDir, "libvndk.cfi.a.json"), |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1046 | filepath.Join(staticDir, "libvendor.a.json"), |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1047 | filepath.Join(staticDir, "libvendor.cfi.a.json"), |
| 1048 | filepath.Join(staticDir, "libvendor_available.a.json"), |
| 1049 | filepath.Join(staticDir, "libvendor_available.cfi.a.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1050 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1051 | // For binary executables, all vendor:true and vendor_available modules are captured. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1052 | if archType == "arm64" { |
| 1053 | binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) |
| 1054 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1055 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) |
| 1056 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) |
| 1057 | jsonFiles = append(jsonFiles, |
| 1058 | filepath.Join(binaryDir, "vendor_bin.json"), |
| 1059 | filepath.Join(binaryDir, "vendor_available_bin.json")) |
| 1060 | } |
| 1061 | |
| 1062 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 1063 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 1064 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1065 | |
| 1066 | // For object modules, all vendor:true and vendor_available modules are captured. |
| 1067 | objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) |
| 1068 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 1069 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 1070 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | for _, jsonFile := range jsonFiles { |
| 1074 | // verify all json files exist |
| 1075 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1076 | t.Errorf("%q expected but not found", jsonFile) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1081 | func TestVendorSnapshotUse(t *testing.T) { |
| 1082 | frameworkBp := ` |
| 1083 | cc_library { |
| 1084 | name: "libvndk", |
| 1085 | vendor_available: true, |
| 1086 | vndk: { |
| 1087 | enabled: true, |
| 1088 | }, |
| 1089 | nocrt: true, |
| 1090 | compile_multilib: "64", |
| 1091 | } |
| 1092 | |
| 1093 | cc_library { |
| 1094 | name: "libvendor", |
| 1095 | vendor: true, |
| 1096 | nocrt: true, |
| 1097 | no_libcrt: true, |
| 1098 | stl: "none", |
| 1099 | system_shared_libs: [], |
| 1100 | compile_multilib: "64", |
| 1101 | } |
| 1102 | |
| 1103 | cc_binary { |
| 1104 | name: "bin", |
| 1105 | vendor: true, |
| 1106 | nocrt: true, |
| 1107 | no_libcrt: true, |
| 1108 | stl: "none", |
| 1109 | system_shared_libs: [], |
| 1110 | compile_multilib: "64", |
| 1111 | } |
| 1112 | ` |
| 1113 | |
| 1114 | vndkBp := ` |
| 1115 | vndk_prebuilt_shared { |
| 1116 | name: "libvndk", |
| 1117 | version: "BOARD", |
| 1118 | target_arch: "arm64", |
| 1119 | vendor_available: true, |
| 1120 | vndk: { |
| 1121 | enabled: true, |
| 1122 | }, |
| 1123 | arch: { |
| 1124 | arm64: { |
| 1125 | srcs: ["libvndk.so"], |
| 1126 | }, |
| 1127 | }, |
| 1128 | } |
| 1129 | ` |
| 1130 | |
| 1131 | vendorProprietaryBp := ` |
| 1132 | cc_library { |
| 1133 | name: "libvendor_without_snapshot", |
| 1134 | vendor: true, |
| 1135 | nocrt: true, |
| 1136 | no_libcrt: true, |
| 1137 | stl: "none", |
| 1138 | system_shared_libs: [], |
| 1139 | compile_multilib: "64", |
| 1140 | } |
| 1141 | |
| 1142 | cc_library_shared { |
| 1143 | name: "libclient", |
| 1144 | vendor: true, |
| 1145 | nocrt: true, |
| 1146 | no_libcrt: true, |
| 1147 | stl: "none", |
| 1148 | system_shared_libs: [], |
| 1149 | shared_libs: ["libvndk"], |
| 1150 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
| 1151 | compile_multilib: "64", |
| 1152 | } |
| 1153 | |
| 1154 | cc_binary { |
| 1155 | name: "bin_without_snapshot", |
| 1156 | vendor: true, |
| 1157 | nocrt: true, |
| 1158 | no_libcrt: true, |
| 1159 | stl: "none", |
| 1160 | system_shared_libs: [], |
| 1161 | static_libs: ["libvndk"], |
| 1162 | compile_multilib: "64", |
| 1163 | } |
| 1164 | |
| 1165 | vendor_snapshot_static { |
| 1166 | name: "libvndk", |
| 1167 | version: "BOARD", |
| 1168 | target_arch: "arm64", |
| 1169 | vendor: true, |
| 1170 | arch: { |
| 1171 | arm64: { |
| 1172 | src: "libvndk.a", |
| 1173 | }, |
| 1174 | }, |
| 1175 | } |
| 1176 | |
| 1177 | vendor_snapshot_shared { |
| 1178 | name: "libvendor", |
| 1179 | version: "BOARD", |
| 1180 | target_arch: "arm64", |
| 1181 | vendor: true, |
| 1182 | arch: { |
| 1183 | arm64: { |
| 1184 | src: "libvendor.so", |
| 1185 | }, |
| 1186 | }, |
| 1187 | } |
| 1188 | |
| 1189 | vendor_snapshot_static { |
| 1190 | name: "libvendor", |
| 1191 | version: "BOARD", |
| 1192 | target_arch: "arm64", |
| 1193 | vendor: true, |
| 1194 | arch: { |
| 1195 | arm64: { |
| 1196 | src: "libvendor.a", |
| 1197 | }, |
| 1198 | }, |
| 1199 | } |
| 1200 | |
| 1201 | vendor_snapshot_binary { |
| 1202 | name: "bin", |
| 1203 | version: "BOARD", |
| 1204 | target_arch: "arm64", |
| 1205 | vendor: true, |
| 1206 | arch: { |
| 1207 | arm64: { |
| 1208 | src: "bin", |
| 1209 | }, |
| 1210 | }, |
| 1211 | } |
| 1212 | ` |
| 1213 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1214 | |
| 1215 | mockFS := map[string][]byte{ |
| 1216 | "deps/Android.bp": []byte(depsBp), |
| 1217 | "framework/Android.bp": []byte(frameworkBp), |
| 1218 | "vendor/Android.bp": []byte(vendorProprietaryBp), |
| 1219 | "vendor/libvndk.a": nil, |
| 1220 | "vendor/libvendor.a": nil, |
| 1221 | "vendor/libvendor.so": nil, |
| 1222 | "vendor/bin": nil, |
| 1223 | "vndk/Android.bp": []byte(vndkBp), |
| 1224 | "vndk/libvndk.so": nil, |
| 1225 | } |
| 1226 | |
| 1227 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1228 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1229 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1230 | ctx := CreateTestContext() |
| 1231 | ctx.Register(config) |
| 1232 | |
| 1233 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"}) |
| 1234 | android.FailIfErrored(t, errs) |
| 1235 | _, errs = ctx.PrepareBuildActions(config) |
| 1236 | android.FailIfErrored(t, errs) |
| 1237 | |
| 1238 | sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared" |
| 1239 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1240 | binaryVariant := "android_vendor.BOARD_arm64_armv8-a" |
| 1241 | |
| 1242 | // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot |
| 1243 | libclientLdRule := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld") |
| 1244 | libclientFlags := libclientLdRule.Args["libFlags"] |
| 1245 | |
| 1246 | for _, input := range [][]string{ |
| 1247 | []string{sharedVariant, "libvndk.vndk.BOARD.arm64"}, |
| 1248 | []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"}, |
| 1249 | []string{staticVariant, "libvendor_without_snapshot"}, |
| 1250 | } { |
| 1251 | outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) |
| 1252 | if !strings.Contains(libclientFlags, outputPaths[0].String()) { |
| 1253 | t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientFlags) |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64 |
| 1258 | binWithoutSnapshotLdRule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld") |
| 1259 | binWithoutSnapshotFlags := binWithoutSnapshotLdRule.Args["libFlags"] |
| 1260 | libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"}) |
| 1261 | if !strings.Contains(binWithoutSnapshotFlags, libVndkStaticOutputPaths[0].String()) { |
| 1262 | t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v", |
| 1263 | libVndkStaticOutputPaths[0], binWithoutSnapshotFlags) |
| 1264 | } |
| 1265 | |
| 1266 | // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64 |
| 1267 | ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so") |
| 1268 | |
| 1269 | // libvendor_without_snapshot.so is installed by libvendor_without_snapshot |
| 1270 | ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so") |
| 1271 | |
| 1272 | // bin is installed by bin.vendor_binary.BOARD.arm64 |
| 1273 | ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin") |
| 1274 | |
| 1275 | // bin_without_snapshot is installed by bin_without_snapshot |
| 1276 | ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot") |
| 1277 | |
| 1278 | // libvendor and bin don't have vendor.BOARD variant |
| 1279 | libvendorVariants := ctx.ModuleVariantsForTests("libvendor") |
| 1280 | if inList(sharedVariant, libvendorVariants) { |
| 1281 | t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant) |
| 1282 | } |
| 1283 | |
| 1284 | binVariants := ctx.ModuleVariantsForTests("bin") |
| 1285 | if inList(binaryVariant, binVariants) { |
| 1286 | t.Errorf("bin must not have variant %#v, but it does", sharedVariant) |
| 1287 | } |
| 1288 | } |
| 1289 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1290 | func TestVendorSnapshotSanitizer(t *testing.T) { |
| 1291 | bp := ` |
| 1292 | vendor_snapshot_static { |
| 1293 | name: "libsnapshot", |
| 1294 | vendor: true, |
| 1295 | target_arch: "arm64", |
| 1296 | version: "BOARD", |
| 1297 | arch: { |
| 1298 | arm64: { |
| 1299 | src: "libsnapshot.a", |
| 1300 | cfi: { |
| 1301 | src: "libsnapshot.cfi.a", |
| 1302 | } |
| 1303 | }, |
| 1304 | }, |
| 1305 | } |
| 1306 | ` |
| 1307 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1308 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1309 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1310 | ctx := testCcWithConfig(t, config) |
| 1311 | |
| 1312 | // Check non-cfi and cfi variant. |
| 1313 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1314 | staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi" |
| 1315 | |
| 1316 | staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module) |
| 1317 | assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a") |
| 1318 | |
| 1319 | staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module) |
| 1320 | assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a") |
| 1321 | } |
| 1322 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1323 | func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) { |
| 1324 | t.Helper() |
| 1325 | if c.ExcludeFromVendorSnapshot() != expected { |
| 1326 | t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected) |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | func TestVendorSnapshotExclude(t *testing.T) { |
| 1331 | |
| 1332 | // This test verifies that the exclude_from_vendor_snapshot property |
| 1333 | // makes its way from the Android.bp source file into the module data |
| 1334 | // structure. It also verifies that modules are correctly included or |
| 1335 | // excluded in the vendor snapshot based on their path (framework or |
| 1336 | // vendor) and the exclude_from_vendor_snapshot property. |
| 1337 | |
| 1338 | frameworkBp := ` |
| 1339 | cc_library_shared { |
| 1340 | name: "libinclude", |
| 1341 | srcs: ["src/include.cpp"], |
| 1342 | vendor_available: true, |
| 1343 | } |
| 1344 | cc_library_shared { |
| 1345 | name: "libexclude", |
| 1346 | srcs: ["src/exclude.cpp"], |
| 1347 | vendor: true, |
| 1348 | exclude_from_vendor_snapshot: true, |
| 1349 | } |
| 1350 | ` |
| 1351 | |
| 1352 | vendorProprietaryBp := ` |
| 1353 | cc_library_shared { |
| 1354 | name: "libvendor", |
| 1355 | srcs: ["vendor.cpp"], |
| 1356 | vendor: true, |
| 1357 | } |
| 1358 | ` |
| 1359 | |
| 1360 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1361 | |
| 1362 | mockFS := map[string][]byte{ |
| 1363 | "deps/Android.bp": []byte(depsBp), |
| 1364 | "framework/Android.bp": []byte(frameworkBp), |
| 1365 | "framework/include.cpp": nil, |
| 1366 | "framework/exclude.cpp": nil, |
| 1367 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1368 | "device/vendor.cpp": nil, |
| 1369 | } |
| 1370 | |
| 1371 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1372 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1373 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1374 | ctx := CreateTestContext() |
| 1375 | ctx.Register(config) |
| 1376 | |
| 1377 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1378 | android.FailIfErrored(t, errs) |
| 1379 | _, errs = ctx.PrepareBuildActions(config) |
| 1380 | android.FailIfErrored(t, errs) |
| 1381 | |
| 1382 | // Test an include and exclude framework module. |
| 1383 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false) |
| 1384 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false) |
| 1385 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true) |
| 1386 | |
| 1387 | // A vendor module is excluded, but by its path, not the |
| 1388 | // exclude_from_vendor_snapshot property. |
| 1389 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false) |
| 1390 | |
| 1391 | // Verify the content of the vendor snapshot. |
| 1392 | |
| 1393 | snapshotDir := "vendor-snapshot" |
| 1394 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1395 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1396 | |
| 1397 | var includeJsonFiles []string |
| 1398 | var excludeJsonFiles []string |
| 1399 | |
| 1400 | for _, arch := range [][]string{ |
| 1401 | []string{"arm64", "armv8-a"}, |
| 1402 | []string{"arm", "armv7-a-neon"}, |
| 1403 | } { |
| 1404 | archType := arch[0] |
| 1405 | archVariant := arch[1] |
| 1406 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1407 | |
| 1408 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 1409 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1410 | |
| 1411 | // Included modules |
| 1412 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1413 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1414 | |
| 1415 | // Excluded modules |
| 1416 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1417 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1418 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1419 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 1420 | } |
| 1421 | |
| 1422 | // Verify that each json file for an included module has a rule. |
| 1423 | for _, jsonFile := range includeJsonFiles { |
| 1424 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1425 | t.Errorf("include json file %q not found", jsonFile) |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | // Verify that each json file for an excluded module has no rule. |
| 1430 | for _, jsonFile := range excludeJsonFiles { |
| 1431 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1432 | t.Errorf("exclude json file %q found", jsonFile) |
| 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) { |
| 1438 | |
| 1439 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1440 | // property on a module in a vendor proprietary path generates an |
| 1441 | // error. These modules are already excluded, so we prohibit using the |
| 1442 | // property in this way, which could add to confusion. |
| 1443 | |
| 1444 | vendorProprietaryBp := ` |
| 1445 | cc_library_shared { |
| 1446 | name: "libvendor", |
| 1447 | srcs: ["vendor.cpp"], |
| 1448 | vendor: true, |
| 1449 | exclude_from_vendor_snapshot: true, |
| 1450 | } |
| 1451 | ` |
| 1452 | |
| 1453 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1454 | |
| 1455 | mockFS := map[string][]byte{ |
| 1456 | "deps/Android.bp": []byte(depsBp), |
| 1457 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1458 | "device/vendor.cpp": nil, |
| 1459 | } |
| 1460 | |
| 1461 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1462 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1463 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1464 | ctx := CreateTestContext() |
| 1465 | ctx.Register(config) |
| 1466 | |
| 1467 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"}) |
| 1468 | android.FailIfErrored(t, errs) |
| 1469 | |
| 1470 | _, errs = ctx.PrepareBuildActions(config) |
| 1471 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1472 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1473 | `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1474 | }) |
| 1475 | } |
| 1476 | |
| 1477 | func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) { |
| 1478 | |
| 1479 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1480 | // property on a module that is vendor available generates an error. A |
| 1481 | // vendor available module must be captured in the vendor snapshot and |
| 1482 | // must not built from source when building the vendor image against |
| 1483 | // the vendor snapshot. |
| 1484 | |
| 1485 | frameworkBp := ` |
| 1486 | cc_library_shared { |
| 1487 | name: "libinclude", |
| 1488 | srcs: ["src/include.cpp"], |
| 1489 | vendor_available: true, |
| 1490 | exclude_from_vendor_snapshot: true, |
| 1491 | } |
| 1492 | ` |
| 1493 | |
| 1494 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1495 | |
| 1496 | mockFS := map[string][]byte{ |
| 1497 | "deps/Android.bp": []byte(depsBp), |
| 1498 | "framework/Android.bp": []byte(frameworkBp), |
| 1499 | "framework/include.cpp": nil, |
| 1500 | } |
| 1501 | |
| 1502 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1503 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1504 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1505 | ctx := CreateTestContext() |
| 1506 | ctx.Register(config) |
| 1507 | |
| 1508 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"}) |
| 1509 | android.FailIfErrored(t, errs) |
| 1510 | |
| 1511 | _, errs = ctx.PrepareBuildActions(config) |
| 1512 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1513 | `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1514 | `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1515 | `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1516 | `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1517 | }) |
| 1518 | } |
| 1519 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1520 | func TestDoubleLoadableDepError(t *testing.T) { |
| 1521 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1522 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1523 | cc_library { |
| 1524 | name: "libllndk", |
| 1525 | shared_libs: ["libnondoubleloadable"], |
| 1526 | } |
| 1527 | |
| 1528 | llndk_library { |
| 1529 | name: "libllndk", |
| 1530 | symbol_file: "", |
| 1531 | } |
| 1532 | |
| 1533 | cc_library { |
| 1534 | name: "libnondoubleloadable", |
| 1535 | vendor_available: true, |
| 1536 | vndk: { |
| 1537 | enabled: true, |
| 1538 | }, |
| 1539 | } |
| 1540 | `) |
| 1541 | |
| 1542 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1543 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1544 | cc_library { |
| 1545 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1546 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1547 | shared_libs: ["libnondoubleloadable"], |
| 1548 | } |
| 1549 | |
| 1550 | llndk_library { |
| 1551 | name: "libllndk", |
| 1552 | symbol_file: "", |
| 1553 | } |
| 1554 | |
| 1555 | cc_library { |
| 1556 | name: "libnondoubleloadable", |
| 1557 | vendor_available: true, |
| 1558 | } |
| 1559 | `) |
| 1560 | |
| 1561 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. |
| 1562 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1563 | cc_library { |
| 1564 | name: "libdoubleloadable", |
| 1565 | vendor_available: true, |
| 1566 | double_loadable: true, |
| 1567 | shared_libs: ["libnondoubleloadable"], |
| 1568 | } |
| 1569 | |
| 1570 | cc_library { |
| 1571 | name: "libnondoubleloadable", |
| 1572 | vendor_available: true, |
| 1573 | } |
| 1574 | `) |
| 1575 | |
| 1576 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib. |
| 1577 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1578 | cc_library { |
| 1579 | name: "libdoubleloadable", |
| 1580 | vendor_available: true, |
| 1581 | double_loadable: true, |
| 1582 | shared_libs: ["libnondoubleloadable"], |
| 1583 | } |
| 1584 | |
| 1585 | cc_library { |
| 1586 | name: "libnondoubleloadable", |
| 1587 | vendor_available: true, |
| 1588 | vndk: { |
| 1589 | enabled: true, |
| 1590 | }, |
| 1591 | } |
| 1592 | `) |
| 1593 | |
| 1594 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. |
| 1595 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1596 | cc_library { |
| 1597 | name: "libdoubleloadable", |
| 1598 | vendor_available: true, |
| 1599 | vndk: { |
| 1600 | enabled: true, |
| 1601 | }, |
| 1602 | double_loadable: true, |
| 1603 | shared_libs: ["libnondoubleloadable"], |
| 1604 | } |
| 1605 | |
| 1606 | cc_library { |
| 1607 | name: "libnondoubleloadable", |
| 1608 | vendor_available: false, |
| 1609 | vndk: { |
| 1610 | enabled: true, |
| 1611 | }, |
| 1612 | } |
| 1613 | `) |
| 1614 | |
| 1615 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1616 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1617 | cc_library { |
| 1618 | name: "libllndk", |
| 1619 | shared_libs: ["libcoreonly"], |
| 1620 | } |
| 1621 | |
| 1622 | llndk_library { |
| 1623 | name: "libllndk", |
| 1624 | symbol_file: "", |
| 1625 | } |
| 1626 | |
| 1627 | cc_library { |
| 1628 | name: "libcoreonly", |
| 1629 | shared_libs: ["libvendoravailable"], |
| 1630 | } |
| 1631 | |
| 1632 | // indirect dependency of LLNDK |
| 1633 | cc_library { |
| 1634 | name: "libvendoravailable", |
| 1635 | vendor_available: true, |
| 1636 | } |
| 1637 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1638 | } |
| 1639 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1640 | func TestVndkExt(t *testing.T) { |
| 1641 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1642 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1643 | cc_library { |
| 1644 | name: "libvndk", |
| 1645 | vendor_available: true, |
| 1646 | vndk: { |
| 1647 | enabled: true, |
| 1648 | }, |
| 1649 | nocrt: true, |
| 1650 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1651 | cc_library { |
| 1652 | name: "libvndk2", |
| 1653 | vendor_available: true, |
| 1654 | vndk: { |
| 1655 | enabled: true, |
| 1656 | }, |
| 1657 | target: { |
| 1658 | vendor: { |
| 1659 | suffix: "-suffix", |
| 1660 | }, |
| 1661 | }, |
| 1662 | nocrt: true, |
| 1663 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1664 | |
| 1665 | cc_library { |
| 1666 | name: "libvndk_ext", |
| 1667 | vendor: true, |
| 1668 | vndk: { |
| 1669 | enabled: true, |
| 1670 | extends: "libvndk", |
| 1671 | }, |
| 1672 | nocrt: true, |
| 1673 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1674 | |
| 1675 | cc_library { |
| 1676 | name: "libvndk2_ext", |
| 1677 | vendor: true, |
| 1678 | vndk: { |
| 1679 | enabled: true, |
| 1680 | extends: "libvndk2", |
| 1681 | }, |
| 1682 | nocrt: true, |
| 1683 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1684 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1685 | cc_library { |
| 1686 | name: "libvndk_ext_product", |
| 1687 | product_specific: true, |
| 1688 | vndk: { |
| 1689 | enabled: true, |
| 1690 | extends: "libvndk", |
| 1691 | }, |
| 1692 | nocrt: true, |
| 1693 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1694 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1695 | cc_library { |
| 1696 | name: "libvndk2_ext_product", |
| 1697 | product_specific: true, |
| 1698 | vndk: { |
| 1699 | enabled: true, |
| 1700 | extends: "libvndk2", |
| 1701 | }, |
| 1702 | nocrt: true, |
| 1703 | } |
| 1704 | ` |
| 1705 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1706 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1707 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1708 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1709 | |
| 1710 | ctx := testCcWithConfig(t, config) |
| 1711 | |
| 1712 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 1713 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 1714 | |
| 1715 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 1716 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 1717 | |
| 1718 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 1719 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1722 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1723 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 1724 | ctx := testCcNoVndk(t, ` |
| 1725 | cc_library { |
| 1726 | name: "libvndk", |
| 1727 | vendor_available: true, |
| 1728 | vndk: { |
| 1729 | enabled: true, |
| 1730 | }, |
| 1731 | nocrt: true, |
| 1732 | } |
| 1733 | |
| 1734 | cc_library { |
| 1735 | name: "libvndk_ext", |
| 1736 | vendor: true, |
| 1737 | vndk: { |
| 1738 | enabled: true, |
| 1739 | extends: "libvndk", |
| 1740 | }, |
| 1741 | nocrt: true, |
| 1742 | } |
| 1743 | `) |
| 1744 | |
| 1745 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 1746 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 1747 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1748 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 1749 | } |
| 1750 | } |
| 1751 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1752 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { |
| 1753 | // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set. |
| 1754 | ctx := testCc(t, ` |
| 1755 | cc_library { |
| 1756 | name: "libvndk", |
| 1757 | vendor_available: true, |
| 1758 | vndk: { |
| 1759 | enabled: true, |
| 1760 | }, |
| 1761 | nocrt: true, |
| 1762 | } |
| 1763 | |
| 1764 | cc_library { |
| 1765 | name: "libvndk_ext_product", |
| 1766 | product_specific: true, |
| 1767 | vndk: { |
| 1768 | enabled: true, |
| 1769 | extends: "libvndk", |
| 1770 | }, |
| 1771 | nocrt: true, |
| 1772 | } |
| 1773 | `) |
| 1774 | |
| 1775 | // Ensures that the core variant of "libvndk_ext_product" can be found. |
| 1776 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) |
| 1777 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1778 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) |
| 1779 | } |
| 1780 | } |
| 1781 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1782 | func TestVndkExtError(t *testing.T) { |
| 1783 | // This test ensures an error is emitted in ill-formed vndk-ext definition. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1784 | testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1785 | cc_library { |
| 1786 | name: "libvndk", |
| 1787 | vendor_available: true, |
| 1788 | vndk: { |
| 1789 | enabled: true, |
| 1790 | }, |
| 1791 | nocrt: true, |
| 1792 | } |
| 1793 | |
| 1794 | cc_library { |
| 1795 | name: "libvndk_ext", |
| 1796 | vndk: { |
| 1797 | enabled: true, |
| 1798 | extends: "libvndk", |
| 1799 | }, |
| 1800 | nocrt: true, |
| 1801 | } |
| 1802 | `) |
| 1803 | |
| 1804 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1805 | cc_library { |
| 1806 | name: "libvndk", |
| 1807 | vendor_available: true, |
| 1808 | vndk: { |
| 1809 | enabled: true, |
| 1810 | }, |
| 1811 | nocrt: true, |
| 1812 | } |
| 1813 | |
| 1814 | cc_library { |
| 1815 | name: "libvndk_ext", |
| 1816 | vendor: true, |
| 1817 | vndk: { |
| 1818 | enabled: true, |
| 1819 | }, |
| 1820 | nocrt: true, |
| 1821 | } |
| 1822 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1823 | |
| 1824 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1825 | cc_library { |
| 1826 | name: "libvndk", |
| 1827 | vendor_available: true, |
| 1828 | vndk: { |
| 1829 | enabled: true, |
| 1830 | }, |
| 1831 | nocrt: true, |
| 1832 | } |
| 1833 | |
| 1834 | cc_library { |
| 1835 | name: "libvndk_ext_product", |
| 1836 | product_specific: true, |
| 1837 | vndk: { |
| 1838 | enabled: true, |
| 1839 | }, |
| 1840 | nocrt: true, |
| 1841 | } |
| 1842 | `) |
| 1843 | |
| 1844 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 1845 | cc_library { |
| 1846 | name: "libvndk", |
| 1847 | vendor_available: true, |
| 1848 | vndk: { |
| 1849 | enabled: true, |
| 1850 | }, |
| 1851 | nocrt: true, |
| 1852 | } |
| 1853 | |
| 1854 | cc_library { |
| 1855 | name: "libvndk_ext_product", |
| 1856 | product_specific: true, |
| 1857 | vendor_available: true, |
| 1858 | vndk: { |
| 1859 | enabled: true, |
| 1860 | extends: "libvndk", |
| 1861 | }, |
| 1862 | nocrt: true, |
| 1863 | } |
| 1864 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 1868 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1869 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1870 | cc_library { |
| 1871 | name: "libvndk", |
| 1872 | vendor_available: true, |
| 1873 | vndk: { |
| 1874 | enabled: true, |
| 1875 | }, |
| 1876 | nocrt: true, |
| 1877 | } |
| 1878 | |
| 1879 | cc_library { |
| 1880 | name: "libvndk_sp_ext", |
| 1881 | vendor: true, |
| 1882 | vndk: { |
| 1883 | enabled: true, |
| 1884 | extends: "libvndk", |
| 1885 | support_system_process: true, |
| 1886 | }, |
| 1887 | nocrt: true, |
| 1888 | } |
| 1889 | `) |
| 1890 | |
| 1891 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1892 | cc_library { |
| 1893 | name: "libvndk_sp", |
| 1894 | vendor_available: true, |
| 1895 | vndk: { |
| 1896 | enabled: true, |
| 1897 | support_system_process: true, |
| 1898 | }, |
| 1899 | nocrt: true, |
| 1900 | } |
| 1901 | |
| 1902 | cc_library { |
| 1903 | name: "libvndk_ext", |
| 1904 | vendor: true, |
| 1905 | vndk: { |
| 1906 | enabled: true, |
| 1907 | extends: "libvndk_sp", |
| 1908 | }, |
| 1909 | nocrt: true, |
| 1910 | } |
| 1911 | `) |
| 1912 | } |
| 1913 | |
| 1914 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1915 | // 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] | 1916 | // with `vendor_available: false`. |
| 1917 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 1918 | cc_library { |
| 1919 | name: "libvndk", |
| 1920 | vendor_available: false, |
| 1921 | vndk: { |
| 1922 | enabled: true, |
| 1923 | }, |
| 1924 | nocrt: true, |
| 1925 | } |
| 1926 | |
| 1927 | cc_library { |
| 1928 | name: "libvndk_ext", |
| 1929 | vendor: true, |
| 1930 | vndk: { |
| 1931 | enabled: true, |
| 1932 | extends: "libvndk", |
| 1933 | }, |
| 1934 | nocrt: true, |
| 1935 | } |
| 1936 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1937 | |
| 1938 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 1939 | cc_library { |
| 1940 | name: "libvndk", |
| 1941 | vendor_available: false, |
| 1942 | vndk: { |
| 1943 | enabled: true, |
| 1944 | }, |
| 1945 | nocrt: true, |
| 1946 | } |
| 1947 | |
| 1948 | cc_library { |
| 1949 | name: "libvndk_ext_product", |
| 1950 | product_specific: true, |
| 1951 | vndk: { |
| 1952 | enabled: true, |
| 1953 | extends: "libvndk", |
| 1954 | }, |
| 1955 | nocrt: true, |
| 1956 | } |
| 1957 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1958 | } |
| 1959 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1960 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 1961 | // 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] | 1962 | testCc(t, ` |
| 1963 | cc_library { |
| 1964 | name: "libvndk", |
| 1965 | vendor_available: true, |
| 1966 | vndk: { |
| 1967 | enabled: true, |
| 1968 | }, |
| 1969 | nocrt: true, |
| 1970 | } |
| 1971 | |
| 1972 | cc_library { |
| 1973 | name: "libvndk_ext", |
| 1974 | vendor: true, |
| 1975 | vndk: { |
| 1976 | enabled: true, |
| 1977 | extends: "libvndk", |
| 1978 | }, |
| 1979 | nocrt: true, |
| 1980 | } |
| 1981 | |
| 1982 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1983 | name: "libvndk_sp", |
| 1984 | vendor_available: true, |
| 1985 | vndk: { |
| 1986 | enabled: true, |
| 1987 | support_system_process: true, |
| 1988 | }, |
| 1989 | nocrt: true, |
| 1990 | } |
| 1991 | |
| 1992 | cc_library { |
| 1993 | name: "libvndk_sp_ext", |
| 1994 | vendor: true, |
| 1995 | vndk: { |
| 1996 | enabled: true, |
| 1997 | extends: "libvndk_sp", |
| 1998 | support_system_process: true, |
| 1999 | }, |
| 2000 | nocrt: true, |
| 2001 | } |
| 2002 | |
| 2003 | cc_library { |
| 2004 | name: "libvendor", |
| 2005 | vendor: true, |
| 2006 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 2007 | nocrt: true, |
| 2008 | } |
| 2009 | `) |
| 2010 | } |
| 2011 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2012 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 2013 | // 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] | 2014 | testCc(t, ` |
| 2015 | cc_library { |
| 2016 | name: "libvndk", |
| 2017 | vendor_available: true, |
| 2018 | vndk: { |
| 2019 | enabled: true, |
| 2020 | }, |
| 2021 | nocrt: true, |
| 2022 | } |
| 2023 | |
| 2024 | cc_library { |
| 2025 | name: "libvndk_ext", |
| 2026 | vendor: true, |
| 2027 | vndk: { |
| 2028 | enabled: true, |
| 2029 | extends: "libvndk", |
| 2030 | }, |
| 2031 | shared_libs: ["libvendor"], |
| 2032 | nocrt: true, |
| 2033 | } |
| 2034 | |
| 2035 | cc_library { |
| 2036 | name: "libvendor", |
| 2037 | vendor: true, |
| 2038 | nocrt: true, |
| 2039 | } |
| 2040 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2041 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2042 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 2043 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2044 | cc_library { |
| 2045 | name: "libvndk_sp", |
| 2046 | vendor_available: true, |
| 2047 | vndk: { |
| 2048 | enabled: true, |
| 2049 | support_system_process: true, |
| 2050 | }, |
| 2051 | nocrt: true, |
| 2052 | } |
| 2053 | |
| 2054 | cc_library { |
| 2055 | name: "libvndk_sp_ext", |
| 2056 | vendor: true, |
| 2057 | vndk: { |
| 2058 | enabled: true, |
| 2059 | extends: "libvndk_sp", |
| 2060 | support_system_process: true, |
| 2061 | }, |
| 2062 | shared_libs: ["libvendor"], // Cause an error |
| 2063 | nocrt: true, |
| 2064 | } |
| 2065 | |
| 2066 | cc_library { |
| 2067 | name: "libvendor", |
| 2068 | vendor: true, |
| 2069 | nocrt: true, |
| 2070 | } |
| 2071 | `) |
| 2072 | } |
| 2073 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2074 | func TestProductVndkExtDependency(t *testing.T) { |
| 2075 | bp := ` |
| 2076 | cc_library { |
| 2077 | name: "libvndk", |
| 2078 | vendor_available: true, |
| 2079 | vndk: { |
| 2080 | enabled: true, |
| 2081 | }, |
| 2082 | nocrt: true, |
| 2083 | } |
| 2084 | |
| 2085 | cc_library { |
| 2086 | name: "libvndk_ext_product", |
| 2087 | product_specific: true, |
| 2088 | vndk: { |
| 2089 | enabled: true, |
| 2090 | extends: "libvndk", |
| 2091 | }, |
| 2092 | shared_libs: ["libproduct_for_vndklibs"], |
| 2093 | nocrt: true, |
| 2094 | } |
| 2095 | |
| 2096 | cc_library { |
| 2097 | name: "libvndk_sp", |
| 2098 | vendor_available: true, |
| 2099 | vndk: { |
| 2100 | enabled: true, |
| 2101 | support_system_process: true, |
| 2102 | }, |
| 2103 | nocrt: true, |
| 2104 | } |
| 2105 | |
| 2106 | cc_library { |
| 2107 | name: "libvndk_sp_ext_product", |
| 2108 | product_specific: true, |
| 2109 | vndk: { |
| 2110 | enabled: true, |
| 2111 | extends: "libvndk_sp", |
| 2112 | support_system_process: true, |
| 2113 | }, |
| 2114 | shared_libs: ["libproduct_for_vndklibs"], |
| 2115 | nocrt: true, |
| 2116 | } |
| 2117 | |
| 2118 | cc_library { |
| 2119 | name: "libproduct", |
| 2120 | product_specific: true, |
| 2121 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 2122 | nocrt: true, |
| 2123 | } |
| 2124 | |
| 2125 | cc_library { |
| 2126 | name: "libproduct_for_vndklibs", |
| 2127 | product_specific: true, |
| 2128 | nocrt: true, |
| 2129 | } |
| 2130 | ` |
| 2131 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2132 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2133 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2134 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2135 | |
| 2136 | testCcWithConfig(t, config) |
| 2137 | } |
| 2138 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2139 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 2140 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 2141 | // library. |
| 2142 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2143 | cc_library { |
| 2144 | name: "libvndk", |
| 2145 | vendor_available: true, |
| 2146 | vndk: { |
| 2147 | enabled: true, |
| 2148 | }, |
| 2149 | nocrt: true, |
| 2150 | } |
| 2151 | |
| 2152 | cc_library { |
| 2153 | name: "libvndk_sp", |
| 2154 | vendor_available: true, |
| 2155 | vndk: { |
| 2156 | enabled: true, |
| 2157 | support_system_process: true, |
| 2158 | }, |
| 2159 | nocrt: true, |
| 2160 | } |
| 2161 | |
| 2162 | cc_library { |
| 2163 | name: "libvndk_sp_ext", |
| 2164 | vendor: true, |
| 2165 | vndk: { |
| 2166 | enabled: true, |
| 2167 | extends: "libvndk_sp", |
| 2168 | support_system_process: true, |
| 2169 | }, |
| 2170 | shared_libs: ["libvndk"], // Cause an error |
| 2171 | nocrt: true, |
| 2172 | } |
| 2173 | `) |
| 2174 | |
| 2175 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 2176 | // library. |
| 2177 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2178 | cc_library { |
| 2179 | name: "libvndk", |
| 2180 | vendor_available: true, |
| 2181 | vndk: { |
| 2182 | enabled: true, |
| 2183 | }, |
| 2184 | nocrt: true, |
| 2185 | } |
| 2186 | |
| 2187 | cc_library { |
| 2188 | name: "libvndk_ext", |
| 2189 | vendor: true, |
| 2190 | vndk: { |
| 2191 | enabled: true, |
| 2192 | extends: "libvndk", |
| 2193 | }, |
| 2194 | nocrt: true, |
| 2195 | } |
| 2196 | |
| 2197 | cc_library { |
| 2198 | name: "libvndk_sp", |
| 2199 | vendor_available: true, |
| 2200 | vndk: { |
| 2201 | enabled: true, |
| 2202 | support_system_process: true, |
| 2203 | }, |
| 2204 | nocrt: true, |
| 2205 | } |
| 2206 | |
| 2207 | cc_library { |
| 2208 | name: "libvndk_sp_ext", |
| 2209 | vendor: true, |
| 2210 | vndk: { |
| 2211 | enabled: true, |
| 2212 | extends: "libvndk_sp", |
| 2213 | support_system_process: true, |
| 2214 | }, |
| 2215 | shared_libs: ["libvndk_ext"], // Cause an error |
| 2216 | nocrt: true, |
| 2217 | } |
| 2218 | `) |
| 2219 | } |
| 2220 | |
| 2221 | func TestVndkUseVndkExtError(t *testing.T) { |
| 2222 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 2223 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2224 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2225 | cc_library { |
| 2226 | name: "libvndk", |
| 2227 | vendor_available: true, |
| 2228 | vndk: { |
| 2229 | enabled: true, |
| 2230 | }, |
| 2231 | nocrt: true, |
| 2232 | } |
| 2233 | |
| 2234 | cc_library { |
| 2235 | name: "libvndk_ext", |
| 2236 | vendor: true, |
| 2237 | vndk: { |
| 2238 | enabled: true, |
| 2239 | extends: "libvndk", |
| 2240 | }, |
| 2241 | nocrt: true, |
| 2242 | } |
| 2243 | |
| 2244 | cc_library { |
| 2245 | name: "libvndk2", |
| 2246 | vendor_available: true, |
| 2247 | vndk: { |
| 2248 | enabled: true, |
| 2249 | }, |
| 2250 | shared_libs: ["libvndk_ext"], |
| 2251 | nocrt: true, |
| 2252 | } |
| 2253 | `) |
| 2254 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2255 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2256 | cc_library { |
| 2257 | name: "libvndk", |
| 2258 | vendor_available: true, |
| 2259 | vndk: { |
| 2260 | enabled: true, |
| 2261 | }, |
| 2262 | nocrt: true, |
| 2263 | } |
| 2264 | |
| 2265 | cc_library { |
| 2266 | name: "libvndk_ext", |
| 2267 | vendor: true, |
| 2268 | vndk: { |
| 2269 | enabled: true, |
| 2270 | extends: "libvndk", |
| 2271 | }, |
| 2272 | nocrt: true, |
| 2273 | } |
| 2274 | |
| 2275 | cc_library { |
| 2276 | name: "libvndk2", |
| 2277 | vendor_available: true, |
| 2278 | vndk: { |
| 2279 | enabled: true, |
| 2280 | }, |
| 2281 | target: { |
| 2282 | vendor: { |
| 2283 | shared_libs: ["libvndk_ext"], |
| 2284 | }, |
| 2285 | }, |
| 2286 | nocrt: true, |
| 2287 | } |
| 2288 | `) |
| 2289 | |
| 2290 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2291 | cc_library { |
| 2292 | name: "libvndk_sp", |
| 2293 | vendor_available: true, |
| 2294 | vndk: { |
| 2295 | enabled: true, |
| 2296 | support_system_process: true, |
| 2297 | }, |
| 2298 | nocrt: true, |
| 2299 | } |
| 2300 | |
| 2301 | cc_library { |
| 2302 | name: "libvndk_sp_ext", |
| 2303 | vendor: true, |
| 2304 | vndk: { |
| 2305 | enabled: true, |
| 2306 | extends: "libvndk_sp", |
| 2307 | support_system_process: true, |
| 2308 | }, |
| 2309 | nocrt: true, |
| 2310 | } |
| 2311 | |
| 2312 | cc_library { |
| 2313 | name: "libvndk_sp_2", |
| 2314 | vendor_available: true, |
| 2315 | vndk: { |
| 2316 | enabled: true, |
| 2317 | support_system_process: true, |
| 2318 | }, |
| 2319 | shared_libs: ["libvndk_sp_ext"], |
| 2320 | nocrt: true, |
| 2321 | } |
| 2322 | `) |
| 2323 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2324 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2325 | cc_library { |
| 2326 | name: "libvndk_sp", |
| 2327 | vendor_available: true, |
| 2328 | vndk: { |
| 2329 | enabled: true, |
| 2330 | }, |
| 2331 | nocrt: true, |
| 2332 | } |
| 2333 | |
| 2334 | cc_library { |
| 2335 | name: "libvndk_sp_ext", |
| 2336 | vendor: true, |
| 2337 | vndk: { |
| 2338 | enabled: true, |
| 2339 | extends: "libvndk_sp", |
| 2340 | }, |
| 2341 | nocrt: true, |
| 2342 | } |
| 2343 | |
| 2344 | cc_library { |
| 2345 | name: "libvndk_sp2", |
| 2346 | vendor_available: true, |
| 2347 | vndk: { |
| 2348 | enabled: true, |
| 2349 | }, |
| 2350 | target: { |
| 2351 | vendor: { |
| 2352 | shared_libs: ["libvndk_sp_ext"], |
| 2353 | }, |
| 2354 | }, |
| 2355 | nocrt: true, |
| 2356 | } |
| 2357 | `) |
| 2358 | } |
| 2359 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2360 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 2361 | bp := ` |
| 2362 | cc_library { |
| 2363 | name: "libllndk", |
| 2364 | } |
| 2365 | llndk_library { |
| 2366 | name: "libllndk", |
| 2367 | symbol_file: "", |
| 2368 | } |
| 2369 | cc_library { |
| 2370 | name: "libvndk", |
| 2371 | vendor_available: true, |
| 2372 | vndk: { |
| 2373 | enabled: true, |
| 2374 | }, |
| 2375 | nocrt: true, |
| 2376 | } |
| 2377 | cc_library { |
| 2378 | name: "libvndk_sp", |
| 2379 | vendor_available: true, |
| 2380 | vndk: { |
| 2381 | enabled: true, |
| 2382 | support_system_process: true, |
| 2383 | }, |
| 2384 | nocrt: true, |
| 2385 | } |
| 2386 | cc_library { |
| 2387 | name: "libva", |
| 2388 | vendor_available: true, |
| 2389 | nocrt: true, |
| 2390 | } |
| 2391 | cc_library { |
| 2392 | name: "libproduct_va", |
| 2393 | product_specific: true, |
| 2394 | vendor_available: true, |
| 2395 | nocrt: true, |
| 2396 | } |
| 2397 | cc_library { |
| 2398 | name: "libprod", |
| 2399 | product_specific: true, |
| 2400 | shared_libs: [ |
| 2401 | "libllndk", |
| 2402 | "libvndk", |
| 2403 | "libvndk_sp", |
| 2404 | "libva", |
| 2405 | "libproduct_va", |
| 2406 | ], |
| 2407 | nocrt: true, |
| 2408 | } |
| 2409 | cc_library { |
| 2410 | name: "libvendor", |
| 2411 | vendor: true, |
| 2412 | shared_libs: [ |
| 2413 | "libllndk", |
| 2414 | "libvndk", |
| 2415 | "libvndk_sp", |
| 2416 | "libva", |
| 2417 | "libproduct_va", |
| 2418 | ], |
| 2419 | nocrt: true, |
| 2420 | } |
| 2421 | ` |
| 2422 | |
| 2423 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2424 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2425 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2426 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2427 | |
| 2428 | ctx := testCcWithConfig(t, config) |
| 2429 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2430 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", productVariant) |
| 2431 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", productVariant) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 2435 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2436 | cc_library { |
| 2437 | name: "libprod", |
| 2438 | product_specific: true, |
| 2439 | shared_libs: [ |
| 2440 | "libvendor", |
| 2441 | ], |
| 2442 | nocrt: true, |
| 2443 | } |
| 2444 | cc_library { |
| 2445 | name: "libvendor", |
| 2446 | vendor: true, |
| 2447 | nocrt: true, |
| 2448 | } |
| 2449 | `) |
| 2450 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2451 | cc_library { |
| 2452 | name: "libprod", |
| 2453 | product_specific: true, |
| 2454 | shared_libs: [ |
| 2455 | "libsystem", |
| 2456 | ], |
| 2457 | nocrt: true, |
| 2458 | } |
| 2459 | cc_library { |
| 2460 | name: "libsystem", |
| 2461 | nocrt: true, |
| 2462 | } |
| 2463 | `) |
| 2464 | testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", ` |
| 2465 | cc_library { |
| 2466 | name: "libprod", |
| 2467 | product_specific: true, |
| 2468 | shared_libs: [ |
| 2469 | "libvndk_private", |
| 2470 | ], |
| 2471 | nocrt: true, |
| 2472 | } |
| 2473 | cc_library { |
| 2474 | name: "libvndk_private", |
| 2475 | vendor_available: false, |
| 2476 | vndk: { |
| 2477 | enabled: true, |
| 2478 | }, |
| 2479 | nocrt: true, |
| 2480 | } |
| 2481 | `) |
| 2482 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2483 | cc_library { |
| 2484 | name: "libprod", |
| 2485 | product_specific: true, |
| 2486 | shared_libs: [ |
| 2487 | "libsystem_ext", |
| 2488 | ], |
| 2489 | nocrt: true, |
| 2490 | } |
| 2491 | cc_library { |
| 2492 | name: "libsystem_ext", |
| 2493 | system_ext_specific: true, |
| 2494 | nocrt: true, |
| 2495 | } |
| 2496 | `) |
| 2497 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2498 | cc_library { |
| 2499 | name: "libsystem", |
| 2500 | shared_libs: [ |
| 2501 | "libproduct_va", |
| 2502 | ], |
| 2503 | nocrt: true, |
| 2504 | } |
| 2505 | cc_library { |
| 2506 | name: "libproduct_va", |
| 2507 | product_specific: true, |
| 2508 | vendor_available: true, |
| 2509 | nocrt: true, |
| 2510 | } |
| 2511 | `) |
| 2512 | } |
| 2513 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2514 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2515 | bp := ` |
| 2516 | cc_library { |
| 2517 | name: "libvndk", |
| 2518 | vendor_available: true, |
| 2519 | vndk: { |
| 2520 | enabled: true, |
| 2521 | }, |
| 2522 | } |
| 2523 | cc_library { |
| 2524 | name: "libvndksp", |
| 2525 | vendor_available: true, |
| 2526 | vndk: { |
| 2527 | enabled: true, |
| 2528 | support_system_process: true, |
| 2529 | }, |
| 2530 | } |
| 2531 | cc_library { |
| 2532 | name: "libvndkprivate", |
| 2533 | vendor_available: false, |
| 2534 | vndk: { |
| 2535 | enabled: true, |
| 2536 | }, |
| 2537 | } |
| 2538 | cc_library { |
| 2539 | name: "libvendor", |
| 2540 | vendor: true, |
| 2541 | } |
| 2542 | cc_library { |
| 2543 | name: "libvndkext", |
| 2544 | vendor: true, |
| 2545 | vndk: { |
| 2546 | enabled: true, |
| 2547 | extends: "libvndk", |
| 2548 | }, |
| 2549 | } |
| 2550 | vndk_prebuilt_shared { |
| 2551 | name: "prevndk", |
| 2552 | version: "27", |
| 2553 | target_arch: "arm", |
| 2554 | binder32bit: true, |
| 2555 | vendor_available: true, |
| 2556 | vndk: { |
| 2557 | enabled: true, |
| 2558 | }, |
| 2559 | arch: { |
| 2560 | arm: { |
| 2561 | srcs: ["liba.so"], |
| 2562 | }, |
| 2563 | }, |
| 2564 | } |
| 2565 | cc_library { |
| 2566 | name: "libllndk", |
| 2567 | } |
| 2568 | llndk_library { |
| 2569 | name: "libllndk", |
| 2570 | symbol_file: "", |
| 2571 | } |
| 2572 | cc_library { |
| 2573 | name: "libllndkprivate", |
| 2574 | } |
| 2575 | llndk_library { |
| 2576 | name: "libllndkprivate", |
| 2577 | vendor_available: false, |
| 2578 | symbol_file: "", |
| 2579 | }` |
| 2580 | |
| 2581 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2582 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2583 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2584 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2585 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2586 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2587 | assertMapKeys(t, vndkCoreLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2588 | []string{"libvndk", "libvndkprivate"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2589 | assertMapKeys(t, vndkSpLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2590 | []string{"libc++", "libvndksp"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2591 | assertMapKeys(t, llndkLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 2592 | []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2593 | assertMapKeys(t, vndkPrivateLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 2594 | []string{"libft2", "libllndkprivate", "libvndkprivate"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2595 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2596 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2597 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2598 | tests := []struct { |
| 2599 | variant string |
| 2600 | name string |
| 2601 | expected string |
| 2602 | }{ |
| 2603 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2604 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2605 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2606 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2607 | {vendorVariant, "libvndkext", "native:vendor"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2608 | {vendorVariant, "libllndk.llndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2609 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2610 | {coreVariant, "libvndk", "native:platform"}, |
| 2611 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2612 | {coreVariant, "libllndk", "native:platform"}, |
| 2613 | } |
| 2614 | for _, test := range tests { |
| 2615 | t.Run(test.name, func(t *testing.T) { |
| 2616 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2617 | assertString(t, module.makeLinkType, test.expected) |
| 2618 | }) |
| 2619 | } |
| 2620 | } |
| 2621 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2622 | var ( |
| 2623 | str11 = "01234567891" |
| 2624 | str10 = str11[:10] |
| 2625 | str9 = str11[:9] |
| 2626 | str5 = str11[:5] |
| 2627 | str4 = str11[:4] |
| 2628 | ) |
| 2629 | |
| 2630 | var splitListForSizeTestCases = []struct { |
| 2631 | in []string |
| 2632 | out [][]string |
| 2633 | size int |
| 2634 | }{ |
| 2635 | { |
| 2636 | in: []string{str10}, |
| 2637 | out: [][]string{{str10}}, |
| 2638 | size: 10, |
| 2639 | }, |
| 2640 | { |
| 2641 | in: []string{str9}, |
| 2642 | out: [][]string{{str9}}, |
| 2643 | size: 10, |
| 2644 | }, |
| 2645 | { |
| 2646 | in: []string{str5}, |
| 2647 | out: [][]string{{str5}}, |
| 2648 | size: 10, |
| 2649 | }, |
| 2650 | { |
| 2651 | in: []string{str11}, |
| 2652 | out: nil, |
| 2653 | size: 10, |
| 2654 | }, |
| 2655 | { |
| 2656 | in: []string{str10, str10}, |
| 2657 | out: [][]string{{str10}, {str10}}, |
| 2658 | size: 10, |
| 2659 | }, |
| 2660 | { |
| 2661 | in: []string{str9, str10}, |
| 2662 | out: [][]string{{str9}, {str10}}, |
| 2663 | size: 10, |
| 2664 | }, |
| 2665 | { |
| 2666 | in: []string{str10, str9}, |
| 2667 | out: [][]string{{str10}, {str9}}, |
| 2668 | size: 10, |
| 2669 | }, |
| 2670 | { |
| 2671 | in: []string{str5, str4}, |
| 2672 | out: [][]string{{str5, str4}}, |
| 2673 | size: 10, |
| 2674 | }, |
| 2675 | { |
| 2676 | in: []string{str5, str4, str5}, |
| 2677 | out: [][]string{{str5, str4}, {str5}}, |
| 2678 | size: 10, |
| 2679 | }, |
| 2680 | { |
| 2681 | in: []string{str5, str4, str5, str4}, |
| 2682 | out: [][]string{{str5, str4}, {str5, str4}}, |
| 2683 | size: 10, |
| 2684 | }, |
| 2685 | { |
| 2686 | in: []string{str5, str4, str5, str5}, |
| 2687 | out: [][]string{{str5, str4}, {str5}, {str5}}, |
| 2688 | size: 10, |
| 2689 | }, |
| 2690 | { |
| 2691 | in: []string{str5, str5, str5, str4}, |
| 2692 | out: [][]string{{str5}, {str5}, {str5, str4}}, |
| 2693 | size: 10, |
| 2694 | }, |
| 2695 | { |
| 2696 | in: []string{str9, str11}, |
| 2697 | out: nil, |
| 2698 | size: 10, |
| 2699 | }, |
| 2700 | { |
| 2701 | in: []string{str11, str9}, |
| 2702 | out: nil, |
| 2703 | size: 10, |
| 2704 | }, |
| 2705 | } |
| 2706 | |
| 2707 | func TestSplitListForSize(t *testing.T) { |
| 2708 | for _, testCase := range splitListForSizeTestCases { |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 2709 | out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2710 | |
| 2711 | var outStrings [][]string |
| 2712 | |
| 2713 | if len(out) > 0 { |
| 2714 | outStrings = make([][]string, len(out)) |
| 2715 | for i, o := range out { |
| 2716 | outStrings[i] = o.Strings() |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | if !reflect.DeepEqual(outStrings, testCase.out) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2721 | t.Errorf("incorrect output:") |
| 2722 | t.Errorf(" input: %#v", testCase.in) |
| 2723 | t.Errorf(" size: %d", testCase.size) |
| 2724 | t.Errorf(" expected: %#v", testCase.out) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2725 | t.Errorf(" got: %#v", outStrings) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2729 | |
| 2730 | var staticLinkDepOrderTestCases = []struct { |
| 2731 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2732 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2733 | inStatic string |
| 2734 | |
| 2735 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2736 | // It models the dependencies declared in an Android.bp file. |
| 2737 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2738 | |
| 2739 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2740 | // The keys of allOrdered specify which modules we would like to check. |
| 2741 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2742 | // dependencies) for each module to test |
| 2743 | allOrdered string |
| 2744 | |
| 2745 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2746 | // The keys of outOrdered specify which modules we would like to check. |
| 2747 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2748 | // for each module to test. |
| 2749 | outOrdered string |
| 2750 | }{ |
| 2751 | // Simple tests |
| 2752 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2753 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2754 | outOrdered: "", |
| 2755 | }, |
| 2756 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2757 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2758 | outOrdered: "a:", |
| 2759 | }, |
| 2760 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2761 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2762 | outOrdered: "a:b; b:", |
| 2763 | }, |
| 2764 | // Tests of reordering |
| 2765 | { |
| 2766 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2767 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2768 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2769 | }, |
| 2770 | { |
| 2771 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2772 | 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] | 2773 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2774 | }, |
| 2775 | { |
| 2776 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2777 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2778 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2779 | }, |
| 2780 | { |
| 2781 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2782 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2783 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2784 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2785 | }, |
| 2786 | { |
| 2787 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2788 | 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] | 2789 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2790 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2791 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2792 | // shared dependencies |
| 2793 | { |
| 2794 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2795 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2796 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2797 | // a shared dependency on b, that that shows up in allOrdered. |
| 2798 | inShared: "c:b", |
| 2799 | allOrdered: "c:b", |
| 2800 | outOrdered: "c:", |
| 2801 | }, |
| 2802 | { |
| 2803 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2804 | // the second phase of the above test would look like |
| 2805 | inStatic: "a:b,c; c:b", |
| 2806 | allOrdered: "a:c,b; c:b", |
| 2807 | outOrdered: "a:c,b; c:b", |
| 2808 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2809 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2810 | // to dictate an order |
| 2811 | { |
| 2812 | // 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] | 2813 | 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] | 2814 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2815 | }, |
| 2816 | { |
| 2817 | // 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] | 2818 | 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] | 2819 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2820 | }, |
| 2821 | // Tests involving duplicate dependencies |
| 2822 | { |
| 2823 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2824 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2825 | outOrdered: "a:c,b", |
| 2826 | }, |
| 2827 | { |
| 2828 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2829 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2830 | outOrdered: "a:d,c,b", |
| 2831 | }, |
| 2832 | // Tests to confirm the nonexistence of infinite loops. |
| 2833 | // These cases should never happen, so as long as the test terminates and the |
| 2834 | // result is deterministic then that should be fine. |
| 2835 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2836 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2837 | outOrdered: "a:a", |
| 2838 | }, |
| 2839 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2840 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2841 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2842 | outOrdered: "a:b; b:c; c:a", |
| 2843 | }, |
| 2844 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2845 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2846 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2847 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2848 | }, |
| 2849 | } |
| 2850 | |
| 2851 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2852 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2853 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2854 | strippedText := strings.Replace(text, " ", "", -1) |
| 2855 | if len(strippedText) < 1 { |
| 2856 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2857 | } |
| 2858 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2859 | |
| 2860 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2861 | moduleTexts := strings.Split(strippedText, ";") |
| 2862 | |
| 2863 | outputForModuleName := func(moduleName string) android.Path { |
| 2864 | return android.PathForTesting(moduleName) |
| 2865 | } |
| 2866 | |
| 2867 | for _, moduleText := range moduleTexts { |
| 2868 | // convert from "a:b,c" to ["a", "b,c"] |
| 2869 | components := strings.Split(moduleText, ":") |
| 2870 | if len(components) != 2 { |
| 2871 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2872 | } |
| 2873 | moduleName := components[0] |
| 2874 | moduleOutput := outputForModuleName(moduleName) |
| 2875 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2876 | |
| 2877 | depString := components[1] |
| 2878 | // convert from "b,c" to ["b", "c"] |
| 2879 | depNames := strings.Split(depString, ",") |
| 2880 | if len(depString) < 1 { |
| 2881 | depNames = []string{} |
| 2882 | } |
| 2883 | var deps []android.Path |
| 2884 | for _, depName := range depNames { |
| 2885 | deps = append(deps, outputForModuleName(depName)) |
| 2886 | } |
| 2887 | allDeps[moduleOutput] = deps |
| 2888 | } |
| 2889 | return modulesInOrder, allDeps |
| 2890 | } |
| 2891 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2892 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 2893 | for _, moduleName := range moduleNames { |
| 2894 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 2895 | output := module.outputFile.Path() |
| 2896 | paths = append(paths, output) |
| 2897 | } |
| 2898 | return paths |
| 2899 | } |
| 2900 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2901 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2902 | ctx := testCc(t, ` |
| 2903 | cc_library { |
| 2904 | name: "a", |
| 2905 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2906 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2907 | } |
| 2908 | cc_library { |
| 2909 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2910 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2911 | } |
| 2912 | cc_library { |
| 2913 | name: "c", |
| 2914 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2915 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2916 | } |
| 2917 | cc_library { |
| 2918 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2919 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | `) |
| 2923 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2924 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2925 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2926 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 2927 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2928 | |
| 2929 | if !reflect.DeepEqual(actual, expected) { |
| 2930 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2931 | "\nactual: %v"+ |
| 2932 | "\nexpected: %v", |
| 2933 | actual, |
| 2934 | expected, |
| 2935 | ) |
| 2936 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2937 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2938 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2939 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 2940 | ctx := testCc(t, ` |
| 2941 | cc_library { |
| 2942 | name: "a", |
| 2943 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2944 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2945 | } |
| 2946 | cc_library { |
| 2947 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2948 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2949 | } |
| 2950 | cc_library { |
| 2951 | name: "c", |
| 2952 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2953 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | `) |
| 2957 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2958 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2959 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2960 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 2961 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2962 | |
| 2963 | if !reflect.DeepEqual(actual, expected) { |
| 2964 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2965 | "\nactual: %v"+ |
| 2966 | "\nexpected: %v", |
| 2967 | actual, |
| 2968 | expected, |
| 2969 | ) |
| 2970 | } |
| 2971 | } |
| 2972 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2973 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2974 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2975 | if !reflect.DeepEqual(actual, expected) { |
| 2976 | t.Errorf(message+ |
| 2977 | "\nactual: %v"+ |
| 2978 | "\nexpected: %v", |
| 2979 | actual, |
| 2980 | expected, |
| 2981 | ) |
| 2982 | } |
| 2983 | } |
| 2984 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2985 | func TestLlndkLibrary(t *testing.T) { |
| 2986 | ctx := testCc(t, ` |
| 2987 | cc_library { |
| 2988 | name: "libllndk", |
| 2989 | stubs: { versions: ["1", "2"] }, |
| 2990 | } |
| 2991 | llndk_library { |
| 2992 | name: "libllndk", |
| 2993 | } |
| 2994 | `) |
| 2995 | actual := ctx.ModuleVariantsForTests("libllndk.llndk") |
| 2996 | expected := []string{ |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2997 | "android_vendor.VER_arm64_armv8-a_shared_1", |
| 2998 | "android_vendor.VER_arm64_armv8-a_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2999 | "android_vendor.VER_arm64_armv8-a_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3000 | "android_vendor.VER_arm_armv7-a-neon_shared_1", |
| 3001 | "android_vendor.VER_arm_armv7-a-neon_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3002 | "android_vendor.VER_arm_armv7-a-neon_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3003 | } |
| 3004 | checkEquals(t, "variants for llndk stubs", expected, actual) |
| 3005 | |
| 3006 | params := ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub") |
| 3007 | checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) |
| 3008 | |
| 3009 | params = ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub") |
| 3010 | checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"]) |
| 3011 | } |
| 3012 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3013 | func TestLlndkHeaders(t *testing.T) { |
| 3014 | ctx := testCc(t, ` |
| 3015 | llndk_headers { |
| 3016 | name: "libllndk_headers", |
| 3017 | export_include_dirs: ["my_include"], |
| 3018 | } |
| 3019 | llndk_library { |
| 3020 | name: "libllndk", |
| 3021 | export_llndk_headers: ["libllndk_headers"], |
| 3022 | } |
| 3023 | cc_library { |
| 3024 | name: "libvendor", |
| 3025 | shared_libs: ["libllndk"], |
| 3026 | vendor: true, |
| 3027 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3028 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 3029 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3030 | } |
| 3031 | `) |
| 3032 | |
| 3033 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3034 | cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc") |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3035 | cflags := cc.Args["cFlags"] |
| 3036 | if !strings.Contains(cflags, "-Imy_include") { |
| 3037 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 3038 | } |
| 3039 | } |
| 3040 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3041 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 3042 | actual := module.Properties.AndroidMkRuntimeLibs |
| 3043 | if !reflect.DeepEqual(actual, expected) { |
| 3044 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 3045 | "\nactual: %v"+ |
| 3046 | "\nexpected: %v", |
| 3047 | actual, |
| 3048 | expected, |
| 3049 | ) |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | const runtimeLibAndroidBp = ` |
| 3054 | cc_library { |
| 3055 | name: "libvendor_available1", |
| 3056 | vendor_available: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3057 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3058 | nocrt : true, |
| 3059 | system_shared_libs : [], |
| 3060 | } |
| 3061 | cc_library { |
| 3062 | name: "libvendor_available2", |
| 3063 | vendor_available: true, |
| 3064 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3065 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3066 | nocrt : true, |
| 3067 | system_shared_libs : [], |
| 3068 | } |
| 3069 | cc_library { |
| 3070 | name: "libvendor_available3", |
| 3071 | vendor_available: true, |
| 3072 | runtime_libs: ["libvendor_available1"], |
| 3073 | target: { |
| 3074 | vendor: { |
| 3075 | exclude_runtime_libs: ["libvendor_available1"], |
| 3076 | } |
| 3077 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3078 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3079 | nocrt : true, |
| 3080 | system_shared_libs : [], |
| 3081 | } |
| 3082 | cc_library { |
| 3083 | name: "libcore", |
| 3084 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3085 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3086 | nocrt : true, |
| 3087 | system_shared_libs : [], |
| 3088 | } |
| 3089 | cc_library { |
| 3090 | name: "libvendor1", |
| 3091 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3092 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3093 | nocrt : true, |
| 3094 | system_shared_libs : [], |
| 3095 | } |
| 3096 | cc_library { |
| 3097 | name: "libvendor2", |
| 3098 | vendor: true, |
| 3099 | runtime_libs: ["libvendor_available1", "libvendor1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3100 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3101 | nocrt : true, |
| 3102 | system_shared_libs : [], |
| 3103 | } |
| 3104 | ` |
| 3105 | |
| 3106 | func TestRuntimeLibs(t *testing.T) { |
| 3107 | ctx := testCc(t, runtimeLibAndroidBp) |
| 3108 | |
| 3109 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3110 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3111 | |
| 3112 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 3113 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 3114 | |
| 3115 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
| 3116 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 3117 | |
| 3118 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 3119 | // and vendor variants. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3120 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3121 | |
| 3122 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 3123 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) |
| 3124 | |
| 3125 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 3126 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) |
| 3127 | } |
| 3128 | |
| 3129 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 3130 | ctx := testCc(t, runtimeLibAndroidBp) |
| 3131 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3132 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3133 | module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 3134 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 3135 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3136 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3137 | module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 3138 | checkRuntimeLibs(t, nil, module) |
| 3139 | } |
| 3140 | |
| 3141 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 3142 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 3143 | |
| 3144 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 3145 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3146 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3147 | |
| 3148 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 3149 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 3150 | |
| 3151 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 3152 | checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) |
| 3153 | } |
| 3154 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3155 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 3156 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3157 | actual := module.Properties.AndroidMkStaticLibs |
| 3158 | if !reflect.DeepEqual(actual, expected) { |
| 3159 | t.Errorf("incorrect static_libs"+ |
| 3160 | "\nactual: %v"+ |
| 3161 | "\nexpected: %v", |
| 3162 | actual, |
| 3163 | expected, |
| 3164 | ) |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | const staticLibAndroidBp = ` |
| 3169 | cc_library { |
| 3170 | name: "lib1", |
| 3171 | } |
| 3172 | cc_library { |
| 3173 | name: "lib2", |
| 3174 | static_libs: ["lib1"], |
| 3175 | } |
| 3176 | ` |
| 3177 | |
| 3178 | func TestStaticLibDepExport(t *testing.T) { |
| 3179 | ctx := testCc(t, staticLibAndroidBp) |
| 3180 | |
| 3181 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3182 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3183 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 3184 | checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3185 | |
| 3186 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3187 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3188 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 3189 | // libc++_static is linked additionally. |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 3190 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3193 | var compilerFlagsTestCases = []struct { |
| 3194 | in string |
| 3195 | out bool |
| 3196 | }{ |
| 3197 | { |
| 3198 | in: "a", |
| 3199 | out: false, |
| 3200 | }, |
| 3201 | { |
| 3202 | in: "-a", |
| 3203 | out: true, |
| 3204 | }, |
| 3205 | { |
| 3206 | in: "-Ipath/to/something", |
| 3207 | out: false, |
| 3208 | }, |
| 3209 | { |
| 3210 | in: "-isystempath/to/something", |
| 3211 | out: false, |
| 3212 | }, |
| 3213 | { |
| 3214 | in: "--coverage", |
| 3215 | out: false, |
| 3216 | }, |
| 3217 | { |
| 3218 | in: "-include a/b", |
| 3219 | out: true, |
| 3220 | }, |
| 3221 | { |
| 3222 | in: "-include a/b c/d", |
| 3223 | out: false, |
| 3224 | }, |
| 3225 | { |
| 3226 | in: "-DMACRO", |
| 3227 | out: true, |
| 3228 | }, |
| 3229 | { |
| 3230 | in: "-DMAC RO", |
| 3231 | out: false, |
| 3232 | }, |
| 3233 | { |
| 3234 | in: "-a -b", |
| 3235 | out: false, |
| 3236 | }, |
| 3237 | { |
| 3238 | in: "-DMACRO=definition", |
| 3239 | out: true, |
| 3240 | }, |
| 3241 | { |
| 3242 | in: "-DMACRO=defi nition", |
| 3243 | out: true, // TODO(jiyong): this should be false |
| 3244 | }, |
| 3245 | { |
| 3246 | in: "-DMACRO(x)=x + 1", |
| 3247 | out: true, |
| 3248 | }, |
| 3249 | { |
| 3250 | in: "-DMACRO=\"defi nition\"", |
| 3251 | out: true, |
| 3252 | }, |
| 3253 | } |
| 3254 | |
| 3255 | type mockContext struct { |
| 3256 | BaseModuleContext |
| 3257 | result bool |
| 3258 | } |
| 3259 | |
| 3260 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 3261 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 3262 | ctx.result = false |
| 3263 | } |
| 3264 | |
| 3265 | func TestCompilerFlags(t *testing.T) { |
| 3266 | for _, testCase := range compilerFlagsTestCases { |
| 3267 | ctx := &mockContext{result: true} |
| 3268 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 3269 | if ctx.result != testCase.out { |
| 3270 | t.Errorf("incorrect output:") |
| 3271 | t.Errorf(" input: %#v", testCase.in) |
| 3272 | t.Errorf(" expected: %#v", testCase.out) |
| 3273 | t.Errorf(" got: %#v", ctx.result) |
| 3274 | } |
| 3275 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3276 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3277 | |
| 3278 | func TestVendorPublicLibraries(t *testing.T) { |
| 3279 | ctx := testCc(t, ` |
| 3280 | cc_library_headers { |
| 3281 | name: "libvendorpublic_headers", |
| 3282 | export_include_dirs: ["my_include"], |
| 3283 | } |
| 3284 | vendor_public_library { |
| 3285 | name: "libvendorpublic", |
| 3286 | symbol_file: "", |
| 3287 | export_public_headers: ["libvendorpublic_headers"], |
| 3288 | } |
| 3289 | cc_library { |
| 3290 | name: "libvendorpublic", |
| 3291 | srcs: ["foo.c"], |
| 3292 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3293 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3294 | nocrt: true, |
| 3295 | } |
| 3296 | |
| 3297 | cc_library { |
| 3298 | name: "libsystem", |
| 3299 | shared_libs: ["libvendorpublic"], |
| 3300 | vendor: false, |
| 3301 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3302 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3303 | nocrt: true, |
| 3304 | } |
| 3305 | cc_library { |
| 3306 | name: "libvendor", |
| 3307 | shared_libs: ["libvendorpublic"], |
| 3308 | vendor: true, |
| 3309 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3310 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3311 | nocrt: true, |
| 3312 | } |
| 3313 | `) |
| 3314 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3315 | coreVariant := "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3316 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3317 | |
| 3318 | // test if header search paths are correctly added |
| 3319 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3320 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3321 | cflags := cc.Args["cFlags"] |
| 3322 | if !strings.Contains(cflags, "-Imy_include") { |
| 3323 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 3324 | } |
| 3325 | |
| 3326 | // test if libsystem is linked to the stub |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3327 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3328 | libflags := ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3329 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3330 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3331 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3332 | } |
| 3333 | |
| 3334 | // test if libvendor is linked to the real shared lib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3335 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3336 | libflags = ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3337 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3338 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3339 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3340 | } |
| 3341 | |
| 3342 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3343 | |
| 3344 | func TestRecovery(t *testing.T) { |
| 3345 | ctx := testCc(t, ` |
| 3346 | cc_library_shared { |
| 3347 | name: "librecovery", |
| 3348 | recovery: true, |
| 3349 | } |
| 3350 | cc_library_shared { |
| 3351 | name: "librecovery32", |
| 3352 | recovery: true, |
| 3353 | compile_multilib:"32", |
| 3354 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3355 | cc_library_shared { |
| 3356 | name: "libHalInRecovery", |
| 3357 | recovery_available: true, |
| 3358 | vendor: true, |
| 3359 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3360 | `) |
| 3361 | |
| 3362 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3363 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3364 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3365 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3366 | } |
| 3367 | |
| 3368 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3369 | if android.InList(arm64, variants) { |
| 3370 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3371 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3372 | |
| 3373 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3374 | if !recoveryModule.Platform() { |
| 3375 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3376 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3377 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3378 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3379 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
| 3380 | bp := ` |
| 3381 | cc_prebuilt_test_library_shared { |
| 3382 | name: "test_lib", |
| 3383 | relative_install_path: "foo/bar/baz", |
| 3384 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3385 | } |
| 3386 | |
| 3387 | cc_test { |
| 3388 | name: "main_test", |
| 3389 | data_libs: ["test_lib"], |
| 3390 | gtest: false, |
| 3391 | } |
| 3392 | ` |
| 3393 | |
| 3394 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3395 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 3396 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 3397 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3398 | |
| 3399 | ctx := testCcWithConfig(t, config) |
| 3400 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3401 | testBinary := module.(*Module).linker.(*testBinary) |
| 3402 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3403 | if err != nil { |
| 3404 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3405 | } |
| 3406 | if len(outputFiles) != 1 { |
| 3407 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3408 | } |
| 3409 | if len(testBinary.dataPaths()) != 1 { |
| 3410 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 3411 | } |
| 3412 | |
| 3413 | outputPath := outputFiles[0].String() |
| 3414 | |
| 3415 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3416 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3417 | } |
| 3418 | entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] |
| 3419 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3420 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3421 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3422 | } |
| 3423 | } |
| 3424 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3425 | func TestVersionedStubs(t *testing.T) { |
| 3426 | ctx := testCc(t, ` |
| 3427 | cc_library_shared { |
| 3428 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3429 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3430 | stubs: { |
| 3431 | symbol_file: "foo.map.txt", |
| 3432 | versions: ["1", "2", "3"], |
| 3433 | }, |
| 3434 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3435 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3436 | cc_library_shared { |
| 3437 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3438 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3439 | shared_libs: ["libFoo#1"], |
| 3440 | }`) |
| 3441 | |
| 3442 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3443 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3444 | "android_arm64_armv8-a_shared", |
| 3445 | "android_arm64_armv8-a_shared_1", |
| 3446 | "android_arm64_armv8-a_shared_2", |
| 3447 | "android_arm64_armv8-a_shared_3", |
| 3448 | "android_arm_armv7-a-neon_shared", |
| 3449 | "android_arm_armv7-a-neon_shared_1", |
| 3450 | "android_arm_armv7-a-neon_shared_2", |
| 3451 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3452 | } |
| 3453 | variantsMismatch := false |
| 3454 | if len(variants) != len(expectedVariants) { |
| 3455 | variantsMismatch = true |
| 3456 | } else { |
| 3457 | for _, v := range expectedVariants { |
| 3458 | if !inList(v, variants) { |
| 3459 | variantsMismatch = false |
| 3460 | } |
| 3461 | } |
| 3462 | } |
| 3463 | if variantsMismatch { |
| 3464 | t.Errorf("variants of libFoo expected:\n") |
| 3465 | for _, v := range expectedVariants { |
| 3466 | t.Errorf("%q\n", v) |
| 3467 | } |
| 3468 | t.Errorf(", but got:\n") |
| 3469 | for _, v := range variants { |
| 3470 | t.Errorf("%q\n", v) |
| 3471 | } |
| 3472 | } |
| 3473 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3474 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3475 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3476 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3477 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 3478 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 3479 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3480 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3481 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3482 | cFlags := libBarCompileRule.Args["cFlags"] |
| 3483 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 3484 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 3485 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 3486 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3487 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3488 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3489 | func TestVersioningMacro(t *testing.T) { |
| 3490 | for _, tc := range []struct{ moduleName, expected string }{ |
| 3491 | {"libc", "__LIBC_API__"}, |
| 3492 | {"libfoo", "__LIBFOO_API__"}, |
| 3493 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 3494 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 3495 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 3496 | } { |
| 3497 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 3498 | } |
| 3499 | } |
| 3500 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3501 | func TestStaticExecutable(t *testing.T) { |
| 3502 | ctx := testCc(t, ` |
| 3503 | cc_binary { |
| 3504 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 3505 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3506 | static_executable: true, |
| 3507 | }`) |
| 3508 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3509 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3510 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 3511 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 3512 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3513 | for _, lib := range systemStaticLibs { |
| 3514 | if !strings.Contains(libFlags, lib) { |
| 3515 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 3516 | } |
| 3517 | } |
| 3518 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 3519 | for _, lib := range systemSharedLibs { |
| 3520 | if strings.Contains(libFlags, lib) { |
| 3521 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 3522 | } |
| 3523 | } |
| 3524 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3525 | |
| 3526 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
| 3527 | ctx := testCc(t, ` |
| 3528 | cc_binary { |
| 3529 | name: "mybin", |
| 3530 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3531 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3532 | static_executable: true, |
| 3533 | stl: "none", |
| 3534 | } |
| 3535 | |
| 3536 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3537 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3538 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3539 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3540 | stl: "none", |
| 3541 | } |
| 3542 | |
| 3543 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3544 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3545 | srcs: ["foo.c"], |
| 3546 | stl: "none", |
| 3547 | stubs: { |
| 3548 | versions: ["1"], |
| 3549 | }, |
| 3550 | }`) |
| 3551 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3552 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 3553 | actual := mybin.Implicits[:2] |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3554 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3555 | |
| 3556 | if !reflect.DeepEqual(actual, expected) { |
| 3557 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3558 | "\nactual: %v"+ |
| 3559 | "\nexpected: %v", |
| 3560 | actual, |
| 3561 | expected, |
| 3562 | ) |
| 3563 | } |
| 3564 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3565 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3566 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
| 3567 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 3568 | cc_library { |
| 3569 | name: "libA", |
| 3570 | srcs: ["foo.c"], |
| 3571 | shared_libs: ["libB"], |
| 3572 | stl: "none", |
| 3573 | } |
| 3574 | |
| 3575 | cc_library { |
| 3576 | name: "libB", |
| 3577 | srcs: ["foo.c"], |
| 3578 | enabled: false, |
| 3579 | stl: "none", |
| 3580 | } |
| 3581 | `) |
| 3582 | } |
| 3583 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3584 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 3585 | // correctly. |
| 3586 | func TestFuzzTarget(t *testing.T) { |
| 3587 | ctx := testCc(t, ` |
| 3588 | cc_fuzz { |
| 3589 | name: "fuzz_smoke_test", |
| 3590 | srcs: ["foo.c"], |
| 3591 | }`) |
| 3592 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 3593 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3594 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 3595 | } |
| 3596 | |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 3597 | func TestAidl(t *testing.T) { |
| 3598 | } |
| 3599 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3600 | func assertString(t *testing.T, got, expected string) { |
| 3601 | t.Helper() |
| 3602 | if got != expected { |
| 3603 | t.Errorf("expected %q got %q", expected, got) |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3608 | t.Helper() |
| 3609 | if len(got) != len(expected) { |
| 3610 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3611 | return |
| 3612 | } |
| 3613 | for i := range got { |
| 3614 | if got[i] != expected[i] { |
| 3615 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3616 | i, expected[i], expected, got[i], got) |
| 3617 | return |
| 3618 | } |
| 3619 | } |
| 3620 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3621 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3622 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 3623 | t.Helper() |
| 3624 | assertArrayString(t, android.SortedStringKeys(m), expected) |
| 3625 | } |
| 3626 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3627 | func TestDefaults(t *testing.T) { |
| 3628 | ctx := testCc(t, ` |
| 3629 | cc_defaults { |
| 3630 | name: "defaults", |
| 3631 | srcs: ["foo.c"], |
| 3632 | static: { |
| 3633 | srcs: ["bar.c"], |
| 3634 | }, |
| 3635 | shared: { |
| 3636 | srcs: ["baz.c"], |
| 3637 | }, |
| 3638 | } |
| 3639 | |
| 3640 | cc_library_static { |
| 3641 | name: "libstatic", |
| 3642 | defaults: ["defaults"], |
| 3643 | } |
| 3644 | |
| 3645 | cc_library_shared { |
| 3646 | name: "libshared", |
| 3647 | defaults: ["defaults"], |
| 3648 | } |
| 3649 | |
| 3650 | cc_library { |
| 3651 | name: "libboth", |
| 3652 | defaults: ["defaults"], |
| 3653 | } |
| 3654 | |
| 3655 | cc_binary { |
| 3656 | name: "binary", |
| 3657 | defaults: ["defaults"], |
| 3658 | }`) |
| 3659 | |
| 3660 | pathsToBase := func(paths android.Paths) []string { |
| 3661 | var ret []string |
| 3662 | for _, p := range paths { |
| 3663 | ret = append(ret, p.Base()) |
| 3664 | } |
| 3665 | return ret |
| 3666 | } |
| 3667 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3668 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3669 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3670 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 3671 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3672 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3673 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3674 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 3675 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3676 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3677 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 3678 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 3679 | } |
| 3680 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3681 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3682 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3683 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 3684 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3685 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3686 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3687 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 3688 | } |
| 3689 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3690 | |
| 3691 | func TestProductVariableDefaults(t *testing.T) { |
| 3692 | bp := ` |
| 3693 | cc_defaults { |
| 3694 | name: "libfoo_defaults", |
| 3695 | srcs: ["foo.c"], |
| 3696 | cppflags: ["-DFOO"], |
| 3697 | product_variables: { |
| 3698 | debuggable: { |
| 3699 | cppflags: ["-DBAR"], |
| 3700 | }, |
| 3701 | }, |
| 3702 | } |
| 3703 | |
| 3704 | cc_library { |
| 3705 | name: "libfoo", |
| 3706 | defaults: ["libfoo_defaults"], |
| 3707 | } |
| 3708 | ` |
| 3709 | |
| 3710 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3711 | config.TestProductVariables.Debuggable = BoolPtr(true) |
| 3712 | |
| 3713 | ctx := CreateTestContext() |
| 3714 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 3715 | ctx.BottomUp("variable", android.VariableMutator).Parallel() |
| 3716 | }) |
| 3717 | ctx.Register(config) |
| 3718 | |
| 3719 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 3720 | android.FailIfErrored(t, errs) |
| 3721 | _, errs = ctx.PrepareBuildActions(config) |
| 3722 | android.FailIfErrored(t, errs) |
| 3723 | |
| 3724 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 3725 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { |
| 3726 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) |
| 3727 | } |
| 3728 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3729 | |
| 3730 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 3731 | t.Parallel() |
| 3732 | bp := ` |
| 3733 | cc_library_static { |
| 3734 | name: "libfoo", |
| 3735 | srcs: ["foo.c"], |
| 3736 | whole_static_libs: ["libbar"], |
| 3737 | } |
| 3738 | |
| 3739 | cc_library_static { |
| 3740 | name: "libbar", |
| 3741 | whole_static_libs: ["libmissing"], |
| 3742 | } |
| 3743 | ` |
| 3744 | |
| 3745 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3746 | config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true) |
| 3747 | |
| 3748 | ctx := CreateTestContext() |
| 3749 | ctx.SetAllowMissingDependencies(true) |
| 3750 | ctx.Register(config) |
| 3751 | |
| 3752 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 3753 | android.FailIfErrored(t, errs) |
| 3754 | _, errs = ctx.PrepareBuildActions(config) |
| 3755 | android.FailIfErrored(t, errs) |
| 3756 | |
| 3757 | libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
| 3758 | if g, w := libbar.Rule, android.ErrorRule; g != w { |
| 3759 | t.Fatalf("Expected libbar rule to be %q, got %q", w, g) |
| 3760 | } |
| 3761 | |
| 3762 | if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) { |
| 3763 | t.Errorf("Expected libbar error to contain %q, was %q", w, g) |
| 3764 | } |
| 3765 | |
| 3766 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
| 3767 | if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) { |
| 3768 | t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g) |
| 3769 | } |
| 3770 | |
| 3771 | } |