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 | |
| 1113 | func TestDoubleLoadableDepError(t *testing.T) { |
| 1114 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1115 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1116 | cc_library { |
| 1117 | name: "libllndk", |
| 1118 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1119 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1123 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1124 | symbol_file: "", |
| 1125 | } |
| 1126 | |
| 1127 | cc_library { |
| 1128 | name: "libnondoubleloadable", |
| 1129 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1130 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1131 | vndk: { |
| 1132 | enabled: true, |
| 1133 | }, |
| 1134 | } |
| 1135 | `) |
| 1136 | |
| 1137 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1138 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1139 | cc_library { |
| 1140 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1141 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1142 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1143 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1147 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1148 | symbol_file: "", |
| 1149 | } |
| 1150 | |
| 1151 | cc_library { |
| 1152 | name: "libnondoubleloadable", |
| 1153 | vendor_available: true, |
| 1154 | } |
| 1155 | `) |
| 1156 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1157 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1158 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1159 | cc_library { |
| 1160 | name: "libllndk", |
| 1161 | shared_libs: ["libcoreonly"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1162 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1166 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1167 | symbol_file: "", |
| 1168 | } |
| 1169 | |
| 1170 | cc_library { |
| 1171 | name: "libcoreonly", |
| 1172 | shared_libs: ["libvendoravailable"], |
| 1173 | } |
| 1174 | |
| 1175 | // indirect dependency of LLNDK |
| 1176 | cc_library { |
| 1177 | name: "libvendoravailable", |
| 1178 | vendor_available: true, |
| 1179 | } |
| 1180 | `) |
Jiyong Park | 0474e1f | 2021-01-14 14:26:06 +0900 | [diff] [blame] | 1181 | |
| 1182 | // The error is not from 'client' but from 'libllndk' |
| 1183 | testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", ` |
| 1184 | cc_library { |
| 1185 | name: "client", |
| 1186 | vendor_available: true, |
| 1187 | double_loadable: true, |
| 1188 | shared_libs: ["libllndk"], |
| 1189 | } |
| 1190 | cc_library { |
| 1191 | name: "libllndk", |
| 1192 | shared_libs: ["libnondoubleloadable"], |
| 1193 | llndk_stubs: "libllndk.llndk", |
| 1194 | } |
| 1195 | llndk_library { |
| 1196 | name: "libllndk.llndk", |
| 1197 | symbol_file: "", |
| 1198 | } |
| 1199 | cc_library { |
| 1200 | name: "libnondoubleloadable", |
| 1201 | vendor_available: true, |
| 1202 | } |
| 1203 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1204 | } |
| 1205 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1206 | func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) { |
| 1207 | testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", ` |
| 1208 | cc_library { |
| 1209 | name: "libvndksp", |
| 1210 | shared_libs: ["libanothervndksp"], |
| 1211 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1212 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1213 | vndk: { |
| 1214 | enabled: true, |
| 1215 | support_system_process: true, |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | cc_library { |
| 1220 | name: "libllndk", |
| 1221 | shared_libs: ["libanothervndksp"], |
| 1222 | } |
| 1223 | |
| 1224 | llndk_library { |
| 1225 | name: "libllndk", |
| 1226 | symbol_file: "", |
| 1227 | } |
| 1228 | |
| 1229 | cc_library { |
| 1230 | name: "libanothervndksp", |
| 1231 | vendor_available: true, |
| 1232 | } |
| 1233 | `) |
| 1234 | } |
| 1235 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1236 | func TestVndkExt(t *testing.T) { |
| 1237 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1238 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1239 | cc_library { |
| 1240 | name: "libvndk", |
| 1241 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1242 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1243 | vndk: { |
| 1244 | enabled: true, |
| 1245 | }, |
| 1246 | nocrt: true, |
| 1247 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1248 | cc_library { |
| 1249 | name: "libvndk2", |
| 1250 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1251 | product_available: true, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1252 | vndk: { |
| 1253 | enabled: true, |
| 1254 | }, |
| 1255 | target: { |
| 1256 | vendor: { |
| 1257 | suffix: "-suffix", |
| 1258 | }, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1259 | product: { |
| 1260 | suffix: "-suffix", |
| 1261 | }, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1262 | }, |
| 1263 | nocrt: true, |
| 1264 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1265 | |
| 1266 | cc_library { |
| 1267 | name: "libvndk_ext", |
| 1268 | vendor: true, |
| 1269 | vndk: { |
| 1270 | enabled: true, |
| 1271 | extends: "libvndk", |
| 1272 | }, |
| 1273 | nocrt: true, |
| 1274 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1275 | |
| 1276 | cc_library { |
| 1277 | name: "libvndk2_ext", |
| 1278 | vendor: true, |
| 1279 | vndk: { |
| 1280 | enabled: true, |
| 1281 | extends: "libvndk2", |
| 1282 | }, |
| 1283 | nocrt: true, |
| 1284 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1285 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1286 | cc_library { |
| 1287 | name: "libvndk_ext_product", |
| 1288 | product_specific: true, |
| 1289 | vndk: { |
| 1290 | enabled: true, |
| 1291 | extends: "libvndk", |
| 1292 | }, |
| 1293 | nocrt: true, |
| 1294 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1295 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1296 | cc_library { |
| 1297 | name: "libvndk2_ext_product", |
| 1298 | product_specific: true, |
| 1299 | vndk: { |
| 1300 | enabled: true, |
| 1301 | extends: "libvndk2", |
| 1302 | }, |
| 1303 | nocrt: true, |
| 1304 | } |
| 1305 | ` |
| 1306 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1307 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1308 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1309 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1310 | |
| 1311 | ctx := testCcWithConfig(t, config) |
| 1312 | |
| 1313 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 1314 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 1315 | |
| 1316 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 1317 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 1318 | |
| 1319 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 1320 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1323 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1324 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 1325 | ctx := testCcNoVndk(t, ` |
| 1326 | cc_library { |
| 1327 | name: "libvndk", |
| 1328 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1329 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1330 | vndk: { |
| 1331 | enabled: true, |
| 1332 | }, |
| 1333 | nocrt: true, |
| 1334 | } |
| 1335 | |
| 1336 | cc_library { |
| 1337 | name: "libvndk_ext", |
| 1338 | vendor: true, |
| 1339 | vndk: { |
| 1340 | enabled: true, |
| 1341 | extends: "libvndk", |
| 1342 | }, |
| 1343 | nocrt: true, |
| 1344 | } |
| 1345 | `) |
| 1346 | |
| 1347 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 1348 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 1349 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1350 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 1351 | } |
| 1352 | } |
| 1353 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1354 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { |
| 1355 | // 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] | 1356 | ctx := testCcNoProductVndk(t, ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1357 | cc_library { |
| 1358 | name: "libvndk", |
| 1359 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1360 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1361 | vndk: { |
| 1362 | enabled: true, |
| 1363 | }, |
| 1364 | nocrt: true, |
| 1365 | } |
| 1366 | |
| 1367 | cc_library { |
| 1368 | name: "libvndk_ext_product", |
| 1369 | product_specific: true, |
| 1370 | vndk: { |
| 1371 | enabled: true, |
| 1372 | extends: "libvndk", |
| 1373 | }, |
| 1374 | nocrt: true, |
| 1375 | } |
| 1376 | `) |
| 1377 | |
| 1378 | // Ensures that the core variant of "libvndk_ext_product" can be found. |
| 1379 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) |
| 1380 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1381 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) |
| 1382 | } |
| 1383 | } |
| 1384 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1385 | func TestVndkExtError(t *testing.T) { |
| 1386 | // 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] | 1387 | 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] | 1388 | cc_library { |
| 1389 | name: "libvndk", |
| 1390 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1391 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1392 | vndk: { |
| 1393 | enabled: true, |
| 1394 | }, |
| 1395 | nocrt: true, |
| 1396 | } |
| 1397 | |
| 1398 | cc_library { |
| 1399 | name: "libvndk_ext", |
| 1400 | vndk: { |
| 1401 | enabled: true, |
| 1402 | extends: "libvndk", |
| 1403 | }, |
| 1404 | nocrt: true, |
| 1405 | } |
| 1406 | `) |
| 1407 | |
| 1408 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1409 | cc_library { |
| 1410 | name: "libvndk", |
| 1411 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1412 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1413 | vndk: { |
| 1414 | enabled: true, |
| 1415 | }, |
| 1416 | nocrt: true, |
| 1417 | } |
| 1418 | |
| 1419 | cc_library { |
| 1420 | name: "libvndk_ext", |
| 1421 | vendor: true, |
| 1422 | vndk: { |
| 1423 | enabled: true, |
| 1424 | }, |
| 1425 | nocrt: true, |
| 1426 | } |
| 1427 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1428 | |
| 1429 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1430 | cc_library { |
| 1431 | name: "libvndk", |
| 1432 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1433 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1434 | vndk: { |
| 1435 | enabled: true, |
| 1436 | }, |
| 1437 | nocrt: true, |
| 1438 | } |
| 1439 | |
| 1440 | cc_library { |
| 1441 | name: "libvndk_ext_product", |
| 1442 | product_specific: true, |
| 1443 | vndk: { |
| 1444 | enabled: true, |
| 1445 | }, |
| 1446 | nocrt: true, |
| 1447 | } |
| 1448 | `) |
| 1449 | |
| 1450 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 1451 | cc_library { |
| 1452 | name: "libvndk", |
| 1453 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1454 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1455 | vndk: { |
| 1456 | enabled: true, |
| 1457 | }, |
| 1458 | nocrt: true, |
| 1459 | } |
| 1460 | |
| 1461 | cc_library { |
| 1462 | name: "libvndk_ext_product", |
| 1463 | product_specific: true, |
| 1464 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1465 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1466 | vndk: { |
| 1467 | enabled: true, |
| 1468 | extends: "libvndk", |
| 1469 | }, |
| 1470 | nocrt: true, |
| 1471 | } |
| 1472 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 1476 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1477 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1478 | cc_library { |
| 1479 | name: "libvndk", |
| 1480 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1481 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1482 | vndk: { |
| 1483 | enabled: true, |
| 1484 | }, |
| 1485 | nocrt: true, |
| 1486 | } |
| 1487 | |
| 1488 | cc_library { |
| 1489 | name: "libvndk_sp_ext", |
| 1490 | vendor: true, |
| 1491 | vndk: { |
| 1492 | enabled: true, |
| 1493 | extends: "libvndk", |
| 1494 | support_system_process: true, |
| 1495 | }, |
| 1496 | nocrt: true, |
| 1497 | } |
| 1498 | `) |
| 1499 | |
| 1500 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1501 | cc_library { |
| 1502 | name: "libvndk_sp", |
| 1503 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1504 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1505 | vndk: { |
| 1506 | enabled: true, |
| 1507 | support_system_process: true, |
| 1508 | }, |
| 1509 | nocrt: true, |
| 1510 | } |
| 1511 | |
| 1512 | cc_library { |
| 1513 | name: "libvndk_ext", |
| 1514 | vendor: true, |
| 1515 | vndk: { |
| 1516 | enabled: true, |
| 1517 | extends: "libvndk_sp", |
| 1518 | }, |
| 1519 | nocrt: true, |
| 1520 | } |
| 1521 | `) |
| 1522 | } |
| 1523 | |
| 1524 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1525 | // 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] | 1526 | // with `private: true`. |
| 1527 | testCcError(t, "`extends` refers module \".*\" which has `private: true`", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1528 | cc_library { |
| 1529 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1530 | vendor_available: true, |
| 1531 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1532 | vndk: { |
| 1533 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1534 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1535 | }, |
| 1536 | nocrt: true, |
| 1537 | } |
| 1538 | |
| 1539 | cc_library { |
| 1540 | name: "libvndk_ext", |
| 1541 | vendor: true, |
| 1542 | vndk: { |
| 1543 | enabled: true, |
| 1544 | extends: "libvndk", |
| 1545 | }, |
| 1546 | nocrt: true, |
| 1547 | } |
| 1548 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1549 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1550 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1551 | cc_library { |
| 1552 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1553 | vendor_available: true, |
| 1554 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1555 | vndk: { |
| 1556 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1557 | private: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1558 | }, |
| 1559 | nocrt: true, |
| 1560 | } |
| 1561 | |
| 1562 | cc_library { |
| 1563 | name: "libvndk_ext_product", |
| 1564 | product_specific: true, |
| 1565 | vndk: { |
| 1566 | enabled: true, |
| 1567 | extends: "libvndk", |
| 1568 | }, |
| 1569 | nocrt: true, |
| 1570 | } |
| 1571 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1572 | } |
| 1573 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1574 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 1575 | // 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] | 1576 | testCc(t, ` |
| 1577 | cc_library { |
| 1578 | name: "libvndk", |
| 1579 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1580 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1581 | vndk: { |
| 1582 | enabled: true, |
| 1583 | }, |
| 1584 | nocrt: true, |
| 1585 | } |
| 1586 | |
| 1587 | cc_library { |
| 1588 | name: "libvndk_ext", |
| 1589 | vendor: true, |
| 1590 | vndk: { |
| 1591 | enabled: true, |
| 1592 | extends: "libvndk", |
| 1593 | }, |
| 1594 | nocrt: true, |
| 1595 | } |
| 1596 | |
| 1597 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1598 | name: "libvndk_sp", |
| 1599 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1600 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1601 | vndk: { |
| 1602 | enabled: true, |
| 1603 | support_system_process: true, |
| 1604 | }, |
| 1605 | nocrt: true, |
| 1606 | } |
| 1607 | |
| 1608 | cc_library { |
| 1609 | name: "libvndk_sp_ext", |
| 1610 | vendor: true, |
| 1611 | vndk: { |
| 1612 | enabled: true, |
| 1613 | extends: "libvndk_sp", |
| 1614 | support_system_process: true, |
| 1615 | }, |
| 1616 | nocrt: true, |
| 1617 | } |
| 1618 | |
| 1619 | cc_library { |
| 1620 | name: "libvendor", |
| 1621 | vendor: true, |
| 1622 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 1623 | nocrt: true, |
| 1624 | } |
| 1625 | `) |
| 1626 | } |
| 1627 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1628 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 1629 | // 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] | 1630 | testCc(t, ` |
| 1631 | cc_library { |
| 1632 | name: "libvndk", |
| 1633 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1634 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1635 | vndk: { |
| 1636 | enabled: true, |
| 1637 | }, |
| 1638 | nocrt: true, |
| 1639 | } |
| 1640 | |
| 1641 | cc_library { |
| 1642 | name: "libvndk_ext", |
| 1643 | vendor: true, |
| 1644 | vndk: { |
| 1645 | enabled: true, |
| 1646 | extends: "libvndk", |
| 1647 | }, |
| 1648 | shared_libs: ["libvendor"], |
| 1649 | nocrt: true, |
| 1650 | } |
| 1651 | |
| 1652 | cc_library { |
| 1653 | name: "libvendor", |
| 1654 | vendor: true, |
| 1655 | nocrt: true, |
| 1656 | } |
| 1657 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1658 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1659 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 1660 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1661 | cc_library { |
| 1662 | name: "libvndk_sp", |
| 1663 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1664 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1665 | vndk: { |
| 1666 | enabled: true, |
| 1667 | support_system_process: true, |
| 1668 | }, |
| 1669 | nocrt: true, |
| 1670 | } |
| 1671 | |
| 1672 | cc_library { |
| 1673 | name: "libvndk_sp_ext", |
| 1674 | vendor: true, |
| 1675 | vndk: { |
| 1676 | enabled: true, |
| 1677 | extends: "libvndk_sp", |
| 1678 | support_system_process: true, |
| 1679 | }, |
| 1680 | shared_libs: ["libvendor"], // Cause an error |
| 1681 | nocrt: true, |
| 1682 | } |
| 1683 | |
| 1684 | cc_library { |
| 1685 | name: "libvendor", |
| 1686 | vendor: true, |
| 1687 | nocrt: true, |
| 1688 | } |
| 1689 | `) |
| 1690 | } |
| 1691 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1692 | func TestProductVndkExtDependency(t *testing.T) { |
| 1693 | bp := ` |
| 1694 | cc_library { |
| 1695 | name: "libvndk", |
| 1696 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1697 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1698 | vndk: { |
| 1699 | enabled: true, |
| 1700 | }, |
| 1701 | nocrt: true, |
| 1702 | } |
| 1703 | |
| 1704 | cc_library { |
| 1705 | name: "libvndk_ext_product", |
| 1706 | product_specific: true, |
| 1707 | vndk: { |
| 1708 | enabled: true, |
| 1709 | extends: "libvndk", |
| 1710 | }, |
| 1711 | shared_libs: ["libproduct_for_vndklibs"], |
| 1712 | nocrt: true, |
| 1713 | } |
| 1714 | |
| 1715 | cc_library { |
| 1716 | name: "libvndk_sp", |
| 1717 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1718 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1719 | vndk: { |
| 1720 | enabled: true, |
| 1721 | support_system_process: true, |
| 1722 | }, |
| 1723 | nocrt: true, |
| 1724 | } |
| 1725 | |
| 1726 | cc_library { |
| 1727 | name: "libvndk_sp_ext_product", |
| 1728 | product_specific: true, |
| 1729 | vndk: { |
| 1730 | enabled: true, |
| 1731 | extends: "libvndk_sp", |
| 1732 | support_system_process: true, |
| 1733 | }, |
| 1734 | shared_libs: ["libproduct_for_vndklibs"], |
| 1735 | nocrt: true, |
| 1736 | } |
| 1737 | |
| 1738 | cc_library { |
| 1739 | name: "libproduct", |
| 1740 | product_specific: true, |
| 1741 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 1742 | nocrt: true, |
| 1743 | } |
| 1744 | |
| 1745 | cc_library { |
| 1746 | name: "libproduct_for_vndklibs", |
| 1747 | product_specific: true, |
| 1748 | nocrt: true, |
| 1749 | } |
| 1750 | ` |
| 1751 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1752 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1753 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1754 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1755 | |
| 1756 | testCcWithConfig(t, config) |
| 1757 | } |
| 1758 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1759 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 1760 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 1761 | // library. |
| 1762 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1763 | cc_library { |
| 1764 | name: "libvndk", |
| 1765 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1766 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1767 | vndk: { |
| 1768 | enabled: true, |
| 1769 | }, |
| 1770 | nocrt: true, |
| 1771 | } |
| 1772 | |
| 1773 | cc_library { |
| 1774 | name: "libvndk_sp", |
| 1775 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1776 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1777 | vndk: { |
| 1778 | enabled: true, |
| 1779 | support_system_process: true, |
| 1780 | }, |
| 1781 | nocrt: true, |
| 1782 | } |
| 1783 | |
| 1784 | cc_library { |
| 1785 | name: "libvndk_sp_ext", |
| 1786 | vendor: true, |
| 1787 | vndk: { |
| 1788 | enabled: true, |
| 1789 | extends: "libvndk_sp", |
| 1790 | support_system_process: true, |
| 1791 | }, |
| 1792 | shared_libs: ["libvndk"], // Cause an error |
| 1793 | nocrt: true, |
| 1794 | } |
| 1795 | `) |
| 1796 | |
| 1797 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 1798 | // library. |
| 1799 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1800 | cc_library { |
| 1801 | name: "libvndk", |
| 1802 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1803 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1804 | vndk: { |
| 1805 | enabled: true, |
| 1806 | }, |
| 1807 | nocrt: true, |
| 1808 | } |
| 1809 | |
| 1810 | cc_library { |
| 1811 | name: "libvndk_ext", |
| 1812 | vendor: true, |
| 1813 | vndk: { |
| 1814 | enabled: true, |
| 1815 | extends: "libvndk", |
| 1816 | }, |
| 1817 | nocrt: true, |
| 1818 | } |
| 1819 | |
| 1820 | cc_library { |
| 1821 | name: "libvndk_sp", |
| 1822 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1823 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1824 | vndk: { |
| 1825 | enabled: true, |
| 1826 | support_system_process: true, |
| 1827 | }, |
| 1828 | nocrt: true, |
| 1829 | } |
| 1830 | |
| 1831 | cc_library { |
| 1832 | name: "libvndk_sp_ext", |
| 1833 | vendor: true, |
| 1834 | vndk: { |
| 1835 | enabled: true, |
| 1836 | extends: "libvndk_sp", |
| 1837 | support_system_process: true, |
| 1838 | }, |
| 1839 | shared_libs: ["libvndk_ext"], // Cause an error |
| 1840 | nocrt: true, |
| 1841 | } |
| 1842 | `) |
| 1843 | } |
| 1844 | |
| 1845 | func TestVndkUseVndkExtError(t *testing.T) { |
| 1846 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 1847 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1848 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1849 | cc_library { |
| 1850 | name: "libvndk", |
| 1851 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1852 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1853 | vndk: { |
| 1854 | enabled: true, |
| 1855 | }, |
| 1856 | nocrt: true, |
| 1857 | } |
| 1858 | |
| 1859 | cc_library { |
| 1860 | name: "libvndk_ext", |
| 1861 | vendor: true, |
| 1862 | vndk: { |
| 1863 | enabled: true, |
| 1864 | extends: "libvndk", |
| 1865 | }, |
| 1866 | nocrt: true, |
| 1867 | } |
| 1868 | |
| 1869 | cc_library { |
| 1870 | name: "libvndk2", |
| 1871 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1872 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1873 | vndk: { |
| 1874 | enabled: true, |
| 1875 | }, |
| 1876 | shared_libs: ["libvndk_ext"], |
| 1877 | nocrt: true, |
| 1878 | } |
| 1879 | `) |
| 1880 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1881 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1882 | cc_library { |
| 1883 | name: "libvndk", |
| 1884 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1885 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1886 | vndk: { |
| 1887 | enabled: true, |
| 1888 | }, |
| 1889 | nocrt: true, |
| 1890 | } |
| 1891 | |
| 1892 | cc_library { |
| 1893 | name: "libvndk_ext", |
| 1894 | vendor: true, |
| 1895 | vndk: { |
| 1896 | enabled: true, |
| 1897 | extends: "libvndk", |
| 1898 | }, |
| 1899 | nocrt: true, |
| 1900 | } |
| 1901 | |
| 1902 | cc_library { |
| 1903 | name: "libvndk2", |
| 1904 | vendor_available: true, |
| 1905 | vndk: { |
| 1906 | enabled: true, |
| 1907 | }, |
| 1908 | target: { |
| 1909 | vendor: { |
| 1910 | shared_libs: ["libvndk_ext"], |
| 1911 | }, |
| 1912 | }, |
| 1913 | nocrt: true, |
| 1914 | } |
| 1915 | `) |
| 1916 | |
| 1917 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1918 | cc_library { |
| 1919 | name: "libvndk_sp", |
| 1920 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1921 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1922 | vndk: { |
| 1923 | enabled: true, |
| 1924 | support_system_process: true, |
| 1925 | }, |
| 1926 | nocrt: true, |
| 1927 | } |
| 1928 | |
| 1929 | cc_library { |
| 1930 | name: "libvndk_sp_ext", |
| 1931 | vendor: true, |
| 1932 | vndk: { |
| 1933 | enabled: true, |
| 1934 | extends: "libvndk_sp", |
| 1935 | support_system_process: true, |
| 1936 | }, |
| 1937 | nocrt: true, |
| 1938 | } |
| 1939 | |
| 1940 | cc_library { |
| 1941 | name: "libvndk_sp_2", |
| 1942 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1943 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1944 | vndk: { |
| 1945 | enabled: true, |
| 1946 | support_system_process: true, |
| 1947 | }, |
| 1948 | shared_libs: ["libvndk_sp_ext"], |
| 1949 | nocrt: true, |
| 1950 | } |
| 1951 | `) |
| 1952 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1953 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1954 | cc_library { |
| 1955 | name: "libvndk_sp", |
| 1956 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1957 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1958 | vndk: { |
| 1959 | enabled: true, |
| 1960 | }, |
| 1961 | nocrt: true, |
| 1962 | } |
| 1963 | |
| 1964 | cc_library { |
| 1965 | name: "libvndk_sp_ext", |
| 1966 | vendor: true, |
| 1967 | vndk: { |
| 1968 | enabled: true, |
| 1969 | extends: "libvndk_sp", |
| 1970 | }, |
| 1971 | nocrt: true, |
| 1972 | } |
| 1973 | |
| 1974 | cc_library { |
| 1975 | name: "libvndk_sp2", |
| 1976 | vendor_available: true, |
| 1977 | vndk: { |
| 1978 | enabled: true, |
| 1979 | }, |
| 1980 | target: { |
| 1981 | vendor: { |
| 1982 | shared_libs: ["libvndk_sp_ext"], |
| 1983 | }, |
| 1984 | }, |
| 1985 | nocrt: true, |
| 1986 | } |
| 1987 | `) |
| 1988 | } |
| 1989 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1990 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 1991 | bp := ` |
| 1992 | cc_library { |
| 1993 | name: "libllndk", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1994 | llndk_stubs: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1995 | } |
| 1996 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1997 | name: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1998 | symbol_file: "", |
| 1999 | } |
| 2000 | cc_library { |
| 2001 | name: "libvndk", |
| 2002 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2003 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2004 | vndk: { |
| 2005 | enabled: true, |
| 2006 | }, |
| 2007 | nocrt: true, |
| 2008 | } |
| 2009 | cc_library { |
| 2010 | name: "libvndk_sp", |
| 2011 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2012 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2013 | vndk: { |
| 2014 | enabled: true, |
| 2015 | support_system_process: true, |
| 2016 | }, |
| 2017 | nocrt: true, |
| 2018 | } |
| 2019 | cc_library { |
| 2020 | name: "libva", |
| 2021 | vendor_available: true, |
| 2022 | nocrt: true, |
| 2023 | } |
| 2024 | cc_library { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2025 | name: "libpa", |
| 2026 | product_available: true, |
| 2027 | nocrt: true, |
| 2028 | } |
| 2029 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2030 | name: "libboth_available", |
| 2031 | vendor_available: true, |
| 2032 | product_available: true, |
| 2033 | nocrt: true, |
| 2034 | target: { |
| 2035 | vendor: { |
| 2036 | suffix: "-vendor", |
| 2037 | }, |
| 2038 | product: { |
| 2039 | suffix: "-product", |
| 2040 | }, |
| 2041 | } |
| 2042 | } |
| 2043 | cc_library { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2044 | name: "libproduct_va", |
| 2045 | product_specific: true, |
| 2046 | vendor_available: true, |
| 2047 | nocrt: true, |
| 2048 | } |
| 2049 | cc_library { |
| 2050 | name: "libprod", |
| 2051 | product_specific: true, |
| 2052 | shared_libs: [ |
| 2053 | "libllndk", |
| 2054 | "libvndk", |
| 2055 | "libvndk_sp", |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2056 | "libpa", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2057 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2058 | "libproduct_va", |
| 2059 | ], |
| 2060 | nocrt: true, |
| 2061 | } |
| 2062 | cc_library { |
| 2063 | name: "libvendor", |
| 2064 | vendor: true, |
| 2065 | shared_libs: [ |
| 2066 | "libllndk", |
| 2067 | "libvndk", |
| 2068 | "libvndk_sp", |
| 2069 | "libva", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2070 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2071 | "libproduct_va", |
| 2072 | ], |
| 2073 | nocrt: true, |
| 2074 | } |
| 2075 | ` |
| 2076 | |
| 2077 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2078 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2079 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2080 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2081 | |
| 2082 | ctx := testCcWithConfig(t, config) |
| 2083 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 2084 | checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant) |
| 2085 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2086 | |
| 2087 | mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module) |
| 2088 | assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so") |
| 2089 | |
| 2090 | mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module) |
| 2091 | assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 2095 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2096 | cc_library { |
| 2097 | name: "libprod", |
| 2098 | product_specific: true, |
| 2099 | shared_libs: [ |
| 2100 | "libvendor", |
| 2101 | ], |
| 2102 | nocrt: true, |
| 2103 | } |
| 2104 | cc_library { |
| 2105 | name: "libvendor", |
| 2106 | vendor: true, |
| 2107 | nocrt: true, |
| 2108 | } |
| 2109 | `) |
| 2110 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2111 | cc_library { |
| 2112 | name: "libprod", |
| 2113 | product_specific: true, |
| 2114 | shared_libs: [ |
| 2115 | "libsystem", |
| 2116 | ], |
| 2117 | nocrt: true, |
| 2118 | } |
| 2119 | cc_library { |
| 2120 | name: "libsystem", |
| 2121 | nocrt: true, |
| 2122 | } |
| 2123 | `) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2124 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2125 | cc_library { |
| 2126 | name: "libprod", |
| 2127 | product_specific: true, |
| 2128 | shared_libs: [ |
| 2129 | "libva", |
| 2130 | ], |
| 2131 | nocrt: true, |
| 2132 | } |
| 2133 | cc_library { |
| 2134 | name: "libva", |
| 2135 | vendor_available: true, |
| 2136 | nocrt: true, |
| 2137 | } |
| 2138 | `) |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2139 | 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] | 2140 | cc_library { |
| 2141 | name: "libprod", |
| 2142 | product_specific: true, |
| 2143 | shared_libs: [ |
| 2144 | "libvndk_private", |
| 2145 | ], |
| 2146 | nocrt: true, |
| 2147 | } |
| 2148 | cc_library { |
| 2149 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2150 | vendor_available: true, |
| 2151 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2152 | vndk: { |
| 2153 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2154 | private: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2155 | }, |
| 2156 | nocrt: true, |
| 2157 | } |
| 2158 | `) |
| 2159 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2160 | cc_library { |
| 2161 | name: "libprod", |
| 2162 | product_specific: true, |
| 2163 | shared_libs: [ |
| 2164 | "libsystem_ext", |
| 2165 | ], |
| 2166 | nocrt: true, |
| 2167 | } |
| 2168 | cc_library { |
| 2169 | name: "libsystem_ext", |
| 2170 | system_ext_specific: true, |
| 2171 | nocrt: true, |
| 2172 | } |
| 2173 | `) |
| 2174 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2175 | cc_library { |
| 2176 | name: "libsystem", |
| 2177 | shared_libs: [ |
| 2178 | "libproduct_va", |
| 2179 | ], |
| 2180 | nocrt: true, |
| 2181 | } |
| 2182 | cc_library { |
| 2183 | name: "libproduct_va", |
| 2184 | product_specific: true, |
| 2185 | vendor_available: true, |
| 2186 | nocrt: true, |
| 2187 | } |
| 2188 | `) |
| 2189 | } |
| 2190 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2191 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2192 | bp := ` |
| 2193 | cc_library { |
| 2194 | name: "libvndk", |
| 2195 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2196 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2197 | vndk: { |
| 2198 | enabled: true, |
| 2199 | }, |
| 2200 | } |
| 2201 | cc_library { |
| 2202 | name: "libvndksp", |
| 2203 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2204 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2205 | vndk: { |
| 2206 | enabled: true, |
| 2207 | support_system_process: true, |
| 2208 | }, |
| 2209 | } |
| 2210 | cc_library { |
| 2211 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2212 | vendor_available: true, |
| 2213 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2214 | vndk: { |
| 2215 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2216 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2217 | }, |
| 2218 | } |
| 2219 | cc_library { |
| 2220 | name: "libvendor", |
| 2221 | vendor: true, |
| 2222 | } |
| 2223 | cc_library { |
| 2224 | name: "libvndkext", |
| 2225 | vendor: true, |
| 2226 | vndk: { |
| 2227 | enabled: true, |
| 2228 | extends: "libvndk", |
| 2229 | }, |
| 2230 | } |
| 2231 | vndk_prebuilt_shared { |
| 2232 | name: "prevndk", |
| 2233 | version: "27", |
| 2234 | target_arch: "arm", |
| 2235 | binder32bit: true, |
| 2236 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2237 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2238 | vndk: { |
| 2239 | enabled: true, |
| 2240 | }, |
| 2241 | arch: { |
| 2242 | arm: { |
| 2243 | srcs: ["liba.so"], |
| 2244 | }, |
| 2245 | }, |
| 2246 | } |
| 2247 | cc_library { |
| 2248 | name: "libllndk", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2249 | llndk_stubs: "libllndk.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2250 | } |
| 2251 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2252 | name: "libllndk.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2253 | symbol_file: "", |
| 2254 | } |
| 2255 | cc_library { |
| 2256 | name: "libllndkprivate", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2257 | llndk_stubs: "libllndkprivate.llndk", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2258 | } |
| 2259 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2260 | name: "libllndkprivate.llndk", |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 2261 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2262 | symbol_file: "", |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | llndk_libraries_txt { |
| 2266 | name: "llndk.libraries.txt", |
| 2267 | } |
| 2268 | vndkcore_libraries_txt { |
| 2269 | name: "vndkcore.libraries.txt", |
| 2270 | } |
| 2271 | vndksp_libraries_txt { |
| 2272 | name: "vndksp.libraries.txt", |
| 2273 | } |
| 2274 | vndkprivate_libraries_txt { |
| 2275 | name: "vndkprivate.libraries.txt", |
| 2276 | } |
| 2277 | vndkcorevariant_libraries_txt { |
| 2278 | name: "vndkcorevariant.libraries.txt", |
| 2279 | insert_vndk_version: false, |
| 2280 | } |
| 2281 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2282 | |
| 2283 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2284 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2285 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2286 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2287 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2288 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2289 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", |
| 2290 | []string{"libvndk.so", "libvndkprivate.so"}) |
| 2291 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", |
| 2292 | []string{"libc++.so", "libvndksp.so"}) |
| 2293 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", |
| 2294 | []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"}) |
| 2295 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", |
| 2296 | []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2297 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2298 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2299 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2300 | tests := []struct { |
| 2301 | variant string |
| 2302 | name string |
| 2303 | expected string |
| 2304 | }{ |
| 2305 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2306 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2307 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2308 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2309 | {vendorVariant, "libvndkext", "native:vendor"}, |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2310 | {vendorVariant, "libllndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2311 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2312 | {coreVariant, "libvndk", "native:platform"}, |
| 2313 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2314 | {coreVariant, "libllndk", "native:platform"}, |
| 2315 | } |
| 2316 | for _, test := range tests { |
| 2317 | t.Run(test.name, func(t *testing.T) { |
| 2318 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2319 | assertString(t, module.makeLinkType, test.expected) |
| 2320 | }) |
| 2321 | } |
| 2322 | } |
| 2323 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2324 | var staticLinkDepOrderTestCases = []struct { |
| 2325 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2326 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2327 | inStatic string |
| 2328 | |
| 2329 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2330 | // It models the dependencies declared in an Android.bp file. |
| 2331 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2332 | |
| 2333 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2334 | // The keys of allOrdered specify which modules we would like to check. |
| 2335 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2336 | // dependencies) for each module to test |
| 2337 | allOrdered string |
| 2338 | |
| 2339 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2340 | // The keys of outOrdered specify which modules we would like to check. |
| 2341 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2342 | // for each module to test. |
| 2343 | outOrdered string |
| 2344 | }{ |
| 2345 | // Simple tests |
| 2346 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2347 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2348 | outOrdered: "", |
| 2349 | }, |
| 2350 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2351 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2352 | outOrdered: "a:", |
| 2353 | }, |
| 2354 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2355 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2356 | outOrdered: "a:b; b:", |
| 2357 | }, |
| 2358 | // Tests of reordering |
| 2359 | { |
| 2360 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2361 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2362 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2363 | }, |
| 2364 | { |
| 2365 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2366 | 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] | 2367 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2368 | }, |
| 2369 | { |
| 2370 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2371 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2372 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2373 | }, |
| 2374 | { |
| 2375 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2376 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2377 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2378 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2379 | }, |
| 2380 | { |
| 2381 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2382 | 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] | 2383 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2384 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2385 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2386 | // shared dependencies |
| 2387 | { |
| 2388 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2389 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2390 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2391 | // a shared dependency on b, that that shows up in allOrdered. |
| 2392 | inShared: "c:b", |
| 2393 | allOrdered: "c:b", |
| 2394 | outOrdered: "c:", |
| 2395 | }, |
| 2396 | { |
| 2397 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2398 | // the second phase of the above test would look like |
| 2399 | inStatic: "a:b,c; c:b", |
| 2400 | allOrdered: "a:c,b; c:b", |
| 2401 | outOrdered: "a:c,b; c:b", |
| 2402 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2403 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2404 | // to dictate an order |
| 2405 | { |
| 2406 | // 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] | 2407 | 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] | 2408 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2409 | }, |
| 2410 | { |
| 2411 | // 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] | 2412 | 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] | 2413 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2414 | }, |
| 2415 | // Tests involving duplicate dependencies |
| 2416 | { |
| 2417 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2418 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2419 | outOrdered: "a:c,b", |
| 2420 | }, |
| 2421 | { |
| 2422 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2423 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2424 | outOrdered: "a:d,c,b", |
| 2425 | }, |
| 2426 | // Tests to confirm the nonexistence of infinite loops. |
| 2427 | // These cases should never happen, so as long as the test terminates and the |
| 2428 | // result is deterministic then that should be fine. |
| 2429 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2430 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2431 | outOrdered: "a:a", |
| 2432 | }, |
| 2433 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2434 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2435 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2436 | outOrdered: "a:b; b:c; c:a", |
| 2437 | }, |
| 2438 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2439 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2440 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2441 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2442 | }, |
| 2443 | } |
| 2444 | |
| 2445 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2446 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2447 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2448 | strippedText := strings.Replace(text, " ", "", -1) |
| 2449 | if len(strippedText) < 1 { |
| 2450 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2451 | } |
| 2452 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2453 | |
| 2454 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2455 | moduleTexts := strings.Split(strippedText, ";") |
| 2456 | |
| 2457 | outputForModuleName := func(moduleName string) android.Path { |
| 2458 | return android.PathForTesting(moduleName) |
| 2459 | } |
| 2460 | |
| 2461 | for _, moduleText := range moduleTexts { |
| 2462 | // convert from "a:b,c" to ["a", "b,c"] |
| 2463 | components := strings.Split(moduleText, ":") |
| 2464 | if len(components) != 2 { |
| 2465 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2466 | } |
| 2467 | moduleName := components[0] |
| 2468 | moduleOutput := outputForModuleName(moduleName) |
| 2469 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2470 | |
| 2471 | depString := components[1] |
| 2472 | // convert from "b,c" to ["b", "c"] |
| 2473 | depNames := strings.Split(depString, ",") |
| 2474 | if len(depString) < 1 { |
| 2475 | depNames = []string{} |
| 2476 | } |
| 2477 | var deps []android.Path |
| 2478 | for _, depName := range depNames { |
| 2479 | deps = append(deps, outputForModuleName(depName)) |
| 2480 | } |
| 2481 | allDeps[moduleOutput] = deps |
| 2482 | } |
| 2483 | return modulesInOrder, allDeps |
| 2484 | } |
| 2485 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2486 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 2487 | for _, moduleName := range moduleNames { |
| 2488 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 2489 | output := module.outputFile.Path() |
| 2490 | paths = append(paths, output) |
| 2491 | } |
| 2492 | return paths |
| 2493 | } |
| 2494 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2495 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2496 | ctx := testCc(t, ` |
| 2497 | cc_library { |
| 2498 | name: "a", |
| 2499 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2500 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2501 | } |
| 2502 | cc_library { |
| 2503 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2504 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2505 | } |
| 2506 | cc_library { |
| 2507 | name: "c", |
| 2508 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2509 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2510 | } |
| 2511 | cc_library { |
| 2512 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2513 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | `) |
| 2517 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2518 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2519 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2520 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 2521 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2522 | |
| 2523 | if !reflect.DeepEqual(actual, expected) { |
| 2524 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2525 | "\nactual: %v"+ |
| 2526 | "\nexpected: %v", |
| 2527 | actual, |
| 2528 | expected, |
| 2529 | ) |
| 2530 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2531 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2532 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2533 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 2534 | ctx := testCc(t, ` |
| 2535 | cc_library { |
| 2536 | name: "a", |
| 2537 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2538 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2539 | } |
| 2540 | cc_library { |
| 2541 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2542 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2543 | } |
| 2544 | cc_library { |
| 2545 | name: "c", |
| 2546 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2547 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | `) |
| 2551 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2552 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2553 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2554 | actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList() |
| 2555 | expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2556 | |
| 2557 | if !reflect.DeepEqual(actual, expected) { |
| 2558 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2559 | "\nactual: %v"+ |
| 2560 | "\nexpected: %v", |
| 2561 | actual, |
| 2562 | expected, |
| 2563 | ) |
| 2564 | } |
| 2565 | } |
| 2566 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2567 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2568 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2569 | if !reflect.DeepEqual(actual, expected) { |
| 2570 | t.Errorf(message+ |
| 2571 | "\nactual: %v"+ |
| 2572 | "\nexpected: %v", |
| 2573 | actual, |
| 2574 | expected, |
| 2575 | ) |
| 2576 | } |
| 2577 | } |
| 2578 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2579 | func TestLlndkLibrary(t *testing.T) { |
| 2580 | ctx := testCc(t, ` |
| 2581 | cc_library { |
| 2582 | name: "libllndk", |
| 2583 | stubs: { versions: ["1", "2"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2584 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2585 | } |
| 2586 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2587 | name: "libllndk.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2588 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2589 | |
| 2590 | cc_prebuilt_library_shared { |
| 2591 | name: "libllndkprebuilt", |
| 2592 | stubs: { versions: ["1", "2"] }, |
| 2593 | llndk_stubs: "libllndkprebuilt.llndk", |
| 2594 | } |
| 2595 | llndk_library { |
| 2596 | name: "libllndkprebuilt.llndk", |
| 2597 | } |
| 2598 | |
| 2599 | cc_library { |
| 2600 | name: "libllndk_with_external_headers", |
| 2601 | stubs: { versions: ["1", "2"] }, |
| 2602 | llndk_stubs: "libllndk_with_external_headers.llndk", |
| 2603 | header_libs: ["libexternal_headers"], |
| 2604 | export_header_lib_headers: ["libexternal_headers"], |
| 2605 | } |
| 2606 | llndk_library { |
| 2607 | name: "libllndk_with_external_headers.llndk", |
| 2608 | } |
| 2609 | cc_library_headers { |
| 2610 | name: "libexternal_headers", |
| 2611 | export_include_dirs: ["include"], |
| 2612 | vendor_available: true, |
| 2613 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2614 | `) |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2615 | actual := ctx.ModuleVariantsForTests("libllndk") |
| 2616 | for i := 0; i < len(actual); i++ { |
| 2617 | if !strings.HasPrefix(actual[i], "android_vendor.VER_") { |
| 2618 | actual = append(actual[:i], actual[i+1:]...) |
| 2619 | i-- |
| 2620 | } |
| 2621 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2622 | expected := []string{ |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2623 | "android_vendor.VER_arm64_armv8-a_shared_1", |
| 2624 | "android_vendor.VER_arm64_armv8-a_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2625 | "android_vendor.VER_arm64_armv8-a_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2626 | "android_vendor.VER_arm_armv7-a-neon_shared_1", |
| 2627 | "android_vendor.VER_arm_armv7-a-neon_shared_2", |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 2628 | "android_vendor.VER_arm_armv7-a-neon_shared", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2629 | } |
| 2630 | checkEquals(t, "variants for llndk stubs", expected, actual) |
| 2631 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2632 | 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] | 2633 | checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) |
| 2634 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2635 | 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] | 2636 | checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"]) |
| 2637 | } |
| 2638 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2639 | func TestLlndkHeaders(t *testing.T) { |
| 2640 | ctx := testCc(t, ` |
| 2641 | llndk_headers { |
| 2642 | name: "libllndk_headers", |
| 2643 | export_include_dirs: ["my_include"], |
| 2644 | } |
| 2645 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2646 | name: "libllndk.llndk", |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2647 | export_llndk_headers: ["libllndk_headers"], |
| 2648 | } |
| 2649 | cc_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2650 | name: "libllndk", |
| 2651 | llndk_stubs: "libllndk.llndk", |
| 2652 | } |
| 2653 | |
| 2654 | cc_library { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2655 | name: "libvendor", |
| 2656 | shared_libs: ["libllndk"], |
| 2657 | vendor: true, |
| 2658 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2659 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2660 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2661 | } |
| 2662 | `) |
| 2663 | |
| 2664 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2665 | 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] | 2666 | cflags := cc.Args["cFlags"] |
| 2667 | if !strings.Contains(cflags, "-Imy_include") { |
| 2668 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2669 | } |
| 2670 | } |
| 2671 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2672 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2673 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2674 | if !reflect.DeepEqual(actual, expected) { |
| 2675 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2676 | "\nactual: %v"+ |
| 2677 | "\nexpected: %v", |
| 2678 | actual, |
| 2679 | expected, |
| 2680 | ) |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | const runtimeLibAndroidBp = ` |
| 2685 | cc_library { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2686 | name: "liball_available", |
| 2687 | vendor_available: true, |
| 2688 | product_available: true, |
| 2689 | no_libcrt : true, |
| 2690 | nocrt : true, |
| 2691 | system_shared_libs : [], |
| 2692 | } |
| 2693 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2694 | name: "libvendor_available1", |
| 2695 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2696 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2697 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2698 | nocrt : true, |
| 2699 | system_shared_libs : [], |
| 2700 | } |
| 2701 | cc_library { |
| 2702 | name: "libvendor_available2", |
| 2703 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2704 | runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2705 | target: { |
| 2706 | vendor: { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2707 | exclude_runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2708 | } |
| 2709 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2710 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2711 | nocrt : true, |
| 2712 | system_shared_libs : [], |
| 2713 | } |
| 2714 | cc_library { |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2715 | name: "libproduct_vendor", |
| 2716 | product_specific: true, |
| 2717 | vendor_available: true, |
| 2718 | no_libcrt : true, |
| 2719 | nocrt : true, |
| 2720 | system_shared_libs : [], |
| 2721 | } |
| 2722 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2723 | name: "libcore", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2724 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2725 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2726 | nocrt : true, |
| 2727 | system_shared_libs : [], |
| 2728 | } |
| 2729 | cc_library { |
| 2730 | name: "libvendor1", |
| 2731 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2732 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2733 | nocrt : true, |
| 2734 | system_shared_libs : [], |
| 2735 | } |
| 2736 | cc_library { |
| 2737 | name: "libvendor2", |
| 2738 | vendor: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2739 | runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"], |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2740 | no_libcrt : true, |
| 2741 | nocrt : true, |
| 2742 | system_shared_libs : [], |
| 2743 | } |
| 2744 | cc_library { |
| 2745 | name: "libproduct_available1", |
| 2746 | product_available: true, |
| 2747 | runtime_libs: ["liball_available"], |
| 2748 | no_libcrt : true, |
| 2749 | nocrt : true, |
| 2750 | system_shared_libs : [], |
| 2751 | } |
| 2752 | cc_library { |
| 2753 | name: "libproduct1", |
| 2754 | product_specific: true, |
| 2755 | no_libcrt : true, |
| 2756 | nocrt : true, |
| 2757 | system_shared_libs : [], |
| 2758 | } |
| 2759 | cc_library { |
| 2760 | name: "libproduct2", |
| 2761 | product_specific: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2762 | runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2763 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2764 | nocrt : true, |
| 2765 | system_shared_libs : [], |
| 2766 | } |
| 2767 | ` |
| 2768 | |
| 2769 | func TestRuntimeLibs(t *testing.T) { |
| 2770 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2771 | |
| 2772 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2773 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2774 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2775 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2776 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
| 2777 | |
| 2778 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2779 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2780 | |
| 2781 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2782 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2783 | |
| 2784 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2785 | // and vendor variants. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2786 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2787 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2788 | module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2789 | checkRuntimeLibs(t, []string{"liball_available.vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2790 | |
| 2791 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2792 | checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2793 | |
| 2794 | // runtime_libs for product variants have '.product' suffixes if the modules have both core |
| 2795 | // and product variants. |
| 2796 | variant = "android_product.VER_arm64_armv8-a_shared" |
| 2797 | |
| 2798 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2799 | checkRuntimeLibs(t, []string{"liball_available.product"}, module) |
| 2800 | |
| 2801 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2802 | checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor.product"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 2806 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2807 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2808 | variant := "android_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2809 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2810 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2811 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2812 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2813 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2814 | checkRuntimeLibs(t, nil, module) |
| 2815 | } |
| 2816 | |
| 2817 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 2818 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 2819 | |
| 2820 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 2821 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2822 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2823 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2824 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2825 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2826 | |
| 2827 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2828 | checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2829 | |
| 2830 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame^] | 2831 | checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2832 | } |
| 2833 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2834 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2835 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2836 | actual := module.Properties.AndroidMkStaticLibs |
| 2837 | if !reflect.DeepEqual(actual, expected) { |
| 2838 | t.Errorf("incorrect static_libs"+ |
| 2839 | "\nactual: %v"+ |
| 2840 | "\nexpected: %v", |
| 2841 | actual, |
| 2842 | expected, |
| 2843 | ) |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | const staticLibAndroidBp = ` |
| 2848 | cc_library { |
| 2849 | name: "lib1", |
| 2850 | } |
| 2851 | cc_library { |
| 2852 | name: "lib2", |
| 2853 | static_libs: ["lib1"], |
| 2854 | } |
| 2855 | ` |
| 2856 | |
| 2857 | func TestStaticLibDepExport(t *testing.T) { |
| 2858 | ctx := testCc(t, staticLibAndroidBp) |
| 2859 | |
| 2860 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2861 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2862 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2863 | 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] | 2864 | |
| 2865 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2866 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2867 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2868 | // libc++_static is linked additionally. |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2869 | 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] | 2870 | } |
| 2871 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2872 | var compilerFlagsTestCases = []struct { |
| 2873 | in string |
| 2874 | out bool |
| 2875 | }{ |
| 2876 | { |
| 2877 | in: "a", |
| 2878 | out: false, |
| 2879 | }, |
| 2880 | { |
| 2881 | in: "-a", |
| 2882 | out: true, |
| 2883 | }, |
| 2884 | { |
| 2885 | in: "-Ipath/to/something", |
| 2886 | out: false, |
| 2887 | }, |
| 2888 | { |
| 2889 | in: "-isystempath/to/something", |
| 2890 | out: false, |
| 2891 | }, |
| 2892 | { |
| 2893 | in: "--coverage", |
| 2894 | out: false, |
| 2895 | }, |
| 2896 | { |
| 2897 | in: "-include a/b", |
| 2898 | out: true, |
| 2899 | }, |
| 2900 | { |
| 2901 | in: "-include a/b c/d", |
| 2902 | out: false, |
| 2903 | }, |
| 2904 | { |
| 2905 | in: "-DMACRO", |
| 2906 | out: true, |
| 2907 | }, |
| 2908 | { |
| 2909 | in: "-DMAC RO", |
| 2910 | out: false, |
| 2911 | }, |
| 2912 | { |
| 2913 | in: "-a -b", |
| 2914 | out: false, |
| 2915 | }, |
| 2916 | { |
| 2917 | in: "-DMACRO=definition", |
| 2918 | out: true, |
| 2919 | }, |
| 2920 | { |
| 2921 | in: "-DMACRO=defi nition", |
| 2922 | out: true, // TODO(jiyong): this should be false |
| 2923 | }, |
| 2924 | { |
| 2925 | in: "-DMACRO(x)=x + 1", |
| 2926 | out: true, |
| 2927 | }, |
| 2928 | { |
| 2929 | in: "-DMACRO=\"defi nition\"", |
| 2930 | out: true, |
| 2931 | }, |
| 2932 | } |
| 2933 | |
| 2934 | type mockContext struct { |
| 2935 | BaseModuleContext |
| 2936 | result bool |
| 2937 | } |
| 2938 | |
| 2939 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 2940 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 2941 | ctx.result = false |
| 2942 | } |
| 2943 | |
| 2944 | func TestCompilerFlags(t *testing.T) { |
| 2945 | for _, testCase := range compilerFlagsTestCases { |
| 2946 | ctx := &mockContext{result: true} |
| 2947 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 2948 | if ctx.result != testCase.out { |
| 2949 | t.Errorf("incorrect output:") |
| 2950 | t.Errorf(" input: %#v", testCase.in) |
| 2951 | t.Errorf(" expected: %#v", testCase.out) |
| 2952 | t.Errorf(" got: %#v", ctx.result) |
| 2953 | } |
| 2954 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2955 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2956 | |
| 2957 | func TestVendorPublicLibraries(t *testing.T) { |
| 2958 | ctx := testCc(t, ` |
| 2959 | cc_library_headers { |
| 2960 | name: "libvendorpublic_headers", |
| 2961 | export_include_dirs: ["my_include"], |
| 2962 | } |
| 2963 | vendor_public_library { |
| 2964 | name: "libvendorpublic", |
| 2965 | symbol_file: "", |
| 2966 | export_public_headers: ["libvendorpublic_headers"], |
| 2967 | } |
| 2968 | cc_library { |
| 2969 | name: "libvendorpublic", |
| 2970 | srcs: ["foo.c"], |
| 2971 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2972 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2973 | nocrt: true, |
| 2974 | } |
| 2975 | |
| 2976 | cc_library { |
| 2977 | name: "libsystem", |
| 2978 | shared_libs: ["libvendorpublic"], |
| 2979 | vendor: false, |
| 2980 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2981 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2982 | nocrt: true, |
| 2983 | } |
| 2984 | cc_library { |
| 2985 | name: "libvendor", |
| 2986 | shared_libs: ["libvendorpublic"], |
| 2987 | vendor: true, |
| 2988 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2989 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2990 | nocrt: true, |
| 2991 | } |
| 2992 | `) |
| 2993 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2994 | coreVariant := "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2995 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2996 | |
| 2997 | // test if header search paths are correctly added |
| 2998 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2999 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3000 | cflags := cc.Args["cFlags"] |
| 3001 | if !strings.Contains(cflags, "-Imy_include") { |
| 3002 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 3003 | } |
| 3004 | |
| 3005 | // test if libsystem is linked to the stub |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3006 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3007 | libflags := ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3008 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3009 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3010 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3011 | } |
| 3012 | |
| 3013 | // test if libvendor is linked to the real shared lib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3014 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3015 | libflags = ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3016 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3017 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 3018 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 3019 | } |
| 3020 | |
| 3021 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3022 | |
| 3023 | func TestRecovery(t *testing.T) { |
| 3024 | ctx := testCc(t, ` |
| 3025 | cc_library_shared { |
| 3026 | name: "librecovery", |
| 3027 | recovery: true, |
| 3028 | } |
| 3029 | cc_library_shared { |
| 3030 | name: "librecovery32", |
| 3031 | recovery: true, |
| 3032 | compile_multilib:"32", |
| 3033 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3034 | cc_library_shared { |
| 3035 | name: "libHalInRecovery", |
| 3036 | recovery_available: true, |
| 3037 | vendor: true, |
| 3038 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3039 | `) |
| 3040 | |
| 3041 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3042 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3043 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3044 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3045 | } |
| 3046 | |
| 3047 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3048 | if android.InList(arm64, variants) { |
| 3049 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3050 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3051 | |
| 3052 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3053 | if !recoveryModule.Platform() { |
| 3054 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3055 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3056 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3057 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3058 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
| 3059 | bp := ` |
| 3060 | cc_prebuilt_test_library_shared { |
| 3061 | name: "test_lib", |
| 3062 | relative_install_path: "foo/bar/baz", |
| 3063 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3064 | } |
| 3065 | |
| 3066 | cc_test { |
| 3067 | name: "main_test", |
| 3068 | data_libs: ["test_lib"], |
| 3069 | gtest: false, |
| 3070 | } |
| 3071 | ` |
| 3072 | |
| 3073 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3074 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 3075 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 3076 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3077 | |
| 3078 | ctx := testCcWithConfig(t, config) |
| 3079 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3080 | testBinary := module.(*Module).linker.(*testBinary) |
| 3081 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3082 | if err != nil { |
| 3083 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3084 | } |
| 3085 | if len(outputFiles) != 1 { |
| 3086 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3087 | } |
| 3088 | if len(testBinary.dataPaths()) != 1 { |
| 3089 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 3090 | } |
| 3091 | |
| 3092 | outputPath := outputFiles[0].String() |
| 3093 | |
| 3094 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3095 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3096 | } |
| 3097 | entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] |
| 3098 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3099 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3100 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3101 | } |
| 3102 | } |
| 3103 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3104 | func TestVersionedStubs(t *testing.T) { |
| 3105 | ctx := testCc(t, ` |
| 3106 | cc_library_shared { |
| 3107 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3108 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3109 | stubs: { |
| 3110 | symbol_file: "foo.map.txt", |
| 3111 | versions: ["1", "2", "3"], |
| 3112 | }, |
| 3113 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3114 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3115 | cc_library_shared { |
| 3116 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3117 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3118 | shared_libs: ["libFoo#1"], |
| 3119 | }`) |
| 3120 | |
| 3121 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3122 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3123 | "android_arm64_armv8-a_shared", |
| 3124 | "android_arm64_armv8-a_shared_1", |
| 3125 | "android_arm64_armv8-a_shared_2", |
| 3126 | "android_arm64_armv8-a_shared_3", |
| 3127 | "android_arm_armv7-a-neon_shared", |
| 3128 | "android_arm_armv7-a-neon_shared_1", |
| 3129 | "android_arm_armv7-a-neon_shared_2", |
| 3130 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3131 | } |
| 3132 | variantsMismatch := false |
| 3133 | if len(variants) != len(expectedVariants) { |
| 3134 | variantsMismatch = true |
| 3135 | } else { |
| 3136 | for _, v := range expectedVariants { |
| 3137 | if !inList(v, variants) { |
| 3138 | variantsMismatch = false |
| 3139 | } |
| 3140 | } |
| 3141 | } |
| 3142 | if variantsMismatch { |
| 3143 | t.Errorf("variants of libFoo expected:\n") |
| 3144 | for _, v := range expectedVariants { |
| 3145 | t.Errorf("%q\n", v) |
| 3146 | } |
| 3147 | t.Errorf(", but got:\n") |
| 3148 | for _, v := range variants { |
| 3149 | t.Errorf("%q\n", v) |
| 3150 | } |
| 3151 | } |
| 3152 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3153 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3154 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3155 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3156 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 3157 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 3158 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3159 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3160 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3161 | cFlags := libBarCompileRule.Args["cFlags"] |
| 3162 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 3163 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 3164 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 3165 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3166 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3167 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3168 | func TestVersioningMacro(t *testing.T) { |
| 3169 | for _, tc := range []struct{ moduleName, expected string }{ |
| 3170 | {"libc", "__LIBC_API__"}, |
| 3171 | {"libfoo", "__LIBFOO_API__"}, |
| 3172 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 3173 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 3174 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 3175 | } { |
| 3176 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 3177 | } |
| 3178 | } |
| 3179 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3180 | func TestStaticExecutable(t *testing.T) { |
| 3181 | ctx := testCc(t, ` |
| 3182 | cc_binary { |
| 3183 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 3184 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3185 | static_executable: true, |
| 3186 | }`) |
| 3187 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3188 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3189 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 3190 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 3191 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3192 | for _, lib := range systemStaticLibs { |
| 3193 | if !strings.Contains(libFlags, lib) { |
| 3194 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 3195 | } |
| 3196 | } |
| 3197 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 3198 | for _, lib := range systemSharedLibs { |
| 3199 | if strings.Contains(libFlags, lib) { |
| 3200 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 3201 | } |
| 3202 | } |
| 3203 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3204 | |
| 3205 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
| 3206 | ctx := testCc(t, ` |
| 3207 | cc_binary { |
| 3208 | name: "mybin", |
| 3209 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3210 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3211 | static_executable: true, |
| 3212 | stl: "none", |
| 3213 | } |
| 3214 | |
| 3215 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3216 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3217 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3218 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3219 | stl: "none", |
| 3220 | } |
| 3221 | |
| 3222 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3223 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3224 | srcs: ["foo.c"], |
| 3225 | stl: "none", |
| 3226 | stubs: { |
| 3227 | versions: ["1"], |
| 3228 | }, |
| 3229 | }`) |
| 3230 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3231 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 3232 | actual := mybin.Implicits[:2] |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3233 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3234 | |
| 3235 | if !reflect.DeepEqual(actual, expected) { |
| 3236 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3237 | "\nactual: %v"+ |
| 3238 | "\nexpected: %v", |
| 3239 | actual, |
| 3240 | expected, |
| 3241 | ) |
| 3242 | } |
| 3243 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3244 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3245 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
| 3246 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 3247 | cc_library { |
| 3248 | name: "libA", |
| 3249 | srcs: ["foo.c"], |
| 3250 | shared_libs: ["libB"], |
| 3251 | stl: "none", |
| 3252 | } |
| 3253 | |
| 3254 | cc_library { |
| 3255 | name: "libB", |
| 3256 | srcs: ["foo.c"], |
| 3257 | enabled: false, |
| 3258 | stl: "none", |
| 3259 | } |
| 3260 | `) |
| 3261 | } |
| 3262 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3263 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 3264 | // correctly. |
| 3265 | func TestFuzzTarget(t *testing.T) { |
| 3266 | ctx := testCc(t, ` |
| 3267 | cc_fuzz { |
| 3268 | name: "fuzz_smoke_test", |
| 3269 | srcs: ["foo.c"], |
| 3270 | }`) |
| 3271 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 3272 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3273 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 3274 | } |
| 3275 | |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 3276 | func TestAidl(t *testing.T) { |
| 3277 | } |
| 3278 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3279 | func assertString(t *testing.T, got, expected string) { |
| 3280 | t.Helper() |
| 3281 | if got != expected { |
| 3282 | t.Errorf("expected %q got %q", expected, got) |
| 3283 | } |
| 3284 | } |
| 3285 | |
| 3286 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3287 | t.Helper() |
| 3288 | if len(got) != len(expected) { |
| 3289 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3290 | return |
| 3291 | } |
| 3292 | for i := range got { |
| 3293 | if got[i] != expected[i] { |
| 3294 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3295 | i, expected[i], expected, got[i], got) |
| 3296 | return |
| 3297 | } |
| 3298 | } |
| 3299 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3300 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3301 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 3302 | t.Helper() |
| 3303 | assertArrayString(t, android.SortedStringKeys(m), expected) |
| 3304 | } |
| 3305 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3306 | func TestDefaults(t *testing.T) { |
| 3307 | ctx := testCc(t, ` |
| 3308 | cc_defaults { |
| 3309 | name: "defaults", |
| 3310 | srcs: ["foo.c"], |
| 3311 | static: { |
| 3312 | srcs: ["bar.c"], |
| 3313 | }, |
| 3314 | shared: { |
| 3315 | srcs: ["baz.c"], |
| 3316 | }, |
| 3317 | } |
| 3318 | |
| 3319 | cc_library_static { |
| 3320 | name: "libstatic", |
| 3321 | defaults: ["defaults"], |
| 3322 | } |
| 3323 | |
| 3324 | cc_library_shared { |
| 3325 | name: "libshared", |
| 3326 | defaults: ["defaults"], |
| 3327 | } |
| 3328 | |
| 3329 | cc_library { |
| 3330 | name: "libboth", |
| 3331 | defaults: ["defaults"], |
| 3332 | } |
| 3333 | |
| 3334 | cc_binary { |
| 3335 | name: "binary", |
| 3336 | defaults: ["defaults"], |
| 3337 | }`) |
| 3338 | |
| 3339 | pathsToBase := func(paths android.Paths) []string { |
| 3340 | var ret []string |
| 3341 | for _, p := range paths { |
| 3342 | ret = append(ret, p.Base()) |
| 3343 | } |
| 3344 | return ret |
| 3345 | } |
| 3346 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3347 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3348 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3349 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 3350 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3351 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3352 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3353 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 3354 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3355 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3356 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 3357 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 3358 | } |
| 3359 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3360 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3361 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3362 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 3363 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3364 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3365 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3366 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 3367 | } |
| 3368 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3369 | |
| 3370 | func TestProductVariableDefaults(t *testing.T) { |
| 3371 | bp := ` |
| 3372 | cc_defaults { |
| 3373 | name: "libfoo_defaults", |
| 3374 | srcs: ["foo.c"], |
| 3375 | cppflags: ["-DFOO"], |
| 3376 | product_variables: { |
| 3377 | debuggable: { |
| 3378 | cppflags: ["-DBAR"], |
| 3379 | }, |
| 3380 | }, |
| 3381 | } |
| 3382 | |
| 3383 | cc_library { |
| 3384 | name: "libfoo", |
| 3385 | defaults: ["libfoo_defaults"], |
| 3386 | } |
| 3387 | ` |
| 3388 | |
| 3389 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3390 | config.TestProductVariables.Debuggable = BoolPtr(true) |
| 3391 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 3392 | ctx := CreateTestContext(config) |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3393 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 3394 | ctx.BottomUp("variable", android.VariableMutator).Parallel() |
| 3395 | }) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 3396 | ctx.Register() |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3397 | |
| 3398 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 3399 | android.FailIfErrored(t, errs) |
| 3400 | _, errs = ctx.PrepareBuildActions(config) |
| 3401 | android.FailIfErrored(t, errs) |
| 3402 | |
| 3403 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 3404 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { |
| 3405 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) |
| 3406 | } |
| 3407 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3408 | |
| 3409 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 3410 | t.Parallel() |
| 3411 | bp := ` |
| 3412 | cc_library_static { |
| 3413 | name: "libfoo", |
| 3414 | srcs: ["foo.c"], |
| 3415 | whole_static_libs: ["libbar"], |
| 3416 | } |
| 3417 | |
| 3418 | cc_library_static { |
| 3419 | name: "libbar", |
| 3420 | whole_static_libs: ["libmissing"], |
| 3421 | } |
| 3422 | ` |
| 3423 | |
| 3424 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3425 | config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true) |
| 3426 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 3427 | ctx := CreateTestContext(config) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3428 | ctx.SetAllowMissingDependencies(true) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 3429 | ctx.Register() |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3430 | |
| 3431 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 3432 | android.FailIfErrored(t, errs) |
| 3433 | _, errs = ctx.PrepareBuildActions(config) |
| 3434 | android.FailIfErrored(t, errs) |
| 3435 | |
| 3436 | libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
| 3437 | if g, w := libbar.Rule, android.ErrorRule; g != w { |
| 3438 | t.Fatalf("Expected libbar rule to be %q, got %q", w, g) |
| 3439 | } |
| 3440 | |
| 3441 | if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) { |
| 3442 | t.Errorf("Expected libbar error to contain %q, was %q", w, g) |
| 3443 | } |
| 3444 | |
| 3445 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
| 3446 | if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) { |
| 3447 | t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g) |
| 3448 | } |
| 3449 | |
| 3450 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 3451 | |
| 3452 | func TestInstallSharedLibs(t *testing.T) { |
| 3453 | bp := ` |
| 3454 | cc_binary { |
| 3455 | name: "bin", |
| 3456 | host_supported: true, |
| 3457 | shared_libs: ["libshared"], |
| 3458 | runtime_libs: ["libruntime"], |
| 3459 | srcs: [":gen"], |
| 3460 | } |
| 3461 | |
| 3462 | cc_library_shared { |
| 3463 | name: "libshared", |
| 3464 | host_supported: true, |
| 3465 | shared_libs: ["libtransitive"], |
| 3466 | } |
| 3467 | |
| 3468 | cc_library_shared { |
| 3469 | name: "libtransitive", |
| 3470 | host_supported: true, |
| 3471 | } |
| 3472 | |
| 3473 | cc_library_shared { |
| 3474 | name: "libruntime", |
| 3475 | host_supported: true, |
| 3476 | } |
| 3477 | |
| 3478 | cc_binary_host { |
| 3479 | name: "tool", |
| 3480 | srcs: ["foo.cpp"], |
| 3481 | } |
| 3482 | |
| 3483 | genrule { |
| 3484 | name: "gen", |
| 3485 | tools: ["tool"], |
| 3486 | out: ["gen.cpp"], |
| 3487 | cmd: "$(location tool) $(out)", |
| 3488 | } |
| 3489 | ` |
| 3490 | |
| 3491 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3492 | ctx := testCcWithConfig(t, config) |
| 3493 | |
| 3494 | hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install") |
| 3495 | hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3496 | hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3497 | hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3498 | hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install") |
| 3499 | |
| 3500 | if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) { |
| 3501 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3502 | } |
| 3503 | |
| 3504 | if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 3505 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3506 | } |
| 3507 | |
| 3508 | if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 3509 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3510 | } |
| 3511 | |
| 3512 | if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) { |
| 3513 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3514 | } |
| 3515 | |
| 3516 | if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 3517 | t.Errorf("expected no host bin dependency %q, got %q", w, g) |
| 3518 | } |
| 3519 | |
| 3520 | deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install") |
| 3521 | deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install") |
| 3522 | deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install") |
| 3523 | deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install") |
| 3524 | |
| 3525 | if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) { |
| 3526 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3527 | } |
| 3528 | |
| 3529 | if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 3530 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3531 | } |
| 3532 | |
| 3533 | if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 3534 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3535 | } |
| 3536 | |
| 3537 | if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) { |
| 3538 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3539 | } |
| 3540 | |
| 3541 | if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 3542 | t.Errorf("expected no device bin dependency %q, got %q", w, g) |
| 3543 | } |
| 3544 | |
| 3545 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 3546 | |
| 3547 | func TestStubsLibReexportsHeaders(t *testing.T) { |
| 3548 | ctx := testCc(t, ` |
| 3549 | cc_library_shared { |
| 3550 | name: "libclient", |
| 3551 | srcs: ["foo.c"], |
| 3552 | shared_libs: ["libfoo#1"], |
| 3553 | } |
| 3554 | |
| 3555 | cc_library_shared { |
| 3556 | name: "libfoo", |
| 3557 | srcs: ["foo.c"], |
| 3558 | shared_libs: ["libbar"], |
| 3559 | export_shared_lib_headers: ["libbar"], |
| 3560 | stubs: { |
| 3561 | symbol_file: "foo.map.txt", |
| 3562 | versions: ["1", "2", "3"], |
| 3563 | }, |
| 3564 | } |
| 3565 | |
| 3566 | cc_library_shared { |
| 3567 | name: "libbar", |
| 3568 | export_include_dirs: ["include/libbar"], |
| 3569 | srcs: ["foo.c"], |
| 3570 | }`) |
| 3571 | |
| 3572 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 3573 | |
| 3574 | if !strings.Contains(cFlags, "-Iinclude/libbar") { |
| 3575 | t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) |
| 3576 | } |
| 3577 | } |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 3578 | |
| 3579 | func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { |
| 3580 | ctx := testCc(t, ` |
| 3581 | cc_library { |
| 3582 | name: "libfoo", |
| 3583 | srcs: ["a/Foo.aidl"], |
| 3584 | aidl: { flags: ["-Werror"], }, |
| 3585 | } |
| 3586 | `) |
| 3587 | |
| 3588 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
| 3589 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 3590 | aidlCommand := manifest.Commands[0].GetCommand() |
| 3591 | expectedAidlFlag := "-Werror" |
| 3592 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 3593 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 3594 | } |
| 3595 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3596 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3597 | type MemtagNoteType int |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3598 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3599 | const ( |
| 3600 | None MemtagNoteType = iota + 1 |
| 3601 | Sync |
| 3602 | Async |
| 3603 | ) |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3604 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3605 | func (t MemtagNoteType) str() string { |
| 3606 | switch t { |
| 3607 | case None: |
| 3608 | return "none" |
| 3609 | case Sync: |
| 3610 | return "sync" |
| 3611 | case Async: |
| 3612 | return "async" |
| 3613 | default: |
| 3614 | panic("invalid note type") |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3615 | } |
| 3616 | } |
| 3617 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3618 | func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) { |
| 3619 | note_async := "note_memtag_heap_async" |
| 3620 | note_sync := "note_memtag_heap_sync" |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3621 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3622 | found := None |
| 3623 | implicits := m.Rule("ld").Implicits |
| 3624 | for _, lib := range implicits { |
| 3625 | if strings.Contains(lib.Rel(), note_async) { |
| 3626 | found = Async |
| 3627 | break |
| 3628 | } else if strings.Contains(lib.Rel(), note_sync) { |
| 3629 | found = Sync |
| 3630 | break |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3631 | } |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3632 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3633 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3634 | if found != expected { |
| 3635 | t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str()) |
| 3636 | } |
| 3637 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3638 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3639 | func makeMemtagTestConfig(t *testing.T) android.Config { |
| 3640 | templateBp := ` |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3641 | cc_test { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3642 | name: "%[1]s_test", |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3643 | gtest: false, |
| 3644 | } |
| 3645 | |
| 3646 | cc_test { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3647 | name: "%[1]s_test_false", |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3648 | gtest: false, |
| 3649 | sanitize: { memtag_heap: false }, |
| 3650 | } |
| 3651 | |
| 3652 | cc_test { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3653 | name: "%[1]s_test_true", |
| 3654 | gtest: false, |
| 3655 | sanitize: { memtag_heap: true }, |
| 3656 | } |
| 3657 | |
| 3658 | cc_test { |
| 3659 | name: "%[1]s_test_true_nodiag", |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3660 | gtest: false, |
| 3661 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 3662 | } |
| 3663 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3664 | cc_test { |
| 3665 | name: "%[1]s_test_true_diag", |
| 3666 | gtest: false, |
| 3667 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 3668 | } |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3669 | |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3670 | cc_binary { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3671 | name: "%[1]s_binary", |
| 3672 | } |
| 3673 | |
| 3674 | cc_binary { |
| 3675 | name: "%[1]s_binary_false", |
| 3676 | sanitize: { memtag_heap: false }, |
| 3677 | } |
| 3678 | |
| 3679 | cc_binary { |
| 3680 | name: "%[1]s_binary_true", |
| 3681 | sanitize: { memtag_heap: true }, |
| 3682 | } |
| 3683 | |
| 3684 | cc_binary { |
| 3685 | name: "%[1]s_binary_true_nodiag", |
| 3686 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 3687 | } |
| 3688 | |
| 3689 | cc_binary { |
| 3690 | name: "%[1]s_binary_true_diag", |
| 3691 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3692 | } |
| 3693 | ` |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3694 | subdirDefaultBp := fmt.Sprintf(templateBp, "default") |
| 3695 | subdirExcludeBp := fmt.Sprintf(templateBp, "exclude") |
| 3696 | subdirSyncBp := fmt.Sprintf(templateBp, "sync") |
| 3697 | subdirAsyncBp := fmt.Sprintf(templateBp, "async") |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3698 | |
| 3699 | mockFS := map[string][]byte{ |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3700 | "subdir_default/Android.bp": []byte(subdirDefaultBp), |
| 3701 | "subdir_exclude/Android.bp": []byte(subdirExcludeBp), |
| 3702 | "subdir_sync/Android.bp": []byte(subdirSyncBp), |
| 3703 | "subdir_async/Android.bp": []byte(subdirAsyncBp), |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3704 | } |
| 3705 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3706 | return TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 3707 | } |
| 3708 | |
| 3709 | func TestSanitizeMemtagHeap(t *testing.T) { |
| 3710 | variant := "android_arm64_armv8-a" |
| 3711 | |
| 3712 | config := makeMemtagTestConfig(t) |
| 3713 | config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3714 | config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"} |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3715 | config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"} |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3716 | ctx := CreateTestContext(config) |
| 3717 | ctx.Register() |
| 3718 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3719 | _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"}) |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3720 | android.FailIfErrored(t, errs) |
| 3721 | _, errs = ctx.PrepareBuildActions(config) |
| 3722 | android.FailIfErrored(t, errs) |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3723 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3724 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) |
| 3725 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) |
| 3726 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async) |
| 3727 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async) |
| 3728 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync) |
| 3729 | |
| 3730 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None) |
| 3731 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None) |
| 3732 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async) |
| 3733 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async) |
| 3734 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync) |
| 3735 | |
| 3736 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync) |
| 3737 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None) |
| 3738 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async) |
| 3739 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async) |
| 3740 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync) |
| 3741 | |
| 3742 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None) |
| 3743 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None) |
| 3744 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async) |
| 3745 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async) |
| 3746 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync) |
| 3747 | |
| 3748 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync) |
| 3749 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None) |
| 3750 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async) |
| 3751 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async) |
| 3752 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync) |
| 3753 | |
| 3754 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async) |
| 3755 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None) |
| 3756 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async) |
| 3757 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async) |
| 3758 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync) |
| 3759 | |
| 3760 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync) |
| 3761 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None) |
| 3762 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync) |
| 3763 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async) |
| 3764 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync) |
| 3765 | |
| 3766 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync) |
| 3767 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None) |
| 3768 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync) |
| 3769 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async) |
| 3770 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync) |
| 3771 | } |
| 3772 | |
| 3773 | func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) { |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3774 | variant := "android_arm64_armv8-a" |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3775 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3776 | config := makeMemtagTestConfig(t) |
| 3777 | config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} |
| 3778 | config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"} |
| 3779 | config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"} |
| 3780 | config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"} |
| 3781 | ctx := CreateTestContext(config) |
| 3782 | ctx.Register() |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3783 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3784 | _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"}) |
| 3785 | android.FailIfErrored(t, errs) |
| 3786 | _, errs = ctx.PrepareBuildActions(config) |
| 3787 | android.FailIfErrored(t, errs) |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3788 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3789 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) |
| 3790 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) |
| 3791 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async) |
| 3792 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async) |
| 3793 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync) |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 3794 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 3795 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async) |
| 3796 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None) |
| 3797 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async) |
| 3798 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async) |
| 3799 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync) |
| 3800 | |
| 3801 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync) |
| 3802 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None) |
| 3803 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async) |
| 3804 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async) |
| 3805 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync) |
| 3806 | |
| 3807 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None) |
| 3808 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None) |
| 3809 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async) |
| 3810 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async) |
| 3811 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync) |
| 3812 | |
| 3813 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync) |
| 3814 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None) |
| 3815 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async) |
| 3816 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async) |
| 3817 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync) |
| 3818 | |
| 3819 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async) |
| 3820 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None) |
| 3821 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async) |
| 3822 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async) |
| 3823 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync) |
| 3824 | |
| 3825 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync) |
| 3826 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None) |
| 3827 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync) |
| 3828 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async) |
| 3829 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync) |
| 3830 | |
| 3831 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync) |
| 3832 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None) |
| 3833 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync) |
| 3834 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async) |
| 3835 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync) |
| 3836 | } |
| 3837 | |
| 3838 | func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) { |
| 3839 | variant := "android_arm64_armv8-a" |
| 3840 | |
| 3841 | config := makeMemtagTestConfig(t) |
| 3842 | config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} |
| 3843 | config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"} |
| 3844 | config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"} |
| 3845 | config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"} |
| 3846 | config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"} |
| 3847 | ctx := CreateTestContext(config) |
| 3848 | ctx.Register() |
| 3849 | |
| 3850 | _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"}) |
| 3851 | android.FailIfErrored(t, errs) |
| 3852 | _, errs = ctx.PrepareBuildActions(config) |
| 3853 | android.FailIfErrored(t, errs) |
| 3854 | |
| 3855 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) |
| 3856 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) |
| 3857 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync) |
| 3858 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async) |
| 3859 | checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync) |
| 3860 | |
| 3861 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync) |
| 3862 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None) |
| 3863 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync) |
| 3864 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async) |
| 3865 | checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync) |
| 3866 | |
| 3867 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync) |
| 3868 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None) |
| 3869 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync) |
| 3870 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async) |
| 3871 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync) |
| 3872 | |
| 3873 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None) |
| 3874 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None) |
| 3875 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync) |
| 3876 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async) |
| 3877 | checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync) |
| 3878 | |
| 3879 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync) |
| 3880 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None) |
| 3881 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync) |
| 3882 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async) |
| 3883 | checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync) |
| 3884 | |
| 3885 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync) |
| 3886 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None) |
| 3887 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync) |
| 3888 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async) |
| 3889 | checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync) |
| 3890 | |
| 3891 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync) |
| 3892 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None) |
| 3893 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync) |
| 3894 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async) |
| 3895 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync) |
| 3896 | |
| 3897 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync) |
| 3898 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None) |
| 3899 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync) |
| 3900 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async) |
| 3901 | checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync) |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3902 | } |