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