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