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" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 23 | "runtime" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 24 | "strings" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 25 | "testing" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 26 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 27 | "android/soong/aidl_library" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 28 | "android/soong/android" |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 29 | "android/soong/bazel/cquery" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 32 | func init() { |
| 33 | registerTestMutators(android.InitRegistrationContext) |
| 34 | } |
| 35 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 36 | func TestMain(m *testing.M) { |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 37 | os.Exit(m.Run()) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 38 | } |
| 39 | |
Paul Duffin | 2e6f90e | 2021-03-22 23:20:25 +0000 | [diff] [blame] | 40 | var prepareForCcTest = android.GroupFixturePreparers( |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 41 | PrepareForTestWithCcIncludeVndk, |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 42 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame^] | 43 | variables.VendorApiLevel = StringPtr("202404") |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 44 | variables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 45 | variables.Platform_vndk_version = StringPtr("29") |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 46 | }), |
| 47 | ) |
| 48 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 49 | var ccLibInApex = "cc_lib_in_apex" |
| 50 | var apexVariationName = "apex28" |
| 51 | var apexVersion = "28" |
| 52 | |
| 53 | func registerTestMutators(ctx android.RegistrationContext) { |
| 54 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 55 | ctx.BottomUp("apex", testApexMutator).Parallel() |
| 56 | ctx.BottomUp("mixed_builds_prep", mixedBuildsPrepareMutator).Parallel() |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | func mixedBuildsPrepareMutator(ctx android.BottomUpMutatorContext) { |
| 61 | if m := ctx.Module(); m.Enabled() { |
| 62 | if mixedBuildMod, ok := m.(android.MixedBuildBuildable); ok { |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 63 | if mixedBuildMod.IsMixedBuildSupported(ctx) && android.MixedBuildsEnabled(ctx) == android.MixedBuildEnabled { |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 64 | mixedBuildMod.QueueBazelCall(ctx) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func testApexMutator(mctx android.BottomUpMutatorContext) { |
| 71 | modules := mctx.CreateVariations(apexVariationName) |
| 72 | apexInfo := android.ApexInfo{ |
| 73 | ApexVariationName: apexVariationName, |
| 74 | MinSdkVersion: android.ApiLevelForTest(apexVersion), |
| 75 | } |
| 76 | mctx.SetVariationProvider(modules[0], android.ApexInfoProvider, apexInfo) |
| 77 | } |
| 78 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 79 | // testCcWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 80 | // |
| 81 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 82 | // |
| 83 | // deprecated |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 84 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 85 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 86 | result := prepareForCcTest.RunTestWithConfig(t, config) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 87 | return result.TestContext |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 90 | // testCc runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 91 | // |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 92 | // 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] | 93 | // easier to customize the test behavior. |
| 94 | // |
| 95 | // 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] | 96 | // 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] | 97 | // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify |
| 98 | // that it did not change the test behavior unexpectedly. |
| 99 | // |
| 100 | // deprecated |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 101 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 102 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 103 | result := prepareForCcTest.RunTestWithBp(t, bp) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 104 | return result.TestContext |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 107 | // testCcErrorWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 108 | // |
| 109 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 110 | // |
| 111 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 112 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 113 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 114 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 115 | prepareForCcTest. |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 116 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 117 | RunTestWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 118 | } |
| 119 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 120 | // testCcError runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 121 | // |
| 122 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 123 | // |
| 124 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 125 | func testCcError(t *testing.T, pattern string, bp string) { |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 126 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 127 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 128 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 129 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 130 | testCcErrorWithConfig(t, pattern, config) |
| 131 | return |
| 132 | } |
| 133 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 134 | // testCcErrorProductVndk runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 135 | // |
| 136 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 137 | // |
| 138 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 139 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 140 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 141 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 142 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 143 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 144 | testCcErrorWithConfig(t, pattern, config) |
| 145 | return |
| 146 | } |
| 147 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 148 | const ( |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 149 | coreVariant = "android_arm64_armv8-a_shared" |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 150 | vendorVariant = "android_vendor.29_arm64_armv8-a_shared" |
| 151 | productVariant = "android_product.29_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 152 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 153 | ) |
| 154 | |
Paul Duffin | db462dd | 2021-03-21 22:01:55 +0000 | [diff] [blame] | 155 | // Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by |
| 156 | // running it in a fixture that requires all source files to exist. |
| 157 | func TestPrepareForTestWithCcDefaultModules(t *testing.T) { |
| 158 | android.GroupFixturePreparers( |
| 159 | PrepareForTestWithCcDefaultModules, |
| 160 | android.PrepareForTestDisallowNonExistentPaths, |
| 161 | ).RunTest(t) |
| 162 | } |
| 163 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 164 | func TestVendorSrc(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 165 | t.Parallel() |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 166 | ctx := testCc(t, ` |
| 167 | cc_library { |
| 168 | name: "libTest", |
| 169 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 170 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 171 | nocrt: true, |
| 172 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 173 | vendor_available: true, |
| 174 | target: { |
| 175 | vendor: { |
| 176 | srcs: ["bar.c"], |
| 177 | }, |
| 178 | }, |
| 179 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 180 | `) |
| 181 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 182 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 183 | var objs []string |
| 184 | for _, o := range ld.Inputs { |
| 185 | objs = append(objs, o.Base()) |
| 186 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 187 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 188 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 189 | } |
| 190 | } |
| 191 | |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 192 | func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) { |
| 193 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
| 194 | partitionDefined := false |
| 195 | checkPartition := func(specific bool, partition string) { |
| 196 | if specific { |
| 197 | if expected != partition && !partitionDefined { |
| 198 | // The variant is installed to the 'partition' |
| 199 | t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition) |
| 200 | } |
| 201 | partitionDefined = true |
| 202 | } else { |
| 203 | // The variant is not installed to the 'partition' |
| 204 | if expected == partition { |
| 205 | t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition) |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | socSpecific := func(m *Module) bool { |
| 210 | return m.SocSpecific() || m.socSpecificModuleContext() |
| 211 | } |
| 212 | deviceSpecific := func(m *Module) bool { |
| 213 | return m.DeviceSpecific() || m.deviceSpecificModuleContext() |
| 214 | } |
| 215 | productSpecific := func(m *Module) bool { |
| 216 | return m.ProductSpecific() || m.productSpecificModuleContext() |
| 217 | } |
| 218 | systemExtSpecific := func(m *Module) bool { |
| 219 | return m.SystemExtSpecific() |
| 220 | } |
| 221 | checkPartition(socSpecific(mod), "vendor") |
| 222 | checkPartition(deviceSpecific(mod), "odm") |
| 223 | checkPartition(productSpecific(mod), "product") |
| 224 | checkPartition(systemExtSpecific(mod), "system_ext") |
| 225 | if !partitionDefined && expected != "system" { |
| 226 | t.Errorf("%s variant of %q is expected to be installed to %s partition,"+ |
| 227 | " but installed to system partition", variant, name, expected) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func TestInstallPartition(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 232 | t.Parallel() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 233 | t.Helper() |
| 234 | ctx := prepareForCcTest.RunTestWithBp(t, ` |
| 235 | cc_library { |
| 236 | name: "libsystem", |
| 237 | } |
| 238 | cc_library { |
| 239 | name: "libsystem_ext", |
| 240 | system_ext_specific: true, |
| 241 | } |
| 242 | cc_library { |
| 243 | name: "libproduct", |
| 244 | product_specific: true, |
| 245 | } |
| 246 | cc_library { |
| 247 | name: "libvendor", |
| 248 | vendor: true, |
| 249 | } |
| 250 | cc_library { |
| 251 | name: "libodm", |
| 252 | device_specific: true, |
| 253 | } |
| 254 | cc_library { |
| 255 | name: "liball_available", |
| 256 | vendor_available: true, |
| 257 | product_available: true, |
| 258 | } |
| 259 | cc_library { |
| 260 | name: "libsystem_ext_all_available", |
| 261 | system_ext_specific: true, |
| 262 | vendor_available: true, |
| 263 | product_available: true, |
| 264 | } |
| 265 | cc_library { |
| 266 | name: "liball_available_odm", |
| 267 | odm_available: true, |
| 268 | product_available: true, |
| 269 | } |
| 270 | cc_library { |
| 271 | name: "libproduct_vendoravailable", |
| 272 | product_specific: true, |
| 273 | vendor_available: true, |
| 274 | } |
| 275 | cc_library { |
| 276 | name: "libproduct_odmavailable", |
| 277 | product_specific: true, |
| 278 | odm_available: true, |
| 279 | } |
| 280 | `).TestContext |
| 281 | |
| 282 | checkInstallPartition(t, ctx, "libsystem", coreVariant, "system") |
| 283 | checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext") |
| 284 | checkInstallPartition(t, ctx, "libproduct", productVariant, "product") |
| 285 | checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor") |
| 286 | checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm") |
| 287 | |
| 288 | checkInstallPartition(t, ctx, "liball_available", coreVariant, "system") |
| 289 | checkInstallPartition(t, ctx, "liball_available", productVariant, "product") |
| 290 | checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor") |
| 291 | |
| 292 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext") |
| 293 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product") |
| 294 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor") |
| 295 | |
| 296 | checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system") |
| 297 | checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product") |
| 298 | checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm") |
| 299 | |
| 300 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product") |
| 301 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor") |
| 302 | |
| 303 | checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product") |
| 304 | checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm") |
| 305 | } |
| 306 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 307 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 308 | isVndkSp bool, extends string, variant string) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 309 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 310 | t.Helper() |
| 311 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 312 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 313 | |
| 314 | // Check library properties. |
| 315 | lib, ok := mod.compiler.(*libraryDecorator) |
| 316 | if !ok { |
| 317 | t.Errorf("%q must have libraryDecorator", name) |
| 318 | } else if lib.baseInstaller.subDir != subDir { |
| 319 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 320 | lib.baseInstaller.subDir) |
| 321 | } |
| 322 | |
| 323 | // Check VNDK properties. |
| 324 | if mod.vndkdep == nil { |
| 325 | t.Fatalf("%q must have `vndkdep`", name) |
| 326 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 327 | if !mod.IsVndk() { |
| 328 | t.Errorf("%q IsVndk() must equal to true", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 329 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 330 | if mod.IsVndkSp() != isVndkSp { |
| 331 | t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // Check VNDK extension properties. |
| 335 | isVndkExt := extends != "" |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 336 | if mod.IsVndkExt() != isVndkExt { |
| 337 | t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 341 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 342 | } |
| 343 | } |
| 344 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 345 | func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { |
| 346 | t.Helper() |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 347 | content := android.ContentFromFileRuleForTests(t, params) |
| 348 | actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 349 | assertArrayString(t, actual, expected) |
| 350 | } |
| 351 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 352 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { |
| 353 | t.Helper() |
| 354 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 355 | checkWriteFileOutput(t, vndkSnapshot.Output(output), expected) |
| 356 | } |
| 357 | |
| 358 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { |
| 359 | t.Helper() |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 360 | got := ctx.ModuleForTests(module, "android_common").Module().(*vndkLibrariesTxt).fileNames |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 361 | assertArrayString(t, got, expected) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 362 | } |
| 363 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 364 | func TestVndk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 365 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 366 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 367 | cc_library { |
| 368 | name: "libvndk", |
| 369 | vendor_available: true, |
| 370 | vndk: { |
| 371 | enabled: true, |
| 372 | }, |
| 373 | nocrt: true, |
| 374 | } |
| 375 | |
| 376 | cc_library { |
| 377 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 378 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 379 | vndk: { |
| 380 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 381 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 382 | }, |
| 383 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 384 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 388 | name: "libvndk_product", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 389 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 390 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 391 | vndk: { |
| 392 | enabled: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 393 | }, |
| 394 | nocrt: true, |
| 395 | target: { |
| 396 | vendor: { |
| 397 | cflags: ["-DTEST"], |
| 398 | }, |
| 399 | product: { |
| 400 | cflags: ["-DTEST"], |
| 401 | }, |
| 402 | }, |
| 403 | } |
| 404 | |
| 405 | cc_library { |
| 406 | name: "libvndk_sp", |
| 407 | vendor_available: true, |
| 408 | vndk: { |
| 409 | enabled: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 410 | support_system_process: true, |
| 411 | }, |
| 412 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 413 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | cc_library { |
| 417 | name: "libvndk_sp_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 418 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 419 | vndk: { |
| 420 | enabled: true, |
| 421 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 422 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 423 | }, |
| 424 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 425 | target: { |
| 426 | vendor: { |
| 427 | suffix: "-x", |
| 428 | }, |
| 429 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 430 | } |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 431 | |
| 432 | cc_library { |
| 433 | name: "libvndk_sp_product_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 434 | vendor_available: true, |
| 435 | product_available: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 436 | vndk: { |
| 437 | enabled: true, |
| 438 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 439 | private: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 440 | }, |
| 441 | nocrt: true, |
| 442 | target: { |
| 443 | vendor: { |
| 444 | suffix: "-x", |
| 445 | }, |
| 446 | product: { |
| 447 | suffix: "-x", |
| 448 | }, |
| 449 | }, |
| 450 | } |
| 451 | |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 452 | cc_library { |
| 453 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 454 | llndk: { |
| 455 | symbol_file: "libllndk.map.txt", |
| 456 | export_llndk_headers: ["libllndk_headers"], |
| 457 | } |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 458 | } |
| 459 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 460 | cc_library { |
| 461 | name: "libclang_rt.hwasan-llndk", |
| 462 | llndk: { |
| 463 | symbol_file: "libclang_rt.hwasan.map.txt", |
| 464 | } |
| 465 | } |
| 466 | |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 467 | cc_library_headers { |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 468 | name: "libllndk_headers", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 469 | llndk: { |
| 470 | llndk_headers: true, |
| 471 | }, |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 472 | export_include_dirs: ["include"], |
| 473 | } |
| 474 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 475 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 476 | name: "llndk.libraries.txt", |
| 477 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 478 | vndkcore_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 479 | name: "vndkcore.libraries.txt", |
| 480 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 481 | vndksp_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 482 | name: "vndksp.libraries.txt", |
| 483 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 484 | vndkprivate_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 485 | name: "vndkprivate.libraries.txt", |
| 486 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 487 | vndkproduct_libraries_txt { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 488 | name: "vndkproduct.libraries.txt", |
| 489 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 490 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 491 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 492 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 493 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 494 | ` |
| 495 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 496 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 497 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 498 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 499 | |
| 500 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 501 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 502 | // subdir == "" because VNDK libs are not supposed to be installed separately. |
| 503 | // They are installed as part of VNDK APEX instead. |
| 504 | checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant) |
| 505 | checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 506 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant) |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 507 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant) |
| 508 | checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 509 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 510 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 511 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant) |
| 512 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 513 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 514 | // Check VNDK snapshot output. |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 515 | snapshotDir := "vndk-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 516 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 517 | |
| 518 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 519 | "arm64", "armv8-a")) |
| 520 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 521 | "arm", "armv7-a-neon")) |
| 522 | |
| 523 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 524 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 525 | llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub") |
| 526 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 527 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 528 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 529 | llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 530 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 531 | variant := "android_vendor.29_arm64_armv8-a_shared" |
| 532 | variant2nd := "android_vendor.29_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 533 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 534 | snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") |
| 535 | |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 536 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 537 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
| 538 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant) |
| 539 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd) |
| 540 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 541 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
| 542 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant) |
| 543 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 544 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 545 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 546 | CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "android_common") |
| 547 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "android_common") |
| 548 | CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "android_common") |
| 549 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "android_common") |
| 550 | 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] | 551 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 552 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 553 | "LLNDK: libc.so", |
| 554 | "LLNDK: libdl.so", |
| 555 | "LLNDK: libft2.so", |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 556 | "LLNDK: libllndk.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 557 | "LLNDK: libm.so", |
| 558 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 559 | "VNDK-SP: libvndk_sp-x.so", |
| 560 | "VNDK-SP: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 561 | "VNDK-SP: libvndk_sp_product_private-x.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 562 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 563 | "VNDK-core: libvndk.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 564 | "VNDK-core: libvndk_product.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 565 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 566 | "VNDK-private: libvndk-private.so", |
| 567 | "VNDK-private: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 568 | "VNDK-private: libvndk_sp_product_private-x.so", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 569 | "VNDK-product: libc++.so", |
| 570 | "VNDK-product: libvndk_product.so", |
| 571 | "VNDK-product: libvndk_sp_product_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 572 | }) |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 573 | 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] | 574 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"}) |
| 575 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) |
| 576 | 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] | 577 | 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] | 578 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 579 | } |
| 580 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 581 | func TestVndkWithHostSupported(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 582 | t.Parallel() |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 583 | ctx := testCc(t, ` |
| 584 | cc_library { |
| 585 | name: "libvndk_host_supported", |
| 586 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 587 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 588 | vndk: { |
| 589 | enabled: true, |
| 590 | }, |
| 591 | host_supported: true, |
| 592 | } |
| 593 | |
| 594 | cc_library { |
| 595 | name: "libvndk_host_supported_but_disabled_on_device", |
| 596 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 597 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 598 | vndk: { |
| 599 | enabled: true, |
| 600 | }, |
| 601 | host_supported: true, |
| 602 | enabled: false, |
| 603 | target: { |
| 604 | host: { |
| 605 | enabled: true, |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 610 | vndkcore_libraries_txt { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 611 | name: "vndkcore.libraries.txt", |
| 612 | } |
| 613 | `) |
| 614 | |
| 615 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"}) |
| 616 | } |
| 617 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 618 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 619 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 620 | bp := ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 621 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 622 | name: "llndk.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 623 | insert_vndk_version: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 624 | }` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 625 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 626 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 627 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 628 | config.TestProductVariables.KeepVndk = BoolPtr(true) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 629 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 630 | |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 631 | module := ctx.ModuleForTests("llndk.libraries.txt", "android_common") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 632 | entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0] |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 633 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | func TestVndkUsingCoreVariant(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 637 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 638 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 639 | cc_library { |
| 640 | name: "libvndk", |
| 641 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 642 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 643 | vndk: { |
| 644 | enabled: true, |
| 645 | }, |
| 646 | nocrt: true, |
| 647 | } |
| 648 | |
| 649 | cc_library { |
| 650 | name: "libvndk_sp", |
| 651 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 652 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 653 | vndk: { |
| 654 | enabled: true, |
| 655 | support_system_process: true, |
| 656 | }, |
| 657 | nocrt: true, |
| 658 | } |
| 659 | |
| 660 | cc_library { |
| 661 | name: "libvndk2", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 662 | vendor_available: true, |
| 663 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 664 | vndk: { |
| 665 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 666 | private: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 667 | }, |
| 668 | nocrt: true, |
| 669 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 670 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 671 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 672 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 673 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 674 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 675 | ` |
| 676 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 677 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 678 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 679 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 680 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
Kiyoung Kim | 03b6cba | 2023-10-06 14:12:43 +0900 | [diff] [blame] | 681 | config.TestProductVariables.KeepVndk = BoolPtr(true) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 682 | |
| 683 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) |
| 684 | |
| 685 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 686 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 687 | 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] | 688 | } |
| 689 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 690 | func TestDataLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 691 | t.Parallel() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 692 | bp := ` |
| 693 | cc_test_library { |
| 694 | name: "test_lib", |
| 695 | srcs: ["test_lib.cpp"], |
| 696 | gtest: false, |
| 697 | } |
| 698 | |
| 699 | cc_test { |
| 700 | name: "main_test", |
| 701 | data_libs: ["test_lib"], |
| 702 | gtest: false, |
| 703 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 704 | ` |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 705 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 706 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 707 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 708 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 709 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 710 | |
| 711 | ctx := testCcWithConfig(t, config) |
| 712 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 713 | testBinary := module.(*Module).linker.(*testBinary) |
| 714 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 715 | if err != nil { |
| 716 | t.Errorf("Expected cc_test to produce output files, error: %s", err) |
| 717 | return |
| 718 | } |
| 719 | if len(outputFiles) != 1 { |
| 720 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 721 | return |
| 722 | } |
| 723 | if len(testBinary.dataPaths()) != 1 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 724 | t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths()) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 725 | return |
| 726 | } |
| 727 | |
| 728 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 729 | testBinaryPath := testBinary.dataPaths()[0].SrcPath.String() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 730 | |
| 731 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 732 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 733 | return |
| 734 | } |
| 735 | if !strings.HasSuffix(testBinaryPath, "/test_lib.so") { |
| 736 | t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath) |
| 737 | return |
| 738 | } |
| 739 | } |
| 740 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 741 | func TestDataLibsRelativeInstallPath(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 742 | t.Parallel() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 743 | bp := ` |
| 744 | cc_test_library { |
| 745 | name: "test_lib", |
| 746 | srcs: ["test_lib.cpp"], |
| 747 | relative_install_path: "foo/bar/baz", |
| 748 | gtest: false, |
| 749 | } |
| 750 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 751 | cc_binary { |
| 752 | name: "test_bin", |
| 753 | relative_install_path: "foo/bar/baz", |
| 754 | compile_multilib: "both", |
| 755 | } |
| 756 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 757 | cc_test { |
| 758 | name: "main_test", |
| 759 | data_libs: ["test_lib"], |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 760 | data_bins: ["test_bin"], |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 761 | gtest: false, |
| 762 | } |
| 763 | ` |
| 764 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 765 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 766 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 767 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 768 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 769 | |
| 770 | ctx := testCcWithConfig(t, config) |
| 771 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 772 | testBinary := module.(*Module).linker.(*testBinary) |
| 773 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 774 | if err != nil { |
| 775 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 776 | } |
| 777 | if len(outputFiles) != 1 { |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 778 | t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 779 | } |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 780 | if len(testBinary.dataPaths()) != 2 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 781 | t.Fatalf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths()) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 785 | |
| 786 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 787 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 788 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 789 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 790 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 791 | 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] | 792 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 793 | } |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 794 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][1], ":test_bin:foo/bar/baz") { |
| 795 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_bin:foo/bar/baz`,"+ |
| 796 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][1]) |
| 797 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 798 | } |
| 799 | |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 800 | func TestTestBinaryTestSuites(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 801 | t.Parallel() |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 802 | bp := ` |
| 803 | cc_test { |
| 804 | name: "main_test", |
| 805 | srcs: ["main_test.cpp"], |
| 806 | test_suites: [ |
| 807 | "suite_1", |
| 808 | "suite_2", |
| 809 | ], |
| 810 | gtest: false, |
| 811 | } |
| 812 | ` |
| 813 | |
| 814 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
| 815 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 816 | |
| 817 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
| 818 | compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"] |
| 819 | if len(compatEntries) != 2 { |
| 820 | t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries)) |
| 821 | } |
| 822 | if compatEntries[0] != "suite_1" { |
| 823 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+ |
| 824 | " but was '%s'", compatEntries[0]) |
| 825 | } |
| 826 | if compatEntries[1] != "suite_2" { |
| 827 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+ |
| 828 | " but was '%s'", compatEntries[1]) |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | func TestTestLibraryTestSuites(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 833 | t.Parallel() |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 834 | bp := ` |
| 835 | cc_test_library { |
| 836 | name: "main_test_lib", |
| 837 | srcs: ["main_test_lib.cpp"], |
| 838 | test_suites: [ |
| 839 | "suite_1", |
| 840 | "suite_2", |
| 841 | ], |
| 842 | gtest: false, |
| 843 | } |
| 844 | ` |
| 845 | |
| 846 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
| 847 | module := ctx.ModuleForTests("main_test_lib", "android_arm_armv7-a-neon_shared").Module() |
| 848 | |
| 849 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
| 850 | compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"] |
| 851 | if len(compatEntries) != 2 { |
| 852 | t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries)) |
| 853 | } |
| 854 | if compatEntries[0] != "suite_1" { |
| 855 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+ |
| 856 | " but was '%s'", compatEntries[0]) |
| 857 | } |
| 858 | if compatEntries[1] != "suite_2" { |
| 859 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+ |
| 860 | " but was '%s'", compatEntries[1]) |
| 861 | } |
| 862 | } |
| 863 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 864 | func TestVndkModuleError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 865 | t.Parallel() |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 866 | // Check the error message for vendor_available and product_available properties. |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 867 | 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] | 868 | cc_library { |
| 869 | name: "libvndk", |
| 870 | vndk: { |
| 871 | enabled: true, |
| 872 | }, |
| 873 | nocrt: true, |
| 874 | } |
| 875 | `) |
| 876 | |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 877 | 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] | 878 | cc_library { |
| 879 | name: "libvndk", |
| 880 | product_available: true, |
| 881 | vndk: { |
| 882 | enabled: true, |
| 883 | }, |
| 884 | nocrt: true, |
| 885 | } |
| 886 | `) |
| 887 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 888 | testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", ` |
| 889 | cc_library { |
| 890 | name: "libvndkprop", |
| 891 | vendor_available: true, |
| 892 | product_available: true, |
| 893 | vndk: { |
| 894 | enabled: true, |
| 895 | }, |
| 896 | nocrt: true, |
| 897 | target: { |
| 898 | vendor: { |
| 899 | cflags: ["-DTEST",], |
| 900 | }, |
| 901 | }, |
| 902 | } |
| 903 | `) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 904 | } |
| 905 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 906 | func TestVndkDepError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 907 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 908 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 909 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 910 | cc_library { |
| 911 | name: "libvndk", |
| 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 | }, |
| 917 | shared_libs: ["libfwk"], // Cause error |
| 918 | nocrt: true, |
| 919 | } |
| 920 | |
| 921 | cc_library { |
| 922 | name: "libfwk", |
| 923 | nocrt: true, |
| 924 | } |
| 925 | `) |
| 926 | |
| 927 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 928 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 929 | cc_library { |
| 930 | name: "libvndk", |
| 931 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 932 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 933 | vndk: { |
| 934 | enabled: true, |
| 935 | }, |
| 936 | shared_libs: ["libvendor"], // Cause error |
| 937 | nocrt: true, |
| 938 | } |
| 939 | |
| 940 | cc_library { |
| 941 | name: "libvendor", |
| 942 | vendor: true, |
| 943 | nocrt: true, |
| 944 | } |
| 945 | `) |
| 946 | |
| 947 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 948 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 949 | cc_library { |
| 950 | name: "libvndk_sp", |
| 951 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 952 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 953 | vndk: { |
| 954 | enabled: true, |
| 955 | support_system_process: true, |
| 956 | }, |
| 957 | shared_libs: ["libfwk"], // Cause error |
| 958 | nocrt: true, |
| 959 | } |
| 960 | |
| 961 | cc_library { |
| 962 | name: "libfwk", |
| 963 | nocrt: true, |
| 964 | } |
| 965 | `) |
| 966 | |
| 967 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 968 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 969 | cc_library { |
| 970 | name: "libvndk_sp", |
| 971 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 972 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 973 | vndk: { |
| 974 | enabled: true, |
| 975 | support_system_process: true, |
| 976 | }, |
| 977 | shared_libs: ["libvendor"], // Cause error |
| 978 | nocrt: true, |
| 979 | } |
| 980 | |
| 981 | cc_library { |
| 982 | name: "libvendor", |
| 983 | vendor: true, |
| 984 | nocrt: true, |
| 985 | } |
| 986 | `) |
| 987 | |
| 988 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 989 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 990 | cc_library { |
| 991 | name: "libvndk_sp", |
| 992 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 993 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 994 | vndk: { |
| 995 | enabled: true, |
| 996 | support_system_process: true, |
| 997 | }, |
| 998 | shared_libs: ["libvndk"], // Cause error |
| 999 | nocrt: true, |
| 1000 | } |
| 1001 | |
| 1002 | cc_library { |
| 1003 | name: "libvndk", |
| 1004 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1005 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1006 | vndk: { |
| 1007 | enabled: true, |
| 1008 | }, |
| 1009 | nocrt: true, |
| 1010 | } |
| 1011 | `) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1012 | |
| 1013 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. |
| 1014 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1015 | cc_library { |
| 1016 | name: "libvndk", |
| 1017 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1018 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1019 | vndk: { |
| 1020 | enabled: true, |
| 1021 | }, |
| 1022 | shared_libs: ["libnonvndk"], |
| 1023 | nocrt: true, |
| 1024 | } |
| 1025 | |
| 1026 | cc_library { |
| 1027 | name: "libnonvndk", |
| 1028 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 1029 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1030 | nocrt: true, |
| 1031 | } |
| 1032 | `) |
| 1033 | |
| 1034 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. |
| 1035 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1036 | cc_library { |
| 1037 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1038 | vendor_available: true, |
| 1039 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1040 | vndk: { |
| 1041 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1042 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1043 | }, |
| 1044 | shared_libs: ["libnonvndk"], |
| 1045 | nocrt: true, |
| 1046 | } |
| 1047 | |
| 1048 | cc_library { |
| 1049 | name: "libnonvndk", |
| 1050 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 1051 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1052 | nocrt: true, |
| 1053 | } |
| 1054 | `) |
| 1055 | |
| 1056 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. |
| 1057 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1058 | cc_library { |
| 1059 | name: "libvndksp", |
| 1060 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1061 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1062 | vndk: { |
| 1063 | enabled: true, |
| 1064 | support_system_process: true, |
| 1065 | }, |
| 1066 | shared_libs: ["libnonvndk"], |
| 1067 | nocrt: true, |
| 1068 | } |
| 1069 | |
| 1070 | cc_library { |
| 1071 | name: "libnonvndk", |
| 1072 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 1073 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1074 | nocrt: true, |
| 1075 | } |
| 1076 | `) |
| 1077 | |
| 1078 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. |
| 1079 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1080 | cc_library { |
| 1081 | name: "libvndkspprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1082 | vendor_available: true, |
| 1083 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1084 | vndk: { |
| 1085 | enabled: true, |
| 1086 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1087 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1088 | }, |
| 1089 | shared_libs: ["libnonvndk"], |
| 1090 | nocrt: true, |
| 1091 | } |
| 1092 | |
| 1093 | cc_library { |
| 1094 | name: "libnonvndk", |
| 1095 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 1096 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1097 | nocrt: true, |
| 1098 | } |
| 1099 | `) |
| 1100 | } |
| 1101 | |
| 1102 | func TestDoubleLoadbleDep(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1103 | t.Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1104 | // okay to link : LLNDK -> double_loadable VNDK |
| 1105 | testCc(t, ` |
| 1106 | cc_library { |
| 1107 | name: "libllndk", |
| 1108 | shared_libs: ["libdoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1109 | llndk: { |
| 1110 | symbol_file: "libllndk.map.txt", |
| 1111 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | cc_library { |
| 1115 | name: "libdoubleloadable", |
| 1116 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1117 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1118 | vndk: { |
| 1119 | enabled: true, |
| 1120 | }, |
| 1121 | double_loadable: true, |
| 1122 | } |
| 1123 | `) |
| 1124 | // okay to link : LLNDK -> VNDK-SP |
| 1125 | testCc(t, ` |
| 1126 | cc_library { |
| 1127 | name: "libllndk", |
| 1128 | shared_libs: ["libvndksp"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1129 | llndk: { |
| 1130 | symbol_file: "libllndk.map.txt", |
| 1131 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | cc_library { |
| 1135 | name: "libvndksp", |
| 1136 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1137 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1138 | vndk: { |
| 1139 | enabled: true, |
| 1140 | support_system_process: true, |
| 1141 | }, |
| 1142 | } |
| 1143 | `) |
| 1144 | // okay to link : double_loadable -> double_loadable |
| 1145 | testCc(t, ` |
| 1146 | cc_library { |
| 1147 | name: "libdoubleloadable1", |
| 1148 | shared_libs: ["libdoubleloadable2"], |
| 1149 | vendor_available: true, |
| 1150 | double_loadable: true, |
| 1151 | } |
| 1152 | |
| 1153 | cc_library { |
| 1154 | name: "libdoubleloadable2", |
| 1155 | vendor_available: true, |
| 1156 | double_loadable: true, |
| 1157 | } |
| 1158 | `) |
| 1159 | // okay to link : double_loadable VNDK -> double_loadable VNDK private |
| 1160 | testCc(t, ` |
| 1161 | cc_library { |
| 1162 | name: "libdoubleloadable", |
| 1163 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1164 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1165 | vndk: { |
| 1166 | enabled: true, |
| 1167 | }, |
| 1168 | double_loadable: true, |
| 1169 | shared_libs: ["libnondoubleloadable"], |
| 1170 | } |
| 1171 | |
| 1172 | cc_library { |
| 1173 | name: "libnondoubleloadable", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1174 | vendor_available: true, |
| 1175 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1176 | vndk: { |
| 1177 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1178 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1179 | }, |
| 1180 | double_loadable: true, |
| 1181 | } |
| 1182 | `) |
| 1183 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable |
| 1184 | testCc(t, ` |
| 1185 | cc_library { |
| 1186 | name: "libllndk", |
| 1187 | shared_libs: ["libcoreonly"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1188 | llndk: { |
| 1189 | symbol_file: "libllndk.map.txt", |
| 1190 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | cc_library { |
| 1194 | name: "libcoreonly", |
| 1195 | shared_libs: ["libvendoravailable"], |
| 1196 | } |
| 1197 | |
| 1198 | // indirect dependency of LLNDK |
| 1199 | cc_library { |
| 1200 | name: "libvendoravailable", |
| 1201 | vendor_available: true, |
| 1202 | double_loadable: true, |
| 1203 | } |
| 1204 | `) |
| 1205 | } |
| 1206 | |
| 1207 | func TestDoubleLoadableDepError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1208 | t.Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1209 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1210 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1211 | cc_library { |
| 1212 | name: "libllndk", |
| 1213 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1214 | llndk: { |
| 1215 | symbol_file: "libllndk.map.txt", |
| 1216 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | cc_library { |
| 1220 | name: "libnondoubleloadable", |
| 1221 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1222 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1223 | vndk: { |
| 1224 | enabled: true, |
| 1225 | }, |
| 1226 | } |
| 1227 | `) |
| 1228 | |
| 1229 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1230 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1231 | cc_library { |
| 1232 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1233 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1234 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1235 | llndk: { |
| 1236 | symbol_file: "libllndk.map.txt", |
| 1237 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | cc_library { |
| 1241 | name: "libnondoubleloadable", |
| 1242 | vendor_available: true, |
| 1243 | } |
| 1244 | `) |
| 1245 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1246 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1247 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1248 | cc_library { |
| 1249 | name: "libllndk", |
| 1250 | shared_libs: ["libcoreonly"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1251 | llndk: { |
| 1252 | symbol_file: "libllndk.map.txt", |
| 1253 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | cc_library { |
| 1257 | name: "libcoreonly", |
| 1258 | shared_libs: ["libvendoravailable"], |
| 1259 | } |
| 1260 | |
| 1261 | // indirect dependency of LLNDK |
| 1262 | cc_library { |
| 1263 | name: "libvendoravailable", |
| 1264 | vendor_available: true, |
| 1265 | } |
| 1266 | `) |
Jiyong Park | 0474e1f | 2021-01-14 14:26:06 +0900 | [diff] [blame] | 1267 | |
| 1268 | // The error is not from 'client' but from 'libllndk' |
| 1269 | testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", ` |
| 1270 | cc_library { |
| 1271 | name: "client", |
| 1272 | vendor_available: true, |
| 1273 | double_loadable: true, |
| 1274 | shared_libs: ["libllndk"], |
| 1275 | } |
| 1276 | cc_library { |
| 1277 | name: "libllndk", |
| 1278 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1279 | llndk: { |
| 1280 | symbol_file: "libllndk.map.txt", |
| 1281 | } |
Jiyong Park | 0474e1f | 2021-01-14 14:26:06 +0900 | [diff] [blame] | 1282 | } |
| 1283 | cc_library { |
| 1284 | name: "libnondoubleloadable", |
| 1285 | vendor_available: true, |
| 1286 | } |
| 1287 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1290 | func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1291 | t.Parallel() |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1292 | testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", ` |
| 1293 | cc_library { |
| 1294 | name: "libvndksp", |
| 1295 | shared_libs: ["libanothervndksp"], |
| 1296 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1297 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1298 | vndk: { |
| 1299 | enabled: true, |
| 1300 | support_system_process: true, |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | cc_library { |
| 1305 | name: "libllndk", |
| 1306 | shared_libs: ["libanothervndksp"], |
| 1307 | } |
| 1308 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1309 | cc_library { |
| 1310 | name: "libanothervndksp", |
| 1311 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 1312 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1313 | } |
| 1314 | `) |
| 1315 | } |
| 1316 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1317 | func TestVndkExt(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1318 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1319 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1320 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1321 | cc_library { |
| 1322 | name: "libvndk", |
| 1323 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1324 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1325 | vndk: { |
| 1326 | enabled: true, |
| 1327 | }, |
| 1328 | nocrt: true, |
| 1329 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1330 | cc_library { |
| 1331 | name: "libvndk2", |
| 1332 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1333 | product_available: true, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1334 | vndk: { |
| 1335 | enabled: true, |
| 1336 | }, |
| 1337 | target: { |
| 1338 | vendor: { |
| 1339 | suffix: "-suffix", |
| 1340 | }, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1341 | product: { |
| 1342 | suffix: "-suffix", |
| 1343 | }, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1344 | }, |
| 1345 | nocrt: true, |
| 1346 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1347 | |
| 1348 | cc_library { |
| 1349 | name: "libvndk_ext", |
| 1350 | vendor: true, |
| 1351 | vndk: { |
| 1352 | enabled: true, |
| 1353 | extends: "libvndk", |
| 1354 | }, |
| 1355 | nocrt: true, |
| 1356 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1357 | |
| 1358 | cc_library { |
| 1359 | name: "libvndk2_ext", |
| 1360 | vendor: true, |
| 1361 | vndk: { |
| 1362 | enabled: true, |
| 1363 | extends: "libvndk2", |
| 1364 | }, |
| 1365 | nocrt: true, |
| 1366 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1367 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1368 | cc_library { |
| 1369 | name: "libvndk_ext_product", |
| 1370 | product_specific: true, |
| 1371 | vndk: { |
| 1372 | enabled: true, |
| 1373 | extends: "libvndk", |
| 1374 | }, |
| 1375 | nocrt: true, |
| 1376 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1377 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1378 | cc_library { |
| 1379 | name: "libvndk2_ext_product", |
| 1380 | product_specific: true, |
| 1381 | vndk: { |
| 1382 | enabled: true, |
| 1383 | extends: "libvndk2", |
| 1384 | }, |
| 1385 | nocrt: true, |
| 1386 | } |
| 1387 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1388 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1389 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1390 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1391 | |
| 1392 | ctx := testCcWithConfig(t, config) |
| 1393 | |
| 1394 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 1395 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 1396 | |
| 1397 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 1398 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 1399 | |
| 1400 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 1401 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1404 | func TestVndkExtError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1405 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1406 | // 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] | 1407 | 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] | 1408 | cc_library { |
| 1409 | name: "libvndk", |
| 1410 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1411 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1412 | vndk: { |
| 1413 | enabled: true, |
| 1414 | }, |
| 1415 | nocrt: true, |
| 1416 | } |
| 1417 | |
| 1418 | cc_library { |
| 1419 | name: "libvndk_ext", |
| 1420 | vndk: { |
| 1421 | enabled: true, |
| 1422 | extends: "libvndk", |
| 1423 | }, |
| 1424 | nocrt: true, |
| 1425 | } |
| 1426 | `) |
| 1427 | |
| 1428 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1429 | cc_library { |
| 1430 | name: "libvndk", |
| 1431 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1432 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1433 | vndk: { |
| 1434 | enabled: true, |
| 1435 | }, |
| 1436 | nocrt: true, |
| 1437 | } |
| 1438 | |
| 1439 | cc_library { |
| 1440 | name: "libvndk_ext", |
| 1441 | vendor: true, |
| 1442 | vndk: { |
| 1443 | enabled: true, |
| 1444 | }, |
| 1445 | nocrt: true, |
| 1446 | } |
| 1447 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1448 | |
| 1449 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1450 | cc_library { |
| 1451 | name: "libvndk", |
| 1452 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1453 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1454 | vndk: { |
| 1455 | enabled: true, |
| 1456 | }, |
| 1457 | nocrt: true, |
| 1458 | } |
| 1459 | |
| 1460 | cc_library { |
| 1461 | name: "libvndk_ext_product", |
| 1462 | product_specific: true, |
| 1463 | vndk: { |
| 1464 | enabled: true, |
| 1465 | }, |
| 1466 | nocrt: true, |
| 1467 | } |
| 1468 | `) |
| 1469 | |
| 1470 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 1471 | cc_library { |
| 1472 | name: "libvndk", |
| 1473 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1474 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1475 | vndk: { |
| 1476 | enabled: true, |
| 1477 | }, |
| 1478 | nocrt: true, |
| 1479 | } |
| 1480 | |
| 1481 | cc_library { |
| 1482 | name: "libvndk_ext_product", |
| 1483 | product_specific: true, |
| 1484 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1485 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1486 | vndk: { |
| 1487 | enabled: true, |
| 1488 | extends: "libvndk", |
| 1489 | }, |
| 1490 | nocrt: true, |
| 1491 | } |
| 1492 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1496 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1497 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1498 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1499 | cc_library { |
| 1500 | name: "libvndk", |
| 1501 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1502 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1503 | vndk: { |
| 1504 | enabled: true, |
| 1505 | }, |
| 1506 | nocrt: true, |
| 1507 | } |
| 1508 | |
| 1509 | cc_library { |
| 1510 | name: "libvndk_sp_ext", |
| 1511 | vendor: true, |
| 1512 | vndk: { |
| 1513 | enabled: true, |
| 1514 | extends: "libvndk", |
| 1515 | support_system_process: true, |
| 1516 | }, |
| 1517 | nocrt: true, |
| 1518 | } |
| 1519 | `) |
| 1520 | |
| 1521 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1522 | cc_library { |
| 1523 | name: "libvndk_sp", |
| 1524 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1525 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1526 | vndk: { |
| 1527 | enabled: true, |
| 1528 | support_system_process: true, |
| 1529 | }, |
| 1530 | nocrt: true, |
| 1531 | } |
| 1532 | |
| 1533 | cc_library { |
| 1534 | name: "libvndk_ext", |
| 1535 | vendor: true, |
| 1536 | vndk: { |
| 1537 | enabled: true, |
| 1538 | extends: "libvndk_sp", |
| 1539 | }, |
| 1540 | nocrt: true, |
| 1541 | } |
| 1542 | `) |
| 1543 | } |
| 1544 | |
| 1545 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1546 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1547 | // 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] | 1548 | // with `private: true`. |
| 1549 | testCcError(t, "`extends` refers module \".*\" which has `private: true`", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1550 | cc_library { |
| 1551 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1552 | vendor_available: true, |
| 1553 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1554 | vndk: { |
| 1555 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1556 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1557 | }, |
| 1558 | nocrt: true, |
| 1559 | } |
| 1560 | |
| 1561 | cc_library { |
| 1562 | name: "libvndk_ext", |
| 1563 | vendor: true, |
| 1564 | vndk: { |
| 1565 | enabled: true, |
| 1566 | extends: "libvndk", |
| 1567 | }, |
| 1568 | nocrt: true, |
| 1569 | } |
| 1570 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1571 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1572 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1573 | cc_library { |
| 1574 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1575 | vendor_available: true, |
| 1576 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1577 | vndk: { |
| 1578 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1579 | private: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1580 | }, |
| 1581 | nocrt: true, |
| 1582 | } |
| 1583 | |
| 1584 | cc_library { |
| 1585 | name: "libvndk_ext_product", |
| 1586 | product_specific: true, |
| 1587 | vndk: { |
| 1588 | enabled: true, |
| 1589 | extends: "libvndk", |
| 1590 | }, |
| 1591 | nocrt: true, |
| 1592 | } |
| 1593 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1594 | } |
| 1595 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1596 | func TestVendorModuleUseVndkExt(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1597 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1598 | // 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] | 1599 | testCc(t, ` |
| 1600 | cc_library { |
| 1601 | name: "libvndk", |
| 1602 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1603 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1604 | vndk: { |
| 1605 | enabled: true, |
| 1606 | }, |
| 1607 | nocrt: true, |
| 1608 | } |
| 1609 | |
| 1610 | cc_library { |
| 1611 | name: "libvndk_ext", |
| 1612 | vendor: true, |
| 1613 | vndk: { |
| 1614 | enabled: true, |
| 1615 | extends: "libvndk", |
| 1616 | }, |
| 1617 | nocrt: true, |
| 1618 | } |
| 1619 | |
| 1620 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1621 | name: "libvndk_sp", |
| 1622 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1623 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1624 | vndk: { |
| 1625 | enabled: true, |
| 1626 | support_system_process: true, |
| 1627 | }, |
| 1628 | nocrt: true, |
| 1629 | } |
| 1630 | |
| 1631 | cc_library { |
| 1632 | name: "libvndk_sp_ext", |
| 1633 | vendor: true, |
| 1634 | vndk: { |
| 1635 | enabled: true, |
| 1636 | extends: "libvndk_sp", |
| 1637 | support_system_process: true, |
| 1638 | }, |
| 1639 | nocrt: true, |
| 1640 | } |
| 1641 | |
| 1642 | cc_library { |
| 1643 | name: "libvendor", |
| 1644 | vendor: true, |
| 1645 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 1646 | nocrt: true, |
| 1647 | } |
| 1648 | `) |
| 1649 | } |
| 1650 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1651 | func TestVndkExtUseVendorLib(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1652 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1653 | // This test ensures a VNDK-Ext library can depend on a vendor library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1654 | testCc(t, ` |
| 1655 | cc_library { |
| 1656 | name: "libvndk", |
| 1657 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1658 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1659 | vndk: { |
| 1660 | enabled: true, |
| 1661 | }, |
| 1662 | nocrt: true, |
| 1663 | } |
| 1664 | |
| 1665 | cc_library { |
| 1666 | name: "libvndk_ext", |
| 1667 | vendor: true, |
| 1668 | vndk: { |
| 1669 | enabled: true, |
| 1670 | extends: "libvndk", |
| 1671 | }, |
| 1672 | shared_libs: ["libvendor"], |
| 1673 | nocrt: true, |
| 1674 | } |
| 1675 | |
| 1676 | cc_library { |
| 1677 | name: "libvendor", |
| 1678 | vendor: true, |
| 1679 | nocrt: true, |
| 1680 | } |
| 1681 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1682 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1683 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 1684 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1685 | cc_library { |
| 1686 | name: "libvndk_sp", |
| 1687 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1688 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1689 | vndk: { |
| 1690 | enabled: true, |
| 1691 | support_system_process: true, |
| 1692 | }, |
| 1693 | nocrt: true, |
| 1694 | } |
| 1695 | |
| 1696 | cc_library { |
| 1697 | name: "libvndk_sp_ext", |
| 1698 | vendor: true, |
| 1699 | vndk: { |
| 1700 | enabled: true, |
| 1701 | extends: "libvndk_sp", |
| 1702 | support_system_process: true, |
| 1703 | }, |
| 1704 | shared_libs: ["libvendor"], // Cause an error |
| 1705 | nocrt: true, |
| 1706 | } |
| 1707 | |
| 1708 | cc_library { |
| 1709 | name: "libvendor", |
| 1710 | vendor: true, |
| 1711 | nocrt: true, |
| 1712 | } |
| 1713 | `) |
| 1714 | } |
| 1715 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1716 | func TestProductVndkExtDependency(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1717 | t.Parallel() |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1718 | bp := ` |
| 1719 | cc_library { |
| 1720 | name: "libvndk", |
| 1721 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1722 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1723 | vndk: { |
| 1724 | enabled: true, |
| 1725 | }, |
| 1726 | nocrt: true, |
| 1727 | } |
| 1728 | |
| 1729 | cc_library { |
| 1730 | name: "libvndk_ext_product", |
| 1731 | product_specific: true, |
| 1732 | vndk: { |
| 1733 | enabled: true, |
| 1734 | extends: "libvndk", |
| 1735 | }, |
| 1736 | shared_libs: ["libproduct_for_vndklibs"], |
| 1737 | nocrt: true, |
| 1738 | } |
| 1739 | |
| 1740 | cc_library { |
| 1741 | name: "libvndk_sp", |
| 1742 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1743 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1744 | vndk: { |
| 1745 | enabled: true, |
| 1746 | support_system_process: true, |
| 1747 | }, |
| 1748 | nocrt: true, |
| 1749 | } |
| 1750 | |
| 1751 | cc_library { |
| 1752 | name: "libvndk_sp_ext_product", |
| 1753 | product_specific: true, |
| 1754 | vndk: { |
| 1755 | enabled: true, |
| 1756 | extends: "libvndk_sp", |
| 1757 | support_system_process: true, |
| 1758 | }, |
| 1759 | shared_libs: ["libproduct_for_vndklibs"], |
| 1760 | nocrt: true, |
| 1761 | } |
| 1762 | |
| 1763 | cc_library { |
| 1764 | name: "libproduct", |
| 1765 | product_specific: true, |
| 1766 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 1767 | nocrt: true, |
| 1768 | } |
| 1769 | |
| 1770 | cc_library { |
| 1771 | name: "libproduct_for_vndklibs", |
| 1772 | product_specific: true, |
| 1773 | nocrt: true, |
| 1774 | } |
| 1775 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1776 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1777 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1778 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1779 | |
| 1780 | testCcWithConfig(t, config) |
| 1781 | } |
| 1782 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1783 | func TestVndkSpExtUseVndkError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1784 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1785 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 1786 | // library. |
| 1787 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1788 | cc_library { |
| 1789 | name: "libvndk", |
| 1790 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1791 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1792 | vndk: { |
| 1793 | enabled: true, |
| 1794 | }, |
| 1795 | nocrt: true, |
| 1796 | } |
| 1797 | |
| 1798 | cc_library { |
| 1799 | name: "libvndk_sp", |
| 1800 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1801 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1802 | vndk: { |
| 1803 | enabled: true, |
| 1804 | support_system_process: true, |
| 1805 | }, |
| 1806 | nocrt: true, |
| 1807 | } |
| 1808 | |
| 1809 | cc_library { |
| 1810 | name: "libvndk_sp_ext", |
| 1811 | vendor: true, |
| 1812 | vndk: { |
| 1813 | enabled: true, |
| 1814 | extends: "libvndk_sp", |
| 1815 | support_system_process: true, |
| 1816 | }, |
| 1817 | shared_libs: ["libvndk"], // Cause an error |
| 1818 | nocrt: true, |
| 1819 | } |
| 1820 | `) |
| 1821 | |
| 1822 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 1823 | // library. |
| 1824 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1825 | cc_library { |
| 1826 | name: "libvndk", |
| 1827 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1828 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1829 | vndk: { |
| 1830 | enabled: true, |
| 1831 | }, |
| 1832 | nocrt: true, |
| 1833 | } |
| 1834 | |
| 1835 | cc_library { |
| 1836 | name: "libvndk_ext", |
| 1837 | vendor: true, |
| 1838 | vndk: { |
| 1839 | enabled: true, |
| 1840 | extends: "libvndk", |
| 1841 | }, |
| 1842 | nocrt: true, |
| 1843 | } |
| 1844 | |
| 1845 | cc_library { |
| 1846 | name: "libvndk_sp", |
| 1847 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1848 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1849 | vndk: { |
| 1850 | enabled: true, |
| 1851 | support_system_process: true, |
| 1852 | }, |
| 1853 | nocrt: true, |
| 1854 | } |
| 1855 | |
| 1856 | cc_library { |
| 1857 | name: "libvndk_sp_ext", |
| 1858 | vendor: true, |
| 1859 | vndk: { |
| 1860 | enabled: true, |
| 1861 | extends: "libvndk_sp", |
| 1862 | support_system_process: true, |
| 1863 | }, |
| 1864 | shared_libs: ["libvndk_ext"], // Cause an error |
| 1865 | nocrt: true, |
| 1866 | } |
| 1867 | `) |
| 1868 | } |
| 1869 | |
| 1870 | func TestVndkUseVndkExtError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1871 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1872 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 1873 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1874 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1875 | cc_library { |
| 1876 | name: "libvndk", |
| 1877 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1878 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1879 | vndk: { |
| 1880 | enabled: true, |
| 1881 | }, |
| 1882 | nocrt: true, |
| 1883 | } |
| 1884 | |
| 1885 | cc_library { |
| 1886 | name: "libvndk_ext", |
| 1887 | vendor: true, |
| 1888 | vndk: { |
| 1889 | enabled: true, |
| 1890 | extends: "libvndk", |
| 1891 | }, |
| 1892 | nocrt: true, |
| 1893 | } |
| 1894 | |
| 1895 | cc_library { |
| 1896 | name: "libvndk2", |
| 1897 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1898 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1899 | vndk: { |
| 1900 | enabled: true, |
| 1901 | }, |
| 1902 | shared_libs: ["libvndk_ext"], |
| 1903 | nocrt: true, |
| 1904 | } |
| 1905 | `) |
| 1906 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1907 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1908 | cc_library { |
| 1909 | name: "libvndk", |
| 1910 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1911 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1912 | vndk: { |
| 1913 | enabled: true, |
| 1914 | }, |
| 1915 | nocrt: true, |
| 1916 | } |
| 1917 | |
| 1918 | cc_library { |
| 1919 | name: "libvndk_ext", |
| 1920 | vendor: true, |
| 1921 | vndk: { |
| 1922 | enabled: true, |
| 1923 | extends: "libvndk", |
| 1924 | }, |
| 1925 | nocrt: true, |
| 1926 | } |
| 1927 | |
| 1928 | cc_library { |
| 1929 | name: "libvndk2", |
| 1930 | vendor_available: true, |
| 1931 | vndk: { |
| 1932 | enabled: true, |
| 1933 | }, |
| 1934 | target: { |
| 1935 | vendor: { |
| 1936 | shared_libs: ["libvndk_ext"], |
| 1937 | }, |
| 1938 | }, |
| 1939 | nocrt: true, |
| 1940 | } |
| 1941 | `) |
| 1942 | |
| 1943 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1944 | cc_library { |
| 1945 | name: "libvndk_sp", |
| 1946 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1947 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1948 | vndk: { |
| 1949 | enabled: true, |
| 1950 | support_system_process: true, |
| 1951 | }, |
| 1952 | nocrt: true, |
| 1953 | } |
| 1954 | |
| 1955 | cc_library { |
| 1956 | name: "libvndk_sp_ext", |
| 1957 | vendor: true, |
| 1958 | vndk: { |
| 1959 | enabled: true, |
| 1960 | extends: "libvndk_sp", |
| 1961 | support_system_process: true, |
| 1962 | }, |
| 1963 | nocrt: true, |
| 1964 | } |
| 1965 | |
| 1966 | cc_library { |
| 1967 | name: "libvndk_sp_2", |
| 1968 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1969 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1970 | vndk: { |
| 1971 | enabled: true, |
| 1972 | support_system_process: true, |
| 1973 | }, |
| 1974 | shared_libs: ["libvndk_sp_ext"], |
| 1975 | nocrt: true, |
| 1976 | } |
| 1977 | `) |
| 1978 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1979 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1980 | cc_library { |
| 1981 | name: "libvndk_sp", |
| 1982 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1983 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1984 | vndk: { |
| 1985 | enabled: true, |
| 1986 | }, |
| 1987 | nocrt: true, |
| 1988 | } |
| 1989 | |
| 1990 | cc_library { |
| 1991 | name: "libvndk_sp_ext", |
| 1992 | vendor: true, |
| 1993 | vndk: { |
| 1994 | enabled: true, |
| 1995 | extends: "libvndk_sp", |
| 1996 | }, |
| 1997 | nocrt: true, |
| 1998 | } |
| 1999 | |
| 2000 | cc_library { |
| 2001 | name: "libvndk_sp2", |
| 2002 | vendor_available: true, |
| 2003 | vndk: { |
| 2004 | enabled: true, |
| 2005 | }, |
| 2006 | target: { |
| 2007 | vendor: { |
| 2008 | shared_libs: ["libvndk_sp_ext"], |
| 2009 | }, |
| 2010 | }, |
| 2011 | nocrt: true, |
| 2012 | } |
| 2013 | `) |
| 2014 | } |
| 2015 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2016 | func TestEnforceProductVndkVersion(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2017 | t.Parallel() |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2018 | bp := ` |
| 2019 | cc_library { |
| 2020 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2021 | llndk: { |
| 2022 | symbol_file: "libllndk.map.txt", |
| 2023 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2024 | } |
| 2025 | cc_library { |
| 2026 | name: "libvndk", |
| 2027 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2028 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2029 | vndk: { |
| 2030 | enabled: true, |
| 2031 | }, |
| 2032 | nocrt: true, |
| 2033 | } |
| 2034 | cc_library { |
| 2035 | name: "libvndk_sp", |
| 2036 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2037 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2038 | vndk: { |
| 2039 | enabled: true, |
| 2040 | support_system_process: true, |
| 2041 | }, |
| 2042 | nocrt: true, |
| 2043 | } |
| 2044 | cc_library { |
| 2045 | name: "libva", |
| 2046 | vendor_available: true, |
| 2047 | nocrt: true, |
| 2048 | } |
| 2049 | cc_library { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2050 | name: "libpa", |
| 2051 | product_available: true, |
| 2052 | nocrt: true, |
| 2053 | } |
| 2054 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2055 | name: "libboth_available", |
| 2056 | vendor_available: true, |
| 2057 | product_available: true, |
| 2058 | nocrt: true, |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2059 | srcs: ["foo.c"], |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2060 | target: { |
| 2061 | vendor: { |
| 2062 | suffix: "-vendor", |
| 2063 | }, |
| 2064 | product: { |
| 2065 | suffix: "-product", |
| 2066 | }, |
| 2067 | } |
| 2068 | } |
| 2069 | cc_library { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2070 | name: "libproduct_va", |
| 2071 | product_specific: true, |
| 2072 | vendor_available: true, |
| 2073 | nocrt: true, |
| 2074 | } |
| 2075 | cc_library { |
| 2076 | name: "libprod", |
| 2077 | product_specific: true, |
| 2078 | shared_libs: [ |
| 2079 | "libllndk", |
| 2080 | "libvndk", |
| 2081 | "libvndk_sp", |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2082 | "libpa", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2083 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2084 | "libproduct_va", |
| 2085 | ], |
| 2086 | nocrt: true, |
| 2087 | } |
| 2088 | cc_library { |
| 2089 | name: "libvendor", |
| 2090 | vendor: true, |
| 2091 | shared_libs: [ |
| 2092 | "libllndk", |
| 2093 | "libvndk", |
| 2094 | "libvndk_sp", |
| 2095 | "libva", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2096 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2097 | "libproduct_va", |
| 2098 | ], |
| 2099 | nocrt: true, |
| 2100 | } |
| 2101 | ` |
| 2102 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 2103 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2104 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 2105 | checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant) |
| 2106 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2107 | |
| 2108 | mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module) |
| 2109 | assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so") |
| 2110 | |
| 2111 | mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module) |
| 2112 | assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so") |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2113 | |
| 2114 | ensureStringContains := func(t *testing.T, str string, substr string) { |
| 2115 | t.Helper() |
| 2116 | if !strings.Contains(str, substr) { |
| 2117 | t.Errorf("%q is not found in %v", substr, str) |
| 2118 | } |
| 2119 | } |
| 2120 | ensureStringNotContains := func(t *testing.T, str string, substr string) { |
| 2121 | t.Helper() |
| 2122 | if strings.Contains(str, substr) { |
| 2123 | t.Errorf("%q is found in %v", substr, str) |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | // _static variant is used since _shared reuses *.o from the static variant |
| 2128 | vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1)) |
| 2129 | product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1)) |
| 2130 | |
| 2131 | vendor_cflags := vendor_static.Rule("cc").Args["cFlags"] |
| 2132 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__") |
| 2133 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__") |
| 2134 | ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__") |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame^] | 2135 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR_API__=202404") |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2136 | |
| 2137 | product_cflags := product_static.Rule("cc").Args["cFlags"] |
| 2138 | ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__") |
| 2139 | ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__") |
| 2140 | ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__") |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame^] | 2141 | ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR_API__=202404") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2145 | t.Parallel() |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2146 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2147 | cc_library { |
| 2148 | name: "libprod", |
| 2149 | product_specific: true, |
| 2150 | shared_libs: [ |
| 2151 | "libvendor", |
| 2152 | ], |
| 2153 | nocrt: true, |
| 2154 | } |
| 2155 | cc_library { |
| 2156 | name: "libvendor", |
| 2157 | vendor: true, |
| 2158 | nocrt: true, |
| 2159 | } |
| 2160 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2161 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2162 | cc_library { |
| 2163 | name: "libprod", |
| 2164 | product_specific: true, |
| 2165 | shared_libs: [ |
| 2166 | "libsystem", |
| 2167 | ], |
| 2168 | nocrt: true, |
| 2169 | } |
| 2170 | cc_library { |
| 2171 | name: "libsystem", |
| 2172 | nocrt: true, |
| 2173 | } |
| 2174 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2175 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2176 | cc_library { |
| 2177 | name: "libprod", |
| 2178 | product_specific: true, |
| 2179 | shared_libs: [ |
| 2180 | "libva", |
| 2181 | ], |
| 2182 | nocrt: true, |
| 2183 | } |
| 2184 | cc_library { |
| 2185 | name: "libva", |
| 2186 | vendor_available: true, |
| 2187 | nocrt: true, |
| 2188 | } |
| 2189 | `) |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2190 | 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] | 2191 | cc_library { |
| 2192 | name: "libprod", |
| 2193 | product_specific: true, |
| 2194 | shared_libs: [ |
| 2195 | "libvndk_private", |
| 2196 | ], |
| 2197 | nocrt: true, |
| 2198 | } |
| 2199 | cc_library { |
| 2200 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2201 | vendor_available: true, |
| 2202 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2203 | vndk: { |
| 2204 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2205 | private: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2206 | }, |
| 2207 | nocrt: true, |
| 2208 | } |
| 2209 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2210 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2211 | cc_library { |
| 2212 | name: "libprod", |
| 2213 | product_specific: true, |
| 2214 | shared_libs: [ |
| 2215 | "libsystem_ext", |
| 2216 | ], |
| 2217 | nocrt: true, |
| 2218 | } |
| 2219 | cc_library { |
| 2220 | name: "libsystem_ext", |
| 2221 | system_ext_specific: true, |
| 2222 | nocrt: true, |
| 2223 | } |
| 2224 | `) |
| 2225 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2226 | cc_library { |
| 2227 | name: "libsystem", |
| 2228 | shared_libs: [ |
| 2229 | "libproduct_va", |
| 2230 | ], |
| 2231 | nocrt: true, |
| 2232 | } |
| 2233 | cc_library { |
| 2234 | name: "libproduct_va", |
| 2235 | product_specific: true, |
| 2236 | vendor_available: true, |
| 2237 | nocrt: true, |
| 2238 | } |
| 2239 | `) |
| 2240 | } |
| 2241 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2242 | func TestMakeLinkType(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2243 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2244 | bp := ` |
| 2245 | cc_library { |
| 2246 | name: "libvndk", |
| 2247 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2248 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2249 | vndk: { |
| 2250 | enabled: true, |
| 2251 | }, |
| 2252 | } |
| 2253 | cc_library { |
| 2254 | name: "libvndksp", |
| 2255 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2256 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2257 | vndk: { |
| 2258 | enabled: true, |
| 2259 | support_system_process: true, |
| 2260 | }, |
| 2261 | } |
| 2262 | cc_library { |
| 2263 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2264 | vendor_available: true, |
| 2265 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2266 | vndk: { |
| 2267 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2268 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2269 | }, |
| 2270 | } |
| 2271 | cc_library { |
| 2272 | name: "libvendor", |
| 2273 | vendor: true, |
| 2274 | } |
| 2275 | cc_library { |
| 2276 | name: "libvndkext", |
| 2277 | vendor: true, |
| 2278 | vndk: { |
| 2279 | enabled: true, |
| 2280 | extends: "libvndk", |
| 2281 | }, |
| 2282 | } |
| 2283 | vndk_prebuilt_shared { |
| 2284 | name: "prevndk", |
| 2285 | version: "27", |
| 2286 | target_arch: "arm", |
| 2287 | binder32bit: true, |
| 2288 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2289 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2290 | vndk: { |
| 2291 | enabled: true, |
| 2292 | }, |
| 2293 | arch: { |
| 2294 | arm: { |
| 2295 | srcs: ["liba.so"], |
| 2296 | }, |
| 2297 | }, |
| 2298 | } |
| 2299 | cc_library { |
| 2300 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2301 | llndk: { |
| 2302 | symbol_file: "libllndk.map.txt", |
| 2303 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2304 | } |
| 2305 | cc_library { |
| 2306 | name: "libllndkprivate", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2307 | llndk: { |
| 2308 | symbol_file: "libllndkprivate.map.txt", |
| 2309 | private: true, |
| 2310 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | llndk_libraries_txt { |
| 2314 | name: "llndk.libraries.txt", |
| 2315 | } |
| 2316 | vndkcore_libraries_txt { |
| 2317 | name: "vndkcore.libraries.txt", |
| 2318 | } |
| 2319 | vndksp_libraries_txt { |
| 2320 | name: "vndksp.libraries.txt", |
| 2321 | } |
| 2322 | vndkprivate_libraries_txt { |
| 2323 | name: "vndkprivate.libraries.txt", |
| 2324 | } |
| 2325 | vndkcorevariant_libraries_txt { |
| 2326 | name: "vndkcorevariant.libraries.txt", |
| 2327 | insert_vndk_version: false, |
| 2328 | } |
| 2329 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2330 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 2331 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2332 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2333 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2334 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2335 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2336 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2337 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", |
| 2338 | []string{"libvndk.so", "libvndkprivate.so"}) |
| 2339 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", |
| 2340 | []string{"libc++.so", "libvndksp.so"}) |
| 2341 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", |
| 2342 | []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"}) |
| 2343 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", |
| 2344 | []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2345 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2346 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2347 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2348 | tests := []struct { |
| 2349 | variant string |
| 2350 | name string |
| 2351 | expected string |
| 2352 | }{ |
| 2353 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2354 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2355 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2356 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2357 | {vendorVariant, "libvndkext", "native:vendor"}, |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2358 | {vendorVariant, "libllndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2359 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2360 | {coreVariant, "libvndk", "native:platform"}, |
| 2361 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2362 | {coreVariant, "libllndk", "native:platform"}, |
| 2363 | } |
| 2364 | for _, test := range tests { |
| 2365 | t.Run(test.name, func(t *testing.T) { |
| 2366 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2367 | assertString(t, module.makeLinkType, test.expected) |
| 2368 | }) |
| 2369 | } |
| 2370 | } |
| 2371 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2372 | var staticLinkDepOrderTestCases = []struct { |
| 2373 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2374 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2375 | inStatic string |
| 2376 | |
| 2377 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2378 | // It models the dependencies declared in an Android.bp file. |
| 2379 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2380 | |
| 2381 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2382 | // The keys of allOrdered specify which modules we would like to check. |
| 2383 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2384 | // dependencies) for each module to test |
| 2385 | allOrdered string |
| 2386 | |
| 2387 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2388 | // The keys of outOrdered specify which modules we would like to check. |
| 2389 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2390 | // for each module to test. |
| 2391 | outOrdered string |
| 2392 | }{ |
| 2393 | // Simple tests |
| 2394 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2395 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2396 | outOrdered: "", |
| 2397 | }, |
| 2398 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2399 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2400 | outOrdered: "a:", |
| 2401 | }, |
| 2402 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2403 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2404 | outOrdered: "a:b; b:", |
| 2405 | }, |
| 2406 | // Tests of reordering |
| 2407 | { |
| 2408 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2409 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2410 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2411 | }, |
| 2412 | { |
| 2413 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2414 | 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] | 2415 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2416 | }, |
| 2417 | { |
| 2418 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2419 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2420 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2421 | }, |
| 2422 | { |
| 2423 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2424 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2425 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2426 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2427 | }, |
| 2428 | { |
| 2429 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2430 | 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] | 2431 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2432 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2433 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2434 | // shared dependencies |
| 2435 | { |
| 2436 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2437 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2438 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2439 | // a shared dependency on b, that that shows up in allOrdered. |
| 2440 | inShared: "c:b", |
| 2441 | allOrdered: "c:b", |
| 2442 | outOrdered: "c:", |
| 2443 | }, |
| 2444 | { |
| 2445 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2446 | // the second phase of the above test would look like |
| 2447 | inStatic: "a:b,c; c:b", |
| 2448 | allOrdered: "a:c,b; c:b", |
| 2449 | outOrdered: "a:c,b; c:b", |
| 2450 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2451 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2452 | // to dictate an order |
| 2453 | { |
| 2454 | // 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] | 2455 | 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] | 2456 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2457 | }, |
| 2458 | { |
| 2459 | // 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] | 2460 | 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] | 2461 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2462 | }, |
| 2463 | // Tests involving duplicate dependencies |
| 2464 | { |
| 2465 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2466 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2467 | outOrdered: "a:c,b", |
| 2468 | }, |
| 2469 | { |
| 2470 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2471 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2472 | outOrdered: "a:d,c,b", |
| 2473 | }, |
| 2474 | // Tests to confirm the nonexistence of infinite loops. |
| 2475 | // These cases should never happen, so as long as the test terminates and the |
| 2476 | // result is deterministic then that should be fine. |
| 2477 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2478 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2479 | outOrdered: "a:a", |
| 2480 | }, |
| 2481 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2482 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2483 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2484 | outOrdered: "a:b; b:c; c:a", |
| 2485 | }, |
| 2486 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2487 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2488 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2489 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2490 | }, |
| 2491 | } |
| 2492 | |
| 2493 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2494 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2495 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2496 | strippedText := strings.Replace(text, " ", "", -1) |
| 2497 | if len(strippedText) < 1 { |
| 2498 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2499 | } |
| 2500 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2501 | |
| 2502 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2503 | moduleTexts := strings.Split(strippedText, ";") |
| 2504 | |
| 2505 | outputForModuleName := func(moduleName string) android.Path { |
| 2506 | return android.PathForTesting(moduleName) |
| 2507 | } |
| 2508 | |
| 2509 | for _, moduleText := range moduleTexts { |
| 2510 | // convert from "a:b,c" to ["a", "b,c"] |
| 2511 | components := strings.Split(moduleText, ":") |
| 2512 | if len(components) != 2 { |
| 2513 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2514 | } |
| 2515 | moduleName := components[0] |
| 2516 | moduleOutput := outputForModuleName(moduleName) |
| 2517 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2518 | |
| 2519 | depString := components[1] |
| 2520 | // convert from "b,c" to ["b", "c"] |
| 2521 | depNames := strings.Split(depString, ",") |
| 2522 | if len(depString) < 1 { |
| 2523 | depNames = []string{} |
| 2524 | } |
| 2525 | var deps []android.Path |
| 2526 | for _, depName := range depNames { |
| 2527 | deps = append(deps, outputForModuleName(depName)) |
| 2528 | } |
| 2529 | allDeps[moduleOutput] = deps |
| 2530 | } |
| 2531 | return modulesInOrder, allDeps |
| 2532 | } |
| 2533 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2534 | func TestStaticLibDepReordering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2535 | t.Parallel() |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2536 | ctx := testCc(t, ` |
| 2537 | cc_library { |
| 2538 | name: "a", |
| 2539 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2540 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2541 | } |
| 2542 | cc_library { |
| 2543 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2544 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2545 | } |
| 2546 | cc_library { |
| 2547 | name: "c", |
| 2548 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2549 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2550 | } |
| 2551 | cc_library { |
| 2552 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2553 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | `) |
| 2557 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2558 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2559 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 2560 | actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). |
| 2561 | TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2562 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2563 | |
| 2564 | if !reflect.DeepEqual(actual, expected) { |
| 2565 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2566 | "\nactual: %v"+ |
| 2567 | "\nexpected: %v", |
| 2568 | actual, |
| 2569 | expected, |
| 2570 | ) |
| 2571 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2572 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2573 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2574 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2575 | t.Parallel() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2576 | ctx := testCc(t, ` |
| 2577 | cc_library { |
| 2578 | name: "a", |
| 2579 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2580 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2581 | } |
| 2582 | cc_library { |
| 2583 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2584 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2585 | } |
| 2586 | cc_library { |
| 2587 | name: "c", |
| 2588 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2589 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | `) |
| 2593 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2594 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2595 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 2596 | actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). |
| 2597 | TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2598 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2599 | |
| 2600 | if !reflect.DeepEqual(actual, expected) { |
| 2601 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2602 | "\nactual: %v"+ |
| 2603 | "\nexpected: %v", |
| 2604 | actual, |
| 2605 | expected, |
| 2606 | ) |
| 2607 | } |
| 2608 | } |
| 2609 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2610 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2611 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2612 | if !reflect.DeepEqual(actual, expected) { |
| 2613 | t.Errorf(message+ |
| 2614 | "\nactual: %v"+ |
| 2615 | "\nexpected: %v", |
| 2616 | actual, |
| 2617 | expected, |
| 2618 | ) |
| 2619 | } |
| 2620 | } |
| 2621 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2622 | func TestLlndkLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2623 | t.Parallel() |
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) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2711 | t.Parallel() |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2712 | ctx := testCc(t, ` |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2713 | cc_library_headers { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2714 | name: "libllndk_headers", |
| 2715 | export_include_dirs: ["my_include"], |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2716 | llndk: { |
| 2717 | llndk_headers: true, |
| 2718 | }, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2719 | } |
| 2720 | cc_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2721 | name: "libllndk", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2722 | llndk: { |
| 2723 | symbol_file: "libllndk.map.txt", |
| 2724 | export_llndk_headers: ["libllndk_headers"], |
| 2725 | } |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | cc_library { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2729 | name: "libvendor", |
| 2730 | shared_libs: ["libllndk"], |
| 2731 | vendor: true, |
| 2732 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2733 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2734 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2735 | } |
| 2736 | `) |
| 2737 | |
| 2738 | // _static variant is used since _shared reuses *.o from the static variant |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2739 | 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] | 2740 | cflags := cc.Args["cFlags"] |
| 2741 | if !strings.Contains(cflags, "-Imy_include") { |
| 2742 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2743 | } |
| 2744 | } |
| 2745 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2746 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2747 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2748 | if !reflect.DeepEqual(actual, expected) { |
| 2749 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2750 | "\nactual: %v"+ |
| 2751 | "\nexpected: %v", |
| 2752 | actual, |
| 2753 | expected, |
| 2754 | ) |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | const runtimeLibAndroidBp = ` |
| 2759 | cc_library { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2760 | name: "liball_available", |
| 2761 | vendor_available: true, |
| 2762 | product_available: true, |
| 2763 | no_libcrt : true, |
| 2764 | nocrt : true, |
| 2765 | system_shared_libs : [], |
| 2766 | } |
| 2767 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2768 | name: "libvendor_available1", |
| 2769 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2770 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2771 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2772 | nocrt : true, |
| 2773 | system_shared_libs : [], |
| 2774 | } |
| 2775 | cc_library { |
| 2776 | name: "libvendor_available2", |
| 2777 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2778 | runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2779 | target: { |
| 2780 | vendor: { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2781 | exclude_runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2782 | } |
| 2783 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2784 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2785 | nocrt : true, |
| 2786 | system_shared_libs : [], |
| 2787 | } |
| 2788 | cc_library { |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2789 | name: "libproduct_vendor", |
| 2790 | product_specific: true, |
| 2791 | vendor_available: true, |
| 2792 | no_libcrt : true, |
| 2793 | nocrt : true, |
| 2794 | system_shared_libs : [], |
| 2795 | } |
| 2796 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2797 | name: "libcore", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2798 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2799 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2800 | nocrt : true, |
| 2801 | system_shared_libs : [], |
| 2802 | } |
| 2803 | cc_library { |
| 2804 | name: "libvendor1", |
| 2805 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2806 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2807 | nocrt : true, |
| 2808 | system_shared_libs : [], |
| 2809 | } |
| 2810 | cc_library { |
| 2811 | name: "libvendor2", |
| 2812 | vendor: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2813 | runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"], |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2814 | no_libcrt : true, |
| 2815 | nocrt : true, |
| 2816 | system_shared_libs : [], |
| 2817 | } |
| 2818 | cc_library { |
| 2819 | name: "libproduct_available1", |
| 2820 | product_available: true, |
| 2821 | runtime_libs: ["liball_available"], |
| 2822 | no_libcrt : true, |
| 2823 | nocrt : true, |
| 2824 | system_shared_libs : [], |
| 2825 | } |
| 2826 | cc_library { |
| 2827 | name: "libproduct1", |
| 2828 | product_specific: true, |
| 2829 | no_libcrt : true, |
| 2830 | nocrt : true, |
| 2831 | system_shared_libs : [], |
| 2832 | } |
| 2833 | cc_library { |
| 2834 | name: "libproduct2", |
| 2835 | product_specific: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2836 | runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2837 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2838 | nocrt : true, |
| 2839 | system_shared_libs : [], |
| 2840 | } |
| 2841 | ` |
| 2842 | |
| 2843 | func TestRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2844 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2845 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2846 | |
| 2847 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2848 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2849 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2850 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2851 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
| 2852 | |
| 2853 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2854 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2855 | |
| 2856 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2857 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2858 | |
| 2859 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2860 | // and vendor variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2861 | variant = "android_vendor.29_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2862 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2863 | module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2864 | checkRuntimeLibs(t, []string{"liball_available.vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2865 | |
| 2866 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2867 | checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2868 | |
| 2869 | // runtime_libs for product variants have '.product' suffixes if the modules have both core |
| 2870 | // and product variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2871 | variant = "android_product.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2872 | |
| 2873 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2874 | checkRuntimeLibs(t, []string{"liball_available.product"}, module) |
| 2875 | |
| 2876 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
Justin Yun | d00f5ca | 2021-02-03 19:43:02 +0900 | [diff] [blame] | 2877 | checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | func TestExcludeRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2881 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2882 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2883 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2884 | variant := "android_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2885 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2886 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2887 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2888 | variant = "android_vendor.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2889 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2890 | checkRuntimeLibs(t, nil, module) |
| 2891 | } |
| 2892 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2893 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2894 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2895 | actual := module.Properties.AndroidMkStaticLibs |
| 2896 | if !reflect.DeepEqual(actual, expected) { |
| 2897 | t.Errorf("incorrect static_libs"+ |
| 2898 | "\nactual: %v"+ |
| 2899 | "\nexpected: %v", |
| 2900 | actual, |
| 2901 | expected, |
| 2902 | ) |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | const staticLibAndroidBp = ` |
| 2907 | cc_library { |
| 2908 | name: "lib1", |
| 2909 | } |
| 2910 | cc_library { |
| 2911 | name: "lib2", |
| 2912 | static_libs: ["lib1"], |
| 2913 | } |
| 2914 | ` |
| 2915 | |
| 2916 | func TestStaticLibDepExport(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2917 | t.Parallel() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2918 | ctx := testCc(t, staticLibAndroidBp) |
| 2919 | |
| 2920 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2921 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2922 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2923 | checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2924 | |
| 2925 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2926 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2927 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2928 | // libc++_static is linked additionally. |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2929 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2932 | func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) { |
| 2933 | bp := ` |
| 2934 | cc_library { |
| 2935 | name: "static_dep", |
| 2936 | } |
| 2937 | cc_library { |
| 2938 | name: "whole_static_dep", |
| 2939 | } |
| 2940 | cc_library { |
| 2941 | name: "shared_dep", |
| 2942 | } |
| 2943 | cc_library { |
| 2944 | name: "lib", |
| 2945 | bazel_module: { label: "//:lib" }, |
| 2946 | static_libs: ["static_dep"], |
| 2947 | whole_static_libs: ["whole_static_dep"], |
| 2948 | shared_libs: ["shared_dep"], |
| 2949 | } |
| 2950 | cc_test { |
| 2951 | name: "test", |
| 2952 | bazel_module: { label: "//:test" }, |
| 2953 | static_libs: ["static_dep"], |
| 2954 | whole_static_libs: ["whole_static_dep"], |
| 2955 | shared_libs: ["shared_dep"], |
| 2956 | gtest: false, |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 2957 | sanitize: { |
| 2958 | // cc_test modules default to memtag_heap: true, |
| 2959 | // but this adds extra dependencies that we don't care about |
| 2960 | never: true, |
| 2961 | } |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2962 | } |
| 2963 | cc_binary { |
| 2964 | name: "binary", |
| 2965 | bazel_module: { label: "//:binary" }, |
| 2966 | static_libs: ["static_dep"], |
| 2967 | whole_static_libs: ["whole_static_dep"], |
| 2968 | shared_libs: ["shared_dep"], |
| 2969 | } |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 2970 | cc_library_headers { |
| 2971 | name: "lib_headers", |
| 2972 | bazel_module: { label: "//:lib_headers" }, |
| 2973 | static_libs: ["static_dep"], |
| 2974 | whole_static_libs: ["whole_static_dep"], |
| 2975 | shared_libs: ["shared_dep"], |
| 2976 | } |
| 2977 | cc_prebuilt_library { |
| 2978 | name: "lib_prebuilt", |
| 2979 | bazel_module: { label: "//:lib_prebuilt" }, |
| 2980 | static_libs: ["static_dep"], |
| 2981 | whole_static_libs: ["whole_static_dep"], |
| 2982 | shared_libs: ["shared_dep"], |
| 2983 | } |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2984 | ` |
| 2985 | |
| 2986 | testCases := []struct { |
| 2987 | name string |
| 2988 | moduleName string |
| 2989 | variant string |
| 2990 | androidMkInfo cquery.CcAndroidMkInfo |
| 2991 | }{ |
| 2992 | { |
| 2993 | name: "shared lib", |
| 2994 | moduleName: "lib", |
| 2995 | variant: "android_arm64_armv8-a_shared", |
| 2996 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 2997 | LocalStaticLibs: []string{"static_dep"}, |
| 2998 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 2999 | LocalSharedLibs: []string{"shared_dep"}, |
| 3000 | }, |
| 3001 | }, |
| 3002 | { |
| 3003 | name: "static lib", |
| 3004 | moduleName: "lib", |
| 3005 | variant: "android_arm64_armv8-a_static", |
| 3006 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3007 | LocalStaticLibs: []string{"static_dep"}, |
| 3008 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3009 | LocalSharedLibs: []string{"shared_dep"}, |
| 3010 | }, |
| 3011 | }, |
| 3012 | { |
| 3013 | name: "cc_test arm64", |
| 3014 | moduleName: "test", |
| 3015 | variant: "android_arm64_armv8-a", |
| 3016 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3017 | LocalStaticLibs: []string{"static_dep"}, |
| 3018 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3019 | LocalSharedLibs: []string{"shared_dep"}, |
| 3020 | }, |
| 3021 | }, |
| 3022 | { |
| 3023 | name: "cc_test arm", |
| 3024 | moduleName: "test", |
| 3025 | variant: "android_arm_armv7-a-neon", |
| 3026 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3027 | LocalStaticLibs: []string{"static_dep"}, |
| 3028 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3029 | LocalSharedLibs: []string{"shared_dep"}, |
| 3030 | }, |
| 3031 | }, |
| 3032 | { |
| 3033 | name: "cc_binary", |
| 3034 | moduleName: "binary", |
| 3035 | variant: "android_arm64_armv8-a", |
| 3036 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3037 | LocalStaticLibs: []string{"static_dep"}, |
| 3038 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3039 | LocalSharedLibs: []string{"shared_dep"}, |
| 3040 | }, |
| 3041 | }, |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3042 | { |
| 3043 | name: "cc_library_headers", |
| 3044 | moduleName: "lib_headers", |
| 3045 | variant: "android_arm64_armv8-a", |
| 3046 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3047 | LocalStaticLibs: []string{"static_dep"}, |
| 3048 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3049 | LocalSharedLibs: []string{"shared_dep"}, |
| 3050 | }, |
| 3051 | }, |
| 3052 | { |
| 3053 | name: "prebuilt lib static", |
| 3054 | moduleName: "lib_prebuilt", |
| 3055 | variant: "android_arm64_armv8-a_static", |
| 3056 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3057 | LocalStaticLibs: []string{"static_dep"}, |
| 3058 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3059 | LocalSharedLibs: []string{"shared_dep"}, |
| 3060 | }, |
| 3061 | }, |
| 3062 | { |
| 3063 | name: "prebuilt lib shared", |
| 3064 | moduleName: "lib_prebuilt", |
| 3065 | variant: "android_arm64_armv8-a_shared", |
| 3066 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3067 | LocalStaticLibs: []string{"static_dep"}, |
| 3068 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3069 | LocalSharedLibs: []string{"shared_dep"}, |
| 3070 | }, |
| 3071 | }, |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | outputBaseDir := "out/bazel" |
| 3075 | for _, tc := range testCases { |
| 3076 | t.Run(tc.name, func(t *testing.T) { |
| 3077 | result := android.GroupFixturePreparers( |
| 3078 | prepareForCcTest, |
| 3079 | android.FixtureModifyConfig(func(config android.Config) { |
| 3080 | config.BazelContext = android.MockBazelContext{ |
| 3081 | OutputBaseDir: outputBaseDir, |
| 3082 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 3083 | "//:lib": cquery.CcInfo{ |
| 3084 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3085 | RootDynamicLibraries: []string{""}, |
| 3086 | }, |
| 3087 | "//:lib_bp2build_cc_library_static": cquery.CcInfo{ |
| 3088 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3089 | RootStaticArchives: []string{""}, |
| 3090 | }, |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3091 | "//:lib_headers": cquery.CcInfo{ |
| 3092 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3093 | OutputFiles: []string{""}, |
| 3094 | }, |
| 3095 | "//:lib_prebuilt": cquery.CcInfo{ |
| 3096 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3097 | }, |
| 3098 | "//:lib_prebuilt_bp2build_cc_library_static": cquery.CcInfo{ |
| 3099 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3100 | }, |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3101 | }, |
| 3102 | LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{ |
Jingwen Chen | 6ee23ad | 2023-07-24 14:56:28 +0000 | [diff] [blame] | 3103 | "//:test__tf_internal": cquery.CcUnstrippedInfo{ |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3104 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3105 | }, |
| 3106 | "//:binary": cquery.CcUnstrippedInfo{ |
| 3107 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3108 | }, |
| 3109 | }, |
| 3110 | } |
| 3111 | }), |
| 3112 | ).RunTestWithBp(t, bp) |
| 3113 | ctx := result.TestContext |
| 3114 | |
| 3115 | module := ctx.ModuleForTests(tc.moduleName, tc.variant).Module().(*Module) |
| 3116 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3117 | if !reflect.DeepEqual(module.Properties.AndroidMkStaticLibs, tc.androidMkInfo.LocalStaticLibs) { |
| 3118 | t.Errorf("incorrect static_libs"+ |
| 3119 | "\nactual: %v"+ |
| 3120 | "\nexpected: %v", |
| 3121 | module.Properties.AndroidMkStaticLibs, |
| 3122 | tc.androidMkInfo.LocalStaticLibs, |
| 3123 | ) |
| 3124 | } |
| 3125 | staticDepsDiffer, missingStaticDeps, additionalStaticDeps := android.ListSetDifference( |
| 3126 | entries.EntryMap["LOCAL_STATIC_LIBRARIES"], |
| 3127 | tc.androidMkInfo.LocalStaticLibs, |
| 3128 | ) |
| 3129 | if staticDepsDiffer { |
| 3130 | t.Errorf( |
| 3131 | "expected LOCAL_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q", |
| 3132 | tc.androidMkInfo.LocalStaticLibs, |
| 3133 | entries.EntryMap["LOCAL_STATIC_LIBRARIES"], |
| 3134 | missingStaticDeps, |
| 3135 | additionalStaticDeps, |
| 3136 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3137 | } |
| 3138 | |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3139 | if !reflect.DeepEqual(module.Properties.AndroidMkWholeStaticLibs, tc.androidMkInfo.LocalWholeStaticLibs) { |
| 3140 | t.Errorf("expected module.Properties.AndroidMkWholeStaticLibs to be %q, but was %q", |
| 3141 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3142 | module.Properties.AndroidMkWholeStaticLibs, |
| 3143 | ) |
| 3144 | } |
| 3145 | wholeStaticDepsDiffer, missingWholeStaticDeps, additionalWholeStaticDeps := android.ListSetDifference( |
| 3146 | entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], |
| 3147 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3148 | ) |
| 3149 | if wholeStaticDepsDiffer { |
| 3150 | t.Errorf( |
| 3151 | "expected LOCAL_WHOLE_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q", |
| 3152 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3153 | entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], |
| 3154 | missingWholeStaticDeps, |
| 3155 | additionalWholeStaticDeps, |
| 3156 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3157 | } |
| 3158 | |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3159 | if !reflect.DeepEqual(module.Properties.AndroidMkSharedLibs, tc.androidMkInfo.LocalSharedLibs) { |
| 3160 | t.Errorf("incorrect shared_libs"+ |
| 3161 | "\nactual: %v"+ |
| 3162 | "\nexpected: %v", |
| 3163 | module.Properties.AndroidMkSharedLibs, |
| 3164 | tc.androidMkInfo.LocalSharedLibs, |
| 3165 | ) |
| 3166 | } |
| 3167 | sharedDepsDiffer, missingSharedDeps, additionalSharedDeps := android.ListSetDifference( |
| 3168 | entries.EntryMap["LOCAL_SHARED_LIBRARIES"], |
| 3169 | tc.androidMkInfo.LocalSharedLibs, |
| 3170 | ) |
| 3171 | if sharedDepsDiffer { |
| 3172 | t.Errorf( |
| 3173 | "expected LOCAL_SHARED_LIBRARIES to be %q but was %q; missing %q; extra %q", |
| 3174 | tc.androidMkInfo.LocalSharedLibs, |
| 3175 | entries.EntryMap["LOCAL_SHARED_LIBRARIES"], |
| 3176 | missingSharedDeps, |
| 3177 | additionalSharedDeps, |
| 3178 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3179 | } |
| 3180 | }) |
| 3181 | } |
| 3182 | } |
| 3183 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3184 | var compilerFlagsTestCases = []struct { |
| 3185 | in string |
| 3186 | out bool |
| 3187 | }{ |
| 3188 | { |
| 3189 | in: "a", |
| 3190 | out: false, |
| 3191 | }, |
| 3192 | { |
| 3193 | in: "-a", |
| 3194 | out: true, |
| 3195 | }, |
| 3196 | { |
| 3197 | in: "-Ipath/to/something", |
| 3198 | out: false, |
| 3199 | }, |
| 3200 | { |
| 3201 | in: "-isystempath/to/something", |
| 3202 | out: false, |
| 3203 | }, |
| 3204 | { |
| 3205 | in: "--coverage", |
| 3206 | out: false, |
| 3207 | }, |
| 3208 | { |
| 3209 | in: "-include a/b", |
| 3210 | out: true, |
| 3211 | }, |
| 3212 | { |
| 3213 | in: "-include a/b c/d", |
| 3214 | out: false, |
| 3215 | }, |
| 3216 | { |
| 3217 | in: "-DMACRO", |
| 3218 | out: true, |
| 3219 | }, |
| 3220 | { |
| 3221 | in: "-DMAC RO", |
| 3222 | out: false, |
| 3223 | }, |
| 3224 | { |
| 3225 | in: "-a -b", |
| 3226 | out: false, |
| 3227 | }, |
| 3228 | { |
| 3229 | in: "-DMACRO=definition", |
| 3230 | out: true, |
| 3231 | }, |
| 3232 | { |
| 3233 | in: "-DMACRO=defi nition", |
| 3234 | out: true, // TODO(jiyong): this should be false |
| 3235 | }, |
| 3236 | { |
| 3237 | in: "-DMACRO(x)=x + 1", |
| 3238 | out: true, |
| 3239 | }, |
| 3240 | { |
| 3241 | in: "-DMACRO=\"defi nition\"", |
| 3242 | out: true, |
| 3243 | }, |
| 3244 | } |
| 3245 | |
| 3246 | type mockContext struct { |
| 3247 | BaseModuleContext |
| 3248 | result bool |
| 3249 | } |
| 3250 | |
| 3251 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 3252 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 3253 | ctx.result = false |
| 3254 | } |
| 3255 | |
| 3256 | func TestCompilerFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3257 | t.Parallel() |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3258 | for _, testCase := range compilerFlagsTestCases { |
| 3259 | ctx := &mockContext{result: true} |
| 3260 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 3261 | if ctx.result != testCase.out { |
| 3262 | t.Errorf("incorrect output:") |
| 3263 | t.Errorf(" input: %#v", testCase.in) |
| 3264 | t.Errorf(" expected: %#v", testCase.out) |
| 3265 | t.Errorf(" got: %#v", ctx.result) |
| 3266 | } |
| 3267 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3268 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3269 | |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3270 | func TestRecovery(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3271 | t.Parallel() |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3272 | ctx := testCc(t, ` |
| 3273 | cc_library_shared { |
| 3274 | name: "librecovery", |
| 3275 | recovery: true, |
| 3276 | } |
| 3277 | cc_library_shared { |
| 3278 | name: "librecovery32", |
| 3279 | recovery: true, |
| 3280 | compile_multilib:"32", |
| 3281 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3282 | cc_library_shared { |
| 3283 | name: "libHalInRecovery", |
| 3284 | recovery_available: true, |
| 3285 | vendor: true, |
| 3286 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3287 | `) |
| 3288 | |
| 3289 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3290 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3291 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3292 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3293 | } |
| 3294 | |
| 3295 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3296 | if android.InList(arm64, variants) { |
| 3297 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3298 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3299 | |
| 3300 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3301 | if !recoveryModule.Platform() { |
| 3302 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3303 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3304 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3305 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3306 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3307 | t.Parallel() |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3308 | bp := ` |
| 3309 | cc_prebuilt_test_library_shared { |
| 3310 | name: "test_lib", |
| 3311 | relative_install_path: "foo/bar/baz", |
| 3312 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3313 | } |
| 3314 | |
| 3315 | cc_test { |
| 3316 | name: "main_test", |
| 3317 | data_libs: ["test_lib"], |
| 3318 | gtest: false, |
| 3319 | } |
| 3320 | ` |
| 3321 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 3322 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3323 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3324 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3325 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3326 | |
| 3327 | ctx := testCcWithConfig(t, config) |
| 3328 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3329 | testBinary := module.(*Module).linker.(*testBinary) |
| 3330 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3331 | if err != nil { |
| 3332 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3333 | } |
| 3334 | if len(outputFiles) != 1 { |
| 3335 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3336 | } |
| 3337 | if len(testBinary.dataPaths()) != 1 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 3338 | t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths()) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | outputPath := outputFiles[0].String() |
| 3342 | |
| 3343 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3344 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3345 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3346 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3347 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3348 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3349 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3350 | } |
| 3351 | } |
| 3352 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3353 | func TestVersionedStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3354 | t.Parallel() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3355 | ctx := testCc(t, ` |
| 3356 | cc_library_shared { |
| 3357 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3358 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3359 | stubs: { |
| 3360 | symbol_file: "foo.map.txt", |
| 3361 | versions: ["1", "2", "3"], |
| 3362 | }, |
| 3363 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3364 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3365 | cc_library_shared { |
| 3366 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3367 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3368 | shared_libs: ["libFoo#1"], |
| 3369 | }`) |
| 3370 | |
| 3371 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3372 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3373 | "android_arm64_armv8-a_shared", |
| 3374 | "android_arm64_armv8-a_shared_1", |
| 3375 | "android_arm64_armv8-a_shared_2", |
| 3376 | "android_arm64_armv8-a_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3377 | "android_arm64_armv8-a_shared_current", |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3378 | "android_arm_armv7-a-neon_shared", |
| 3379 | "android_arm_armv7-a-neon_shared_1", |
| 3380 | "android_arm_armv7-a-neon_shared_2", |
| 3381 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3382 | "android_arm_armv7-a-neon_shared_current", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3383 | } |
| 3384 | variantsMismatch := false |
| 3385 | if len(variants) != len(expectedVariants) { |
| 3386 | variantsMismatch = true |
| 3387 | } else { |
| 3388 | for _, v := range expectedVariants { |
| 3389 | if !inList(v, variants) { |
| 3390 | variantsMismatch = false |
| 3391 | } |
| 3392 | } |
| 3393 | } |
| 3394 | if variantsMismatch { |
| 3395 | t.Errorf("variants of libFoo expected:\n") |
| 3396 | for _, v := range expectedVariants { |
| 3397 | t.Errorf("%q\n", v) |
| 3398 | } |
| 3399 | t.Errorf(", but got:\n") |
| 3400 | for _, v := range variants { |
| 3401 | t.Errorf("%q\n", v) |
| 3402 | } |
| 3403 | } |
| 3404 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3405 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3406 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3407 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3408 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 3409 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 3410 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3411 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3412 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3413 | cFlags := libBarCompileRule.Args["cFlags"] |
| 3414 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 3415 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 3416 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 3417 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3418 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3419 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3420 | func TestStubsForLibraryInMultipleApexes(t *testing.T) { |
| 3421 | t.Parallel() |
| 3422 | ctx := testCc(t, ` |
| 3423 | cc_library_shared { |
| 3424 | name: "libFoo", |
| 3425 | srcs: ["foo.c"], |
| 3426 | stubs: { |
| 3427 | symbol_file: "foo.map.txt", |
| 3428 | versions: ["current"], |
| 3429 | }, |
| 3430 | apex_available: ["bar", "a1"], |
| 3431 | } |
| 3432 | |
| 3433 | cc_library_shared { |
| 3434 | name: "libBar", |
| 3435 | srcs: ["bar.c"], |
| 3436 | shared_libs: ["libFoo"], |
| 3437 | apex_available: ["a1"], |
| 3438 | } |
| 3439 | |
| 3440 | cc_library_shared { |
| 3441 | name: "libA1", |
| 3442 | srcs: ["a1.c"], |
| 3443 | shared_libs: ["libFoo"], |
| 3444 | apex_available: ["a1"], |
| 3445 | } |
| 3446 | |
| 3447 | cc_library_shared { |
| 3448 | name: "libBarA1", |
| 3449 | srcs: ["bara1.c"], |
| 3450 | shared_libs: ["libFoo"], |
| 3451 | apex_available: ["bar", "a1"], |
| 3452 | } |
| 3453 | |
| 3454 | cc_library_shared { |
| 3455 | name: "libAnyApex", |
| 3456 | srcs: ["anyApex.c"], |
| 3457 | shared_libs: ["libFoo"], |
| 3458 | apex_available: ["//apex_available:anyapex"], |
| 3459 | } |
| 3460 | |
| 3461 | cc_library_shared { |
| 3462 | name: "libBaz", |
| 3463 | srcs: ["baz.c"], |
| 3464 | shared_libs: ["libFoo"], |
| 3465 | apex_available: ["baz"], |
| 3466 | } |
| 3467 | |
| 3468 | cc_library_shared { |
| 3469 | name: "libQux", |
| 3470 | srcs: ["qux.c"], |
| 3471 | shared_libs: ["libFoo"], |
| 3472 | apex_available: ["qux", "bar"], |
| 3473 | }`) |
| 3474 | |
| 3475 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3476 | expectedVariants := []string{ |
| 3477 | "android_arm64_armv8-a_shared", |
| 3478 | "android_arm64_armv8-a_shared_current", |
| 3479 | "android_arm_armv7-a-neon_shared", |
| 3480 | "android_arm_armv7-a-neon_shared_current", |
| 3481 | } |
| 3482 | variantsMismatch := false |
| 3483 | if len(variants) != len(expectedVariants) { |
| 3484 | variantsMismatch = true |
| 3485 | } else { |
| 3486 | for _, v := range expectedVariants { |
| 3487 | if !inList(v, variants) { |
| 3488 | variantsMismatch = false |
| 3489 | } |
| 3490 | } |
| 3491 | } |
| 3492 | if variantsMismatch { |
| 3493 | t.Errorf("variants of libFoo expected:\n") |
| 3494 | for _, v := range expectedVariants { |
| 3495 | t.Errorf("%q\n", v) |
| 3496 | } |
| 3497 | t.Errorf(", but got:\n") |
| 3498 | for _, v := range variants { |
| 3499 | t.Errorf("%q\n", v) |
| 3500 | } |
| 3501 | } |
| 3502 | |
| 3503 | linkAgainstFoo := []string{"libBarA1"} |
| 3504 | linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} |
| 3505 | |
| 3506 | libFooPath := "libFoo/android_arm64_armv8-a_shared/libFoo.so" |
| 3507 | for _, lib := range linkAgainstFoo { |
| 3508 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3509 | libFlags := libLinkRule.Args["libFlags"] |
| 3510 | if !strings.Contains(libFlags, libFooPath) { |
| 3511 | t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | libFooStubPath := "libFoo/android_arm64_armv8-a_shared_current/libFoo.so" |
| 3516 | for _, lib := range linkAgainstFooStubs { |
| 3517 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3518 | libFlags := libLinkRule.Args["libFlags"] |
| 3519 | if !strings.Contains(libFlags, libFooStubPath) { |
| 3520 | t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) |
| 3521 | } |
| 3522 | } |
| 3523 | } |
| 3524 | |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 3525 | func TestMixedBuildUsesStubs(t *testing.T) { |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 3526 | t.Parallel() |
| 3527 | bp := ` |
| 3528 | cc_library_shared { |
| 3529 | name: "libFoo", |
| 3530 | bazel_module: { label: "//:libFoo" }, |
| 3531 | srcs: ["foo.c"], |
| 3532 | stubs: { |
| 3533 | symbol_file: "foo.map.txt", |
| 3534 | versions: ["current"], |
| 3535 | }, |
| 3536 | apex_available: ["bar", "a1"], |
| 3537 | } |
| 3538 | |
| 3539 | cc_library_shared { |
| 3540 | name: "libBar", |
| 3541 | srcs: ["bar.c"], |
| 3542 | shared_libs: ["libFoo"], |
| 3543 | apex_available: ["a1"], |
| 3544 | } |
| 3545 | |
| 3546 | cc_library_shared { |
| 3547 | name: "libA1", |
| 3548 | srcs: ["a1.c"], |
| 3549 | shared_libs: ["libFoo"], |
| 3550 | apex_available: ["a1"], |
| 3551 | } |
| 3552 | |
| 3553 | cc_library_shared { |
| 3554 | name: "libBarA1", |
| 3555 | srcs: ["bara1.c"], |
| 3556 | shared_libs: ["libFoo"], |
| 3557 | apex_available: ["bar", "a1"], |
| 3558 | } |
| 3559 | |
| 3560 | cc_library_shared { |
| 3561 | name: "libAnyApex", |
| 3562 | srcs: ["anyApex.c"], |
| 3563 | shared_libs: ["libFoo"], |
| 3564 | apex_available: ["//apex_available:anyapex"], |
| 3565 | } |
| 3566 | |
| 3567 | cc_library_shared { |
| 3568 | name: "libBaz", |
| 3569 | srcs: ["baz.c"], |
| 3570 | shared_libs: ["libFoo"], |
| 3571 | apex_available: ["baz"], |
| 3572 | } |
| 3573 | |
| 3574 | cc_library_shared { |
| 3575 | name: "libQux", |
| 3576 | srcs: ["qux.c"], |
| 3577 | shared_libs: ["libFoo"], |
| 3578 | apex_available: ["qux", "bar"], |
| 3579 | }` |
| 3580 | |
| 3581 | result := android.GroupFixturePreparers( |
| 3582 | prepareForCcTest, |
| 3583 | android.FixtureModifyConfig(func(config android.Config) { |
| 3584 | config.BazelContext = android.MockBazelContext{ |
| 3585 | OutputBaseDir: "out/bazel", |
| 3586 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 3587 | "//:libFoo": { |
| 3588 | RootDynamicLibraries: []string{"libFoo.so"}, |
| 3589 | }, |
| 3590 | "//:libFoo_stub_libs-current": { |
| 3591 | RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"}, |
| 3592 | }, |
| 3593 | }, |
| 3594 | } |
| 3595 | }), |
| 3596 | ).RunTestWithBp(t, bp) |
| 3597 | ctx := result.TestContext |
| 3598 | |
| 3599 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3600 | expectedVariants := []string{ |
| 3601 | "android_arm64_armv8-a_shared", |
| 3602 | "android_arm64_armv8-a_shared_current", |
| 3603 | "android_arm_armv7-a-neon_shared", |
| 3604 | "android_arm_armv7-a-neon_shared_current", |
| 3605 | } |
| 3606 | variantsMismatch := false |
| 3607 | if len(variants) != len(expectedVariants) { |
| 3608 | variantsMismatch = true |
| 3609 | } else { |
| 3610 | for _, v := range expectedVariants { |
| 3611 | if !inList(v, variants) { |
| 3612 | variantsMismatch = false |
| 3613 | } |
| 3614 | } |
| 3615 | } |
| 3616 | if variantsMismatch { |
| 3617 | t.Errorf("variants of libFoo expected:\n") |
| 3618 | for _, v := range expectedVariants { |
| 3619 | t.Errorf("%q\n", v) |
| 3620 | } |
| 3621 | t.Errorf(", but got:\n") |
| 3622 | for _, v := range variants { |
| 3623 | t.Errorf("%q\n", v) |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | linkAgainstFoo := []string{"libBarA1"} |
| 3628 | linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} |
| 3629 | |
| 3630 | libFooPath := "out/bazel/execroot/__main__/libFoo.so" |
| 3631 | for _, lib := range linkAgainstFoo { |
| 3632 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3633 | libFlags := libLinkRule.Args["libFlags"] |
| 3634 | if !strings.Contains(libFlags, libFooPath) { |
| 3635 | t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so" |
| 3640 | for _, lib := range linkAgainstFooStubs { |
| 3641 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3642 | libFlags := libLinkRule.Args["libFlags"] |
| 3643 | if !strings.Contains(libFlags, libFooStubPath) { |
| 3644 | t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) |
| 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3649 | func TestVersioningMacro(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3650 | t.Parallel() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3651 | for _, tc := range []struct{ moduleName, expected string }{ |
| 3652 | {"libc", "__LIBC_API__"}, |
| 3653 | {"libfoo", "__LIBFOO_API__"}, |
| 3654 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 3655 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 3656 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 3657 | } { |
| 3658 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 3659 | } |
| 3660 | } |
| 3661 | |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3662 | func pathsToBase(paths android.Paths) []string { |
| 3663 | var ret []string |
| 3664 | for _, p := range paths { |
| 3665 | ret = append(ret, p.Base()) |
| 3666 | } |
| 3667 | return ret |
| 3668 | } |
| 3669 | |
| 3670 | func TestStaticLibArchiveArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3671 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3672 | ctx := testCc(t, ` |
| 3673 | cc_library_static { |
| 3674 | name: "foo", |
| 3675 | srcs: ["foo.c"], |
| 3676 | } |
| 3677 | |
| 3678 | cc_library_static { |
| 3679 | name: "bar", |
| 3680 | srcs: ["bar.c"], |
| 3681 | } |
| 3682 | |
| 3683 | cc_library_shared { |
| 3684 | name: "qux", |
| 3685 | srcs: ["qux.c"], |
| 3686 | } |
| 3687 | |
| 3688 | cc_library_static { |
| 3689 | name: "baz", |
| 3690 | srcs: ["baz.c"], |
| 3691 | static_libs: ["foo"], |
| 3692 | shared_libs: ["qux"], |
| 3693 | whole_static_libs: ["bar"], |
| 3694 | }`) |
| 3695 | |
| 3696 | variant := "android_arm64_armv8-a_static" |
| 3697 | arRule := ctx.ModuleForTests("baz", variant).Rule("ar") |
| 3698 | |
| 3699 | // For static libraries, the object files of a whole static dep are included in the archive |
| 3700 | // directly |
| 3701 | if g, w := pathsToBase(arRule.Inputs), []string{"bar.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3702 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3703 | } |
| 3704 | |
| 3705 | // non whole static dependencies are not linked into the archive |
| 3706 | if len(arRule.Implicits) > 0 { |
| 3707 | t.Errorf("Expected 0 additional deps, got %q", arRule.Implicits) |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | func TestSharedLibLinkingArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3712 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3713 | ctx := testCc(t, ` |
| 3714 | cc_library_static { |
| 3715 | name: "foo", |
| 3716 | srcs: ["foo.c"], |
| 3717 | } |
| 3718 | |
| 3719 | cc_library_static { |
| 3720 | name: "bar", |
| 3721 | srcs: ["bar.c"], |
| 3722 | } |
| 3723 | |
| 3724 | cc_library_shared { |
| 3725 | name: "qux", |
| 3726 | srcs: ["qux.c"], |
| 3727 | } |
| 3728 | |
| 3729 | cc_library_shared { |
| 3730 | name: "baz", |
| 3731 | srcs: ["baz.c"], |
| 3732 | static_libs: ["foo"], |
| 3733 | shared_libs: ["qux"], |
| 3734 | whole_static_libs: ["bar"], |
| 3735 | }`) |
| 3736 | |
| 3737 | variant := "android_arm64_armv8-a_shared" |
| 3738 | linkRule := ctx.ModuleForTests("baz", variant).Rule("ld") |
| 3739 | libFlags := linkRule.Args["libFlags"] |
| 3740 | // When dynamically linking, we expect static dependencies to be found on the command line |
| 3741 | if expected := "foo.a"; !strings.Contains(libFlags, expected) { |
| 3742 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3743 | } |
| 3744 | // When dynamically linking, we expect whole static dependencies to be found on the command line |
| 3745 | if expected := "bar.a"; !strings.Contains(libFlags, expected) { |
| 3746 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3747 | } |
| 3748 | |
| 3749 | // When dynamically linking, we expect shared dependencies to be found on the command line |
| 3750 | if expected := "qux.so"; !strings.Contains(libFlags, expected) { |
| 3751 | t.Errorf("Shared lib %q was not found in %q", expected, libFlags) |
| 3752 | } |
| 3753 | |
| 3754 | // We should only have the objects from the shared library srcs, not the whole static dependencies |
| 3755 | if g, w := pathsToBase(linkRule.Inputs), []string{"baz.o"}; !reflect.DeepEqual(w, g) { |
| 3756 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3757 | } |
| 3758 | } |
| 3759 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3760 | func TestStaticExecutable(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3761 | t.Parallel() |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3762 | ctx := testCc(t, ` |
| 3763 | cc_binary { |
| 3764 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 3765 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3766 | static_executable: true, |
| 3767 | }`) |
| 3768 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3769 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3770 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 3771 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 3772 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3773 | for _, lib := range systemStaticLibs { |
| 3774 | if !strings.Contains(libFlags, lib) { |
| 3775 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 3776 | } |
| 3777 | } |
| 3778 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 3779 | for _, lib := range systemSharedLibs { |
| 3780 | if strings.Contains(libFlags, lib) { |
| 3781 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 3782 | } |
| 3783 | } |
| 3784 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3785 | |
| 3786 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3787 | t.Parallel() |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3788 | ctx := testCc(t, ` |
| 3789 | cc_binary { |
| 3790 | name: "mybin", |
| 3791 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3792 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3793 | static_executable: true, |
| 3794 | stl: "none", |
| 3795 | } |
| 3796 | |
| 3797 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3798 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3799 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3800 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3801 | stl: "none", |
| 3802 | } |
| 3803 | |
| 3804 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3805 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3806 | srcs: ["foo.c"], |
| 3807 | stl: "none", |
| 3808 | stubs: { |
| 3809 | versions: ["1"], |
| 3810 | }, |
| 3811 | }`) |
| 3812 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3813 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 3814 | actual := mybin.Implicits[:2] |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 3815 | expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3816 | |
| 3817 | if !reflect.DeepEqual(actual, expected) { |
| 3818 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3819 | "\nactual: %v"+ |
| 3820 | "\nexpected: %v", |
| 3821 | actual, |
| 3822 | expected, |
| 3823 | ) |
| 3824 | } |
| 3825 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3826 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3827 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3828 | t.Parallel() |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3829 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 3830 | cc_library { |
| 3831 | name: "libA", |
| 3832 | srcs: ["foo.c"], |
| 3833 | shared_libs: ["libB"], |
| 3834 | stl: "none", |
| 3835 | } |
| 3836 | |
| 3837 | cc_library { |
| 3838 | name: "libB", |
| 3839 | srcs: ["foo.c"], |
| 3840 | enabled: false, |
| 3841 | stl: "none", |
| 3842 | } |
| 3843 | `) |
| 3844 | } |
| 3845 | |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3846 | func VerifyAFLFuzzTargetVariant(t *testing.T, variant string) { |
| 3847 | bp := ` |
| 3848 | cc_fuzz { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3849 | name: "test_afl_fuzz_target", |
| 3850 | srcs: ["foo.c"], |
| 3851 | host_supported: true, |
| 3852 | static_libs: [ |
| 3853 | "afl_fuzz_static_lib", |
| 3854 | ], |
| 3855 | shared_libs: [ |
| 3856 | "afl_fuzz_shared_lib", |
| 3857 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3858 | fuzzing_frameworks: { |
| 3859 | afl: true, |
| 3860 | libfuzzer: false, |
| 3861 | }, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3862 | } |
| 3863 | cc_library { |
| 3864 | name: "afl_fuzz_static_lib", |
| 3865 | host_supported: true, |
| 3866 | srcs: ["static_file.c"], |
| 3867 | } |
| 3868 | cc_library { |
| 3869 | name: "libfuzzer_only_static_lib", |
| 3870 | host_supported: true, |
| 3871 | srcs: ["static_file.c"], |
| 3872 | } |
| 3873 | cc_library { |
| 3874 | name: "afl_fuzz_shared_lib", |
| 3875 | host_supported: true, |
| 3876 | srcs: ["shared_file.c"], |
| 3877 | static_libs: [ |
| 3878 | "second_static_lib", |
| 3879 | ], |
| 3880 | } |
| 3881 | cc_library_headers { |
| 3882 | name: "libafl_headers", |
| 3883 | vendor_available: true, |
| 3884 | host_supported: true, |
| 3885 | export_include_dirs: [ |
| 3886 | "include", |
| 3887 | "instrumentation", |
| 3888 | ], |
| 3889 | } |
| 3890 | cc_object { |
| 3891 | name: "afl-compiler-rt", |
| 3892 | vendor_available: true, |
| 3893 | host_supported: true, |
| 3894 | cflags: [ |
| 3895 | "-fPIC", |
| 3896 | ], |
| 3897 | srcs: [ |
| 3898 | "instrumentation/afl-compiler-rt.o.c", |
| 3899 | ], |
| 3900 | } |
| 3901 | cc_library { |
| 3902 | name: "second_static_lib", |
| 3903 | host_supported: true, |
| 3904 | srcs: ["second_file.c"], |
| 3905 | } |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3906 | cc_object { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3907 | name: "aflpp_driver", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3908 | host_supported: true, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3909 | srcs: [ |
| 3910 | "aflpp_driver.c", |
| 3911 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3912 | }` |
| 3913 | |
| 3914 | testEnv := map[string]string{ |
| 3915 | "FUZZ_FRAMEWORK": "AFL", |
| 3916 | } |
| 3917 | |
| 3918 | ctx := android.GroupFixturePreparers(prepareForCcTest, android.FixtureMergeEnv(testEnv)).RunTestWithBp(t, bp) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3919 | |
| 3920 | checkPcGuardFlag := func( |
| 3921 | modName string, variantName string, shouldHave bool) { |
| 3922 | cc := ctx.ModuleForTests(modName, variantName).Rule("cc") |
| 3923 | |
| 3924 | cFlags, ok := cc.Args["cFlags"] |
| 3925 | if !ok { |
| 3926 | t.Errorf("Could not find cFlags for module %s and variant %s", |
| 3927 | modName, variantName) |
| 3928 | } |
| 3929 | |
| 3930 | if strings.Contains( |
| 3931 | cFlags, "-fsanitize-coverage=trace-pc-guard") != shouldHave { |
| 3932 | t.Errorf("Flag was found: %t. Expected to find flag: %t. "+ |
| 3933 | "Test failed for module %s and variant %s", |
| 3934 | !shouldHave, shouldHave, modName, variantName) |
| 3935 | } |
| 3936 | } |
| 3937 | |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3938 | moduleName := "test_afl_fuzz_target" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3939 | checkPcGuardFlag(moduleName, variant+"_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3940 | |
| 3941 | moduleName = "afl_fuzz_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3942 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3943 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3944 | |
| 3945 | moduleName = "second_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3946 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3947 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3948 | |
| 3949 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
| 3950 | "android_arm64_armv8-a_shared").Rule("cc") |
| 3951 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3952 | "android_arm64_armv8-a_shared_fuzzer").Rule("cc") |
| 3953 | } |
| 3954 | |
| 3955 | func TestAFLFuzzTargetForDevice(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3956 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3957 | VerifyAFLFuzzTargetVariant(t, "android_arm64_armv8-a") |
| 3958 | } |
| 3959 | |
| 3960 | func TestAFLFuzzTargetForLinuxHost(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3961 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3962 | if runtime.GOOS != "linux" { |
| 3963 | t.Skip("requires linux") |
| 3964 | } |
| 3965 | |
| 3966 | VerifyAFLFuzzTargetVariant(t, "linux_glibc_x86_64") |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3969 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 3970 | // correctly. |
| 3971 | func TestFuzzTarget(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3972 | t.Parallel() |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3973 | ctx := testCc(t, ` |
| 3974 | cc_fuzz { |
| 3975 | name: "fuzz_smoke_test", |
| 3976 | srcs: ["foo.c"], |
| 3977 | }`) |
| 3978 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 3979 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3980 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 3981 | } |
| 3982 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3983 | func assertString(t *testing.T, got, expected string) { |
| 3984 | t.Helper() |
| 3985 | if got != expected { |
| 3986 | t.Errorf("expected %q got %q", expected, got) |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3991 | t.Helper() |
| 3992 | if len(got) != len(expected) { |
| 3993 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3994 | return |
| 3995 | } |
| 3996 | for i := range got { |
| 3997 | if got[i] != expected[i] { |
| 3998 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3999 | i, expected[i], expected, got[i], got) |
| 4000 | return |
| 4001 | } |
| 4002 | } |
| 4003 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4004 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 4005 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 4006 | t.Helper() |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 4007 | assertArrayString(t, android.SortedKeys(m), expected) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 4008 | } |
| 4009 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4010 | func TestDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4011 | t.Parallel() |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4012 | ctx := testCc(t, ` |
| 4013 | cc_defaults { |
| 4014 | name: "defaults", |
| 4015 | srcs: ["foo.c"], |
| 4016 | static: { |
| 4017 | srcs: ["bar.c"], |
| 4018 | }, |
| 4019 | shared: { |
| 4020 | srcs: ["baz.c"], |
| 4021 | }, |
Liz Kammer | 3cf5211 | 2021-03-31 15:42:03 -0400 | [diff] [blame] | 4022 | bazel_module: { |
| 4023 | bp2build_available: true, |
| 4024 | }, |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | cc_library_static { |
| 4028 | name: "libstatic", |
| 4029 | defaults: ["defaults"], |
| 4030 | } |
| 4031 | |
| 4032 | cc_library_shared { |
| 4033 | name: "libshared", |
| 4034 | defaults: ["defaults"], |
| 4035 | } |
| 4036 | |
| 4037 | cc_library { |
| 4038 | name: "libboth", |
| 4039 | defaults: ["defaults"], |
| 4040 | } |
| 4041 | |
| 4042 | cc_binary { |
| 4043 | name: "binary", |
| 4044 | defaults: ["defaults"], |
| 4045 | }`) |
| 4046 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4047 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4048 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4049 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 4050 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4051 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4052 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4053 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 4054 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4055 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4056 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 4057 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 4058 | } |
| 4059 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4060 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4061 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4062 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 4063 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4064 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4065 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4066 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 4067 | } |
| 4068 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4069 | |
| 4070 | func TestProductVariableDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4071 | t.Parallel() |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4072 | bp := ` |
| 4073 | cc_defaults { |
| 4074 | name: "libfoo_defaults", |
| 4075 | srcs: ["foo.c"], |
| 4076 | cppflags: ["-DFOO"], |
| 4077 | product_variables: { |
| 4078 | debuggable: { |
| 4079 | cppflags: ["-DBAR"], |
| 4080 | }, |
| 4081 | }, |
| 4082 | } |
| 4083 | |
| 4084 | cc_library { |
| 4085 | name: "libfoo", |
| 4086 | defaults: ["libfoo_defaults"], |
| 4087 | } |
| 4088 | ` |
| 4089 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 4090 | result := android.GroupFixturePreparers( |
| 4091 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4092 | android.PrepareForTestWithVariables, |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4093 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4094 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4095 | variables.Debuggable = BoolPtr(true) |
| 4096 | }), |
| 4097 | ).RunTestWithBp(t, bp) |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4098 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4099 | libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module) |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4100 | android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR") |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4101 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4102 | |
| 4103 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 4104 | t.Parallel() |
| 4105 | bp := ` |
| 4106 | cc_library_static { |
| 4107 | name: "libfoo", |
| 4108 | srcs: ["foo.c"], |
| 4109 | whole_static_libs: ["libbar"], |
| 4110 | } |
| 4111 | |
| 4112 | cc_library_static { |
| 4113 | name: "libbar", |
| 4114 | whole_static_libs: ["libmissing"], |
| 4115 | } |
| 4116 | ` |
| 4117 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 4118 | result := android.GroupFixturePreparers( |
| 4119 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4120 | android.PrepareForTestWithAllowMissingDependencies, |
| 4121 | ).RunTestWithBp(t, bp) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4122 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4123 | libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4124 | android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4125 | |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4126 | android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing") |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4127 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4128 | libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4129 | android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String()) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4130 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4131 | |
| 4132 | func TestInstallSharedLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4133 | t.Parallel() |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4134 | bp := ` |
| 4135 | cc_binary { |
| 4136 | name: "bin", |
| 4137 | host_supported: true, |
| 4138 | shared_libs: ["libshared"], |
| 4139 | runtime_libs: ["libruntime"], |
| 4140 | srcs: [":gen"], |
| 4141 | } |
| 4142 | |
| 4143 | cc_library_shared { |
| 4144 | name: "libshared", |
| 4145 | host_supported: true, |
| 4146 | shared_libs: ["libtransitive"], |
| 4147 | } |
| 4148 | |
| 4149 | cc_library_shared { |
| 4150 | name: "libtransitive", |
| 4151 | host_supported: true, |
| 4152 | } |
| 4153 | |
| 4154 | cc_library_shared { |
| 4155 | name: "libruntime", |
| 4156 | host_supported: true, |
| 4157 | } |
| 4158 | |
| 4159 | cc_binary_host { |
| 4160 | name: "tool", |
| 4161 | srcs: ["foo.cpp"], |
| 4162 | } |
| 4163 | |
| 4164 | genrule { |
| 4165 | name: "gen", |
| 4166 | tools: ["tool"], |
| 4167 | out: ["gen.cpp"], |
| 4168 | cmd: "$(location tool) $(out)", |
| 4169 | } |
| 4170 | ` |
| 4171 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 4172 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4173 | ctx := testCcWithConfig(t, config) |
| 4174 | |
| 4175 | hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install") |
| 4176 | hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4177 | hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4178 | hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4179 | hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install") |
| 4180 | |
| 4181 | if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) { |
| 4182 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4183 | } |
| 4184 | |
| 4185 | if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4186 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4187 | } |
| 4188 | |
| 4189 | if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4190 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4191 | } |
| 4192 | |
| 4193 | if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) { |
| 4194 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4195 | } |
| 4196 | |
| 4197 | if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4198 | t.Errorf("expected no host bin dependency %q, got %q", w, g) |
| 4199 | } |
| 4200 | |
| 4201 | deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install") |
| 4202 | deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install") |
| 4203 | deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install") |
| 4204 | deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install") |
| 4205 | |
| 4206 | if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) { |
| 4207 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4208 | } |
| 4209 | |
| 4210 | if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4211 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4212 | } |
| 4213 | |
| 4214 | if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4215 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4216 | } |
| 4217 | |
| 4218 | if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) { |
| 4219 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4220 | } |
| 4221 | |
| 4222 | if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4223 | t.Errorf("expected no device bin dependency %q, got %q", w, g) |
| 4224 | } |
| 4225 | |
| 4226 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 4227 | |
| 4228 | func TestStubsLibReexportsHeaders(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4229 | t.Parallel() |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 4230 | ctx := testCc(t, ` |
| 4231 | cc_library_shared { |
| 4232 | name: "libclient", |
| 4233 | srcs: ["foo.c"], |
| 4234 | shared_libs: ["libfoo#1"], |
| 4235 | } |
| 4236 | |
| 4237 | cc_library_shared { |
| 4238 | name: "libfoo", |
| 4239 | srcs: ["foo.c"], |
| 4240 | shared_libs: ["libbar"], |
| 4241 | export_shared_lib_headers: ["libbar"], |
| 4242 | stubs: { |
| 4243 | symbol_file: "foo.map.txt", |
| 4244 | versions: ["1", "2", "3"], |
| 4245 | }, |
| 4246 | } |
| 4247 | |
| 4248 | cc_library_shared { |
| 4249 | name: "libbar", |
| 4250 | export_include_dirs: ["include/libbar"], |
| 4251 | srcs: ["foo.c"], |
| 4252 | }`) |
| 4253 | |
| 4254 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4255 | |
| 4256 | if !strings.Contains(cFlags, "-Iinclude/libbar") { |
| 4257 | t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) |
| 4258 | } |
| 4259 | } |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4260 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4261 | func TestAidlLibraryWithHeaders(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4262 | t.Parallel() |
| 4263 | ctx := android.GroupFixturePreparers( |
| 4264 | prepareForCcTest, |
| 4265 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4266 | android.MockFS{ |
| 4267 | "package_bar/Android.bp": []byte(` |
| 4268 | aidl_library { |
| 4269 | name: "bar", |
| 4270 | srcs: ["x/y/Bar.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4271 | hdrs: ["x/HeaderBar.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4272 | strip_import_prefix: "x", |
| 4273 | } |
| 4274 | `)}.AddToFixture(), |
| 4275 | android.MockFS{ |
| 4276 | "package_foo/Android.bp": []byte(` |
| 4277 | aidl_library { |
| 4278 | name: "foo", |
| 4279 | srcs: ["a/b/Foo.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4280 | hdrs: ["a/HeaderFoo.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4281 | strip_import_prefix: "a", |
| 4282 | deps: ["bar"], |
| 4283 | } |
| 4284 | cc_library { |
| 4285 | name: "libfoo", |
| 4286 | aidl: { |
| 4287 | libs: ["foo"], |
| 4288 | } |
| 4289 | } |
| 4290 | `), |
| 4291 | }.AddToFixture(), |
| 4292 | ).RunTest(t).TestContext |
| 4293 | |
| 4294 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4295 | |
| 4296 | android.AssertPathsRelativeToTopEquals( |
| 4297 | t, |
| 4298 | "aidl headers", |
| 4299 | []string{ |
| 4300 | "package_bar/x/HeaderBar.aidl", |
| 4301 | "package_foo/a/HeaderFoo.aidl", |
| 4302 | "package_foo/a/b/Foo.aidl", |
| 4303 | "out/soong/.intermediates/package_foo/libfoo/android_arm64_armv8-a_static/gen/aidl_library.sbox.textproto", |
| 4304 | }, |
| 4305 | libfoo.Rule("aidl_library").Implicits, |
| 4306 | ) |
| 4307 | |
| 4308 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl_library.sbox.textproto")) |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4309 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4310 | |
| 4311 | expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x" |
| 4312 | if !strings.Contains(aidlCommand, expectedAidlFlags) { |
| 4313 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags) |
| 4314 | } |
| 4315 | |
| 4316 | outputs := strings.Join(libfoo.AllOutputs(), " ") |
| 4317 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4318 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BpFoo.h") |
| 4319 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BnFoo.h") |
| 4320 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/Foo.h") |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4321 | android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp") |
| 4322 | // Confirm that the aidl header doesn't get compiled to cpp and h files |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4323 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BpBar.h") |
| 4324 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BnBar.h") |
| 4325 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/Bar.h") |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4326 | android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp") |
| 4327 | } |
| 4328 | |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4329 | func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4330 | t.Parallel() |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4331 | ctx := android.GroupFixturePreparers( |
| 4332 | prepareForCcTest, |
| 4333 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4334 | ).RunTestWithBp(t, ` |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4335 | cc_library { |
| 4336 | name: "libfoo", |
| 4337 | srcs: ["a/Foo.aidl"], |
| 4338 | aidl: { flags: ["-Werror"], }, |
| 4339 | } |
| 4340 | `) |
| 4341 | |
| 4342 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
| 4343 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 4344 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4345 | expectedAidlFlag := "-Werror" |
| 4346 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4347 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4348 | } |
| 4349 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 4350 | |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 4351 | func TestAidlFlagsWithMinSdkVersion(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4352 | t.Parallel() |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 4353 | for _, tc := range []struct { |
| 4354 | name string |
| 4355 | sdkVersion string |
| 4356 | variant string |
| 4357 | expected string |
| 4358 | }{ |
| 4359 | { |
| 4360 | name: "default is current", |
| 4361 | sdkVersion: "", |
| 4362 | variant: "android_arm64_armv8-a_static", |
| 4363 | expected: "platform_apis", |
| 4364 | }, |
| 4365 | { |
| 4366 | name: "use sdk_version", |
| 4367 | sdkVersion: `sdk_version: "29"`, |
| 4368 | variant: "android_arm64_armv8-a_static", |
| 4369 | expected: "platform_apis", |
| 4370 | }, |
| 4371 | { |
| 4372 | name: "use sdk_version(sdk variant)", |
| 4373 | sdkVersion: `sdk_version: "29"`, |
| 4374 | variant: "android_arm64_armv8-a_sdk_static", |
| 4375 | expected: "29", |
| 4376 | }, |
| 4377 | { |
| 4378 | name: "use min_sdk_version", |
| 4379 | sdkVersion: `min_sdk_version: "29"`, |
| 4380 | variant: "android_arm64_armv8-a_static", |
| 4381 | expected: "29", |
| 4382 | }, |
| 4383 | } { |
| 4384 | t.Run(tc.name, func(t *testing.T) { |
| 4385 | ctx := testCc(t, ` |
| 4386 | cc_library { |
| 4387 | name: "libfoo", |
| 4388 | stl: "none", |
| 4389 | srcs: ["a/Foo.aidl"], |
| 4390 | `+tc.sdkVersion+` |
| 4391 | } |
| 4392 | `) |
| 4393 | libfoo := ctx.ModuleForTests("libfoo", tc.variant) |
| 4394 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 4395 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4396 | expectedAidlFlag := "--min_sdk_version=" + tc.expected |
| 4397 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4398 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4399 | } |
| 4400 | }) |
| 4401 | } |
| 4402 | } |
| 4403 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4404 | func TestInvalidAidlProp(t *testing.T) { |
| 4405 | t.Parallel() |
| 4406 | |
| 4407 | testCases := []struct { |
| 4408 | description string |
| 4409 | bp string |
| 4410 | }{ |
| 4411 | { |
| 4412 | description: "Invalid use of aidl.libs and aidl.include_dirs", |
| 4413 | bp: ` |
| 4414 | cc_library { |
| 4415 | name: "foo", |
| 4416 | aidl: { |
| 4417 | libs: ["foo_aidl"], |
| 4418 | include_dirs: ["bar/include"], |
| 4419 | } |
| 4420 | } |
| 4421 | `, |
| 4422 | }, |
| 4423 | { |
| 4424 | description: "Invalid use of aidl.libs and aidl.local_include_dirs", |
| 4425 | bp: ` |
| 4426 | cc_library { |
| 4427 | name: "foo", |
| 4428 | aidl: { |
| 4429 | libs: ["foo_aidl"], |
| 4430 | local_include_dirs: ["include"], |
| 4431 | } |
| 4432 | } |
| 4433 | `, |
| 4434 | }, |
| 4435 | } |
| 4436 | |
| 4437 | for _, testCase := range testCases { |
| 4438 | t.Run(testCase.description, func(t *testing.T) { |
| 4439 | bp := ` |
| 4440 | aidl_library { |
| 4441 | name: "foo_aidl", |
| 4442 | srcs: ["Foo.aidl"], |
| 4443 | } ` + testCase.bp |
| 4444 | android.GroupFixturePreparers( |
| 4445 | prepareForCcTest, |
| 4446 | aidl_library.PrepareForTestWithAidlLibrary. |
| 4447 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("For aidl headers, please only use aidl.libs prop")), |
| 4448 | ).RunTestWithBp(t, bp) |
| 4449 | }) |
| 4450 | } |
| 4451 | } |
| 4452 | |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4453 | func TestMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4454 | t.Parallel() |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4455 | ctx := testCc(t, ` |
| 4456 | cc_library_shared { |
| 4457 | name: "libfoo", |
| 4458 | srcs: ["foo.c"], |
| 4459 | min_sdk_version: "29", |
| 4460 | }`) |
| 4461 | |
| 4462 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4463 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29") |
| 4464 | } |
| 4465 | |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4466 | func TestNonDigitMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4467 | t.Parallel() |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4468 | bp := ` |
| 4469 | cc_library_shared { |
| 4470 | name: "libfoo", |
| 4471 | srcs: ["foo.c"], |
| 4472 | min_sdk_version: "S", |
| 4473 | } |
| 4474 | ` |
| 4475 | result := android.GroupFixturePreparers( |
| 4476 | prepareForCcTest, |
| 4477 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4478 | variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu"} |
| 4479 | }), |
| 4480 | ).RunTestWithBp(t, bp) |
| 4481 | ctx := result.TestContext |
| 4482 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4483 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android31") |
| 4484 | } |
| 4485 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4486 | func TestIncludeDirsExporting(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4487 | t.Parallel() |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4488 | |
| 4489 | // Trim spaces from the beginning, end and immediately after any newline characters. Leaves |
| 4490 | // embedded newline characters alone. |
| 4491 | trimIndentingSpaces := func(s string) string { |
| 4492 | return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1")) |
| 4493 | } |
| 4494 | |
| 4495 | checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) { |
| 4496 | t.Helper() |
| 4497 | expected = trimIndentingSpaces(expected) |
| 4498 | actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n")) |
| 4499 | if expected != actual { |
| 4500 | t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual) |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo) |
| 4505 | |
| 4506 | checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) { |
| 4507 | t.Helper() |
| 4508 | exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo) |
| 4509 | name := module.Name() |
| 4510 | |
| 4511 | for _, checker := range checkers { |
| 4512 | checker(t, name, exported) |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | expectedIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4517 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4518 | t.Helper() |
| 4519 | checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs) |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4524 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4525 | t.Helper() |
| 4526 | checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs) |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | expectedGeneratedHeaders := func(expectedPaths string) exportedChecker { |
| 4531 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4532 | t.Helper() |
| 4533 | checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders) |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker { |
| 4538 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4539 | t.Helper() |
| 4540 | checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps) |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | genRuleModules := ` |
| 4545 | genrule { |
| 4546 | name: "genrule_foo", |
| 4547 | cmd: "generate-foo", |
| 4548 | out: [ |
| 4549 | "generated_headers/foo/generated_header.h", |
| 4550 | ], |
| 4551 | export_include_dirs: [ |
| 4552 | "generated_headers", |
| 4553 | ], |
| 4554 | } |
| 4555 | |
| 4556 | genrule { |
| 4557 | name: "genrule_bar", |
| 4558 | cmd: "generate-bar", |
| 4559 | out: [ |
| 4560 | "generated_headers/bar/generated_header.h", |
| 4561 | ], |
| 4562 | export_include_dirs: [ |
| 4563 | "generated_headers", |
| 4564 | ], |
| 4565 | } |
| 4566 | ` |
| 4567 | |
| 4568 | t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) { |
| 4569 | ctx := testCc(t, genRuleModules+` |
| 4570 | cc_library { |
| 4571 | name: "libfoo", |
| 4572 | srcs: ["foo.c"], |
| 4573 | export_include_dirs: ["foo/standard"], |
| 4574 | export_system_include_dirs: ["foo/system"], |
| 4575 | generated_headers: ["genrule_foo"], |
| 4576 | export_generated_headers: ["genrule_foo"], |
| 4577 | } |
| 4578 | |
| 4579 | cc_library { |
| 4580 | name: "libbar", |
| 4581 | srcs: ["bar.c"], |
| 4582 | shared_libs: ["libfoo"], |
| 4583 | export_include_dirs: ["bar/standard"], |
| 4584 | export_system_include_dirs: ["bar/system"], |
| 4585 | generated_headers: ["genrule_bar"], |
| 4586 | export_generated_headers: ["genrule_bar"], |
| 4587 | } |
| 4588 | `) |
| 4589 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4590 | checkIncludeDirs(t, ctx, foo, |
| 4591 | expectedIncludeDirs(` |
| 4592 | foo/standard |
| 4593 | .intermediates/genrule_foo/gen/generated_headers |
| 4594 | `), |
| 4595 | expectedSystemIncludeDirs(`foo/system`), |
| 4596 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4597 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4598 | ) |
| 4599 | |
| 4600 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4601 | checkIncludeDirs(t, ctx, bar, |
| 4602 | expectedIncludeDirs(` |
| 4603 | bar/standard |
| 4604 | .intermediates/genrule_bar/gen/generated_headers |
| 4605 | `), |
| 4606 | expectedSystemIncludeDirs(`bar/system`), |
| 4607 | expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4608 | expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4609 | ) |
| 4610 | }) |
| 4611 | |
| 4612 | t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) { |
| 4613 | ctx := testCc(t, genRuleModules+` |
| 4614 | cc_library { |
| 4615 | name: "libfoo", |
| 4616 | srcs: ["foo.c"], |
| 4617 | export_include_dirs: ["foo/standard"], |
| 4618 | export_system_include_dirs: ["foo/system"], |
| 4619 | generated_headers: ["genrule_foo"], |
| 4620 | export_generated_headers: ["genrule_foo"], |
| 4621 | } |
| 4622 | |
| 4623 | cc_library { |
| 4624 | name: "libbar", |
| 4625 | srcs: ["bar.c"], |
| 4626 | whole_static_libs: ["libfoo"], |
| 4627 | export_include_dirs: ["bar/standard"], |
| 4628 | export_system_include_dirs: ["bar/system"], |
| 4629 | generated_headers: ["genrule_bar"], |
| 4630 | export_generated_headers: ["genrule_bar"], |
| 4631 | } |
| 4632 | `) |
| 4633 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4634 | checkIncludeDirs(t, ctx, foo, |
| 4635 | expectedIncludeDirs(` |
| 4636 | foo/standard |
| 4637 | .intermediates/genrule_foo/gen/generated_headers |
| 4638 | `), |
| 4639 | expectedSystemIncludeDirs(`foo/system`), |
| 4640 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4641 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4642 | ) |
| 4643 | |
| 4644 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4645 | checkIncludeDirs(t, ctx, bar, |
| 4646 | expectedIncludeDirs(` |
| 4647 | bar/standard |
| 4648 | foo/standard |
| 4649 | .intermediates/genrule_foo/gen/generated_headers |
| 4650 | .intermediates/genrule_bar/gen/generated_headers |
| 4651 | `), |
| 4652 | expectedSystemIncludeDirs(` |
| 4653 | bar/system |
| 4654 | foo/system |
| 4655 | `), |
| 4656 | expectedGeneratedHeaders(` |
| 4657 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4658 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4659 | `), |
| 4660 | expectedOrderOnlyDeps(` |
| 4661 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4662 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4663 | `), |
| 4664 | ) |
| 4665 | }) |
| 4666 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4667 | t.Run("ensure only aidl headers are exported", func(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4668 | ctx := android.GroupFixturePreparers( |
| 4669 | prepareForCcTest, |
| 4670 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4671 | ).RunTestWithBp(t, ` |
| 4672 | aidl_library { |
| 4673 | name: "libfoo_aidl", |
| 4674 | srcs: ["x/y/Bar.aidl"], |
| 4675 | strip_import_prefix: "x", |
| 4676 | } |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4677 | cc_library_shared { |
| 4678 | name: "libfoo", |
| 4679 | srcs: [ |
| 4680 | "foo.c", |
| 4681 | "b.aidl", |
| 4682 | "a.proto", |
| 4683 | ], |
| 4684 | aidl: { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4685 | libs: ["libfoo_aidl"], |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4686 | export_aidl_headers: true, |
| 4687 | } |
| 4688 | } |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4689 | `).TestContext |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4690 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4691 | checkIncludeDirs(t, ctx, foo, |
| 4692 | expectedIncludeDirs(` |
| 4693 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4694 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4695 | `), |
| 4696 | expectedSystemIncludeDirs(``), |
| 4697 | expectedGeneratedHeaders(` |
| 4698 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4699 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4700 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4701 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4702 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4703 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4704 | `), |
| 4705 | expectedOrderOnlyDeps(` |
| 4706 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4707 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4708 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4709 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4710 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4711 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4712 | `), |
| 4713 | ) |
| 4714 | }) |
| 4715 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4716 | t.Run("ensure only proto headers are exported", func(t *testing.T) { |
| 4717 | ctx := testCc(t, genRuleModules+` |
| 4718 | cc_library_shared { |
| 4719 | name: "libfoo", |
| 4720 | srcs: [ |
| 4721 | "foo.c", |
| 4722 | "b.aidl", |
| 4723 | "a.proto", |
| 4724 | ], |
| 4725 | proto: { |
| 4726 | export_proto_headers: true, |
| 4727 | } |
| 4728 | } |
| 4729 | `) |
| 4730 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4731 | checkIncludeDirs(t, ctx, foo, |
| 4732 | expectedIncludeDirs(` |
| 4733 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto |
| 4734 | `), |
| 4735 | expectedSystemIncludeDirs(``), |
| 4736 | expectedGeneratedHeaders(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4737 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4738 | `), |
| 4739 | expectedOrderOnlyDeps(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4740 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4741 | `), |
| 4742 | ) |
| 4743 | }) |
| 4744 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 4745 | t.Run("ensure only sysprop headers are exported", func(t *testing.T) { |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4746 | ctx := testCc(t, genRuleModules+` |
| 4747 | cc_library_shared { |
| 4748 | name: "libfoo", |
| 4749 | srcs: [ |
| 4750 | "foo.c", |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4751 | "path/to/a.sysprop", |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4752 | "b.aidl", |
| 4753 | "a.proto", |
| 4754 | ], |
| 4755 | } |
| 4756 | `) |
| 4757 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4758 | checkIncludeDirs(t, ctx, foo, |
| 4759 | expectedIncludeDirs(` |
| 4760 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include |
| 4761 | `), |
| 4762 | expectedSystemIncludeDirs(``), |
| 4763 | expectedGeneratedHeaders(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4764 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4765 | `), |
| 4766 | expectedOrderOnlyDeps(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4767 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h |
| 4768 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/path/to/a.sysprop.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4769 | `), |
| 4770 | ) |
| 4771 | }) |
| 4772 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4773 | |
| 4774 | func TestIncludeDirectoryOrdering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4775 | t.Parallel() |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4776 | baseExpectedFlags := []string{ |
| 4777 | "${config.ArmThumbCflags}", |
| 4778 | "${config.ArmCflags}", |
| 4779 | "${config.CommonGlobalCflags}", |
| 4780 | "${config.DeviceGlobalCflags}", |
| 4781 | "${config.ExternalCflags}", |
| 4782 | "${config.ArmToolchainCflags}", |
| 4783 | "${config.ArmArmv7ANeonCflags}", |
| 4784 | "${config.ArmGenericCflags}", |
| 4785 | "-target", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4786 | "armv7a-linux-androideabi21", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | expectedIncludes := []string{ |
| 4790 | "external/foo/android_arm_export_include_dirs", |
| 4791 | "external/foo/lib32_export_include_dirs", |
| 4792 | "external/foo/arm_export_include_dirs", |
| 4793 | "external/foo/android_export_include_dirs", |
| 4794 | "external/foo/linux_export_include_dirs", |
| 4795 | "external/foo/export_include_dirs", |
| 4796 | "external/foo/android_arm_local_include_dirs", |
| 4797 | "external/foo/lib32_local_include_dirs", |
| 4798 | "external/foo/arm_local_include_dirs", |
| 4799 | "external/foo/android_local_include_dirs", |
| 4800 | "external/foo/linux_local_include_dirs", |
| 4801 | "external/foo/local_include_dirs", |
| 4802 | "external/foo", |
| 4803 | "external/foo/libheader1", |
| 4804 | "external/foo/libheader2", |
| 4805 | "external/foo/libwhole1", |
| 4806 | "external/foo/libwhole2", |
| 4807 | "external/foo/libstatic1", |
| 4808 | "external/foo/libstatic2", |
| 4809 | "external/foo/libshared1", |
| 4810 | "external/foo/libshared2", |
| 4811 | "external/foo/liblinux", |
| 4812 | "external/foo/libandroid", |
| 4813 | "external/foo/libarm", |
| 4814 | "external/foo/lib32", |
| 4815 | "external/foo/libandroid_arm", |
| 4816 | "defaults/cc/common/ndk_libc++_shared", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"} |
| 4820 | cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"} |
| 4821 | |
Elliott Hughes | ed4a27b | 2022-05-18 13:15:00 -0700 | [diff] [blame] | 4822 | cflags := []string{"-Werror", "-std=candcpp"} |
Elliott Hughes | fb294e3 | 2023-06-14 10:42:45 -0700 | [diff] [blame] | 4823 | cstd := []string{"-std=gnu17", "-std=conly"} |
Liz Kammer | 9dc6577 | 2021-12-16 11:38:50 -0500 | [diff] [blame] | 4824 | cppstd := []string{"-std=gnu++17", "-std=cpp", "-fno-rtti"} |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4825 | |
| 4826 | lastIncludes := []string{ |
| 4827 | "out/soong/ndk/sysroot/usr/include", |
| 4828 | "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi", |
| 4829 | } |
| 4830 | |
| 4831 | combineSlices := func(slices ...[]string) []string { |
| 4832 | var ret []string |
| 4833 | for _, s := range slices { |
| 4834 | ret = append(ret, s...) |
| 4835 | } |
| 4836 | return ret |
| 4837 | } |
| 4838 | |
| 4839 | testCases := []struct { |
| 4840 | name string |
| 4841 | src string |
| 4842 | expected []string |
| 4843 | }{ |
| 4844 | { |
| 4845 | name: "c", |
| 4846 | src: "foo.c", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4847 | expected: combineSlices(baseExpectedFlags, conly, expectedIncludes, cflags, cstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}), |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4848 | }, |
| 4849 | { |
| 4850 | name: "cc", |
| 4851 | src: "foo.cc", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4852 | expected: combineSlices(baseExpectedFlags, cppOnly, expectedIncludes, cflags, cppstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}), |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4853 | }, |
| 4854 | { |
| 4855 | name: "assemble", |
| 4856 | src: "foo.s", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4857 | expected: combineSlices(baseExpectedFlags, []string{"${config.CommonGlobalAsflags}"}, expectedIncludes, lastIncludes), |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4858 | }, |
| 4859 | } |
| 4860 | |
| 4861 | for _, tc := range testCases { |
| 4862 | t.Run(tc.name, func(t *testing.T) { |
| 4863 | bp := fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4864 | cc_library { |
| 4865 | name: "libfoo", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4866 | srcs: ["%s"], |
Liz Kammer | 9dc6577 | 2021-12-16 11:38:50 -0500 | [diff] [blame] | 4867 | cflags: ["-std=candcpp"], |
| 4868 | conlyflags: ["-std=conly"], |
| 4869 | cppflags: ["-std=cpp"], |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4870 | local_include_dirs: ["local_include_dirs"], |
| 4871 | export_include_dirs: ["export_include_dirs"], |
| 4872 | export_system_include_dirs: ["export_system_include_dirs"], |
| 4873 | static_libs: ["libstatic1", "libstatic2"], |
| 4874 | whole_static_libs: ["libwhole1", "libwhole2"], |
| 4875 | shared_libs: ["libshared1", "libshared2"], |
| 4876 | header_libs: ["libheader1", "libheader2"], |
| 4877 | target: { |
| 4878 | android: { |
| 4879 | shared_libs: ["libandroid"], |
| 4880 | local_include_dirs: ["android_local_include_dirs"], |
| 4881 | export_include_dirs: ["android_export_include_dirs"], |
| 4882 | }, |
| 4883 | android_arm: { |
| 4884 | shared_libs: ["libandroid_arm"], |
| 4885 | local_include_dirs: ["android_arm_local_include_dirs"], |
| 4886 | export_include_dirs: ["android_arm_export_include_dirs"], |
| 4887 | }, |
| 4888 | linux: { |
| 4889 | shared_libs: ["liblinux"], |
| 4890 | local_include_dirs: ["linux_local_include_dirs"], |
| 4891 | export_include_dirs: ["linux_export_include_dirs"], |
| 4892 | }, |
| 4893 | }, |
| 4894 | multilib: { |
| 4895 | lib32: { |
| 4896 | shared_libs: ["lib32"], |
| 4897 | local_include_dirs: ["lib32_local_include_dirs"], |
| 4898 | export_include_dirs: ["lib32_export_include_dirs"], |
| 4899 | }, |
| 4900 | }, |
| 4901 | arch: { |
| 4902 | arm: { |
| 4903 | shared_libs: ["libarm"], |
| 4904 | local_include_dirs: ["arm_local_include_dirs"], |
| 4905 | export_include_dirs: ["arm_export_include_dirs"], |
| 4906 | }, |
| 4907 | }, |
| 4908 | stl: "libc++", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4909 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | cc_library_headers { |
| 4913 | name: "libheader1", |
| 4914 | export_include_dirs: ["libheader1"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4915 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4916 | stl: "none", |
| 4917 | } |
| 4918 | |
| 4919 | cc_library_headers { |
| 4920 | name: "libheader2", |
| 4921 | export_include_dirs: ["libheader2"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4922 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4923 | stl: "none", |
| 4924 | } |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4925 | `, tc.src) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4926 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4927 | libs := []string{ |
| 4928 | "libstatic1", |
| 4929 | "libstatic2", |
| 4930 | "libwhole1", |
| 4931 | "libwhole2", |
| 4932 | "libshared1", |
| 4933 | "libshared2", |
| 4934 | "libandroid", |
| 4935 | "libandroid_arm", |
| 4936 | "liblinux", |
| 4937 | "lib32", |
| 4938 | "libarm", |
| 4939 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4940 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4941 | for _, lib := range libs { |
| 4942 | bp += fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4943 | cc_library { |
| 4944 | name: "%s", |
| 4945 | export_include_dirs: ["%s"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4946 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4947 | stl: "none", |
| 4948 | } |
| 4949 | `, lib, lib) |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | ctx := android.GroupFixturePreparers( |
| 4953 | PrepareForIntegrationTestWithCc, |
| 4954 | android.FixtureAddTextFile("external/foo/Android.bp", bp), |
| 4955 | ).RunTest(t) |
| 4956 | // Use the arm variant instead of the arm64 variant so that it gets headers from |
| 4957 | // ndk_libandroid_support to test LateStaticLibs. |
| 4958 | cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"] |
| 4959 | |
| 4960 | var includes []string |
| 4961 | flags := strings.Split(cflags, " ") |
| 4962 | for _, flag := range flags { |
| 4963 | if strings.HasPrefix(flag, "-I") { |
| 4964 | includes = append(includes, strings.TrimPrefix(flag, "-I")) |
| 4965 | } else if flag == "-isystem" { |
| 4966 | // skip isystem, include next |
| 4967 | } else if len(flag) > 0 { |
| 4968 | includes = append(includes, flag) |
| 4969 | } |
| 4970 | } |
| 4971 | |
| 4972 | android.AssertArrayString(t, "includes", tc.expected, includes) |
| 4973 | }) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4976 | } |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 4977 | |
zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 4978 | func TestAddnoOverride64GlobalCflags(t *testing.T) { |
| 4979 | t.Parallel() |
| 4980 | ctx := testCc(t, ` |
| 4981 | cc_library_shared { |
| 4982 | name: "libclient", |
| 4983 | srcs: ["foo.c"], |
| 4984 | shared_libs: ["libfoo#1"], |
| 4985 | } |
| 4986 | |
| 4987 | cc_library_shared { |
| 4988 | name: "libfoo", |
| 4989 | srcs: ["foo.c"], |
| 4990 | shared_libs: ["libbar"], |
| 4991 | export_shared_lib_headers: ["libbar"], |
| 4992 | stubs: { |
| 4993 | symbol_file: "foo.map.txt", |
| 4994 | versions: ["1", "2", "3"], |
| 4995 | }, |
| 4996 | } |
| 4997 | |
| 4998 | cc_library_shared { |
| 4999 | name: "libbar", |
| 5000 | export_include_dirs: ["include/libbar"], |
| 5001 | srcs: ["foo.c"], |
| 5002 | }`) |
| 5003 | |
| 5004 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 5005 | |
| 5006 | if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") { |
| 5007 | t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags) |
| 5008 | } |
| 5009 | } |
| 5010 | |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 5011 | func TestCcBuildBrokenClangProperty(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5012 | t.Parallel() |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 5013 | tests := []struct { |
| 5014 | name string |
| 5015 | clang bool |
| 5016 | BuildBrokenClangProperty bool |
| 5017 | err string |
| 5018 | }{ |
| 5019 | { |
| 5020 | name: "error when clang is set to false", |
| 5021 | clang: false, |
| 5022 | err: "is no longer supported", |
| 5023 | }, |
| 5024 | { |
| 5025 | name: "error when clang is set to true", |
| 5026 | clang: true, |
| 5027 | err: "property is deprecated, see Changes.md", |
| 5028 | }, |
| 5029 | { |
| 5030 | name: "no error when BuildBrokenClangProperty is explicitly set to true", |
| 5031 | clang: true, |
| 5032 | BuildBrokenClangProperty: true, |
| 5033 | }, |
| 5034 | } |
| 5035 | |
| 5036 | for _, test := range tests { |
| 5037 | t.Run(test.name, func(t *testing.T) { |
| 5038 | bp := fmt.Sprintf(` |
| 5039 | cc_library { |
| 5040 | name: "foo", |
| 5041 | clang: %t, |
| 5042 | }`, test.clang) |
| 5043 | |
| 5044 | if test.err == "" { |
| 5045 | android.GroupFixturePreparers( |
| 5046 | prepareForCcTest, |
| 5047 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5048 | if test.BuildBrokenClangProperty { |
| 5049 | variables.BuildBrokenClangProperty = test.BuildBrokenClangProperty |
| 5050 | } |
| 5051 | }), |
| 5052 | ).RunTestWithBp(t, bp) |
| 5053 | } else { |
| 5054 | prepareForCcTest. |
| 5055 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5056 | RunTestWithBp(t, bp) |
| 5057 | } |
| 5058 | }) |
| 5059 | } |
| 5060 | } |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5061 | |
| 5062 | func TestCcBuildBrokenClangAsFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5063 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5064 | tests := []struct { |
| 5065 | name string |
| 5066 | clangAsFlags []string |
| 5067 | BuildBrokenClangAsFlags bool |
| 5068 | err string |
| 5069 | }{ |
| 5070 | { |
| 5071 | name: "error when clang_asflags is set", |
| 5072 | clangAsFlags: []string{"-a", "-b"}, |
| 5073 | err: "clang_asflags: property is deprecated", |
| 5074 | }, |
| 5075 | { |
| 5076 | name: "no error when BuildBrokenClangAsFlags is explicitly set to true", |
| 5077 | clangAsFlags: []string{"-a", "-b"}, |
| 5078 | BuildBrokenClangAsFlags: true, |
| 5079 | }, |
| 5080 | } |
| 5081 | |
| 5082 | for _, test := range tests { |
| 5083 | t.Run(test.name, func(t *testing.T) { |
| 5084 | bp := fmt.Sprintf(` |
| 5085 | cc_library { |
| 5086 | name: "foo", |
| 5087 | clang_asflags: %s, |
| 5088 | }`, `["`+strings.Join(test.clangAsFlags, `","`)+`"]`) |
| 5089 | |
| 5090 | if test.err == "" { |
| 5091 | android.GroupFixturePreparers( |
| 5092 | prepareForCcTest, |
| 5093 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5094 | if test.BuildBrokenClangAsFlags { |
| 5095 | variables.BuildBrokenClangAsFlags = test.BuildBrokenClangAsFlags |
| 5096 | } |
| 5097 | }), |
| 5098 | ).RunTestWithBp(t, bp) |
| 5099 | } else { |
| 5100 | prepareForCcTest. |
| 5101 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5102 | RunTestWithBp(t, bp) |
| 5103 | } |
| 5104 | }) |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | func TestCcBuildBrokenClangCFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5109 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5110 | tests := []struct { |
| 5111 | name string |
| 5112 | clangCFlags []string |
| 5113 | BuildBrokenClangCFlags bool |
| 5114 | err string |
| 5115 | }{ |
| 5116 | { |
| 5117 | name: "error when clang_cflags is set", |
| 5118 | clangCFlags: []string{"-a", "-b"}, |
| 5119 | err: "clang_cflags: property is deprecated", |
| 5120 | }, |
| 5121 | { |
| 5122 | name: "no error when BuildBrokenClangCFlags is explicitly set to true", |
| 5123 | clangCFlags: []string{"-a", "-b"}, |
| 5124 | BuildBrokenClangCFlags: true, |
| 5125 | }, |
| 5126 | } |
| 5127 | |
| 5128 | for _, test := range tests { |
| 5129 | t.Run(test.name, func(t *testing.T) { |
| 5130 | bp := fmt.Sprintf(` |
| 5131 | cc_library { |
| 5132 | name: "foo", |
| 5133 | clang_cflags: %s, |
| 5134 | }`, `["`+strings.Join(test.clangCFlags, `","`)+`"]`) |
| 5135 | |
| 5136 | if test.err == "" { |
| 5137 | android.GroupFixturePreparers( |
| 5138 | prepareForCcTest, |
| 5139 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5140 | if test.BuildBrokenClangCFlags { |
| 5141 | variables.BuildBrokenClangCFlags = test.BuildBrokenClangCFlags |
| 5142 | } |
| 5143 | }), |
| 5144 | ).RunTestWithBp(t, bp) |
| 5145 | } else { |
| 5146 | prepareForCcTest. |
| 5147 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5148 | RunTestWithBp(t, bp) |
| 5149 | } |
| 5150 | }) |
| 5151 | } |
| 5152 | } |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 5153 | |
| 5154 | func TestDclaLibraryInApex(t *testing.T) { |
| 5155 | t.Parallel() |
| 5156 | bp := ` |
| 5157 | cc_library_shared { |
| 5158 | name: "cc_lib_in_apex", |
| 5159 | srcs: ["foo.cc"], |
| 5160 | apex_available: ["myapex"], |
| 5161 | bazel_module: { label: "//foo/bar:bar" }, |
| 5162 | }` |
| 5163 | label := "//foo/bar:bar" |
| 5164 | arch64 := "arm64_armv8-a" |
| 5165 | arch32 := "arm_armv7-a-neon" |
| 5166 | apexCfgKey := android.ApexConfigKey{ |
| 5167 | WithinApex: true, |
| 5168 | ApexSdkVersion: "28", |
| 5169 | } |
| 5170 | |
| 5171 | result := android.GroupFixturePreparers( |
| 5172 | prepareForCcTest, |
| 5173 | android.FixtureRegisterWithContext(registerTestMutators), |
| 5174 | android.FixtureModifyConfig(func(config android.Config) { |
| 5175 | config.BazelContext = android.MockBazelContext{ |
| 5176 | OutputBaseDir: "outputbase", |
| 5177 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 5178 | android.BuildMockBazelContextResultKey(label, arch32, android.Android, apexCfgKey): cquery.CcInfo{ |
| 5179 | RootDynamicLibraries: []string{"foo.so"}, |
| 5180 | }, |
| 5181 | android.BuildMockBazelContextResultKey(label, arch64, android.Android, apexCfgKey): cquery.CcInfo{ |
| 5182 | RootDynamicLibraries: []string{"foo.so"}, |
| 5183 | }, |
| 5184 | }, |
| 5185 | BazelRequests: make(map[string]bool), |
| 5186 | } |
| 5187 | }), |
| 5188 | ).RunTestWithBp(t, bp) |
| 5189 | ctx := result.TestContext |
| 5190 | |
| 5191 | // Test if the bazel request is queued correctly |
| 5192 | key := android.BuildMockBazelContextRequestKey(label, cquery.GetCcInfo, arch32, android.Android, apexCfgKey) |
| 5193 | if !ctx.Config().BazelContext.(android.MockBazelContext).BazelRequests[key] { |
| 5194 | t.Errorf("Bazel request was not queued: %s", key) |
| 5195 | } |
| 5196 | |
| 5197 | sharedFoo := ctx.ModuleForTests(ccLibInApex, "android_arm_armv7-a-neon_shared_"+apexVariationName).Module() |
| 5198 | producer := sharedFoo.(android.OutputFileProducer) |
| 5199 | outputFiles, err := producer.OutputFiles("") |
| 5200 | if err != nil { |
| 5201 | t.Errorf("Unexpected error getting cc_object outputfiles %s", err) |
| 5202 | } |
| 5203 | expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.so"} |
| 5204 | android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings()) |
| 5205 | } |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 5206 | |
| 5207 | func TestDisableSanitizerVariantsInMixedBuilds(t *testing.T) { |
| 5208 | t.Parallel() |
| 5209 | bp := ` |
| 5210 | cc_library_static { |
| 5211 | name: "foo_ubsan_minimal", |
| 5212 | srcs: ["foo.cc"], |
| 5213 | bazel_module: { label: "//foo_ubsan_minimal" }, |
| 5214 | sanitize: { |
| 5215 | all_undefined: true, |
| 5216 | integer_overflow: true, |
| 5217 | }, |
| 5218 | } |
| 5219 | cc_library_static { |
| 5220 | name: "foo", |
| 5221 | srcs: ["foo.cc"], |
| 5222 | bazel_module: { label: "//foo" }, |
| 5223 | sanitize: { |
| 5224 | address: true, |
| 5225 | hwaddress: true, |
| 5226 | fuzzer: true, |
| 5227 | integer_overflow: true, |
| 5228 | scs: true, |
| 5229 | }, |
| 5230 | } |
| 5231 | cc_library_static { |
| 5232 | name: "foo_tsan", |
| 5233 | srcs: ["foo.cc"], |
| 5234 | bazel_module: { label: "//foo_tsan" }, |
| 5235 | sanitize: { |
| 5236 | thread: true, |
| 5237 | }, |
| 5238 | } |
| 5239 | cc_library_static { |
| 5240 | name: "foo_cfi", |
| 5241 | srcs: ["foo.cc"], |
| 5242 | bazel_module: { label: "//foo_cfi" }, |
| 5243 | sanitize: { |
| 5244 | cfi: true, |
| 5245 | }, |
| 5246 | } |
| 5247 | cc_library_static { |
| 5248 | name: "foo_memtag_stack", |
| 5249 | srcs: ["foo.cc"], |
| 5250 | bazel_module: { label: "//foo_memtag_stack" }, |
| 5251 | sanitize: { |
| 5252 | memtag_stack: true, |
| 5253 | }, |
| 5254 | } |
| 5255 | cc_library_static { |
| 5256 | name: "foo_memtag_heap", |
| 5257 | srcs: ["foo.cc"], |
| 5258 | bazel_module: { label: "//foo_memtag_heap" }, |
| 5259 | sanitize: { |
| 5260 | memtag_heap: true, |
| 5261 | }, |
| 5262 | } |
| 5263 | cc_library_static { |
| 5264 | name: "foo_safestack", |
| 5265 | srcs: ["foo.cc"], |
| 5266 | bazel_module: { label: "//foo_safestack" }, |
| 5267 | sanitize: { |
| 5268 | safestack: true, |
| 5269 | }, |
| 5270 | } |
| 5271 | cc_library_static { |
| 5272 | name: "foo_scudo", |
| 5273 | srcs: ["foo.cc"], |
| 5274 | bazel_module: { label: "//foo_scudo" }, |
| 5275 | sanitize: { |
| 5276 | scudo: true, |
| 5277 | }, |
| 5278 | } |
| 5279 | ` |
| 5280 | testcases := []struct { |
| 5281 | name string |
| 5282 | variant string |
| 5283 | expectedOutputPaths []string |
| 5284 | }{ |
| 5285 | { |
| 5286 | name: "foo_ubsan_minimal", |
| 5287 | variant: "android_arm64_armv8-a_static_apex28", |
| 5288 | expectedOutputPaths: []string{ |
| 5289 | "outputbase/execroot/__main__/foo_ubsan_minimal.a", |
| 5290 | }, |
| 5291 | }, |
| 5292 | { |
| 5293 | name: "foo", |
| 5294 | variant: "android_arm64_armv8-a_static_apex28", |
| 5295 | expectedOutputPaths: []string{ |
| 5296 | "outputbase/execroot/__main__/foo.a", |
| 5297 | }, |
| 5298 | }, |
| 5299 | { |
| 5300 | name: "foo", |
| 5301 | variant: "android_arm_armv7-a-neon_static_asan_apex28", |
| 5302 | expectedOutputPaths: []string{ |
| 5303 | "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_apex28/foo.a", |
| 5304 | }, |
| 5305 | }, |
| 5306 | { |
| 5307 | name: "foo", |
| 5308 | variant: "android_arm64_armv8-a_static_hwasan_apex28", |
| 5309 | expectedOutputPaths: []string{ |
| 5310 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_apex28/foo.a", |
| 5311 | }, |
| 5312 | }, |
| 5313 | { |
| 5314 | name: "foo", |
| 5315 | variant: "android_arm64_armv8-a_static_fuzzer_apex28", |
| 5316 | expectedOutputPaths: []string{ |
| 5317 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_fuzzer_apex28/foo.a", |
| 5318 | }, |
| 5319 | }, |
| 5320 | { |
| 5321 | name: "foo", |
| 5322 | variant: "android_arm_armv7-a-neon_static_asan_fuzzer_apex28", |
| 5323 | expectedOutputPaths: []string{ |
| 5324 | "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_fuzzer_apex28/foo.a", |
| 5325 | }, |
| 5326 | }, |
| 5327 | { |
| 5328 | name: "foo", |
| 5329 | variant: "android_arm64_armv8-a_static_hwasan_fuzzer_apex28", |
| 5330 | expectedOutputPaths: []string{ |
| 5331 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_fuzzer_apex28/foo.a", |
| 5332 | }, |
| 5333 | }, |
| 5334 | { |
| 5335 | name: "foo", |
| 5336 | variant: "android_arm64_armv8-a_static_scs_apex28", |
| 5337 | expectedOutputPaths: []string{ |
| 5338 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_scs_apex28/foo.a", |
| 5339 | }, |
| 5340 | }, |
| 5341 | { |
| 5342 | name: "foo", |
| 5343 | variant: "android_arm64_armv8-a_static_hwasan_scs_apex28", |
| 5344 | expectedOutputPaths: []string{ |
| 5345 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_apex28/foo.a", |
| 5346 | }, |
| 5347 | }, |
| 5348 | { |
| 5349 | name: "foo", |
| 5350 | variant: "android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28", |
| 5351 | expectedOutputPaths: []string{ |
| 5352 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28/foo.a", |
| 5353 | }, |
| 5354 | }, |
| 5355 | { |
| 5356 | name: "foo_tsan", |
| 5357 | variant: "android_arm64_armv8-a_static_apex28", |
| 5358 | expectedOutputPaths: []string{ |
| 5359 | "outputbase/execroot/__main__/foo_tsan.a", |
| 5360 | }, |
| 5361 | }, |
| 5362 | { |
| 5363 | name: "foo_tsan", |
| 5364 | variant: "android_arm64_armv8-a_static_tsan_apex28", |
| 5365 | expectedOutputPaths: []string{ |
| 5366 | "out/soong/.intermediates/foo_tsan/android_arm64_armv8-a_static_tsan_apex28/foo_tsan.a", |
| 5367 | }, |
| 5368 | }, |
| 5369 | { |
| 5370 | name: "foo_cfi", |
| 5371 | variant: "android_arm64_armv8-a_static_apex28", |
| 5372 | expectedOutputPaths: []string{ |
| 5373 | "outputbase/execroot/__main__/foo_cfi.a", |
| 5374 | }, |
| 5375 | }, |
| 5376 | { |
| 5377 | name: "foo_cfi", |
| 5378 | variant: "android_arm64_armv8-a_static_cfi_apex28", |
| 5379 | expectedOutputPaths: []string{ |
Yu Liu | 95497dc | 2023-05-25 11:15:07 -0700 | [diff] [blame] | 5380 | "outputbase/execroot/__main__/foo_cfi.a", |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 5381 | }, |
| 5382 | }, |
| 5383 | { |
| 5384 | name: "foo_memtag_stack", |
| 5385 | variant: "android_arm64_armv8-a_static_apex28", |
| 5386 | expectedOutputPaths: []string{ |
| 5387 | "out/soong/.intermediates/foo_memtag_stack/android_arm64_armv8-a_static_apex28/foo_memtag_stack.a", |
| 5388 | }, |
| 5389 | }, |
| 5390 | { |
| 5391 | name: "foo_memtag_heap", |
| 5392 | variant: "android_arm64_armv8-a_static_apex28", |
| 5393 | expectedOutputPaths: []string{ |
| 5394 | "out/soong/.intermediates/foo_memtag_heap/android_arm64_armv8-a_static_apex28/foo_memtag_heap.a", |
| 5395 | }, |
| 5396 | }, |
| 5397 | { |
| 5398 | name: "foo_safestack", |
| 5399 | variant: "android_arm64_armv8-a_static_apex28", |
| 5400 | expectedOutputPaths: []string{ |
| 5401 | "out/soong/.intermediates/foo_safestack/android_arm64_armv8-a_static_apex28/foo_safestack.a", |
| 5402 | }, |
| 5403 | }, |
| 5404 | { |
| 5405 | name: "foo_scudo", |
| 5406 | variant: "android_arm64_armv8-a_static_apex28", |
| 5407 | expectedOutputPaths: []string{ |
| 5408 | "out/soong/.intermediates/foo_scudo/android_arm64_armv8-a_static_apex28/foo_scudo.a", |
| 5409 | }, |
| 5410 | }, |
| 5411 | } |
| 5412 | |
| 5413 | ctx := android.GroupFixturePreparers( |
| 5414 | prepareForCcTest, |
| 5415 | prepareForAsanTest, |
| 5416 | android.FixtureRegisterWithContext(registerTestMutators), |
| 5417 | android.FixtureModifyConfig(func(config android.Config) { |
| 5418 | config.BazelContext = android.MockBazelContext{ |
| 5419 | OutputBaseDir: "outputbase", |
| 5420 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 5421 | "//foo_ubsan_minimal": { |
| 5422 | RootStaticArchives: []string{"foo_ubsan_minimal.a"}, |
| 5423 | }, |
| 5424 | "//foo": { |
| 5425 | RootStaticArchives: []string{"foo.a"}, |
| 5426 | }, |
| 5427 | "//foo_tsan": { |
| 5428 | RootStaticArchives: []string{"foo_tsan.a"}, |
| 5429 | }, |
| 5430 | "//foo_cfi": { |
| 5431 | RootStaticArchives: []string{"foo_cfi.a"}, |
| 5432 | }, |
| 5433 | "//foo_memtag_stack": { |
| 5434 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5435 | }, |
| 5436 | "//foo_memtag_heap": { |
| 5437 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5438 | }, |
| 5439 | "//foo_safestack": { |
| 5440 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5441 | }, |
| 5442 | "//foo_scudo": { |
| 5443 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5444 | }, |
| 5445 | }, |
| 5446 | } |
| 5447 | }), |
| 5448 | ).RunTestWithBp(t, bp).TestContext |
| 5449 | |
| 5450 | for _, tc := range testcases { |
| 5451 | fooMod := ctx.ModuleForTests(tc.name, tc.variant).Module() |
| 5452 | outputFiles, err := fooMod.(android.OutputFileProducer).OutputFiles("") |
| 5453 | if err != nil { |
| 5454 | t.Errorf("Unexpected error getting cc_object outputfiles %s", err) |
| 5455 | } |
| 5456 | android.AssertPathsRelativeToTopEquals(t, "output files", tc.expectedOutputPaths, outputFiles) |
| 5457 | } |
| 5458 | } |