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