blob: f29de767c3a22d62e312e195aa88bfeab1373390 [file] [log] [blame]
Jiyong Parkdda8f692020-11-09 18:38:48 +09001// Copyright 2020 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
15package android
16
17import (
Jiyong Parkdda8f692020-11-09 18:38:48 +090018 "testing"
Jiyong Park65b62242020-11-25 12:44:59 +090019
20 "github.com/google/blueprint"
Jiyong Parkdda8f692020-11-09 18:38:48 +090021)
22
23// Module to be packaged
24type componentTestModule struct {
25 ModuleBase
26 props struct {
27 Deps []string
28 }
29}
30
Jiyong Parkd630bdd2020-11-25 11:47:24 +090031// dep tag used in this test. All dependencies are considered as installable.
32type installDepTag struct {
33 blueprint.BaseDependencyTag
34 InstallAlwaysNeededDependencyTag
35}
36
Jiyong Parkdda8f692020-11-09 18:38:48 +090037func componentTestModuleFactory() Module {
38 m := &componentTestModule{}
39 m.AddProperties(&m.props)
40 InitAndroidArchModule(m, HostAndDeviceSupported, MultilibBoth)
41 return m
42}
43
44func (m *componentTestModule) DepsMutator(ctx BottomUpMutatorContext) {
Jiyong Parkd630bdd2020-11-25 11:47:24 +090045 ctx.AddDependency(ctx.Module(), installDepTag{}, m.props.Deps...)
Jiyong Parkdda8f692020-11-09 18:38:48 +090046}
47
48func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
49 builtFile := PathForModuleOut(ctx, m.Name())
50 dir := ctx.Target().Arch.ArchType.Multilib
51 installDir := PathForModuleInstall(ctx, dir)
52 ctx.InstallFile(installDir, m.Name(), builtFile)
53}
54
55// Module that itself is a package
56type packageTestModule struct {
57 ModuleBase
58 PackagingBase
59
60 entries []string
61}
62
Jiyong Park2136d152021-02-01 23:24:56 +090063func packageMultiTargetTestModuleFactory() Module {
Jiyong Parkdda8f692020-11-09 18:38:48 +090064 module := &packageTestModule{}
65 InitPackageModule(module)
66 InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon)
67 return module
68}
69
Jiyong Park2136d152021-02-01 23:24:56 +090070func packageTestModuleFactory() Module {
71 module := &packageTestModule{}
72 InitPackageModule(module)
73 InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
74 return module
75}
76
Jiyong Parkdda8f692020-11-09 18:38:48 +090077func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) {
Jiyong Parkd630bdd2020-11-25 11:47:24 +090078 m.AddDeps(ctx, installDepTag{})
Jiyong Parkdda8f692020-11-09 18:38:48 +090079}
80
81func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Paul Duffin4076a752021-02-02 10:59:54 +000082 zipFile := PathForModuleOut(ctx, "myzip.zip")
Jiyong Parkdda8f692020-11-09 18:38:48 +090083 m.entries = m.CopyDepsToZip(ctx, zipFile)
84}
85
Jiyong Park2136d152021-02-01 23:24:56 +090086func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []string) {
Jiyong Parkdda8f692020-11-09 18:38:48 +090087 t.Helper()
88
Jiyong Park2136d152021-02-01 23:24:56 +090089 var archVariant string
Paul Duffinc3bdd312021-03-17 00:06:49 +000090 var moduleFactory ModuleFactory
Jiyong Park2136d152021-02-01 23:24:56 +090091 if multitarget {
92 archVariant = "android_common"
Paul Duffinc3bdd312021-03-17 00:06:49 +000093 moduleFactory = packageMultiTargetTestModuleFactory
Jiyong Park2136d152021-02-01 23:24:56 +090094 } else {
95 archVariant = "android_arm64_armv8-a"
Paul Duffinc3bdd312021-03-17 00:06:49 +000096 moduleFactory = packageTestModuleFactory
Jiyong Park2136d152021-02-01 23:24:56 +090097 }
Jiyong Parkdda8f692020-11-09 18:38:48 +090098
Paul Duffin30ac3e72021-03-20 00:36:14 +000099 result := GroupFixturePreparers(
Paul Duffinc3bdd312021-03-17 00:06:49 +0000100 PrepareForTestWithArchMutator,
101 FixtureRegisterWithContext(func(ctx RegistrationContext) {
102 ctx.RegisterModuleType("component", componentTestModuleFactory)
103 ctx.RegisterModuleType("package_module", moduleFactory)
104 }),
105 FixtureWithRootAndroidBp(bp),
Paul Duffin30ac3e72021-03-20 00:36:14 +0000106 ).RunTest(t)
Jiyong Parkdda8f692020-11-09 18:38:48 +0900107
Paul Duffinc3bdd312021-03-17 00:06:49 +0000108 p := result.Module("package", archVariant).(*packageTestModule)
Jiyong Parkdda8f692020-11-09 18:38:48 +0900109 actual := p.entries
110 actual = SortedUniqueStrings(actual)
111 expected = SortedUniqueStrings(expected)
Paul Duffinc3bdd312021-03-17 00:06:49 +0000112 AssertDeepEquals(t, "package entries", expected, actual)
Jiyong Parkdda8f692020-11-09 18:38:48 +0900113}
114
Jiyong Park2136d152021-02-01 23:24:56 +0900115func TestPackagingBaseMultiTarget(t *testing.T) {
116 multiTarget := true
117 runPackagingTest(t, multiTarget,
Jiyong Parkdda8f692020-11-09 18:38:48 +0900118 `
119 component {
120 name: "foo",
121 }
122
123 package_module {
124 name: "package",
125 deps: ["foo"],
126 }
127 `, []string{"lib64/foo"})
128
Jiyong Park2136d152021-02-01 23:24:56 +0900129 runPackagingTest(t, multiTarget,
Jiyong Parkdda8f692020-11-09 18:38:48 +0900130 `
131 component {
132 name: "foo",
133 deps: ["bar"],
134 }
135
136 component {
137 name: "bar",
138 }
139
140 package_module {
141 name: "package",
142 deps: ["foo"],
143 }
144 `, []string{"lib64/foo", "lib64/bar"})
145
Jiyong Park2136d152021-02-01 23:24:56 +0900146 runPackagingTest(t, multiTarget,
Jiyong Parkdda8f692020-11-09 18:38:48 +0900147 `
148 component {
149 name: "foo",
150 deps: ["bar"],
151 }
152
153 component {
154 name: "bar",
155 }
156
157 package_module {
158 name: "package",
159 deps: ["foo"],
160 compile_multilib: "both",
161 }
162 `, []string{"lib32/foo", "lib32/bar", "lib64/foo", "lib64/bar"})
163
Jiyong Park2136d152021-02-01 23:24:56 +0900164 runPackagingTest(t, multiTarget,
Jiyong Parkdda8f692020-11-09 18:38:48 +0900165 `
166 component {
167 name: "foo",
168 }
169
170 component {
171 name: "bar",
172 compile_multilib: "32",
173 }
174
175 package_module {
176 name: "package",
177 deps: ["foo"],
178 multilib: {
179 lib32: {
180 deps: ["bar"],
181 },
182 },
183 compile_multilib: "both",
184 }
185 `, []string{"lib32/foo", "lib32/bar", "lib64/foo"})
186
Jiyong Park2136d152021-02-01 23:24:56 +0900187 runPackagingTest(t, multiTarget,
Jiyong Parkdda8f692020-11-09 18:38:48 +0900188 `
189 component {
190 name: "foo",
191 }
192
193 component {
194 name: "bar",
195 }
196
197 package_module {
198 name: "package",
199 deps: ["foo"],
200 multilib: {
201 first: {
202 deps: ["bar"],
203 },
204 },
205 compile_multilib: "both",
206 }
207 `, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
Jiyong Park2136d152021-02-01 23:24:56 +0900208
209 runPackagingTest(t, multiTarget,
210 `
211 component {
212 name: "foo",
213 }
214
215 component {
216 name: "bar",
217 }
218
219 component {
220 name: "baz",
221 }
222
223 package_module {
224 name: "package",
225 deps: ["foo"],
226 arch: {
227 arm64: {
228 deps: ["bar"],
229 },
230 x86_64: {
231 deps: ["baz"],
232 },
233 },
234 compile_multilib: "both",
235 }
236 `, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
237}
238
239func TestPackagingBaseSingleTarget(t *testing.T) {
240 multiTarget := false
241 runPackagingTest(t, multiTarget,
242 `
243 component {
244 name: "foo",
245 }
246
247 package_module {
248 name: "package",
249 deps: ["foo"],
250 }
251 `, []string{"lib64/foo"})
252
253 runPackagingTest(t, multiTarget,
254 `
255 component {
256 name: "foo",
257 deps: ["bar"],
258 }
259
260 component {
261 name: "bar",
262 }
263
264 package_module {
265 name: "package",
266 deps: ["foo"],
267 }
268 `, []string{"lib64/foo", "lib64/bar"})
269
270 runPackagingTest(t, multiTarget,
271 `
272 component {
273 name: "foo",
274 }
275
276 component {
277 name: "bar",
278 compile_multilib: "32",
279 }
280
281 package_module {
282 name: "package",
283 deps: ["foo"],
284 multilib: {
285 lib32: {
286 deps: ["bar"],
287 },
288 },
289 }
290 `, []string{"lib64/foo"})
291
292 runPackagingTest(t, multiTarget,
293 `
294 component {
295 name: "foo",
296 }
297
298 component {
299 name: "bar",
300 }
301
302 package_module {
303 name: "package",
304 deps: ["foo"],
305 multilib: {
306 lib64: {
307 deps: ["bar"],
308 },
309 },
310 }
311 `, []string{"lib64/foo", "lib64/bar"})
312
313 runPackagingTest(t, multiTarget,
314 `
315 component {
316 name: "foo",
317 }
318
319 component {
320 name: "bar",
321 }
322
323 component {
324 name: "baz",
325 }
326
327 package_module {
328 name: "package",
329 deps: ["foo"],
330 arch: {
331 arm64: {
332 deps: ["bar"],
333 },
334 x86_64: {
335 deps: ["baz"],
336 },
337 },
338 }
339 `, []string{"lib64/foo", "lib64/bar"})
Jiyong Parkdda8f692020-11-09 18:38:48 +0900340}