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