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