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