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