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