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