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