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