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