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