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