blob: bc22dbb9d10a8b01fff3b2bb0129c549566e198f [file] [log] [blame]
Paul Duffina80fdec2019-12-03 15:25:00 +00001// Copyright (C) 2019 The Android Open Source Project
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
15package sdk
16
17import (
18 "testing"
19
20 "android/soong/cc"
21)
22
Paul Duffind835daa2019-11-30 17:49:09 +000023func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
24 t.Helper()
25
26 fs := map[string][]byte{
27 "Test.cpp": nil,
28 "include/Test.h": nil,
29 "libfoo.so": nil,
30 "aidl/foo/bar/Test.aidl": nil,
31 }
32 return testSdkWithFs(t, bp, fs)
33}
34
Paul Duffina80fdec2019-12-03 15:25:00 +000035// Contains tests for SDK members provided by the cc package.
36
37func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000038 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000039 sdk {
40 name: "mysdk",
41 native_shared_libs: ["sdkmember"],
42 }
43
44 cc_library_shared {
45 name: "sdkmember",
46 srcs: ["Test.cpp"],
47 system_shared_libs: [],
48 stl: "none",
49 }
50 `)
51
52 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_core_shared").(*cc.Module).OutputFile()
53 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_core_shared").(*cc.Module).OutputFile()
54
55 var inputs []string
56 buildParams := result.Module("mysdk", "android_common").BuildParamsForTests()
57 for _, bp := range buildParams {
58 if bp.Input != nil {
59 inputs = append(inputs, bp.Input.String())
60 }
61 }
62
63 // ensure that both 32/64 outputs are inputs of the sdk snapshot
64 ensureListContains(t, inputs, armOutput.String())
65 ensureListContains(t, inputs, arm64Output.String())
66}
67
68func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000069 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000070 sdk {
71 name: "mysdk",
72 native_shared_libs: ["sdkmember"],
73 }
74
75 sdk_snapshot {
76 name: "mysdk@1",
77 native_shared_libs: ["sdkmember_mysdk_1"],
78 }
79
80 sdk_snapshot {
81 name: "mysdk@2",
82 native_shared_libs: ["sdkmember_mysdk_2"],
83 }
84
85 cc_prebuilt_library_shared {
86 name: "sdkmember",
87 srcs: ["libfoo.so"],
88 prefer: false,
89 system_shared_libs: [],
90 stl: "none",
91 }
92
93 cc_prebuilt_library_shared {
94 name: "sdkmember_mysdk_1",
95 sdk_member_name: "sdkmember",
96 srcs: ["libfoo.so"],
97 system_shared_libs: [],
98 stl: "none",
99 }
100
101 cc_prebuilt_library_shared {
102 name: "sdkmember_mysdk_2",
103 sdk_member_name: "sdkmember",
104 srcs: ["libfoo.so"],
105 system_shared_libs: [],
106 stl: "none",
107 }
108
109 cc_library_shared {
110 name: "mycpplib",
111 srcs: ["Test.cpp"],
112 shared_libs: ["sdkmember"],
113 system_shared_libs: [],
114 stl: "none",
115 }
116
117 apex {
118 name: "myapex",
119 native_shared_libs: ["mycpplib"],
120 uses_sdks: ["mysdk@1"],
121 key: "myapex.key",
122 certificate: ":myapex.cert",
123 }
124
125 apex {
126 name: "myapex2",
127 native_shared_libs: ["mycpplib"],
128 uses_sdks: ["mysdk@2"],
129 key: "myapex.key",
130 certificate: ":myapex.cert",
131 }
132 `)
133
134 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_core_shared_myapex").Rule("toc").Output
135 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_core_shared_myapex2").Rule("toc").Output
136
137 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex")
138 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex2")
139
140 // Depending on the uses_sdks value, different libs are linked
141 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
142 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
143}
144
Paul Duffinc62a5102019-12-11 18:34:15 +0000145func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
146 result := testSdkWithCc(t, `
147 sdk {
148 name: "mysdk",
149 native_shared_libs: ["mynativelib1", "mynativelib2"],
150 }
151
152 cc_library_shared {
153 name: "mynativelib1",
154 srcs: [
155 "Test.cpp",
156 ],
157 export_include_dirs: ["include"],
158 system_shared_libs: [],
159 stl: "none",
160 }
161
162 cc_library_shared {
163 name: "mynativelib2",
164 srcs: [
165 "Test.cpp",
166 ],
167 export_include_dirs: ["include"],
168 system_shared_libs: [],
169 stl: "none",
170 }
171 `)
172
173 result.CheckSnapshot("mysdk", "android_common", "",
174 checkAllCopyRules(`
175include/Test.h -> include/include/Test.h
176.intermediates/mynativelib1/android_arm64_armv8-a_core_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
177.intermediates/mynativelib1/android_arm_armv7-a-neon_core_shared/mynativelib1.so -> arm/lib/mynativelib1.so
178.intermediates/mynativelib2/android_arm64_armv8-a_core_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
179.intermediates/mynativelib2/android_arm_armv7-a-neon_core_shared/mynativelib2.so -> arm/lib/mynativelib2.so
180`),
181 )
182}
183
Paul Duffin9ab556f2019-12-11 18:42:17 +0000184func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000185 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000186 sdk {
187 name: "mysdk",
188 native_shared_libs: ["mynativelib"],
189 }
190
191 cc_library_shared {
192 name: "mynativelib",
193 srcs: [
194 "Test.cpp",
195 "aidl/foo/bar/Test.aidl",
196 ],
197 export_include_dirs: ["include"],
198 aidl: {
199 export_aidl_headers: true,
200 },
201 system_shared_libs: [],
202 stl: "none",
203 }
204 `)
205
Paul Duffin593b3c92019-12-05 14:31:48 +0000206 result.CheckSnapshot("mysdk", "android_common", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000207 checkAndroidBpContents(`
208// This is auto-generated. DO NOT EDIT.
209
210cc_prebuilt_library_shared {
211 name: "mysdk_mynativelib@current",
212 sdk_member_name: "mynativelib",
213 arch: {
214 arm64: {
215 srcs: ["arm64/lib/mynativelib.so"],
216 export_include_dirs: [
217 "arm64/include/include",
218 "arm64/include_gen/mynativelib",
219 ],
220 },
221 arm: {
222 srcs: ["arm/lib/mynativelib.so"],
223 export_include_dirs: [
224 "arm/include/include",
225 "arm/include_gen/mynativelib",
226 ],
227 },
228 },
229 stl: "none",
230 system_shared_libs: [],
231}
232
233cc_prebuilt_library_shared {
234 name: "mynativelib",
235 prefer: false,
236 arch: {
237 arm64: {
238 srcs: ["arm64/lib/mynativelib.so"],
239 export_include_dirs: [
240 "arm64/include/include",
241 "arm64/include_gen/mynativelib",
242 ],
243 },
244 arm: {
245 srcs: ["arm/lib/mynativelib.so"],
246 export_include_dirs: [
247 "arm/include/include",
248 "arm/include_gen/mynativelib",
249 ],
250 },
251 },
252 stl: "none",
253 system_shared_libs: [],
254}
255
256sdk_snapshot {
257 name: "mysdk@current",
258 native_shared_libs: ["mysdk_mynativelib@current"],
259}
260`),
261 checkAllCopyRules(`
262.intermediates/mynativelib/android_arm64_armv8-a_core_shared/mynativelib.so -> arm64/lib/mynativelib.so
263include/Test.h -> arm64/include/include/Test.h
264.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
265.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
266.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
267.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/mynativelib.so -> arm/lib/mynativelib.so
268include/Test.h -> arm/include/include/Test.h
269.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
270.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
271.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
272`),
273 )
274}
275
Paul Duffin9ab556f2019-12-11 18:42:17 +0000276func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000277 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
278 SkipIfNotLinux(t)
279
Paul Duffind835daa2019-11-30 17:49:09 +0000280 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000281 sdk {
282 name: "mysdk",
283 device_supported: false,
284 host_supported: true,
285 native_shared_libs: ["mynativelib"],
286 }
287
288 cc_library_shared {
289 name: "mynativelib",
290 device_supported: false,
291 host_supported: true,
292 srcs: [
293 "Test.cpp",
294 "aidl/foo/bar/Test.aidl",
295 ],
296 export_include_dirs: ["include"],
297 aidl: {
298 export_aidl_headers: true,
299 },
300 system_shared_libs: [],
301 stl: "none",
302 }
303 `)
304
Paul Duffin593b3c92019-12-05 14:31:48 +0000305 result.CheckSnapshot("mysdk", "linux_glibc_common", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000306 checkAndroidBpContents(`
307// This is auto-generated. DO NOT EDIT.
308
309cc_prebuilt_library_shared {
310 name: "mysdk_mynativelib@current",
311 sdk_member_name: "mynativelib",
312 device_supported: false,
313 host_supported: true,
314 arch: {
315 x86_64: {
316 srcs: ["x86_64/lib/mynativelib.so"],
317 export_include_dirs: [
318 "x86_64/include/include",
319 "x86_64/include_gen/mynativelib",
320 ],
321 },
322 x86: {
323 srcs: ["x86/lib/mynativelib.so"],
324 export_include_dirs: [
325 "x86/include/include",
326 "x86/include_gen/mynativelib",
327 ],
328 },
329 },
330 stl: "none",
331 system_shared_libs: [],
332}
333
334cc_prebuilt_library_shared {
335 name: "mynativelib",
336 prefer: false,
337 device_supported: false,
338 host_supported: true,
339 arch: {
340 x86_64: {
341 srcs: ["x86_64/lib/mynativelib.so"],
342 export_include_dirs: [
343 "x86_64/include/include",
344 "x86_64/include_gen/mynativelib",
345 ],
346 },
347 x86: {
348 srcs: ["x86/lib/mynativelib.so"],
349 export_include_dirs: [
350 "x86/include/include",
351 "x86/include_gen/mynativelib",
352 ],
353 },
354 },
355 stl: "none",
356 system_shared_libs: [],
357}
358
359sdk_snapshot {
360 name: "mysdk@current",
361 device_supported: false,
362 host_supported: true,
363 native_shared_libs: ["mysdk_mynativelib@current"],
364}
365`),
366 checkAllCopyRules(`
367.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
368include/Test.h -> x86_64/include/include/Test.h
369.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
370.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
371.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
372.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
373include/Test.h -> x86/include/include/Test.h
374.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
375.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
376.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
377`),
378 )
379}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000380
381func TestSnapshotWithCcStaticLibrary(t *testing.T) {
382 result := testSdkWithCc(t, `
383 sdk {
384 name: "mysdk",
385 native_static_libs: ["mynativelib"],
386 }
387
388 cc_library_static {
389 name: "mynativelib",
390 srcs: [
391 "Test.cpp",
392 "aidl/foo/bar/Test.aidl",
393 ],
394 export_include_dirs: ["include"],
395 aidl: {
396 export_aidl_headers: true,
397 },
398 system_shared_libs: [],
399 stl: "none",
400 }
401 `)
402
403 result.CheckSnapshot("mysdk", "android_common", "",
404 checkAndroidBpContents(`
405// This is auto-generated. DO NOT EDIT.
406
407cc_prebuilt_library_static {
408 name: "mysdk_mynativelib@current",
409 sdk_member_name: "mynativelib",
410 arch: {
411 arm64: {
412 srcs: ["arm64/lib/mynativelib.a"],
413 export_include_dirs: [
414 "arm64/include/include",
415 "arm64/include_gen/mynativelib",
416 ],
417 },
418 arm: {
419 srcs: ["arm/lib/mynativelib.a"],
420 export_include_dirs: [
421 "arm/include/include",
422 "arm/include_gen/mynativelib",
423 ],
424 },
425 },
426 stl: "none",
427 system_shared_libs: [],
428}
429
430cc_prebuilt_library_static {
431 name: "mynativelib",
432 prefer: false,
433 arch: {
434 arm64: {
435 srcs: ["arm64/lib/mynativelib.a"],
436 export_include_dirs: [
437 "arm64/include/include",
438 "arm64/include_gen/mynativelib",
439 ],
440 },
441 arm: {
442 srcs: ["arm/lib/mynativelib.a"],
443 export_include_dirs: [
444 "arm/include/include",
445 "arm/include_gen/mynativelib",
446 ],
447 },
448 },
449 stl: "none",
450 system_shared_libs: [],
451}
452
453sdk_snapshot {
454 name: "mysdk@current",
455 native_static_libs: ["mysdk_mynativelib@current"],
456}
457`),
458 checkAllCopyRules(`
459.intermediates/mynativelib/android_arm64_armv8-a_core_static/mynativelib.a -> arm64/lib/mynativelib.a
460include/Test.h -> arm64/include/include/Test.h
461.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
462.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
463.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
464.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/mynativelib.a -> arm/lib/mynativelib.a
465include/Test.h -> arm/include/include/Test.h
466.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
467.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
468.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
469`),
470 )
471}
472
473func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
474 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
475 SkipIfNotLinux(t)
476
477 result := testSdkWithCc(t, `
478 sdk {
479 name: "mysdk",
480 device_supported: false,
481 host_supported: true,
482 native_static_libs: ["mynativelib"],
483 }
484
485 cc_library_static {
486 name: "mynativelib",
487 device_supported: false,
488 host_supported: true,
489 srcs: [
490 "Test.cpp",
491 "aidl/foo/bar/Test.aidl",
492 ],
493 export_include_dirs: ["include"],
494 aidl: {
495 export_aidl_headers: true,
496 },
497 system_shared_libs: [],
498 stl: "none",
499 }
500 `)
501
502 result.CheckSnapshot("mysdk", "linux_glibc_common", "",
503 checkAndroidBpContents(`
504// This is auto-generated. DO NOT EDIT.
505
506cc_prebuilt_library_static {
507 name: "mysdk_mynativelib@current",
508 sdk_member_name: "mynativelib",
509 device_supported: false,
510 host_supported: true,
511 arch: {
512 x86_64: {
513 srcs: ["x86_64/lib/mynativelib.a"],
514 export_include_dirs: [
515 "x86_64/include/include",
516 "x86_64/include_gen/mynativelib",
517 ],
518 },
519 x86: {
520 srcs: ["x86/lib/mynativelib.a"],
521 export_include_dirs: [
522 "x86/include/include",
523 "x86/include_gen/mynativelib",
524 ],
525 },
526 },
527 stl: "none",
528 system_shared_libs: [],
529}
530
531cc_prebuilt_library_static {
532 name: "mynativelib",
533 prefer: false,
534 device_supported: false,
535 host_supported: true,
536 arch: {
537 x86_64: {
538 srcs: ["x86_64/lib/mynativelib.a"],
539 export_include_dirs: [
540 "x86_64/include/include",
541 "x86_64/include_gen/mynativelib",
542 ],
543 },
544 x86: {
545 srcs: ["x86/lib/mynativelib.a"],
546 export_include_dirs: [
547 "x86/include/include",
548 "x86/include_gen/mynativelib",
549 ],
550 },
551 },
552 stl: "none",
553 system_shared_libs: [],
554}
555
556sdk_snapshot {
557 name: "mysdk@current",
558 device_supported: false,
559 host_supported: true,
560 native_static_libs: ["mysdk_mynativelib@current"],
561}
562`),
563 checkAllCopyRules(`
564.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
565include/Test.h -> x86_64/include/include/Test.h
566.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
567.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
568.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
569.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
570include/Test.h -> x86/include/include/Test.h
571.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
572.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
573.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
574`),
575 )
576}