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