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