Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 1 | // Copyright 2019 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 18 | "runtime" |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint" |
| 23 | ) |
| 24 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 25 | var prepareForPrebuiltTest = android.GroupFixturePreparers( |
| 26 | prepareForCcTest, |
Paul Duffin | 6a1160e | 2021-03-07 15:47:42 +0000 | [diff] [blame] | 27 | android.PrepareForTestWithAndroidMk, |
| 28 | ) |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 29 | |
Paul Duffin | 6a1160e | 2021-03-07 15:47:42 +0000 | [diff] [blame] | 30 | func testPrebuilt(t *testing.T, bp string, fs android.MockFS, handlers ...android.FixturePreparer) *android.TestContext { |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 31 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 32 | result := android.GroupFixturePreparers( |
| 33 | prepareForPrebuiltTest, |
Paul Duffin | 6a1160e | 2021-03-07 15:47:42 +0000 | [diff] [blame] | 34 | fs.AddToFixture(), |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 35 | android.GroupFixturePreparers(handlers...), |
| 36 | ).RunTestWithBp(t, bp) |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 37 | |
Paul Duffin | 6a1160e | 2021-03-07 15:47:42 +0000 | [diff] [blame] | 38 | return result.TestContext |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 41 | type configCustomizer func(config android.Config) |
| 42 | |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 43 | func TestPrebuilt(t *testing.T) { |
| 44 | bp := ` |
| 45 | cc_library { |
| 46 | name: "liba", |
| 47 | } |
| 48 | |
| 49 | cc_prebuilt_library_shared { |
| 50 | name: "liba", |
| 51 | srcs: ["liba.so"], |
| 52 | } |
| 53 | |
| 54 | cc_library { |
| 55 | name: "libb", |
| 56 | } |
| 57 | |
| 58 | cc_prebuilt_library_static { |
| 59 | name: "libb", |
| 60 | srcs: ["libb.a"], |
| 61 | } |
| 62 | |
| 63 | cc_library_shared { |
| 64 | name: "libd", |
| 65 | } |
| 66 | |
| 67 | cc_prebuilt_library_shared { |
| 68 | name: "libd", |
| 69 | srcs: ["libd.so"], |
| 70 | } |
| 71 | |
| 72 | cc_library_static { |
| 73 | name: "libe", |
| 74 | } |
| 75 | |
| 76 | cc_prebuilt_library_static { |
| 77 | name: "libe", |
| 78 | srcs: ["libe.a"], |
| 79 | } |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 80 | |
| 81 | cc_library { |
| 82 | name: "libf", |
| 83 | } |
| 84 | |
| 85 | cc_prebuilt_library { |
| 86 | name: "libf", |
| 87 | static: { |
| 88 | srcs: ["libf.a"], |
| 89 | }, |
| 90 | shared: { |
| 91 | srcs: ["libf.so"], |
| 92 | }, |
| 93 | } |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 94 | |
| 95 | cc_object { |
| 96 | name: "crtx", |
| 97 | } |
| 98 | |
| 99 | cc_prebuilt_object { |
| 100 | name: "crtx", |
| 101 | srcs: ["crtx.o"], |
| 102 | } |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 103 | ` |
| 104 | |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 105 | ctx := testPrebuilt(t, bp, map[string][]byte{ |
| 106 | "liba.so": nil, |
| 107 | "libb.a": nil, |
| 108 | "libd.so": nil, |
| 109 | "libe.a": nil, |
| 110 | "libf.a": nil, |
| 111 | "libf.so": nil, |
| 112 | "crtx.o": nil, |
| 113 | }) |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 114 | |
| 115 | // Verify that all the modules exist and that their dependencies were connected correctly |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 116 | liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module() |
| 117 | libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module() |
| 118 | libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").Module() |
| 119 | libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_static").Module() |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 120 | libfStatic := ctx.ModuleForTests("libf", "android_arm64_armv8-a_static").Module() |
| 121 | libfShared := ctx.ModuleForTests("libf", "android_arm64_armv8-a_shared").Module() |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 122 | crtx := ctx.ModuleForTests("crtx", "android_arm64_armv8-a").Module() |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 123 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 124 | prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module() |
| 125 | prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module() |
| 126 | prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").Module() |
| 127 | prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_static").Module() |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 128 | prebuiltLibfStatic := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_static").Module() |
| 129 | prebuiltLibfShared := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_shared").Module() |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 130 | prebuiltCrtx := ctx.ModuleForTests("prebuilt_crtx", "android_arm64_armv8-a").Module() |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 131 | |
| 132 | hasDep := func(m android.Module, wantDep android.Module) bool { |
| 133 | t.Helper() |
| 134 | var found bool |
| 135 | ctx.VisitDirectDeps(m, func(dep blueprint.Module) { |
| 136 | if dep == wantDep { |
| 137 | found = true |
| 138 | } |
| 139 | }) |
| 140 | return found |
| 141 | } |
| 142 | |
| 143 | if !hasDep(liba, prebuiltLiba) { |
| 144 | t.Errorf("liba missing dependency on prebuilt_liba") |
| 145 | } |
| 146 | |
| 147 | if !hasDep(libb, prebuiltLibb) { |
| 148 | t.Errorf("libb missing dependency on prebuilt_libb") |
| 149 | } |
| 150 | |
| 151 | if !hasDep(libd, prebuiltLibd) { |
| 152 | t.Errorf("libd missing dependency on prebuilt_libd") |
| 153 | } |
| 154 | |
| 155 | if !hasDep(libe, prebuiltLibe) { |
| 156 | t.Errorf("libe missing dependency on prebuilt_libe") |
| 157 | } |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 158 | |
| 159 | if !hasDep(libfStatic, prebuiltLibfStatic) { |
| 160 | t.Errorf("libf static missing dependency on prebuilt_libf") |
| 161 | } |
| 162 | |
| 163 | if !hasDep(libfShared, prebuiltLibfShared) { |
| 164 | t.Errorf("libf shared missing dependency on prebuilt_libf") |
| 165 | } |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 166 | |
| 167 | if !hasDep(crtx, prebuiltCrtx) { |
| 168 | t.Errorf("crtx missing dependency on prebuilt_crtx") |
| 169 | } |
Wei Li | 598f92d | 2023-01-04 17:12:24 -0800 | [diff] [blame] | 170 | |
| 171 | entries := android.AndroidMkEntriesForTest(t, ctx, prebuiltLiba)[0] |
| 172 | android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_prebuilt_library_shared", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0]) |
| 173 | entries = android.AndroidMkEntriesForTest(t, ctx, prebuiltLibb)[0] |
| 174 | android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_prebuilt_library_static", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0]) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 177 | func TestPrebuiltLibraryShared(t *testing.T) { |
| 178 | ctx := testPrebuilt(t, ` |
| 179 | cc_prebuilt_library_shared { |
| 180 | name: "libtest", |
| 181 | srcs: ["libf.so"], |
| 182 | strip: { |
| 183 | none: true, |
| 184 | }, |
| 185 | } |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 186 | `, map[string][]byte{ |
| 187 | "libf.so": nil, |
| 188 | }) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 189 | |
| 190 | shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 191 | assertString(t, shared.OutputFile().Path().Base(), "libtest.so") |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | func TestPrebuiltLibraryStatic(t *testing.T) { |
| 195 | ctx := testPrebuilt(t, ` |
| 196 | cc_prebuilt_library_static { |
| 197 | name: "libtest", |
| 198 | srcs: ["libf.a"], |
| 199 | } |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 200 | `, map[string][]byte{ |
| 201 | "libf.a": nil, |
| 202 | }) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 203 | |
| 204 | static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 205 | assertString(t, static.OutputFile().Path().Base(), "libf.a") |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | func TestPrebuiltLibrary(t *testing.T) { |
| 209 | ctx := testPrebuilt(t, ` |
| 210 | cc_prebuilt_library { |
| 211 | name: "libtest", |
| 212 | static: { |
| 213 | srcs: ["libf.a"], |
| 214 | }, |
| 215 | shared: { |
| 216 | srcs: ["libf.so"], |
| 217 | }, |
| 218 | strip: { |
| 219 | none: true, |
| 220 | }, |
| 221 | } |
Martin Stjernholm | adeb088 | 2020-04-01 23:02:57 +0100 | [diff] [blame] | 222 | `, map[string][]byte{ |
| 223 | "libf.a": nil, |
| 224 | "libf.so": nil, |
| 225 | }) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 226 | |
| 227 | shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 228 | assertString(t, shared.OutputFile().Path().Base(), "libtest.so") |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 229 | |
| 230 | static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 231 | assertString(t, static.OutputFile().Path().Base(), "libf.a") |
| 232 | } |
| 233 | |
| 234 | func TestPrebuiltLibraryStem(t *testing.T) { |
| 235 | ctx := testPrebuilt(t, ` |
| 236 | cc_prebuilt_library { |
| 237 | name: "libfoo", |
| 238 | stem: "libbar", |
| 239 | static: { |
| 240 | srcs: ["libfoo.a"], |
| 241 | }, |
| 242 | shared: { |
| 243 | srcs: ["libfoo.so"], |
| 244 | }, |
| 245 | strip: { |
| 246 | none: true, |
| 247 | }, |
| 248 | } |
| 249 | `, map[string][]byte{ |
| 250 | "libfoo.a": nil, |
| 251 | "libfoo.so": nil, |
| 252 | }) |
| 253 | |
| 254 | static := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 255 | assertString(t, static.OutputFile().Path().Base(), "libfoo.a") |
| 256 | |
| 257 | shared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*Module) |
| 258 | assertString(t, shared.OutputFile().Path().Base(), "libbar.so") |
| 259 | } |
| 260 | |
| 261 | func TestPrebuiltLibrarySharedStem(t *testing.T) { |
| 262 | ctx := testPrebuilt(t, ` |
| 263 | cc_prebuilt_library_shared { |
| 264 | name: "libfoo", |
| 265 | stem: "libbar", |
| 266 | srcs: ["libfoo.so"], |
| 267 | strip: { |
| 268 | none: true, |
| 269 | }, |
| 270 | } |
| 271 | `, map[string][]byte{ |
| 272 | "libfoo.so": nil, |
| 273 | }) |
| 274 | |
| 275 | shared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*Module) |
| 276 | assertString(t, shared.OutputFile().Path().Base(), "libbar.so") |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 277 | } |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 278 | |
| 279 | func TestPrebuiltSymlinkedHostBinary(t *testing.T) { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 280 | if runtime.GOOS != "linux" { |
| 281 | t.Skipf("Skipping host prebuilt testing that is only supported on linux not %s", runtime.GOOS) |
Martin Stjernholm | 6a9a146 | 2020-09-15 02:56:19 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 284 | ctx := testPrebuilt(t, ` |
| 285 | cc_prebuilt_library_shared { |
| 286 | name: "libfoo", |
| 287 | device_supported: false, |
| 288 | host_supported: true, |
| 289 | target: { |
| 290 | linux_glibc_x86_64: { |
| 291 | srcs: ["linux_glibc_x86_64/lib64/libfoo.so"], |
| 292 | }, |
| 293 | }, |
| 294 | } |
| 295 | |
| 296 | cc_prebuilt_binary { |
| 297 | name: "foo", |
| 298 | device_supported: false, |
| 299 | host_supported: true, |
| 300 | shared_libs: ["libfoo"], |
| 301 | target: { |
| 302 | linux_glibc_x86_64: { |
| 303 | srcs: ["linux_glibc_x86_64/bin/foo"], |
| 304 | }, |
| 305 | }, |
| 306 | } |
| 307 | `, map[string][]byte{ |
| 308 | "libfoo.so": nil, |
| 309 | "foo": nil, |
| 310 | }) |
| 311 | |
| 312 | fooRule := ctx.ModuleForTests("foo", "linux_glibc_x86_64").Rule("Symlink") |
Paul Duffin | e8366da | 2021-03-24 10:40:38 +0000 | [diff] [blame] | 313 | assertString(t, fooRule.Output.String(), "out/soong/.intermediates/foo/linux_glibc_x86_64/foo") |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 314 | assertString(t, fooRule.Args["fromPath"], "$$PWD/linux_glibc_x86_64/bin/foo") |
| 315 | |
| 316 | var libfooDep android.Path |
| 317 | for _, dep := range fooRule.Implicits { |
| 318 | if dep.Base() == "libfoo.so" { |
| 319 | libfooDep = dep |
| 320 | break |
| 321 | } |
| 322 | } |
Paul Duffin | e8366da | 2021-03-24 10:40:38 +0000 | [diff] [blame] | 323 | assertString(t, libfooDep.String(), "out/soong/.intermediates/libfoo/linux_glibc_x86_64_shared/libfoo.so") |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 324 | } |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 325 | |
| 326 | func TestPrebuiltLibrarySanitized(t *testing.T) { |
| 327 | bp := `cc_prebuilt_library { |
| 328 | name: "libtest", |
| 329 | static: { |
| 330 | sanitized: { none: { srcs: ["libf.a"], }, hwaddress: { srcs: ["libf.hwasan.a"], }, }, |
| 331 | }, |
| 332 | shared: { |
| 333 | sanitized: { none: { srcs: ["libf.so"], }, hwaddress: { srcs: ["hwasan/libf.so"], }, }, |
| 334 | }, |
| 335 | } |
| 336 | cc_prebuilt_library_static { |
| 337 | name: "libtest_static", |
| 338 | sanitized: { none: { srcs: ["libf.a"], }, hwaddress: { srcs: ["libf.hwasan.a"], }, }, |
| 339 | } |
| 340 | cc_prebuilt_library_shared { |
| 341 | name: "libtest_shared", |
| 342 | sanitized: { none: { srcs: ["libf.so"], }, hwaddress: { srcs: ["hwasan/libf.so"], }, }, |
| 343 | }` |
| 344 | |
| 345 | fs := map[string][]byte{ |
| 346 | "libf.a": nil, |
| 347 | "libf.hwasan.a": nil, |
| 348 | "libf.so": nil, |
| 349 | "hwasan/libf.so": nil, |
| 350 | } |
| 351 | |
| 352 | // Without SANITIZE_TARGET. |
| 353 | ctx := testPrebuilt(t, bp, fs) |
| 354 | |
| 355 | shared_rule := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Rule("android/soong/cc.strip") |
| 356 | assertString(t, shared_rule.Input.String(), "libf.so") |
| 357 | |
| 358 | static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) |
| 359 | assertString(t, static.OutputFile().Path().Base(), "libf.a") |
| 360 | |
| 361 | shared_rule2 := ctx.ModuleForTests("libtest_shared", "android_arm64_armv8-a_shared").Rule("android/soong/cc.strip") |
| 362 | assertString(t, shared_rule2.Input.String(), "libf.so") |
| 363 | |
| 364 | static2 := ctx.ModuleForTests("libtest_static", "android_arm64_armv8-a_static").Module().(*Module) |
| 365 | assertString(t, static2.OutputFile().Path().Base(), "libf.a") |
| 366 | |
| 367 | // With SANITIZE_TARGET=hwaddress |
Paul Duffin | 6a1160e | 2021-03-07 15:47:42 +0000 | [diff] [blame] | 368 | ctx = testPrebuilt(t, bp, fs, |
| 369 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 370 | variables.SanitizeDevice = []string{"hwaddress"} |
| 371 | }), |
| 372 | ) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 373 | |
| 374 | shared_rule = ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared_hwasan").Rule("android/soong/cc.strip") |
| 375 | assertString(t, shared_rule.Input.String(), "hwasan/libf.so") |
| 376 | |
| 377 | static = ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static_hwasan").Module().(*Module) |
| 378 | assertString(t, static.OutputFile().Path().Base(), "libf.hwasan.a") |
| 379 | |
| 380 | shared_rule2 = ctx.ModuleForTests("libtest_shared", "android_arm64_armv8-a_shared_hwasan").Rule("android/soong/cc.strip") |
| 381 | assertString(t, shared_rule2.Input.String(), "hwasan/libf.so") |
| 382 | |
| 383 | static2 = ctx.ModuleForTests("libtest_static", "android_arm64_armv8-a_static_hwasan").Module().(*Module) |
| 384 | assertString(t, static2.OutputFile().Path().Base(), "libf.hwasan.a") |
| 385 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c3b97c3 | 2021-10-05 13:43:23 -0400 | [diff] [blame] | 386 | |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 387 | func TestPrebuiltStubNoinstall(t *testing.T) { |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 388 | testFunc := func(t *testing.T, expectLibfooOnSystemLib bool, fs android.MockFS) { |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 389 | result := android.GroupFixturePreparers( |
| 390 | prepareForPrebuiltTest, |
| 391 | android.PrepareForTestWithMakevars, |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 392 | android.FixtureMergeMockFs(fs), |
| 393 | ).RunTest(t) |
| 394 | |
| 395 | ldRule := result.ModuleForTests("installedlib", "android_arm64_armv8-a_shared").Rule("ld") |
| 396 | android.AssertStringDoesContain(t, "", ldRule.Args["libFlags"], "android_arm64_armv8-a_shared/libfoo.so") |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 397 | |
| 398 | installRules := result.InstallMakeRulesForTesting(t) |
| 399 | var installedlibRule *android.InstallMakeRule |
| 400 | for i, rule := range installRules { |
| 401 | if rule.Target == "out/target/product/test_device/system/lib/installedlib.so" { |
| 402 | if installedlibRule != nil { |
| 403 | t.Errorf("Duplicate install rules for %s", rule.Target) |
| 404 | } |
| 405 | installedlibRule = &installRules[i] |
| 406 | } |
| 407 | } |
| 408 | if installedlibRule == nil { |
| 409 | t.Errorf("No install rule found for installedlib") |
| 410 | return |
| 411 | } |
| 412 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 413 | if expectLibfooOnSystemLib { |
| 414 | android.AssertStringListContains(t, |
| 415 | "installedlib doesn't have install dependency on libfoo impl", |
| 416 | installedlibRule.OrderOnlyDeps, |
| 417 | "out/target/product/test_device/system/lib/libfoo.so") |
| 418 | } else { |
| 419 | android.AssertStringListDoesNotContain(t, |
| 420 | "installedlib has install dependency on libfoo stub", |
| 421 | installedlibRule.Deps, |
| 422 | "out/target/product/test_device/system/lib/libfoo.so") |
| 423 | android.AssertStringListDoesNotContain(t, |
| 424 | "installedlib has order-only install dependency on libfoo stub", |
| 425 | installedlibRule.OrderOnlyDeps, |
| 426 | "out/target/product/test_device/system/lib/libfoo.so") |
| 427 | } |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 430 | prebuiltLibfooBp := []byte(` |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 431 | cc_prebuilt_library { |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 432 | name: "libfoo", |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 433 | prefer: true, |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 434 | srcs: ["libfoo.so"], |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 435 | stubs: { |
| 436 | versions: ["1"], |
| 437 | }, |
| 438 | } |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 439 | `) |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 440 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 441 | installedlibBp := []byte(` |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 442 | cc_library { |
| 443 | name: "installedlib", |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 444 | shared_libs: ["libfoo"], |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 445 | } |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 446 | `) |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 447 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 448 | t.Run("prebuilt stub (without source): no install", func(t *testing.T) { |
| 449 | testFunc( |
| 450 | t, |
| 451 | /*expectLibfooOnSystemLib=*/ false, |
| 452 | android.MockFS{ |
| 453 | "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, |
| 454 | "Android.bp": installedlibBp, |
| 455 | }, |
| 456 | ) |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 457 | }) |
| 458 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 459 | disabledSourceLibfooBp := []byte(` |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 460 | cc_library { |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 461 | name: "libfoo", |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 462 | enabled: false, |
| 463 | stubs: { |
| 464 | versions: ["1"], |
| 465 | }, |
| 466 | } |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 467 | `) |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 468 | |
Jooyung Han | e5f063e | 2023-03-23 14:31:19 +0900 | [diff] [blame] | 469 | t.Run("prebuilt stub (with disabled source): no install", func(t *testing.T) { |
| 470 | testFunc( |
| 471 | t, |
| 472 | /*expectLibfooOnSystemLib=*/ false, |
| 473 | android.MockFS{ |
| 474 | "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, |
| 475 | "impl/Android.bp": disabledSourceLibfooBp, |
| 476 | "Android.bp": installedlibBp, |
| 477 | }, |
| 478 | ) |
| 479 | }) |
| 480 | |
| 481 | t.Run("prebuilt impl (with `stubs` property set): install", func(t *testing.T) { |
| 482 | testFunc( |
| 483 | t, |
| 484 | /*expectLibfooOnSystemLib=*/ true, |
| 485 | android.MockFS{ |
| 486 | "impl/Android.bp": prebuiltLibfooBp, |
| 487 | "Android.bp": installedlibBp, |
| 488 | }, |
| 489 | ) |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 490 | }) |
| 491 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b1bd770 | 2022-10-04 17:45:24 +0000 | [diff] [blame] | 492 | |
| 493 | func TestPrebuiltBinaryNoSrcsNoError(t *testing.T) { |
| 494 | const bp = ` |
| 495 | cc_prebuilt_binary { |
| 496 | name: "bintest", |
| 497 | srcs: [], |
| 498 | }` |
| 499 | ctx := testPrebuilt(t, bp, map[string][]byte{}) |
| 500 | mod := ctx.ModuleForTests("bintest", "android_arm64_armv8-a").Module().(*Module) |
| 501 | android.AssertBoolEquals(t, `expected no srcs to yield no output file`, false, mod.OutputFile().Valid()) |
| 502 | } |
| 503 | |
| 504 | func TestPrebuiltBinaryMultipleSrcs(t *testing.T) { |
| 505 | const bp = ` |
| 506 | cc_prebuilt_binary { |
| 507 | name: "bintest", |
| 508 | srcs: ["foo", "bar"], |
| 509 | }` |
| 510 | testCcError(t, `Android.bp:4:6: module "bintest" variant "android_arm64_armv8-a": srcs: multiple prebuilt source files`, bp) |
| 511 | } |