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