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