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 | } |
| 1248 | } |
| 1249 | |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1250 | func TestVendorSnapshotUse(t *testing.T) { |
| 1251 | frameworkBp := ` |
| 1252 | cc_library { |
| 1253 | name: "libvndk", |
| 1254 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1255 | product_available: true, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1256 | vndk: { |
| 1257 | enabled: true, |
| 1258 | }, |
| 1259 | nocrt: true, |
| 1260 | compile_multilib: "64", |
| 1261 | } |
| 1262 | |
| 1263 | cc_library { |
| 1264 | name: "libvendor", |
| 1265 | vendor: true, |
| 1266 | nocrt: true, |
| 1267 | no_libcrt: true, |
| 1268 | stl: "none", |
| 1269 | system_shared_libs: [], |
| 1270 | compile_multilib: "64", |
| 1271 | } |
| 1272 | |
| 1273 | cc_binary { |
| 1274 | name: "bin", |
| 1275 | vendor: true, |
| 1276 | nocrt: true, |
| 1277 | no_libcrt: true, |
| 1278 | stl: "none", |
| 1279 | system_shared_libs: [], |
| 1280 | compile_multilib: "64", |
| 1281 | } |
| 1282 | ` |
| 1283 | |
| 1284 | vndkBp := ` |
| 1285 | vndk_prebuilt_shared { |
| 1286 | name: "libvndk", |
| 1287 | version: "BOARD", |
| 1288 | target_arch: "arm64", |
| 1289 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1290 | product_available: true, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1291 | vndk: { |
| 1292 | enabled: true, |
| 1293 | }, |
| 1294 | arch: { |
| 1295 | arm64: { |
| 1296 | srcs: ["libvndk.so"], |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1297 | export_include_dirs: ["include/libvndk"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1298 | }, |
| 1299 | }, |
| 1300 | } |
| 1301 | ` |
| 1302 | |
| 1303 | vendorProprietaryBp := ` |
| 1304 | cc_library { |
| 1305 | name: "libvendor_without_snapshot", |
| 1306 | vendor: true, |
| 1307 | nocrt: true, |
| 1308 | no_libcrt: true, |
| 1309 | stl: "none", |
| 1310 | system_shared_libs: [], |
| 1311 | compile_multilib: "64", |
| 1312 | } |
| 1313 | |
| 1314 | cc_library_shared { |
| 1315 | name: "libclient", |
| 1316 | vendor: true, |
| 1317 | nocrt: true, |
| 1318 | no_libcrt: true, |
| 1319 | stl: "none", |
| 1320 | system_shared_libs: [], |
| 1321 | shared_libs: ["libvndk"], |
| 1322 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
| 1323 | compile_multilib: "64", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1324 | srcs: ["client.cpp"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | cc_binary { |
| 1328 | name: "bin_without_snapshot", |
| 1329 | vendor: true, |
| 1330 | nocrt: true, |
| 1331 | no_libcrt: true, |
| 1332 | stl: "none", |
| 1333 | system_shared_libs: [], |
| 1334 | static_libs: ["libvndk"], |
| 1335 | compile_multilib: "64", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1336 | srcs: ["bin.cpp"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | vendor_snapshot_static { |
| 1340 | name: "libvndk", |
| 1341 | version: "BOARD", |
| 1342 | target_arch: "arm64", |
| 1343 | vendor: true, |
| 1344 | arch: { |
| 1345 | arm64: { |
| 1346 | src: "libvndk.a", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1347 | export_include_dirs: ["include/libvndk"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1348 | }, |
| 1349 | }, |
| 1350 | } |
| 1351 | |
| 1352 | vendor_snapshot_shared { |
| 1353 | name: "libvendor", |
| 1354 | version: "BOARD", |
| 1355 | target_arch: "arm64", |
| 1356 | vendor: true, |
| 1357 | arch: { |
| 1358 | arm64: { |
| 1359 | src: "libvendor.so", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1360 | export_include_dirs: ["include/libvendor"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1361 | }, |
| 1362 | }, |
| 1363 | } |
| 1364 | |
| 1365 | vendor_snapshot_static { |
| 1366 | name: "libvendor", |
| 1367 | version: "BOARD", |
| 1368 | target_arch: "arm64", |
| 1369 | vendor: true, |
| 1370 | arch: { |
| 1371 | arm64: { |
| 1372 | src: "libvendor.a", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1373 | export_include_dirs: ["include/libvendor"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1374 | }, |
| 1375 | }, |
| 1376 | } |
| 1377 | |
| 1378 | vendor_snapshot_binary { |
| 1379 | name: "bin", |
| 1380 | version: "BOARD", |
| 1381 | target_arch: "arm64", |
| 1382 | vendor: true, |
| 1383 | arch: { |
| 1384 | arm64: { |
| 1385 | src: "bin", |
| 1386 | }, |
| 1387 | }, |
| 1388 | } |
| 1389 | ` |
| 1390 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1391 | |
| 1392 | mockFS := map[string][]byte{ |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1393 | "deps/Android.bp": []byte(depsBp), |
| 1394 | "framework/Android.bp": []byte(frameworkBp), |
| 1395 | "vendor/Android.bp": []byte(vendorProprietaryBp), |
| 1396 | "vendor/bin": nil, |
| 1397 | "vendor/bin.cpp": nil, |
| 1398 | "vendor/client.cpp": nil, |
| 1399 | "vendor/include/libvndk/a.h": nil, |
| 1400 | "vendor/include/libvendor/b.h": nil, |
| 1401 | "vendor/libvndk.a": nil, |
| 1402 | "vendor/libvendor.a": nil, |
| 1403 | "vendor/libvendor.so": nil, |
| 1404 | "vndk/Android.bp": []byte(vndkBp), |
| 1405 | "vndk/include/libvndk/a.h": nil, |
| 1406 | "vndk/libvndk.so": nil, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1410 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1411 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1412 | ctx := CreateTestContext(config) |
| 1413 | ctx.Register() |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1414 | |
| 1415 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"}) |
| 1416 | android.FailIfErrored(t, errs) |
| 1417 | _, errs = ctx.PrepareBuildActions(config) |
| 1418 | android.FailIfErrored(t, errs) |
| 1419 | |
| 1420 | sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared" |
| 1421 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1422 | binaryVariant := "android_vendor.BOARD_arm64_armv8-a" |
| 1423 | |
| 1424 | // 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] | 1425 | libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"] |
| 1426 | for _, includeFlags := range []string{ |
| 1427 | "-Ivndk/include/libvndk", // libvndk |
| 1428 | "-Ivendor/include/libvendor", // libvendor |
| 1429 | } { |
| 1430 | if !strings.Contains(libclientCcFlags, includeFlags) { |
| 1431 | t.Errorf("flags for libclient must contain %#v, but was %#v.", |
| 1432 | includeFlags, libclientCcFlags) |
| 1433 | } |
| 1434 | } |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1435 | |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1436 | libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"] |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1437 | for _, input := range [][]string{ |
| 1438 | []string{sharedVariant, "libvndk.vndk.BOARD.arm64"}, |
| 1439 | []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"}, |
| 1440 | []string{staticVariant, "libvendor_without_snapshot"}, |
| 1441 | } { |
| 1442 | outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1443 | if !strings.Contains(libclientLdFlags, outputPaths[0].String()) { |
| 1444 | 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] | 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64 |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1449 | binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"] |
| 1450 | if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") { |
| 1451 | t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.", |
| 1452 | "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags) |
| 1453 | } |
| 1454 | |
| 1455 | binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"] |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1456 | libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"}) |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1457 | if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) { |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1458 | 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] | 1459 | libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags) |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64 |
| 1463 | ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so") |
| 1464 | |
| 1465 | // libvendor_without_snapshot.so is installed by libvendor_without_snapshot |
| 1466 | ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so") |
| 1467 | |
| 1468 | // bin is installed by bin.vendor_binary.BOARD.arm64 |
| 1469 | ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin") |
| 1470 | |
| 1471 | // bin_without_snapshot is installed by bin_without_snapshot |
| 1472 | ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot") |
| 1473 | |
| 1474 | // libvendor and bin don't have vendor.BOARD variant |
| 1475 | libvendorVariants := ctx.ModuleVariantsForTests("libvendor") |
| 1476 | if inList(sharedVariant, libvendorVariants) { |
| 1477 | t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant) |
| 1478 | } |
| 1479 | |
| 1480 | binVariants := ctx.ModuleVariantsForTests("bin") |
| 1481 | if inList(binaryVariant, binVariants) { |
| 1482 | t.Errorf("bin must not have variant %#v, but it does", sharedVariant) |
| 1483 | } |
| 1484 | } |
| 1485 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1486 | func TestVendorSnapshotSanitizer(t *testing.T) { |
| 1487 | bp := ` |
| 1488 | vendor_snapshot_static { |
| 1489 | name: "libsnapshot", |
| 1490 | vendor: true, |
| 1491 | target_arch: "arm64", |
| 1492 | version: "BOARD", |
| 1493 | arch: { |
| 1494 | arm64: { |
| 1495 | src: "libsnapshot.a", |
| 1496 | cfi: { |
| 1497 | src: "libsnapshot.cfi.a", |
| 1498 | } |
| 1499 | }, |
| 1500 | }, |
| 1501 | } |
| 1502 | ` |
| 1503 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1504 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1505 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1506 | ctx := testCcWithConfig(t, config) |
| 1507 | |
| 1508 | // Check non-cfi and cfi variant. |
| 1509 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1510 | staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi" |
| 1511 | |
| 1512 | staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module) |
| 1513 | assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a") |
| 1514 | |
| 1515 | staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module) |
| 1516 | assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a") |
| 1517 | } |
| 1518 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1519 | func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) { |
| 1520 | t.Helper() |
| 1521 | if c.ExcludeFromVendorSnapshot() != expected { |
| 1522 | t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected) |
| 1523 | } |
| 1524 | } |
| 1525 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1526 | func assertExcludeFromRecoverySnapshotIs(t *testing.T, c *Module, expected bool) { |
| 1527 | t.Helper() |
| 1528 | if c.ExcludeFromRecoverySnapshot() != expected { |
| 1529 | t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", c.String(), expected) |
| 1530 | } |
| 1531 | } |
| 1532 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1533 | func TestVendorSnapshotExclude(t *testing.T) { |
| 1534 | |
| 1535 | // This test verifies that the exclude_from_vendor_snapshot property |
| 1536 | // makes its way from the Android.bp source file into the module data |
| 1537 | // structure. It also verifies that modules are correctly included or |
| 1538 | // excluded in the vendor snapshot based on their path (framework or |
| 1539 | // vendor) and the exclude_from_vendor_snapshot property. |
| 1540 | |
| 1541 | frameworkBp := ` |
| 1542 | cc_library_shared { |
| 1543 | name: "libinclude", |
| 1544 | srcs: ["src/include.cpp"], |
| 1545 | vendor_available: true, |
| 1546 | } |
| 1547 | cc_library_shared { |
| 1548 | name: "libexclude", |
| 1549 | srcs: ["src/exclude.cpp"], |
| 1550 | vendor: true, |
| 1551 | exclude_from_vendor_snapshot: true, |
| 1552 | } |
| 1553 | ` |
| 1554 | |
| 1555 | vendorProprietaryBp := ` |
| 1556 | cc_library_shared { |
| 1557 | name: "libvendor", |
| 1558 | srcs: ["vendor.cpp"], |
| 1559 | vendor: true, |
| 1560 | } |
| 1561 | ` |
| 1562 | |
| 1563 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1564 | |
| 1565 | mockFS := map[string][]byte{ |
| 1566 | "deps/Android.bp": []byte(depsBp), |
| 1567 | "framework/Android.bp": []byte(frameworkBp), |
| 1568 | "framework/include.cpp": nil, |
| 1569 | "framework/exclude.cpp": nil, |
| 1570 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1571 | "device/vendor.cpp": nil, |
| 1572 | } |
| 1573 | |
| 1574 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1575 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1576 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1577 | ctx := CreateTestContext(config) |
| 1578 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1579 | |
| 1580 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1581 | android.FailIfErrored(t, errs) |
| 1582 | _, errs = ctx.PrepareBuildActions(config) |
| 1583 | android.FailIfErrored(t, errs) |
| 1584 | |
| 1585 | // Test an include and exclude framework module. |
| 1586 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false) |
| 1587 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false) |
| 1588 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true) |
| 1589 | |
| 1590 | // A vendor module is excluded, but by its path, not the |
| 1591 | // exclude_from_vendor_snapshot property. |
| 1592 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false) |
| 1593 | |
| 1594 | // Verify the content of the vendor snapshot. |
| 1595 | |
| 1596 | snapshotDir := "vendor-snapshot" |
| 1597 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1598 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1599 | |
| 1600 | var includeJsonFiles []string |
| 1601 | var excludeJsonFiles []string |
| 1602 | |
| 1603 | for _, arch := range [][]string{ |
| 1604 | []string{"arm64", "armv8-a"}, |
| 1605 | []string{"arm", "armv7-a-neon"}, |
| 1606 | } { |
| 1607 | archType := arch[0] |
| 1608 | archVariant := arch[1] |
| 1609 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1610 | |
| 1611 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 1612 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1613 | |
| 1614 | // Included modules |
| 1615 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1616 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1617 | |
| 1618 | // Excluded modules |
| 1619 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1620 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1621 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1622 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 1623 | } |
| 1624 | |
| 1625 | // Verify that each json file for an included module has a rule. |
| 1626 | for _, jsonFile := range includeJsonFiles { |
| 1627 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1628 | t.Errorf("include json file %q not found", jsonFile) |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | // Verify that each json file for an excluded module has no rule. |
| 1633 | for _, jsonFile := range excludeJsonFiles { |
| 1634 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1635 | t.Errorf("exclude json file %q found", jsonFile) |
| 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) { |
| 1641 | |
| 1642 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1643 | // property on a module in a vendor proprietary path generates an |
| 1644 | // error. These modules are already excluded, so we prohibit using the |
| 1645 | // property in this way, which could add to confusion. |
| 1646 | |
| 1647 | vendorProprietaryBp := ` |
| 1648 | cc_library_shared { |
| 1649 | name: "libvendor", |
| 1650 | srcs: ["vendor.cpp"], |
| 1651 | vendor: true, |
| 1652 | exclude_from_vendor_snapshot: true, |
| 1653 | } |
| 1654 | ` |
| 1655 | |
| 1656 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1657 | |
| 1658 | mockFS := map[string][]byte{ |
| 1659 | "deps/Android.bp": []byte(depsBp), |
| 1660 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1661 | "device/vendor.cpp": nil, |
| 1662 | } |
| 1663 | |
| 1664 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1665 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1666 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1667 | ctx := CreateTestContext(config) |
| 1668 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1669 | |
| 1670 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"}) |
| 1671 | android.FailIfErrored(t, errs) |
| 1672 | |
| 1673 | _, errs = ctx.PrepareBuildActions(config) |
| 1674 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1675 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1676 | `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] | 1677 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1678 | `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] | 1679 | }) |
| 1680 | } |
| 1681 | |
| 1682 | func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) { |
| 1683 | |
| 1684 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1685 | // property on a module that is vendor available generates an error. A |
| 1686 | // vendor available module must be captured in the vendor snapshot and |
| 1687 | // must not built from source when building the vendor image against |
| 1688 | // the vendor snapshot. |
| 1689 | |
| 1690 | frameworkBp := ` |
| 1691 | cc_library_shared { |
| 1692 | name: "libinclude", |
| 1693 | srcs: ["src/include.cpp"], |
| 1694 | vendor_available: true, |
| 1695 | exclude_from_vendor_snapshot: true, |
| 1696 | } |
| 1697 | ` |
| 1698 | |
| 1699 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1700 | |
| 1701 | mockFS := map[string][]byte{ |
| 1702 | "deps/Android.bp": []byte(depsBp), |
| 1703 | "framework/Android.bp": []byte(frameworkBp), |
| 1704 | "framework/include.cpp": nil, |
| 1705 | } |
| 1706 | |
| 1707 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1708 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1709 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1710 | ctx := CreateTestContext(config) |
| 1711 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1712 | |
| 1713 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"}) |
| 1714 | android.FailIfErrored(t, errs) |
| 1715 | |
| 1716 | _, errs = ctx.PrepareBuildActions(config) |
| 1717 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1718 | `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1719 | `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1720 | `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1721 | `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1722 | }) |
| 1723 | } |
| 1724 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 1725 | func TestRecoverySnapshotCapture(t *testing.T) { |
| 1726 | bp := ` |
| 1727 | cc_library { |
| 1728 | name: "libvndk", |
| 1729 | vendor_available: true, |
| 1730 | recovery_available: true, |
| 1731 | product_available: true, |
| 1732 | vndk: { |
| 1733 | enabled: true, |
| 1734 | }, |
| 1735 | nocrt: true, |
| 1736 | } |
| 1737 | |
| 1738 | cc_library { |
| 1739 | name: "librecovery", |
| 1740 | recovery: true, |
| 1741 | nocrt: true, |
| 1742 | } |
| 1743 | |
| 1744 | cc_library { |
| 1745 | name: "librecovery_available", |
| 1746 | recovery_available: true, |
| 1747 | nocrt: true, |
| 1748 | } |
| 1749 | |
| 1750 | cc_library_headers { |
| 1751 | name: "librecovery_headers", |
| 1752 | recovery_available: true, |
| 1753 | nocrt: true, |
| 1754 | } |
| 1755 | |
| 1756 | cc_binary { |
| 1757 | name: "recovery_bin", |
| 1758 | recovery: true, |
| 1759 | nocrt: true, |
| 1760 | } |
| 1761 | |
| 1762 | cc_binary { |
| 1763 | name: "recovery_available_bin", |
| 1764 | recovery_available: true, |
| 1765 | nocrt: true, |
| 1766 | } |
| 1767 | |
| 1768 | toolchain_library { |
| 1769 | name: "libb", |
| 1770 | recovery_available: true, |
| 1771 | src: "libb.a", |
| 1772 | } |
| 1773 | |
| 1774 | cc_object { |
| 1775 | name: "obj", |
| 1776 | recovery_available: true, |
| 1777 | } |
| 1778 | ` |
| 1779 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1780 | config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 1781 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1782 | ctx := testCcWithConfig(t, config) |
| 1783 | |
| 1784 | // Check Recovery snapshot output. |
| 1785 | |
| 1786 | snapshotDir := "recovery-snapshot" |
| 1787 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1788 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1789 | |
| 1790 | var jsonFiles []string |
| 1791 | |
| 1792 | for _, arch := range [][]string{ |
| 1793 | []string{"arm64", "armv8-a"}, |
| 1794 | } { |
| 1795 | archType := arch[0] |
| 1796 | archVariant := arch[1] |
| 1797 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1798 | |
| 1799 | // For shared libraries, only recovery_available modules are captured. |
| 1800 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1801 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1802 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant) |
| 1803 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1804 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1805 | jsonFiles = append(jsonFiles, |
| 1806 | filepath.Join(sharedDir, "libvndk.so.json"), |
| 1807 | filepath.Join(sharedDir, "librecovery.so.json"), |
| 1808 | filepath.Join(sharedDir, "librecovery_available.so.json")) |
| 1809 | |
| 1810 | // For static libraries, all recovery:true and recovery_available modules are captured. |
| 1811 | staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant) |
| 1812 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
| 1813 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 1814 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) |
| 1815 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) |
| 1816 | jsonFiles = append(jsonFiles, |
| 1817 | filepath.Join(staticDir, "libb.a.json"), |
| 1818 | filepath.Join(staticDir, "librecovery.a.json"), |
| 1819 | filepath.Join(staticDir, "librecovery_available.a.json")) |
| 1820 | |
| 1821 | // For binary executables, all recovery:true and recovery_available modules are captured. |
| 1822 | if archType == "arm64" { |
| 1823 | binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1824 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 1825 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) |
| 1826 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) |
| 1827 | jsonFiles = append(jsonFiles, |
| 1828 | filepath.Join(binaryDir, "recovery_bin.json"), |
| 1829 | filepath.Join(binaryDir, "recovery_available_bin.json")) |
| 1830 | } |
| 1831 | |
| 1832 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 1833 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 1834 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json")) |
| 1835 | |
| 1836 | // For object modules, all vendor:true and vendor_available modules are captured. |
| 1837 | objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1838 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 1839 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 1840 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
| 1841 | } |
| 1842 | |
| 1843 | for _, jsonFile := range jsonFiles { |
| 1844 | // verify all json files exist |
| 1845 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1846 | t.Errorf("%q expected but not found", jsonFile) |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1851 | func TestRecoverySnapshotExclude(t *testing.T) { |
| 1852 | // This test verifies that the exclude_from_recovery_snapshot property |
| 1853 | // makes its way from the Android.bp source file into the module data |
| 1854 | // structure. It also verifies that modules are correctly included or |
| 1855 | // excluded in the recovery snapshot based on their path (framework or |
| 1856 | // vendor) and the exclude_from_recovery_snapshot property. |
| 1857 | |
| 1858 | frameworkBp := ` |
| 1859 | cc_library_shared { |
| 1860 | name: "libinclude", |
| 1861 | srcs: ["src/include.cpp"], |
| 1862 | recovery_available: true, |
| 1863 | } |
| 1864 | cc_library_shared { |
| 1865 | name: "libexclude", |
| 1866 | srcs: ["src/exclude.cpp"], |
| 1867 | recovery: true, |
| 1868 | exclude_from_recovery_snapshot: true, |
| 1869 | } |
| 1870 | ` |
| 1871 | |
| 1872 | vendorProprietaryBp := ` |
| 1873 | cc_library_shared { |
| 1874 | name: "libvendor", |
| 1875 | srcs: ["vendor.cpp"], |
| 1876 | recovery: true, |
| 1877 | } |
| 1878 | ` |
| 1879 | |
| 1880 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1881 | |
| 1882 | mockFS := map[string][]byte{ |
| 1883 | "deps/Android.bp": []byte(depsBp), |
| 1884 | "framework/Android.bp": []byte(frameworkBp), |
| 1885 | "framework/include.cpp": nil, |
| 1886 | "framework/exclude.cpp": nil, |
| 1887 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1888 | "device/vendor.cpp": nil, |
| 1889 | } |
| 1890 | |
| 1891 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1892 | config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current") |
| 1893 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1894 | ctx := CreateTestContext(config) |
| 1895 | ctx.Register() |
| 1896 | |
| 1897 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1898 | android.FailIfErrored(t, errs) |
| 1899 | _, errs = ctx.PrepareBuildActions(config) |
| 1900 | android.FailIfErrored(t, errs) |
| 1901 | |
| 1902 | // Test an include and exclude framework module. |
| 1903 | assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false) |
| 1904 | assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", recoveryVariant).Module().(*Module), false) |
| 1905 | assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libexclude", recoveryVariant).Module().(*Module), true) |
| 1906 | |
| 1907 | // A vendor module is excluded, but by its path, not the |
| 1908 | // exclude_from_recovery_snapshot property. |
| 1909 | assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libvendor", recoveryVariant).Module().(*Module), false) |
| 1910 | |
| 1911 | // Verify the content of the recovery snapshot. |
| 1912 | |
| 1913 | snapshotDir := "recovery-snapshot" |
| 1914 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1915 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1916 | |
| 1917 | var includeJsonFiles []string |
| 1918 | var excludeJsonFiles []string |
| 1919 | |
| 1920 | for _, arch := range [][]string{ |
| 1921 | []string{"arm64", "armv8-a"}, |
| 1922 | } { |
| 1923 | archType := arch[0] |
| 1924 | archVariant := arch[1] |
| 1925 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1926 | |
| 1927 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1928 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1929 | |
| 1930 | // Included modules |
| 1931 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1932 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1933 | |
| 1934 | // Excluded modules |
| 1935 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1936 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1937 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1938 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 1939 | } |
| 1940 | |
| 1941 | // Verify that each json file for an included module has a rule. |
| 1942 | for _, jsonFile := range includeJsonFiles { |
| 1943 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1944 | t.Errorf("include json file %q not found", jsonFile) |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | // Verify that each json file for an excluded module has no rule. |
| 1949 | for _, jsonFile := range excludeJsonFiles { |
| 1950 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1951 | t.Errorf("exclude json file %q found", jsonFile) |
| 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1956 | func TestDoubleLoadableDepError(t *testing.T) { |
| 1957 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1958 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1959 | cc_library { |
| 1960 | name: "libllndk", |
| 1961 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1962 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1966 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1967 | symbol_file: "", |
| 1968 | } |
| 1969 | |
| 1970 | cc_library { |
| 1971 | name: "libnondoubleloadable", |
| 1972 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1973 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1974 | vndk: { |
| 1975 | enabled: true, |
| 1976 | }, |
| 1977 | } |
| 1978 | `) |
| 1979 | |
| 1980 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1981 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1982 | cc_library { |
| 1983 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1984 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1985 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1986 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1990 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1991 | symbol_file: "", |
| 1992 | } |
| 1993 | |
| 1994 | cc_library { |
| 1995 | name: "libnondoubleloadable", |
| 1996 | vendor_available: true, |
| 1997 | } |
| 1998 | `) |
| 1999 | |
| 2000 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. |
| 2001 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 2002 | cc_library { |
| 2003 | name: "libdoubleloadable", |
| 2004 | vendor_available: true, |
| 2005 | double_loadable: true, |
| 2006 | shared_libs: ["libnondoubleloadable"], |
| 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 VNDK 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, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2027 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2028 | vndk: { |
| 2029 | enabled: true, |
| 2030 | }, |
| 2031 | } |
| 2032 | `) |
| 2033 | |
| 2034 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. |
| 2035 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 2036 | cc_library { |
| 2037 | name: "libdoubleloadable", |
| 2038 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2039 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2040 | vndk: { |
| 2041 | enabled: true, |
| 2042 | }, |
| 2043 | double_loadable: true, |
| 2044 | shared_libs: ["libnondoubleloadable"], |
| 2045 | } |
| 2046 | |
| 2047 | cc_library { |
| 2048 | name: "libnondoubleloadable", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2049 | vendor_available: true, |
| 2050 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2051 | vndk: { |
| 2052 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2053 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2054 | }, |
| 2055 | } |
| 2056 | `) |
| 2057 | |
| 2058 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 2059 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 2060 | cc_library { |
| 2061 | name: "libllndk", |
| 2062 | shared_libs: ["libcoreonly"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2063 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2067 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2068 | symbol_file: "", |
| 2069 | } |
| 2070 | |
| 2071 | cc_library { |
| 2072 | name: "libcoreonly", |
| 2073 | shared_libs: ["libvendoravailable"], |
| 2074 | } |
| 2075 | |
| 2076 | // indirect dependency of LLNDK |
| 2077 | cc_library { |
| 2078 | name: "libvendoravailable", |
| 2079 | vendor_available: true, |
| 2080 | } |
| 2081 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2082 | } |
| 2083 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 2084 | func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) { |
| 2085 | testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", ` |
| 2086 | cc_library { |
| 2087 | name: "libvndksp", |
| 2088 | shared_libs: ["libanothervndksp"], |
| 2089 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2090 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 2091 | vndk: { |
| 2092 | enabled: true, |
| 2093 | support_system_process: true, |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | cc_library { |
| 2098 | name: "libllndk", |
| 2099 | shared_libs: ["libanothervndksp"], |
| 2100 | } |
| 2101 | |
| 2102 | llndk_library { |
| 2103 | name: "libllndk", |
| 2104 | symbol_file: "", |
| 2105 | } |
| 2106 | |
| 2107 | cc_library { |
| 2108 | name: "libanothervndksp", |
| 2109 | vendor_available: true, |
| 2110 | } |
| 2111 | `) |
| 2112 | } |
| 2113 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2114 | func TestVndkExt(t *testing.T) { |
| 2115 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2116 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2117 | cc_library { |
| 2118 | name: "libvndk", |
| 2119 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2120 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2121 | vndk: { |
| 2122 | enabled: true, |
| 2123 | }, |
| 2124 | nocrt: true, |
| 2125 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2126 | cc_library { |
| 2127 | name: "libvndk2", |
| 2128 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2129 | product_available: true, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2130 | vndk: { |
| 2131 | enabled: true, |
| 2132 | }, |
| 2133 | target: { |
| 2134 | vendor: { |
| 2135 | suffix: "-suffix", |
| 2136 | }, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2137 | product: { |
| 2138 | suffix: "-suffix", |
| 2139 | }, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2140 | }, |
| 2141 | nocrt: true, |
| 2142 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2143 | |
| 2144 | cc_library { |
| 2145 | name: "libvndk_ext", |
| 2146 | vendor: true, |
| 2147 | vndk: { |
| 2148 | enabled: true, |
| 2149 | extends: "libvndk", |
| 2150 | }, |
| 2151 | nocrt: true, |
| 2152 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2153 | |
| 2154 | cc_library { |
| 2155 | name: "libvndk2_ext", |
| 2156 | vendor: true, |
| 2157 | vndk: { |
| 2158 | enabled: true, |
| 2159 | extends: "libvndk2", |
| 2160 | }, |
| 2161 | nocrt: true, |
| 2162 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2163 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2164 | cc_library { |
| 2165 | name: "libvndk_ext_product", |
| 2166 | product_specific: true, |
| 2167 | vndk: { |
| 2168 | enabled: true, |
| 2169 | extends: "libvndk", |
| 2170 | }, |
| 2171 | nocrt: true, |
| 2172 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2173 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2174 | cc_library { |
| 2175 | name: "libvndk2_ext_product", |
| 2176 | product_specific: true, |
| 2177 | vndk: { |
| 2178 | enabled: true, |
| 2179 | extends: "libvndk2", |
| 2180 | }, |
| 2181 | nocrt: true, |
| 2182 | } |
| 2183 | ` |
| 2184 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2185 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2186 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2187 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2188 | |
| 2189 | ctx := testCcWithConfig(t, config) |
| 2190 | |
| 2191 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 2192 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 2193 | |
| 2194 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 2195 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 2196 | |
| 2197 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 2198 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2199 | } |
| 2200 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2201 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2202 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 2203 | ctx := testCcNoVndk(t, ` |
| 2204 | cc_library { |
| 2205 | name: "libvndk", |
| 2206 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2207 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2208 | vndk: { |
| 2209 | enabled: true, |
| 2210 | }, |
| 2211 | nocrt: true, |
| 2212 | } |
| 2213 | |
| 2214 | cc_library { |
| 2215 | name: "libvndk_ext", |
| 2216 | vendor: true, |
| 2217 | vndk: { |
| 2218 | enabled: true, |
| 2219 | extends: "libvndk", |
| 2220 | }, |
| 2221 | nocrt: true, |
| 2222 | } |
| 2223 | `) |
| 2224 | |
| 2225 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 2226 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 2227 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 2228 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 2229 | } |
| 2230 | } |
| 2231 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2232 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { |
| 2233 | // 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] | 2234 | ctx := testCcNoProductVndk(t, ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2235 | cc_library { |
| 2236 | name: "libvndk", |
| 2237 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2238 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2239 | vndk: { |
| 2240 | enabled: true, |
| 2241 | }, |
| 2242 | nocrt: true, |
| 2243 | } |
| 2244 | |
| 2245 | cc_library { |
| 2246 | name: "libvndk_ext_product", |
| 2247 | product_specific: true, |
| 2248 | vndk: { |
| 2249 | enabled: true, |
| 2250 | extends: "libvndk", |
| 2251 | }, |
| 2252 | nocrt: true, |
| 2253 | } |
| 2254 | `) |
| 2255 | |
| 2256 | // Ensures that the core variant of "libvndk_ext_product" can be found. |
| 2257 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) |
| 2258 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 2259 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) |
| 2260 | } |
| 2261 | } |
| 2262 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2263 | func TestVndkExtError(t *testing.T) { |
| 2264 | // 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] | 2265 | 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] | 2266 | cc_library { |
| 2267 | name: "libvndk", |
| 2268 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2269 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2270 | vndk: { |
| 2271 | enabled: true, |
| 2272 | }, |
| 2273 | nocrt: true, |
| 2274 | } |
| 2275 | |
| 2276 | cc_library { |
| 2277 | name: "libvndk_ext", |
| 2278 | vndk: { |
| 2279 | enabled: true, |
| 2280 | extends: "libvndk", |
| 2281 | }, |
| 2282 | nocrt: true, |
| 2283 | } |
| 2284 | `) |
| 2285 | |
| 2286 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 2287 | cc_library { |
| 2288 | name: "libvndk", |
| 2289 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2290 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2291 | vndk: { |
| 2292 | enabled: true, |
| 2293 | }, |
| 2294 | nocrt: true, |
| 2295 | } |
| 2296 | |
| 2297 | cc_library { |
| 2298 | name: "libvndk_ext", |
| 2299 | vendor: true, |
| 2300 | vndk: { |
| 2301 | enabled: true, |
| 2302 | }, |
| 2303 | nocrt: true, |
| 2304 | } |
| 2305 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2306 | |
| 2307 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 2308 | cc_library { |
| 2309 | name: "libvndk", |
| 2310 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2311 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2312 | vndk: { |
| 2313 | enabled: true, |
| 2314 | }, |
| 2315 | nocrt: true, |
| 2316 | } |
| 2317 | |
| 2318 | cc_library { |
| 2319 | name: "libvndk_ext_product", |
| 2320 | product_specific: true, |
| 2321 | vndk: { |
| 2322 | enabled: true, |
| 2323 | }, |
| 2324 | nocrt: true, |
| 2325 | } |
| 2326 | `) |
| 2327 | |
| 2328 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 2329 | cc_library { |
| 2330 | name: "libvndk", |
| 2331 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2332 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2333 | vndk: { |
| 2334 | enabled: true, |
| 2335 | }, |
| 2336 | nocrt: true, |
| 2337 | } |
| 2338 | |
| 2339 | cc_library { |
| 2340 | name: "libvndk_ext_product", |
| 2341 | product_specific: true, |
| 2342 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2343 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2344 | vndk: { |
| 2345 | enabled: true, |
| 2346 | extends: "libvndk", |
| 2347 | }, |
| 2348 | nocrt: true, |
| 2349 | } |
| 2350 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 2354 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 2355 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 2356 | cc_library { |
| 2357 | name: "libvndk", |
| 2358 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2359 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2360 | vndk: { |
| 2361 | enabled: true, |
| 2362 | }, |
| 2363 | nocrt: true, |
| 2364 | } |
| 2365 | |
| 2366 | cc_library { |
| 2367 | name: "libvndk_sp_ext", |
| 2368 | vendor: true, |
| 2369 | vndk: { |
| 2370 | enabled: true, |
| 2371 | extends: "libvndk", |
| 2372 | support_system_process: true, |
| 2373 | }, |
| 2374 | nocrt: true, |
| 2375 | } |
| 2376 | `) |
| 2377 | |
| 2378 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 2379 | cc_library { |
| 2380 | name: "libvndk_sp", |
| 2381 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2382 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2383 | vndk: { |
| 2384 | enabled: true, |
| 2385 | support_system_process: true, |
| 2386 | }, |
| 2387 | nocrt: true, |
| 2388 | } |
| 2389 | |
| 2390 | cc_library { |
| 2391 | name: "libvndk_ext", |
| 2392 | vendor: true, |
| 2393 | vndk: { |
| 2394 | enabled: true, |
| 2395 | extends: "libvndk_sp", |
| 2396 | }, |
| 2397 | nocrt: true, |
| 2398 | } |
| 2399 | `) |
| 2400 | } |
| 2401 | |
| 2402 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2403 | // 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] | 2404 | // with `private: true`. |
| 2405 | testCcError(t, "`extends` refers module \".*\" which has `private: true`", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2406 | cc_library { |
| 2407 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2408 | vendor_available: true, |
| 2409 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2410 | vndk: { |
| 2411 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2412 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2413 | }, |
| 2414 | nocrt: true, |
| 2415 | } |
| 2416 | |
| 2417 | cc_library { |
| 2418 | name: "libvndk_ext", |
| 2419 | vendor: true, |
| 2420 | vndk: { |
| 2421 | enabled: true, |
| 2422 | extends: "libvndk", |
| 2423 | }, |
| 2424 | nocrt: true, |
| 2425 | } |
| 2426 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2427 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2428 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2429 | cc_library { |
| 2430 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2431 | vendor_available: true, |
| 2432 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2433 | vndk: { |
| 2434 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2435 | private: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2436 | }, |
| 2437 | nocrt: true, |
| 2438 | } |
| 2439 | |
| 2440 | cc_library { |
| 2441 | name: "libvndk_ext_product", |
| 2442 | product_specific: true, |
| 2443 | vndk: { |
| 2444 | enabled: true, |
| 2445 | extends: "libvndk", |
| 2446 | }, |
| 2447 | nocrt: true, |
| 2448 | } |
| 2449 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2450 | } |
| 2451 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2452 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 2453 | // 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] | 2454 | testCc(t, ` |
| 2455 | cc_library { |
| 2456 | name: "libvndk", |
| 2457 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2458 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2459 | vndk: { |
| 2460 | enabled: true, |
| 2461 | }, |
| 2462 | nocrt: true, |
| 2463 | } |
| 2464 | |
| 2465 | cc_library { |
| 2466 | name: "libvndk_ext", |
| 2467 | vendor: true, |
| 2468 | vndk: { |
| 2469 | enabled: true, |
| 2470 | extends: "libvndk", |
| 2471 | }, |
| 2472 | nocrt: true, |
| 2473 | } |
| 2474 | |
| 2475 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2476 | name: "libvndk_sp", |
| 2477 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2478 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2479 | vndk: { |
| 2480 | enabled: true, |
| 2481 | support_system_process: true, |
| 2482 | }, |
| 2483 | nocrt: true, |
| 2484 | } |
| 2485 | |
| 2486 | cc_library { |
| 2487 | name: "libvndk_sp_ext", |
| 2488 | vendor: true, |
| 2489 | vndk: { |
| 2490 | enabled: true, |
| 2491 | extends: "libvndk_sp", |
| 2492 | support_system_process: true, |
| 2493 | }, |
| 2494 | nocrt: true, |
| 2495 | } |
| 2496 | |
| 2497 | cc_library { |
| 2498 | name: "libvendor", |
| 2499 | vendor: true, |
| 2500 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 2501 | nocrt: true, |
| 2502 | } |
| 2503 | `) |
| 2504 | } |
| 2505 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2506 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 2507 | // 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] | 2508 | testCc(t, ` |
| 2509 | cc_library { |
| 2510 | name: "libvndk", |
| 2511 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2512 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2513 | vndk: { |
| 2514 | enabled: true, |
| 2515 | }, |
| 2516 | nocrt: true, |
| 2517 | } |
| 2518 | |
| 2519 | cc_library { |
| 2520 | name: "libvndk_ext", |
| 2521 | vendor: true, |
| 2522 | vndk: { |
| 2523 | enabled: true, |
| 2524 | extends: "libvndk", |
| 2525 | }, |
| 2526 | shared_libs: ["libvendor"], |
| 2527 | nocrt: true, |
| 2528 | } |
| 2529 | |
| 2530 | cc_library { |
| 2531 | name: "libvendor", |
| 2532 | vendor: true, |
| 2533 | nocrt: true, |
| 2534 | } |
| 2535 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2536 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2537 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 2538 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2539 | cc_library { |
| 2540 | name: "libvndk_sp", |
| 2541 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2542 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2543 | vndk: { |
| 2544 | enabled: true, |
| 2545 | support_system_process: true, |
| 2546 | }, |
| 2547 | nocrt: true, |
| 2548 | } |
| 2549 | |
| 2550 | cc_library { |
| 2551 | name: "libvndk_sp_ext", |
| 2552 | vendor: true, |
| 2553 | vndk: { |
| 2554 | enabled: true, |
| 2555 | extends: "libvndk_sp", |
| 2556 | support_system_process: true, |
| 2557 | }, |
| 2558 | shared_libs: ["libvendor"], // Cause an error |
| 2559 | nocrt: true, |
| 2560 | } |
| 2561 | |
| 2562 | cc_library { |
| 2563 | name: "libvendor", |
| 2564 | vendor: true, |
| 2565 | nocrt: true, |
| 2566 | } |
| 2567 | `) |
| 2568 | } |
| 2569 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2570 | func TestProductVndkExtDependency(t *testing.T) { |
| 2571 | bp := ` |
| 2572 | cc_library { |
| 2573 | name: "libvndk", |
| 2574 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2575 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2576 | vndk: { |
| 2577 | enabled: true, |
| 2578 | }, |
| 2579 | nocrt: true, |
| 2580 | } |
| 2581 | |
| 2582 | cc_library { |
| 2583 | name: "libvndk_ext_product", |
| 2584 | product_specific: true, |
| 2585 | vndk: { |
| 2586 | enabled: true, |
| 2587 | extends: "libvndk", |
| 2588 | }, |
| 2589 | shared_libs: ["libproduct_for_vndklibs"], |
| 2590 | nocrt: true, |
| 2591 | } |
| 2592 | |
| 2593 | cc_library { |
| 2594 | name: "libvndk_sp", |
| 2595 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2596 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2597 | vndk: { |
| 2598 | enabled: true, |
| 2599 | support_system_process: true, |
| 2600 | }, |
| 2601 | nocrt: true, |
| 2602 | } |
| 2603 | |
| 2604 | cc_library { |
| 2605 | name: "libvndk_sp_ext_product", |
| 2606 | product_specific: true, |
| 2607 | vndk: { |
| 2608 | enabled: true, |
| 2609 | extends: "libvndk_sp", |
| 2610 | support_system_process: true, |
| 2611 | }, |
| 2612 | shared_libs: ["libproduct_for_vndklibs"], |
| 2613 | nocrt: true, |
| 2614 | } |
| 2615 | |
| 2616 | cc_library { |
| 2617 | name: "libproduct", |
| 2618 | product_specific: true, |
| 2619 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 2620 | nocrt: true, |
| 2621 | } |
| 2622 | |
| 2623 | cc_library { |
| 2624 | name: "libproduct_for_vndklibs", |
| 2625 | product_specific: true, |
| 2626 | nocrt: true, |
| 2627 | } |
| 2628 | ` |
| 2629 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2630 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2631 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2632 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2633 | |
| 2634 | testCcWithConfig(t, config) |
| 2635 | } |
| 2636 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2637 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 2638 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 2639 | // library. |
| 2640 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2641 | cc_library { |
| 2642 | name: "libvndk", |
| 2643 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2644 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2645 | vndk: { |
| 2646 | enabled: true, |
| 2647 | }, |
| 2648 | nocrt: true, |
| 2649 | } |
| 2650 | |
| 2651 | cc_library { |
| 2652 | name: "libvndk_sp", |
| 2653 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2654 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2655 | vndk: { |
| 2656 | enabled: true, |
| 2657 | support_system_process: true, |
| 2658 | }, |
| 2659 | nocrt: true, |
| 2660 | } |
| 2661 | |
| 2662 | cc_library { |
| 2663 | name: "libvndk_sp_ext", |
| 2664 | vendor: true, |
| 2665 | vndk: { |
| 2666 | enabled: true, |
| 2667 | extends: "libvndk_sp", |
| 2668 | support_system_process: true, |
| 2669 | }, |
| 2670 | shared_libs: ["libvndk"], // Cause an error |
| 2671 | nocrt: true, |
| 2672 | } |
| 2673 | `) |
| 2674 | |
| 2675 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 2676 | // library. |
| 2677 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2678 | cc_library { |
| 2679 | name: "libvndk", |
| 2680 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2681 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2682 | vndk: { |
| 2683 | enabled: true, |
| 2684 | }, |
| 2685 | nocrt: true, |
| 2686 | } |
| 2687 | |
| 2688 | cc_library { |
| 2689 | name: "libvndk_ext", |
| 2690 | vendor: true, |
| 2691 | vndk: { |
| 2692 | enabled: true, |
| 2693 | extends: "libvndk", |
| 2694 | }, |
| 2695 | nocrt: true, |
| 2696 | } |
| 2697 | |
| 2698 | cc_library { |
| 2699 | name: "libvndk_sp", |
| 2700 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2701 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2702 | vndk: { |
| 2703 | enabled: true, |
| 2704 | support_system_process: true, |
| 2705 | }, |
| 2706 | nocrt: true, |
| 2707 | } |
| 2708 | |
| 2709 | cc_library { |
| 2710 | name: "libvndk_sp_ext", |
| 2711 | vendor: true, |
| 2712 | vndk: { |
| 2713 | enabled: true, |
| 2714 | extends: "libvndk_sp", |
| 2715 | support_system_process: true, |
| 2716 | }, |
| 2717 | shared_libs: ["libvndk_ext"], // Cause an error |
| 2718 | nocrt: true, |
| 2719 | } |
| 2720 | `) |
| 2721 | } |
| 2722 | |
| 2723 | func TestVndkUseVndkExtError(t *testing.T) { |
| 2724 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 2725 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2726 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2727 | cc_library { |
| 2728 | name: "libvndk", |
| 2729 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2730 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2731 | vndk: { |
| 2732 | enabled: true, |
| 2733 | }, |
| 2734 | nocrt: true, |
| 2735 | } |
| 2736 | |
| 2737 | cc_library { |
| 2738 | name: "libvndk_ext", |
| 2739 | vendor: true, |
| 2740 | vndk: { |
| 2741 | enabled: true, |
| 2742 | extends: "libvndk", |
| 2743 | }, |
| 2744 | nocrt: true, |
| 2745 | } |
| 2746 | |
| 2747 | cc_library { |
| 2748 | name: "libvndk2", |
| 2749 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2750 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2751 | vndk: { |
| 2752 | enabled: true, |
| 2753 | }, |
| 2754 | shared_libs: ["libvndk_ext"], |
| 2755 | nocrt: true, |
| 2756 | } |
| 2757 | `) |
| 2758 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2759 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2760 | cc_library { |
| 2761 | name: "libvndk", |
| 2762 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2763 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2764 | vndk: { |
| 2765 | enabled: true, |
| 2766 | }, |
| 2767 | nocrt: true, |
| 2768 | } |
| 2769 | |
| 2770 | cc_library { |
| 2771 | name: "libvndk_ext", |
| 2772 | vendor: true, |
| 2773 | vndk: { |
| 2774 | enabled: true, |
| 2775 | extends: "libvndk", |
| 2776 | }, |
| 2777 | nocrt: true, |
| 2778 | } |
| 2779 | |
| 2780 | cc_library { |
| 2781 | name: "libvndk2", |
| 2782 | vendor_available: true, |
| 2783 | vndk: { |
| 2784 | enabled: true, |
| 2785 | }, |
| 2786 | target: { |
| 2787 | vendor: { |
| 2788 | shared_libs: ["libvndk_ext"], |
| 2789 | }, |
| 2790 | }, |
| 2791 | nocrt: true, |
| 2792 | } |
| 2793 | `) |
| 2794 | |
| 2795 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2796 | cc_library { |
| 2797 | name: "libvndk_sp", |
| 2798 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2799 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2800 | vndk: { |
| 2801 | enabled: true, |
| 2802 | support_system_process: true, |
| 2803 | }, |
| 2804 | nocrt: true, |
| 2805 | } |
| 2806 | |
| 2807 | cc_library { |
| 2808 | name: "libvndk_sp_ext", |
| 2809 | vendor: true, |
| 2810 | vndk: { |
| 2811 | enabled: true, |
| 2812 | extends: "libvndk_sp", |
| 2813 | support_system_process: true, |
| 2814 | }, |
| 2815 | nocrt: true, |
| 2816 | } |
| 2817 | |
| 2818 | cc_library { |
| 2819 | name: "libvndk_sp_2", |
| 2820 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2821 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2822 | vndk: { |
| 2823 | enabled: true, |
| 2824 | support_system_process: true, |
| 2825 | }, |
| 2826 | shared_libs: ["libvndk_sp_ext"], |
| 2827 | nocrt: true, |
| 2828 | } |
| 2829 | `) |
| 2830 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2831 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2832 | cc_library { |
| 2833 | name: "libvndk_sp", |
| 2834 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2835 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2836 | vndk: { |
| 2837 | enabled: true, |
| 2838 | }, |
| 2839 | nocrt: true, |
| 2840 | } |
| 2841 | |
| 2842 | cc_library { |
| 2843 | name: "libvndk_sp_ext", |
| 2844 | vendor: true, |
| 2845 | vndk: { |
| 2846 | enabled: true, |
| 2847 | extends: "libvndk_sp", |
| 2848 | }, |
| 2849 | nocrt: true, |
| 2850 | } |
| 2851 | |
| 2852 | cc_library { |
| 2853 | name: "libvndk_sp2", |
| 2854 | vendor_available: true, |
| 2855 | vndk: { |
| 2856 | enabled: true, |
| 2857 | }, |
| 2858 | target: { |
| 2859 | vendor: { |
| 2860 | shared_libs: ["libvndk_sp_ext"], |
| 2861 | }, |
| 2862 | }, |
| 2863 | nocrt: true, |
| 2864 | } |
| 2865 | `) |
| 2866 | } |
| 2867 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2868 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 2869 | bp := ` |
| 2870 | cc_library { |
| 2871 | name: "libllndk", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2872 | llndk_stubs: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2873 | } |
| 2874 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2875 | name: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2876 | symbol_file: "", |
| 2877 | } |
| 2878 | cc_library { |
| 2879 | name: "libvndk", |
| 2880 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2881 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2882 | vndk: { |
| 2883 | enabled: true, |
| 2884 | }, |
| 2885 | nocrt: true, |
| 2886 | } |
| 2887 | cc_library { |
| 2888 | name: "libvndk_sp", |
| 2889 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2890 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2891 | vndk: { |
| 2892 | enabled: true, |
| 2893 | support_system_process: true, |
| 2894 | }, |
| 2895 | nocrt: true, |
| 2896 | } |
| 2897 | cc_library { |
| 2898 | name: "libva", |
| 2899 | vendor_available: true, |
| 2900 | nocrt: true, |
| 2901 | } |
| 2902 | cc_library { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2903 | name: "libpa", |
| 2904 | product_available: true, |
| 2905 | nocrt: true, |
| 2906 | } |
| 2907 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2908 | name: "libboth_available", |
| 2909 | vendor_available: true, |
| 2910 | product_available: true, |
| 2911 | nocrt: true, |
| 2912 | target: { |
| 2913 | vendor: { |
| 2914 | suffix: "-vendor", |
| 2915 | }, |
| 2916 | product: { |
| 2917 | suffix: "-product", |
| 2918 | }, |
| 2919 | } |
| 2920 | } |
| 2921 | cc_library { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2922 | name: "libproduct_va", |
| 2923 | product_specific: true, |
| 2924 | vendor_available: true, |
| 2925 | nocrt: true, |
| 2926 | } |
| 2927 | cc_library { |
| 2928 | name: "libprod", |
| 2929 | product_specific: true, |
| 2930 | shared_libs: [ |
| 2931 | "libllndk", |
| 2932 | "libvndk", |
| 2933 | "libvndk_sp", |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2934 | "libpa", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2935 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2936 | "libproduct_va", |
| 2937 | ], |
| 2938 | nocrt: true, |
| 2939 | } |
| 2940 | cc_library { |
| 2941 | name: "libvendor", |
| 2942 | vendor: true, |
| 2943 | shared_libs: [ |
| 2944 | "libllndk", |
| 2945 | "libvndk", |
| 2946 | "libvndk_sp", |
| 2947 | "libva", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2948 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2949 | "libproduct_va", |
| 2950 | ], |
| 2951 | nocrt: true, |
| 2952 | } |
| 2953 | ` |
| 2954 | |
| 2955 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2956 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2957 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2958 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2959 | |
| 2960 | ctx := testCcWithConfig(t, config) |
| 2961 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 2962 | checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant) |
| 2963 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2964 | |
| 2965 | mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module) |
| 2966 | assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so") |
| 2967 | |
| 2968 | mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module) |
| 2969 | assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 2973 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2974 | cc_library { |
| 2975 | name: "libprod", |
| 2976 | product_specific: true, |
| 2977 | shared_libs: [ |
| 2978 | "libvendor", |
| 2979 | ], |
| 2980 | nocrt: true, |
| 2981 | } |
| 2982 | cc_library { |
| 2983 | name: "libvendor", |
| 2984 | vendor: true, |
| 2985 | nocrt: true, |
| 2986 | } |
| 2987 | `) |
| 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 | "libsystem", |
| 2994 | ], |
| 2995 | nocrt: true, |
| 2996 | } |
| 2997 | cc_library { |
| 2998 | name: "libsystem", |
| 2999 | nocrt: true, |
| 3000 | } |
| 3001 | `) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 3002 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 3003 | cc_library { |
| 3004 | name: "libprod", |
| 3005 | product_specific: true, |
| 3006 | shared_libs: [ |
| 3007 | "libva", |
| 3008 | ], |
| 3009 | nocrt: true, |
| 3010 | } |
| 3011 | cc_library { |
| 3012 | name: "libva", |
| 3013 | vendor_available: true, |
| 3014 | nocrt: true, |
| 3015 | } |
| 3016 | `) |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 3017 | 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] | 3018 | cc_library { |
| 3019 | name: "libprod", |
| 3020 | product_specific: true, |
| 3021 | shared_libs: [ |
| 3022 | "libvndk_private", |
| 3023 | ], |
| 3024 | nocrt: true, |
| 3025 | } |
| 3026 | cc_library { |
| 3027 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 3028 | vendor_available: true, |
| 3029 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 3030 | vndk: { |
| 3031 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 3032 | private: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 3033 | }, |
| 3034 | nocrt: true, |
| 3035 | } |
| 3036 | `) |
| 3037 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 3038 | cc_library { |
| 3039 | name: "libprod", |
| 3040 | product_specific: true, |
| 3041 | shared_libs: [ |
| 3042 | "libsystem_ext", |
| 3043 | ], |
| 3044 | nocrt: true, |
| 3045 | } |
| 3046 | cc_library { |
| 3047 | name: "libsystem_ext", |
| 3048 | system_ext_specific: true, |
| 3049 | nocrt: true, |
| 3050 | } |
| 3051 | `) |
| 3052 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 3053 | cc_library { |
| 3054 | name: "libsystem", |
| 3055 | shared_libs: [ |
| 3056 | "libproduct_va", |
| 3057 | ], |
| 3058 | nocrt: true, |
| 3059 | } |
| 3060 | cc_library { |
| 3061 | name: "libproduct_va", |
| 3062 | product_specific: true, |
| 3063 | vendor_available: true, |
| 3064 | nocrt: true, |
| 3065 | } |
| 3066 | `) |
| 3067 | } |
| 3068 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3069 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3070 | bp := ` |
| 3071 | cc_library { |
| 3072 | name: "libvndk", |
| 3073 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3074 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3075 | vndk: { |
| 3076 | enabled: true, |
| 3077 | }, |
| 3078 | } |
| 3079 | cc_library { |
| 3080 | name: "libvndksp", |
| 3081 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3082 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3083 | vndk: { |
| 3084 | enabled: true, |
| 3085 | support_system_process: true, |
| 3086 | }, |
| 3087 | } |
| 3088 | cc_library { |
| 3089 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 3090 | vendor_available: true, |
| 3091 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3092 | vndk: { |
| 3093 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 3094 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3095 | }, |
| 3096 | } |
| 3097 | cc_library { |
| 3098 | name: "libvendor", |
| 3099 | vendor: true, |
| 3100 | } |
| 3101 | cc_library { |
| 3102 | name: "libvndkext", |
| 3103 | vendor: true, |
| 3104 | vndk: { |
| 3105 | enabled: true, |
| 3106 | extends: "libvndk", |
| 3107 | }, |
| 3108 | } |
| 3109 | vndk_prebuilt_shared { |
| 3110 | name: "prevndk", |
| 3111 | version: "27", |
| 3112 | target_arch: "arm", |
| 3113 | binder32bit: true, |
| 3114 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3115 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3116 | vndk: { |
| 3117 | enabled: true, |
| 3118 | }, |
| 3119 | arch: { |
| 3120 | arm: { |
| 3121 | srcs: ["liba.so"], |
| 3122 | }, |
| 3123 | }, |
| 3124 | } |
| 3125 | cc_library { |
| 3126 | name: "libllndk", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3127 | llndk_stubs: "libllndk.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3128 | } |
| 3129 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3130 | name: "libllndk.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3131 | symbol_file: "", |
| 3132 | } |
| 3133 | cc_library { |
| 3134 | name: "libllndkprivate", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3135 | llndk_stubs: "libllndkprivate.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3136 | } |
| 3137 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3138 | name: "libllndkprivate.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3139 | vendor_available: false, |
| 3140 | symbol_file: "", |
| 3141 | }` |
| 3142 | |
| 3143 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3144 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 3145 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 3146 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 3147 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3148 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3149 | assertMapKeys(t, vndkCoreLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3150 | []string{"libvndk", "libvndkprivate"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3151 | assertMapKeys(t, vndkSpLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3152 | []string{"libc++", "libvndksp"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3153 | assertMapKeys(t, llndkLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 3154 | []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3155 | assertMapKeys(t, vndkPrivateLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 3156 | []string{"libft2", "libllndkprivate", "libvndkprivate"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3157 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3158 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 3159 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3160 | tests := []struct { |
| 3161 | variant string |
| 3162 | name string |
| 3163 | expected string |
| 3164 | }{ |
| 3165 | {vendorVariant, "libvndk", "native:vndk"}, |
| 3166 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 3167 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 3168 | {vendorVariant, "libvendor", "native:vendor"}, |
| 3169 | {vendorVariant, "libvndkext", "native:vendor"}, |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 3170 | {vendorVariant, "libllndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 3171 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3172 | {coreVariant, "libvndk", "native:platform"}, |
| 3173 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 3174 | {coreVariant, "libllndk", "native:platform"}, |
| 3175 | } |
| 3176 | for _, test := range tests { |
| 3177 | t.Run(test.name, func(t *testing.T) { |
| 3178 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 3179 | assertString(t, module.makeLinkType, test.expected) |
| 3180 | }) |
| 3181 | } |
| 3182 | } |
| 3183 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3184 | var staticLinkDepOrderTestCases = []struct { |
| 3185 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 3186 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3187 | inStatic string |
| 3188 | |
| 3189 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 3190 | // It models the dependencies declared in an Android.bp file. |
| 3191 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3192 | |
| 3193 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 3194 | // The keys of allOrdered specify which modules we would like to check. |
| 3195 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 3196 | // dependencies) for each module to test |
| 3197 | allOrdered string |
| 3198 | |
| 3199 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 3200 | // The keys of outOrdered specify which modules we would like to check. |
| 3201 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 3202 | // for each module to test. |
| 3203 | outOrdered string |
| 3204 | }{ |
| 3205 | // Simple tests |
| 3206 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3207 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3208 | outOrdered: "", |
| 3209 | }, |
| 3210 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3211 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3212 | outOrdered: "a:", |
| 3213 | }, |
| 3214 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3215 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3216 | outOrdered: "a:b; b:", |
| 3217 | }, |
| 3218 | // Tests of reordering |
| 3219 | { |
| 3220 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3221 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3222 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 3223 | }, |
| 3224 | { |
| 3225 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3226 | 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] | 3227 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 3228 | }, |
| 3229 | { |
| 3230 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3231 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3232 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 3233 | }, |
| 3234 | { |
| 3235 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3236 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3237 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 3238 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 3239 | }, |
| 3240 | { |
| 3241 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3242 | 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] | 3243 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 3244 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 3245 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3246 | // shared dependencies |
| 3247 | { |
| 3248 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 3249 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 3250 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 3251 | // a shared dependency on b, that that shows up in allOrdered. |
| 3252 | inShared: "c:b", |
| 3253 | allOrdered: "c:b", |
| 3254 | outOrdered: "c:", |
| 3255 | }, |
| 3256 | { |
| 3257 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 3258 | // the second phase of the above test would look like |
| 3259 | inStatic: "a:b,c; c:b", |
| 3260 | allOrdered: "a:c,b; c:b", |
| 3261 | outOrdered: "a:c,b; c:b", |
| 3262 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3263 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 3264 | // to dictate an order |
| 3265 | { |
| 3266 | // 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] | 3267 | 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] | 3268 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 3269 | }, |
| 3270 | { |
| 3271 | // 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] | 3272 | 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] | 3273 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 3274 | }, |
| 3275 | // Tests involving duplicate dependencies |
| 3276 | { |
| 3277 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3278 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3279 | outOrdered: "a:c,b", |
| 3280 | }, |
| 3281 | { |
| 3282 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3283 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3284 | outOrdered: "a:d,c,b", |
| 3285 | }, |
| 3286 | // Tests to confirm the nonexistence of infinite loops. |
| 3287 | // These cases should never happen, so as long as the test terminates and the |
| 3288 | // result is deterministic then that should be fine. |
| 3289 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3290 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3291 | outOrdered: "a:a", |
| 3292 | }, |
| 3293 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3294 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3295 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 3296 | outOrdered: "a:b; b:c; c:a", |
| 3297 | }, |
| 3298 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3299 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3300 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 3301 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 3302 | }, |
| 3303 | } |
| 3304 | |
| 3305 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 3306 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 3307 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 3308 | strippedText := strings.Replace(text, " ", "", -1) |
| 3309 | if len(strippedText) < 1 { |
| 3310 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 3311 | } |
| 3312 | allDeps = make(map[android.Path][]android.Path, 0) |
| 3313 | |
| 3314 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 3315 | moduleTexts := strings.Split(strippedText, ";") |
| 3316 | |
| 3317 | outputForModuleName := func(moduleName string) android.Path { |
| 3318 | return android.PathForTesting(moduleName) |
| 3319 | } |
| 3320 | |
| 3321 | for _, moduleText := range moduleTexts { |
| 3322 | // convert from "a:b,c" to ["a", "b,c"] |
| 3323 | components := strings.Split(moduleText, ":") |
| 3324 | if len(components) != 2 { |
| 3325 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 3326 | } |
| 3327 | moduleName := components[0] |
| 3328 | moduleOutput := outputForModuleName(moduleName) |
| 3329 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 3330 | |
| 3331 | depString := components[1] |
| 3332 | // convert from "b,c" to ["b", "c"] |
| 3333 | depNames := strings.Split(depString, ",") |
| 3334 | if len(depString) < 1 { |
| 3335 | depNames = []string{} |
| 3336 | } |
| 3337 | var deps []android.Path |
| 3338 | for _, depName := range depNames { |
| 3339 | deps = append(deps, outputForModuleName(depName)) |
| 3340 | } |
| 3341 | allDeps[moduleOutput] = deps |
| 3342 | } |
| 3343 | return modulesInOrder, allDeps |
| 3344 | } |
| 3345 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3346 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 3347 | for _, moduleName := range moduleNames { |
| 3348 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 3349 | output := module.outputFile.Path() |
| 3350 | paths = append(paths, output) |
| 3351 | } |
| 3352 | return paths |
| 3353 | } |
| 3354 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3355 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3356 | ctx := testCc(t, ` |
| 3357 | cc_library { |
| 3358 | name: "a", |
| 3359 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3360 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3361 | } |
| 3362 | cc_library { |
| 3363 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3364 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3365 | } |
| 3366 | cc_library { |
| 3367 | name: "c", |
| 3368 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3369 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3370 | } |
| 3371 | cc_library { |
| 3372 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3373 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | `) |
| 3377 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3378 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3379 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3380 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 3381 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3382 | |
| 3383 | if !reflect.DeepEqual(actual, expected) { |
| 3384 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3385 | "\nactual: %v"+ |
| 3386 | "\nexpected: %v", |
| 3387 | actual, |
| 3388 | expected, |
| 3389 | ) |
| 3390 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3391 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3392 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3393 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 3394 | ctx := testCc(t, ` |
| 3395 | cc_library { |
| 3396 | name: "a", |
| 3397 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3398 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3399 | } |
| 3400 | cc_library { |
| 3401 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3402 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3403 | } |
| 3404 | cc_library { |
| 3405 | name: "c", |
| 3406 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3407 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | `) |
| 3411 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3412 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3413 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3414 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 3415 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 3416 | |
| 3417 | if !reflect.DeepEqual(actual, expected) { |
| 3418 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 3419 | "\nactual: %v"+ |
| 3420 | "\nexpected: %v", |
| 3421 | actual, |
| 3422 | expected, |
| 3423 | ) |
| 3424 | } |
| 3425 | } |
| 3426 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3427 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 3428 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3429 | if !reflect.DeepEqual(actual, expected) { |
| 3430 | t.Errorf(message+ |
| 3431 | "\nactual: %v"+ |
| 3432 | "\nexpected: %v", |
| 3433 | actual, |
| 3434 | expected, |
| 3435 | ) |
| 3436 | } |
| 3437 | } |
| 3438 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3439 | func TestLlndkLibrary(t *testing.T) { |
| 3440 | ctx := testCc(t, ` |
| 3441 | cc_library { |
| 3442 | name: "libllndk", |
| 3443 | stubs: { versions: ["1", "2"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3444 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3445 | } |
| 3446 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3447 | name: "libllndk.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3448 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 3449 | |
| 3450 | cc_prebuilt_library_shared { |
| 3451 | name: "libllndkprebuilt", |
| 3452 | stubs: { versions: ["1", "2"] }, |
| 3453 | llndk_stubs: "libllndkprebuilt.llndk", |
| 3454 | } |
| 3455 | llndk_library { |
| 3456 | name: "libllndkprebuilt.llndk", |
| 3457 | } |
| 3458 | |
| 3459 | cc_library { |
| 3460 | name: "libllndk_with_external_headers", |
| 3461 | stubs: { versions: ["1", "2"] }, |
| 3462 | llndk_stubs: "libllndk_with_external_headers.llndk", |
| 3463 | header_libs: ["libexternal_headers"], |
| 3464 | export_header_lib_headers: ["libexternal_headers"], |
| 3465 | } |
| 3466 | llndk_library { |
| 3467 | name: "libllndk_with_external_headers.llndk", |
| 3468 | } |
| 3469 | cc_library_headers { |
| 3470 | name: "libexternal_headers", |
| 3471 | export_include_dirs: ["include"], |
| 3472 | vendor_available: true, |
| 3473 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3474 | `) |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 3475 | actual := ctx.ModuleVariantsForTests("libllndk") |
| 3476 | for i := 0; i < len(actual); i++ { |
| 3477 | if !strings.HasPrefix(actual[i], "android_vendor.VER_") { |
| 3478 | actual = append(actual[:i], actual[i+1:]...) |
| 3479 | i-- |
| 3480 | } |
| 3481 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3482 | expected := []string{ |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3483 | "android_vendor.VER_arm64_armv8-a_shared_1", |
| 3484 | "android_vendor.VER_arm64_armv8-a_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3485 | "android_vendor.VER_arm64_armv8-a_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3486 | "android_vendor.VER_arm_armv7-a-neon_shared_1", |
| 3487 | "android_vendor.VER_arm_armv7-a-neon_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3488 | "android_vendor.VER_arm_armv7-a-neon_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 3489 | } |
| 3490 | checkEquals(t, "variants for llndk stubs", expected, actual) |
| 3491 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 3492 | 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] | 3493 | checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) |
| 3494 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 3495 | 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] | 3496 | checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"]) |
| 3497 | } |
| 3498 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3499 | func TestLlndkHeaders(t *testing.T) { |
| 3500 | ctx := testCc(t, ` |
| 3501 | llndk_headers { |
| 3502 | name: "libllndk_headers", |
| 3503 | export_include_dirs: ["my_include"], |
| 3504 | } |
| 3505 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3506 | name: "libllndk.llndk", |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3507 | export_llndk_headers: ["libllndk_headers"], |
| 3508 | } |
| 3509 | cc_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 3510 | name: "libllndk", |
| 3511 | llndk_stubs: "libllndk.llndk", |
| 3512 | } |
| 3513 | |
| 3514 | cc_library { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3515 | name: "libvendor", |
| 3516 | shared_libs: ["libllndk"], |
| 3517 | vendor: true, |
| 3518 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3519 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 3520 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 3521 | } |
| 3522 | `) |
| 3523 | |
| 3524 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3525 | 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] | 3526 | cflags := cc.Args["cFlags"] |
| 3527 | if !strings.Contains(cflags, "-Imy_include") { |
| 3528 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 3529 | } |
| 3530 | } |
| 3531 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3532 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 3533 | actual := module.Properties.AndroidMkRuntimeLibs |
| 3534 | if !reflect.DeepEqual(actual, expected) { |
| 3535 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 3536 | "\nactual: %v"+ |
| 3537 | "\nexpected: %v", |
| 3538 | actual, |
| 3539 | expected, |
| 3540 | ) |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | const runtimeLibAndroidBp = ` |
| 3545 | cc_library { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3546 | name: "liball_available", |
| 3547 | vendor_available: true, |
| 3548 | product_available: true, |
| 3549 | no_libcrt : true, |
| 3550 | nocrt : true, |
| 3551 | system_shared_libs : [], |
| 3552 | } |
| 3553 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3554 | name: "libvendor_available1", |
| 3555 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3556 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3557 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3558 | nocrt : true, |
| 3559 | system_shared_libs : [], |
| 3560 | } |
| 3561 | cc_library { |
| 3562 | name: "libvendor_available2", |
| 3563 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3564 | runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3565 | target: { |
| 3566 | vendor: { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3567 | exclude_runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3568 | } |
| 3569 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3570 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3571 | nocrt : true, |
| 3572 | system_shared_libs : [], |
| 3573 | } |
| 3574 | cc_library { |
| 3575 | name: "libcore", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3576 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3577 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3578 | nocrt : true, |
| 3579 | system_shared_libs : [], |
| 3580 | } |
| 3581 | cc_library { |
| 3582 | name: "libvendor1", |
| 3583 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3584 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3585 | nocrt : true, |
| 3586 | system_shared_libs : [], |
| 3587 | } |
| 3588 | cc_library { |
| 3589 | name: "libvendor2", |
| 3590 | vendor: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3591 | runtime_libs: ["liball_available", "libvendor1"], |
| 3592 | no_libcrt : true, |
| 3593 | nocrt : true, |
| 3594 | system_shared_libs : [], |
| 3595 | } |
| 3596 | cc_library { |
| 3597 | name: "libproduct_available1", |
| 3598 | product_available: true, |
| 3599 | runtime_libs: ["liball_available"], |
| 3600 | no_libcrt : true, |
| 3601 | nocrt : true, |
| 3602 | system_shared_libs : [], |
| 3603 | } |
| 3604 | cc_library { |
| 3605 | name: "libproduct1", |
| 3606 | product_specific: true, |
| 3607 | no_libcrt : true, |
| 3608 | nocrt : true, |
| 3609 | system_shared_libs : [], |
| 3610 | } |
| 3611 | cc_library { |
| 3612 | name: "libproduct2", |
| 3613 | product_specific: true, |
| 3614 | runtime_libs: ["liball_available", "libproduct1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3615 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3616 | nocrt : true, |
| 3617 | system_shared_libs : [], |
| 3618 | } |
| 3619 | ` |
| 3620 | |
| 3621 | func TestRuntimeLibs(t *testing.T) { |
| 3622 | ctx := testCc(t, runtimeLibAndroidBp) |
| 3623 | |
| 3624 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3625 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3626 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3627 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 3628 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
| 3629 | |
| 3630 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 3631 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3632 | |
| 3633 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3634 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3635 | |
| 3636 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 3637 | // and vendor variants. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3638 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3639 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3640 | module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 3641 | checkRuntimeLibs(t, []string{"liball_available.vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3642 | |
| 3643 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3644 | checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module) |
| 3645 | |
| 3646 | // runtime_libs for product variants have '.product' suffixes if the modules have both core |
| 3647 | // and product variants. |
| 3648 | variant = "android_product.VER_arm64_armv8-a_shared" |
| 3649 | |
| 3650 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 3651 | checkRuntimeLibs(t, []string{"liball_available.product"}, module) |
| 3652 | |
| 3653 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
| 3654 | checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 3658 | ctx := testCc(t, runtimeLibAndroidBp) |
| 3659 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3660 | variant := "android_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3661 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 3662 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3663 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3664 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3665 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3666 | checkRuntimeLibs(t, nil, module) |
| 3667 | } |
| 3668 | |
| 3669 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 3670 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 3671 | |
| 3672 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 3673 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3674 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3675 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3676 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 3677 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3678 | |
| 3679 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3680 | checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module) |
| 3681 | |
| 3682 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
| 3683 | checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 3684 | } |
| 3685 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3686 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 3687 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3688 | actual := module.Properties.AndroidMkStaticLibs |
| 3689 | if !reflect.DeepEqual(actual, expected) { |
| 3690 | t.Errorf("incorrect static_libs"+ |
| 3691 | "\nactual: %v"+ |
| 3692 | "\nexpected: %v", |
| 3693 | actual, |
| 3694 | expected, |
| 3695 | ) |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | const staticLibAndroidBp = ` |
| 3700 | cc_library { |
| 3701 | name: "lib1", |
| 3702 | } |
| 3703 | cc_library { |
| 3704 | name: "lib2", |
| 3705 | static_libs: ["lib1"], |
| 3706 | } |
| 3707 | ` |
| 3708 | |
| 3709 | func TestStaticLibDepExport(t *testing.T) { |
| 3710 | ctx := testCc(t, staticLibAndroidBp) |
| 3711 | |
| 3712 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3713 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3714 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 3715 | 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] | 3716 | |
| 3717 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3718 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 3719 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 3720 | // libc++_static is linked additionally. |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 3721 | 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] | 3722 | } |
| 3723 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3724 | var compilerFlagsTestCases = []struct { |
| 3725 | in string |
| 3726 | out bool |
| 3727 | }{ |
| 3728 | { |
| 3729 | in: "a", |
| 3730 | out: false, |
| 3731 | }, |
| 3732 | { |
| 3733 | in: "-a", |
| 3734 | out: true, |
| 3735 | }, |
| 3736 | { |
| 3737 | in: "-Ipath/to/something", |
| 3738 | out: false, |
| 3739 | }, |
| 3740 | { |
| 3741 | in: "-isystempath/to/something", |
| 3742 | out: false, |
| 3743 | }, |
| 3744 | { |
| 3745 | in: "--coverage", |
| 3746 | out: false, |
| 3747 | }, |
| 3748 | { |
| 3749 | in: "-include a/b", |
| 3750 | out: true, |
| 3751 | }, |
| 3752 | { |
| 3753 | in: "-include a/b c/d", |
| 3754 | out: false, |
| 3755 | }, |
| 3756 | { |
| 3757 | in: "-DMACRO", |
| 3758 | out: true, |
| 3759 | }, |
| 3760 | { |
| 3761 | in: "-DMAC RO", |
| 3762 | out: false, |
| 3763 | }, |
| 3764 | { |
| 3765 | in: "-a -b", |
| 3766 | out: false, |
| 3767 | }, |
| 3768 | { |
| 3769 | in: "-DMACRO=definition", |
| 3770 | out: true, |
| 3771 | }, |
| 3772 | { |
| 3773 | in: "-DMACRO=defi nition", |
| 3774 | out: true, // TODO(jiyong): this should be false |
| 3775 | }, |
| 3776 | { |
| 3777 | in: "-DMACRO(x)=x + 1", |
| 3778 | out: true, |
| 3779 | }, |
| 3780 | { |
| 3781 | in: "-DMACRO=\"defi nition\"", |
| 3782 | out: true, |
| 3783 | }, |
| 3784 | } |
| 3785 | |
| 3786 | type mockContext struct { |
| 3787 | BaseModuleContext |
| 3788 | result bool |
| 3789 | } |
| 3790 | |
| 3791 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 3792 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 3793 | ctx.result = false |
| 3794 | } |
| 3795 | |
| 3796 | func TestCompilerFlags(t *testing.T) { |
| 3797 | for _, testCase := range compilerFlagsTestCases { |
| 3798 | ctx := &mockContext{result: true} |
| 3799 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 3800 | if ctx.result != testCase.out { |
| 3801 | t.Errorf("incorrect output:") |
| 3802 | t.Errorf(" input: %#v", testCase.in) |
| 3803 | t.Errorf(" expected: %#v", testCase.out) |
| 3804 | t.Errorf(" got: %#v", ctx.result) |
| 3805 | } |
| 3806 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3807 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3808 | |
| 3809 | func TestVendorPublicLibraries(t *testing.T) { |
| 3810 | ctx := testCc(t, ` |
| 3811 | cc_library_headers { |
| 3812 | name: "libvendorpublic_headers", |
| 3813 | export_include_dirs: ["my_include"], |
| 3814 | } |
| 3815 | vendor_public_library { |
| 3816 | name: "libvendorpublic", |
| 3817 | symbol_file: "", |
| 3818 | export_public_headers: ["libvendorpublic_headers"], |
| 3819 | } |
| 3820 | cc_library { |
| 3821 | name: "libvendorpublic", |
| 3822 | srcs: ["foo.c"], |
| 3823 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3824 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3825 | nocrt: true, |
| 3826 | } |
| 3827 | |
| 3828 | cc_library { |
| 3829 | name: "libsystem", |
| 3830 | shared_libs: ["libvendorpublic"], |
| 3831 | vendor: false, |
| 3832 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3833 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3834 | nocrt: true, |
| 3835 | } |
| 3836 | cc_library { |
| 3837 | name: "libvendor", |
| 3838 | shared_libs: ["libvendorpublic"], |
| 3839 | vendor: true, |
| 3840 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 3841 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3842 | nocrt: true, |
| 3843 | } |
| 3844 | `) |
| 3845 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3846 | coreVariant := "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3847 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3848 | |
| 3849 | // test if header search paths are correctly added |
| 3850 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3851 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3852 | cflags := cc.Args["cFlags"] |
| 3853 | if !strings.Contains(cflags, "-Imy_include") { |
| 3854 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 3855 | } |
| 3856 | |
| 3857 | // test if libsystem is linked to the stub |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3858 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3859 | libflags := ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3860 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3861 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3862 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3863 | } |
| 3864 | |
| 3865 | // test if libvendor is linked to the real shared lib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3866 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3867 | libflags = ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3868 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3869 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3870 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3871 | } |
| 3872 | |
| 3873 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3874 | |
| 3875 | func TestRecovery(t *testing.T) { |
| 3876 | ctx := testCc(t, ` |
| 3877 | cc_library_shared { |
| 3878 | name: "librecovery", |
| 3879 | recovery: true, |
| 3880 | } |
| 3881 | cc_library_shared { |
| 3882 | name: "librecovery32", |
| 3883 | recovery: true, |
| 3884 | compile_multilib:"32", |
| 3885 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3886 | cc_library_shared { |
| 3887 | name: "libHalInRecovery", |
| 3888 | recovery_available: true, |
| 3889 | vendor: true, |
| 3890 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3891 | `) |
| 3892 | |
| 3893 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3894 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3895 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3896 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3897 | } |
| 3898 | |
| 3899 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3900 | if android.InList(arm64, variants) { |
| 3901 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3902 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3903 | |
| 3904 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3905 | if !recoveryModule.Platform() { |
| 3906 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3907 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3908 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3909 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3910 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
| 3911 | bp := ` |
| 3912 | cc_prebuilt_test_library_shared { |
| 3913 | name: "test_lib", |
| 3914 | relative_install_path: "foo/bar/baz", |
| 3915 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3916 | } |
| 3917 | |
| 3918 | cc_test { |
| 3919 | name: "main_test", |
| 3920 | data_libs: ["test_lib"], |
| 3921 | gtest: false, |
| 3922 | } |
| 3923 | ` |
| 3924 | |
| 3925 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3926 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 3927 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 3928 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3929 | |
| 3930 | ctx := testCcWithConfig(t, config) |
| 3931 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3932 | testBinary := module.(*Module).linker.(*testBinary) |
| 3933 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3934 | if err != nil { |
| 3935 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3936 | } |
| 3937 | if len(outputFiles) != 1 { |
| 3938 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3939 | } |
| 3940 | if len(testBinary.dataPaths()) != 1 { |
| 3941 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 3942 | } |
| 3943 | |
| 3944 | outputPath := outputFiles[0].String() |
| 3945 | |
| 3946 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3947 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3948 | } |
| 3949 | entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] |
| 3950 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3951 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3952 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3953 | } |
| 3954 | } |
| 3955 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3956 | func TestVersionedStubs(t *testing.T) { |
| 3957 | ctx := testCc(t, ` |
| 3958 | cc_library_shared { |
| 3959 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3960 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3961 | stubs: { |
| 3962 | symbol_file: "foo.map.txt", |
| 3963 | versions: ["1", "2", "3"], |
| 3964 | }, |
| 3965 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3966 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3967 | cc_library_shared { |
| 3968 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3969 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3970 | shared_libs: ["libFoo#1"], |
| 3971 | }`) |
| 3972 | |
| 3973 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3974 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3975 | "android_arm64_armv8-a_shared", |
| 3976 | "android_arm64_armv8-a_shared_1", |
| 3977 | "android_arm64_armv8-a_shared_2", |
| 3978 | "android_arm64_armv8-a_shared_3", |
| 3979 | "android_arm_armv7-a-neon_shared", |
| 3980 | "android_arm_armv7-a-neon_shared_1", |
| 3981 | "android_arm_armv7-a-neon_shared_2", |
| 3982 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3983 | } |
| 3984 | variantsMismatch := false |
| 3985 | if len(variants) != len(expectedVariants) { |
| 3986 | variantsMismatch = true |
| 3987 | } else { |
| 3988 | for _, v := range expectedVariants { |
| 3989 | if !inList(v, variants) { |
| 3990 | variantsMismatch = false |
| 3991 | } |
| 3992 | } |
| 3993 | } |
| 3994 | if variantsMismatch { |
| 3995 | t.Errorf("variants of libFoo expected:\n") |
| 3996 | for _, v := range expectedVariants { |
| 3997 | t.Errorf("%q\n", v) |
| 3998 | } |
| 3999 | t.Errorf(", but got:\n") |
| 4000 | for _, v := range variants { |
| 4001 | t.Errorf("%q\n", v) |
| 4002 | } |
| 4003 | } |
| 4004 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4005 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 4006 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4007 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 4008 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 4009 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 4010 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 4011 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4012 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 4013 | cFlags := libBarCompileRule.Args["cFlags"] |
| 4014 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 4015 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 4016 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 4017 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 4018 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 4019 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 4020 | func TestVersioningMacro(t *testing.T) { |
| 4021 | for _, tc := range []struct{ moduleName, expected string }{ |
| 4022 | {"libc", "__LIBC_API__"}, |
| 4023 | {"libfoo", "__LIBFOO_API__"}, |
| 4024 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 4025 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 4026 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 4027 | } { |
| 4028 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 4029 | } |
| 4030 | } |
| 4031 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 4032 | func TestStaticExecutable(t *testing.T) { |
| 4033 | ctx := testCc(t, ` |
| 4034 | cc_binary { |
| 4035 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 4036 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 4037 | static_executable: true, |
| 4038 | }`) |
| 4039 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4040 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 4041 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 4042 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 4043 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 4044 | for _, lib := range systemStaticLibs { |
| 4045 | if !strings.Contains(libFlags, lib) { |
| 4046 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 4047 | } |
| 4048 | } |
| 4049 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 4050 | for _, lib := range systemSharedLibs { |
| 4051 | if strings.Contains(libFlags, lib) { |
| 4052 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 4053 | } |
| 4054 | } |
| 4055 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4056 | |
| 4057 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
| 4058 | ctx := testCc(t, ` |
| 4059 | cc_binary { |
| 4060 | name: "mybin", |
| 4061 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 4062 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4063 | static_executable: true, |
| 4064 | stl: "none", |
| 4065 | } |
| 4066 | |
| 4067 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 4068 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4069 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 4070 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4071 | stl: "none", |
| 4072 | } |
| 4073 | |
| 4074 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 4075 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4076 | srcs: ["foo.c"], |
| 4077 | stl: "none", |
| 4078 | stubs: { |
| 4079 | versions: ["1"], |
| 4080 | }, |
| 4081 | }`) |
| 4082 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 4083 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 4084 | actual := mybin.Implicits[:2] |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 4085 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 4086 | |
| 4087 | if !reflect.DeepEqual(actual, expected) { |
| 4088 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 4089 | "\nactual: %v"+ |
| 4090 | "\nexpected: %v", |
| 4091 | actual, |
| 4092 | expected, |
| 4093 | ) |
| 4094 | } |
| 4095 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 4096 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4097 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
| 4098 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 4099 | cc_library { |
| 4100 | name: "libA", |
| 4101 | srcs: ["foo.c"], |
| 4102 | shared_libs: ["libB"], |
| 4103 | stl: "none", |
| 4104 | } |
| 4105 | |
| 4106 | cc_library { |
| 4107 | name: "libB", |
| 4108 | srcs: ["foo.c"], |
| 4109 | enabled: false, |
| 4110 | stl: "none", |
| 4111 | } |
| 4112 | `) |
| 4113 | } |
| 4114 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 4115 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 4116 | // correctly. |
| 4117 | func TestFuzzTarget(t *testing.T) { |
| 4118 | ctx := testCc(t, ` |
| 4119 | cc_fuzz { |
| 4120 | name: "fuzz_smoke_test", |
| 4121 | srcs: ["foo.c"], |
| 4122 | }`) |
| 4123 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 4124 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 4125 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 4126 | } |
| 4127 | |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 4128 | func TestAidl(t *testing.T) { |
| 4129 | } |
| 4130 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 4131 | func assertString(t *testing.T, got, expected string) { |
| 4132 | t.Helper() |
| 4133 | if got != expected { |
| 4134 | t.Errorf("expected %q got %q", expected, got) |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | func assertArrayString(t *testing.T, got, expected []string) { |
| 4139 | t.Helper() |
| 4140 | if len(got) != len(expected) { |
| 4141 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 4142 | return |
| 4143 | } |
| 4144 | for i := range got { |
| 4145 | if got[i] != expected[i] { |
| 4146 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 4147 | i, expected[i], expected, got[i], got) |
| 4148 | return |
| 4149 | } |
| 4150 | } |
| 4151 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4152 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 4153 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 4154 | t.Helper() |
| 4155 | assertArrayString(t, android.SortedStringKeys(m), expected) |
| 4156 | } |
| 4157 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4158 | func TestDefaults(t *testing.T) { |
| 4159 | ctx := testCc(t, ` |
| 4160 | cc_defaults { |
| 4161 | name: "defaults", |
| 4162 | srcs: ["foo.c"], |
| 4163 | static: { |
| 4164 | srcs: ["bar.c"], |
| 4165 | }, |
| 4166 | shared: { |
| 4167 | srcs: ["baz.c"], |
| 4168 | }, |
| 4169 | } |
| 4170 | |
| 4171 | cc_library_static { |
| 4172 | name: "libstatic", |
| 4173 | defaults: ["defaults"], |
| 4174 | } |
| 4175 | |
| 4176 | cc_library_shared { |
| 4177 | name: "libshared", |
| 4178 | defaults: ["defaults"], |
| 4179 | } |
| 4180 | |
| 4181 | cc_library { |
| 4182 | name: "libboth", |
| 4183 | defaults: ["defaults"], |
| 4184 | } |
| 4185 | |
| 4186 | cc_binary { |
| 4187 | name: "binary", |
| 4188 | defaults: ["defaults"], |
| 4189 | }`) |
| 4190 | |
| 4191 | pathsToBase := func(paths android.Paths) []string { |
| 4192 | var ret []string |
| 4193 | for _, p := range paths { |
| 4194 | ret = append(ret, p.Base()) |
| 4195 | } |
| 4196 | return ret |
| 4197 | } |
| 4198 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4199 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4200 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4201 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 4202 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4203 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4204 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4205 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 4206 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4207 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4208 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 4209 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 4210 | } |
| 4211 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4212 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4213 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4214 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 4215 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4216 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4217 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4218 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 4219 | } |
| 4220 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4221 | |
| 4222 | func TestProductVariableDefaults(t *testing.T) { |
| 4223 | bp := ` |
| 4224 | cc_defaults { |
| 4225 | name: "libfoo_defaults", |
| 4226 | srcs: ["foo.c"], |
| 4227 | cppflags: ["-DFOO"], |
| 4228 | product_variables: { |
| 4229 | debuggable: { |
| 4230 | cppflags: ["-DBAR"], |
| 4231 | }, |
| 4232 | }, |
| 4233 | } |
| 4234 | |
| 4235 | cc_library { |
| 4236 | name: "libfoo", |
| 4237 | defaults: ["libfoo_defaults"], |
| 4238 | } |
| 4239 | ` |
| 4240 | |
| 4241 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 4242 | config.TestProductVariables.Debuggable = BoolPtr(true) |
| 4243 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 4244 | ctx := CreateTestContext(config) |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4245 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 4246 | ctx.BottomUp("variable", android.VariableMutator).Parallel() |
| 4247 | }) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 4248 | ctx.Register() |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4249 | |
| 4250 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 4251 | android.FailIfErrored(t, errs) |
| 4252 | _, errs = ctx.PrepareBuildActions(config) |
| 4253 | android.FailIfErrored(t, errs) |
| 4254 | |
| 4255 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 4256 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { |
| 4257 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) |
| 4258 | } |
| 4259 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4260 | |
| 4261 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 4262 | t.Parallel() |
| 4263 | bp := ` |
| 4264 | cc_library_static { |
| 4265 | name: "libfoo", |
| 4266 | srcs: ["foo.c"], |
| 4267 | whole_static_libs: ["libbar"], |
| 4268 | } |
| 4269 | |
| 4270 | cc_library_static { |
| 4271 | name: "libbar", |
| 4272 | whole_static_libs: ["libmissing"], |
| 4273 | } |
| 4274 | ` |
| 4275 | |
| 4276 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 4277 | config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true) |
| 4278 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 4279 | ctx := CreateTestContext(config) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4280 | ctx.SetAllowMissingDependencies(true) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 4281 | ctx.Register() |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4282 | |
| 4283 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 4284 | android.FailIfErrored(t, errs) |
| 4285 | _, errs = ctx.PrepareBuildActions(config) |
| 4286 | android.FailIfErrored(t, errs) |
| 4287 | |
| 4288 | libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
| 4289 | if g, w := libbar.Rule, android.ErrorRule; g != w { |
| 4290 | t.Fatalf("Expected libbar rule to be %q, got %q", w, g) |
| 4291 | } |
| 4292 | |
| 4293 | if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) { |
| 4294 | t.Errorf("Expected libbar error to contain %q, was %q", w, g) |
| 4295 | } |
| 4296 | |
| 4297 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
| 4298 | if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) { |
| 4299 | t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g) |
| 4300 | } |
| 4301 | |
| 4302 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4303 | |
| 4304 | func TestInstallSharedLibs(t *testing.T) { |
| 4305 | bp := ` |
| 4306 | cc_binary { |
| 4307 | name: "bin", |
| 4308 | host_supported: true, |
| 4309 | shared_libs: ["libshared"], |
| 4310 | runtime_libs: ["libruntime"], |
| 4311 | srcs: [":gen"], |
| 4312 | } |
| 4313 | |
| 4314 | cc_library_shared { |
| 4315 | name: "libshared", |
| 4316 | host_supported: true, |
| 4317 | shared_libs: ["libtransitive"], |
| 4318 | } |
| 4319 | |
| 4320 | cc_library_shared { |
| 4321 | name: "libtransitive", |
| 4322 | host_supported: true, |
| 4323 | } |
| 4324 | |
| 4325 | cc_library_shared { |
| 4326 | name: "libruntime", |
| 4327 | host_supported: true, |
| 4328 | } |
| 4329 | |
| 4330 | cc_binary_host { |
| 4331 | name: "tool", |
| 4332 | srcs: ["foo.cpp"], |
| 4333 | } |
| 4334 | |
| 4335 | genrule { |
| 4336 | name: "gen", |
| 4337 | tools: ["tool"], |
| 4338 | out: ["gen.cpp"], |
| 4339 | cmd: "$(location tool) $(out)", |
| 4340 | } |
| 4341 | ` |
| 4342 | |
| 4343 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 4344 | ctx := testCcWithConfig(t, config) |
| 4345 | |
| 4346 | hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install") |
| 4347 | hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4348 | hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4349 | hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4350 | hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install") |
| 4351 | |
| 4352 | if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) { |
| 4353 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4354 | } |
| 4355 | |
| 4356 | if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4357 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4358 | } |
| 4359 | |
| 4360 | if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4361 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4362 | } |
| 4363 | |
| 4364 | if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) { |
| 4365 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4366 | } |
| 4367 | |
| 4368 | if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4369 | t.Errorf("expected no host bin dependency %q, got %q", w, g) |
| 4370 | } |
| 4371 | |
| 4372 | deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install") |
| 4373 | deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install") |
| 4374 | deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install") |
| 4375 | deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install") |
| 4376 | |
| 4377 | if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) { |
| 4378 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4379 | } |
| 4380 | |
| 4381 | if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4382 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4383 | } |
| 4384 | |
| 4385 | if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4386 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4387 | } |
| 4388 | |
| 4389 | if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) { |
| 4390 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4391 | } |
| 4392 | |
| 4393 | if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4394 | t.Errorf("expected no device bin dependency %q, got %q", w, g) |
| 4395 | } |
| 4396 | |
| 4397 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 4398 | |
| 4399 | func TestStubsLibReexportsHeaders(t *testing.T) { |
| 4400 | ctx := testCc(t, ` |
| 4401 | cc_library_shared { |
| 4402 | name: "libclient", |
| 4403 | srcs: ["foo.c"], |
| 4404 | shared_libs: ["libfoo#1"], |
| 4405 | } |
| 4406 | |
| 4407 | cc_library_shared { |
| 4408 | name: "libfoo", |
| 4409 | srcs: ["foo.c"], |
| 4410 | shared_libs: ["libbar"], |
| 4411 | export_shared_lib_headers: ["libbar"], |
| 4412 | stubs: { |
| 4413 | symbol_file: "foo.map.txt", |
| 4414 | versions: ["1", "2", "3"], |
| 4415 | }, |
| 4416 | } |
| 4417 | |
| 4418 | cc_library_shared { |
| 4419 | name: "libbar", |
| 4420 | export_include_dirs: ["include/libbar"], |
| 4421 | srcs: ["foo.c"], |
| 4422 | }`) |
| 4423 | |
| 4424 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4425 | |
| 4426 | if !strings.Contains(cFlags, "-Iinclude/libbar") { |
| 4427 | t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) |
| 4428 | } |
| 4429 | } |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4430 | |
| 4431 | func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { |
| 4432 | ctx := testCc(t, ` |
| 4433 | cc_library { |
| 4434 | name: "libfoo", |
| 4435 | srcs: ["a/Foo.aidl"], |
| 4436 | aidl: { flags: ["-Werror"], }, |
| 4437 | } |
| 4438 | `) |
| 4439 | |
| 4440 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
| 4441 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 4442 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4443 | expectedAidlFlag := "-Werror" |
| 4444 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4445 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4446 | } |
| 4447 | } |