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