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