blob: 2682682cfb796afeaf19bfea8b12373efce6f0f5 [file] [log] [blame]
Colin Cross3bc7ffa2017-11-22 16:19:37 -08001// 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
15package java
16
17import (
Colin Crossd09b0b62018-04-18 11:06:47 -070018 "fmt"
Colin Crossa4f08812018-10-02 22:03:40 -070019 "path/filepath"
Colin Cross3bc7ffa2017-11-22 16:19:37 -080020 "reflect"
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070021 "regexp"
Colin Crossb69301e2017-12-01 10:48:26 -080022 "sort"
Colin Crossd09b0b62018-04-18 11:06:47 -070023 "strings"
Colin Cross3bc7ffa2017-11-22 16:19:37 -080024 "testing"
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070025
26 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Colin Cross3bc7ffa2017-11-22 16:19:37 -080030)
31
32var (
33 resourceFiles = []string{
34 "res/layout/layout.xml",
35 "res/values/strings.xml",
36 "res/values-en-rUS/strings.xml",
37 }
38
39 compiledResourceFiles = []string{
40 "aapt2/res/layout_layout.xml.flat",
41 "aapt2/res/values_strings.arsc.flat",
42 "aapt2/res/values-en-rUS_strings.arsc.flat",
43 }
44)
45
Colin Cross98be1bb2019-12-13 20:41:13 -080046func testAppConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Colin Cross527012a2017-11-30 22:56:16 -080047 appFS := map[string][]byte{}
48 for k, v := range fs {
49 appFS[k] = v
Colin Cross3bc7ffa2017-11-22 16:19:37 -080050 }
51
Colin Cross527012a2017-11-30 22:56:16 -080052 for _, file := range resourceFiles {
53 appFS[file] = nil
54 }
55
Colin Cross98be1bb2019-12-13 20:41:13 -080056 return testConfig(env, bp, appFS)
Colin Cross527012a2017-11-30 22:56:16 -080057}
58
59func testApp(t *testing.T, bp string) *android.TestContext {
Colin Cross98be1bb2019-12-13 20:41:13 -080060 config := testAppConfig(nil, bp, nil)
Colin Cross527012a2017-11-30 22:56:16 -080061
Colin Cross98be1bb2019-12-13 20:41:13 -080062 ctx := testContext()
Colin Cross527012a2017-11-30 22:56:16 -080063
64 run(t, ctx, config)
65
66 return ctx
Colin Cross3bc7ffa2017-11-22 16:19:37 -080067}
68
69func TestApp(t *testing.T) {
Colin Crossa97c5d32018-03-28 14:58:31 -070070 for _, moduleType := range []string{"android_app", "android_library"} {
71 t.Run(moduleType, func(t *testing.T) {
72 ctx := testApp(t, moduleType+` {
73 name: "foo",
74 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +090075 sdk_version: "current"
Colin Crossa97c5d32018-03-28 14:58:31 -070076 }
77 `)
Colin Cross3bc7ffa2017-11-22 16:19:37 -080078
Colin Crossa97c5d32018-03-28 14:58:31 -070079 foo := ctx.ModuleForTests("foo", "android_common")
Colin Cross3bc7ffa2017-11-22 16:19:37 -080080
Colin Cross31656952018-05-24 16:11:20 -070081 var expectedLinkImplicits []string
82
83 manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml")
84 expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String())
Colin Cross3bc7ffa2017-11-22 16:19:37 -080085
Colin Crossa97c5d32018-03-28 14:58:31 -070086 frameworkRes := ctx.ModuleForTests("framework-res", "android_common")
87 expectedLinkImplicits = append(expectedLinkImplicits,
88 frameworkRes.Output("package-res.apk").Output.String())
Colin Cross3bc7ffa2017-11-22 16:19:37 -080089
Colin Crossa97c5d32018-03-28 14:58:31 -070090 // Test the mapping from input files to compiled output file names
91 compile := foo.Output(compiledResourceFiles[0])
92 if !reflect.DeepEqual(resourceFiles, compile.Inputs.Strings()) {
93 t.Errorf("expected aapt2 compile inputs expected:\n %#v\n got:\n %#v",
94 resourceFiles, compile.Inputs.Strings())
95 }
Colin Crossb69301e2017-12-01 10:48:26 -080096
Colin Crossa97c5d32018-03-28 14:58:31 -070097 compiledResourceOutputs := compile.Outputs.Strings()
98 sort.Strings(compiledResourceOutputs)
Colin Crossb69301e2017-12-01 10:48:26 -080099
Colin Crossa97c5d32018-03-28 14:58:31 -0700100 expectedLinkImplicits = append(expectedLinkImplicits, compiledResourceOutputs...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800101
Colin Crossa97c5d32018-03-28 14:58:31 -0700102 list := foo.Output("aapt2/res.list")
103 expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String())
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800104
Colin Crossa97c5d32018-03-28 14:58:31 -0700105 // Check that the link rule uses
106 res := ctx.ModuleForTests("foo", "android_common").Output("package-res.apk")
107 if !reflect.DeepEqual(expectedLinkImplicits, res.Implicits.Strings()) {
108 t.Errorf("expected aapt2 link implicits expected:\n %#v\n got:\n %#v",
109 expectedLinkImplicits, res.Implicits.Strings())
110 }
111 })
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800112 }
113}
Colin Cross890ff552017-11-30 20:13:19 -0800114
Colin Crosse560c4a2019-03-19 16:03:11 -0700115func TestAppSplits(t *testing.T) {
116 ctx := testApp(t, `
117 android_app {
118 name: "foo",
119 srcs: ["a.java"],
120 package_splits: ["v4", "v7,hdpi"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900121 sdk_version: "current"
Colin Crosse560c4a2019-03-19 16:03:11 -0700122 }`)
123
124 foo := ctx.ModuleForTests("foo", "android_common")
125
126 expectedOutputs := []string{
127 filepath.Join(buildDir, ".intermediates/foo/android_common/foo.apk"),
128 filepath.Join(buildDir, ".intermediates/foo/android_common/foo_v4.apk"),
129 filepath.Join(buildDir, ".intermediates/foo/android_common/foo_v7_hdpi.apk"),
130 }
131 for _, expectedOutput := range expectedOutputs {
132 foo.Output(expectedOutput)
133 }
134
Colin Cross41955e82019-05-29 14:40:35 -0700135 outputFiles, err := foo.Module().(*AndroidApp).OutputFiles("")
136 if err != nil {
137 t.Fatal(err)
138 }
139 if g, w := outputFiles.Strings(), expectedOutputs; !reflect.DeepEqual(g, w) {
140 t.Errorf(`want OutputFiles("") = %q, got %q`, w, g)
Colin Crosse560c4a2019-03-19 16:03:11 -0700141 }
142}
143
Jeongik Cha538c0d02019-07-11 15:54:27 +0900144func TestPlatformAPIs(t *testing.T) {
145 testJava(t, `
146 android_app {
147 name: "foo",
148 srcs: ["a.java"],
149 platform_apis: true,
150 }
151 `)
152
153 testJava(t, `
154 android_app {
155 name: "foo",
156 srcs: ["a.java"],
157 sdk_version: "current",
158 }
159 `)
160
161 testJavaError(t, "platform_apis must be true when sdk_version is empty.", `
162 android_app {
163 name: "bar",
164 srcs: ["b.java"],
165 }
166 `)
167
168 testJavaError(t, "platform_apis must be false when sdk_version is not empty.", `
169 android_app {
170 name: "bar",
171 srcs: ["b.java"],
172 sdk_version: "system_current",
173 platform_apis: true,
174 }
175 `)
176}
177
Jeongik Chae403e9e2019-12-07 00:16:24 +0900178func TestAndroidAppLinkType(t *testing.T) {
179 testJava(t, `
180 android_app {
181 name: "foo",
182 srcs: ["a.java"],
183 libs: ["bar"],
184 static_libs: ["baz"],
185 platform_apis: true,
186 }
187
188 java_library {
189 name: "bar",
190 sdk_version: "current",
191 srcs: ["b.java"],
192 }
193
194 android_library {
195 name: "baz",
196 sdk_version: "system_current",
197 srcs: ["c.java"],
198 }
199 `)
200
201 testJavaError(t, "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source.", `
202 android_app {
203 name: "foo",
204 srcs: ["a.java"],
205 libs: ["bar"],
206 sdk_version: "current",
207 static_libs: ["baz"],
208 }
209
210 java_library {
211 name: "bar",
212 sdk_version: "current",
213 srcs: ["b.java"],
214 }
215
216 android_library {
217 name: "baz",
218 sdk_version: "system_current",
219 srcs: ["c.java"],
220 }
221 `)
222
223 testJava(t, `
224 android_app {
225 name: "foo",
226 srcs: ["a.java"],
227 libs: ["bar"],
228 sdk_version: "system_current",
229 static_libs: ["baz"],
230 }
231
232 java_library {
233 name: "bar",
234 sdk_version: "current",
235 srcs: ["b.java"],
236 }
237
238 android_library {
239 name: "baz",
240 sdk_version: "system_current",
241 srcs: ["c.java"],
242 }
243 `)
244
245 testJavaError(t, "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source.", `
246 android_app {
247 name: "foo",
248 srcs: ["a.java"],
249 libs: ["bar"],
250 sdk_version: "system_current",
251 static_libs: ["baz"],
252 }
253
254 java_library {
255 name: "bar",
256 sdk_version: "current",
257 srcs: ["b.java"],
258 }
259
260 android_library {
261 name: "baz",
262 srcs: ["c.java"],
263 }
264 `)
265}
266
Colin Cross0ddae7f2019-02-07 15:30:01 -0800267func TestResourceDirs(t *testing.T) {
268 testCases := []struct {
269 name string
270 prop string
271 resources []string
272 }{
273 {
274 name: "no resource_dirs",
275 prop: "",
276 resources: []string{"res/res/values/strings.xml"},
277 },
278 {
279 name: "resource_dirs",
280 prop: `resource_dirs: ["res"]`,
281 resources: []string{"res/res/values/strings.xml"},
282 },
283 {
284 name: "empty resource_dirs",
285 prop: `resource_dirs: []`,
286 resources: nil,
287 },
288 }
289
290 fs := map[string][]byte{
291 "res/res/values/strings.xml": nil,
292 }
293
294 bp := `
295 android_app {
296 name: "foo",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900297 sdk_version: "current",
Colin Cross0ddae7f2019-02-07 15:30:01 -0800298 %s
299 }
300 `
301
302 for _, testCase := range testCases {
303 t.Run(testCase.name, func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800304 config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs)
305 ctx := testContext()
Colin Cross0ddae7f2019-02-07 15:30:01 -0800306 run(t, ctx, config)
307
308 module := ctx.ModuleForTests("foo", "android_common")
309 resourceList := module.MaybeOutput("aapt2/res.list")
310
311 var resources []string
312 if resourceList.Rule != nil {
313 for _, compiledResource := range resourceList.Inputs.Strings() {
314 resources = append(resources, module.Output(compiledResource).Inputs.Strings()...)
315 }
316 }
317
318 if !reflect.DeepEqual(resources, testCase.resources) {
319 t.Errorf("expected resource files %q, got %q",
320 testCase.resources, resources)
321 }
322 })
323 }
324}
325
Colin Crossbec85302019-02-13 13:15:46 -0800326func TestAndroidResources(t *testing.T) {
Colin Cross5c4791c2019-02-01 11:44:44 -0800327 testCases := []struct {
328 name string
329 enforceRROTargets []string
330 enforceRROExcludedOverlays []string
Colin Crossbec85302019-02-13 13:15:46 -0800331 resourceFiles map[string][]string
Colin Cross5c4791c2019-02-01 11:44:44 -0800332 overlayFiles map[string][]string
333 rroDirs map[string][]string
334 }{
335 {
336 name: "no RRO",
337 enforceRROTargets: nil,
338 enforceRROExcludedOverlays: nil,
Colin Crossbec85302019-02-13 13:15:46 -0800339 resourceFiles: map[string][]string{
340 "foo": nil,
341 "bar": {"bar/res/res/values/strings.xml"},
342 "lib": nil,
343 "lib2": {"lib2/res/res/values/strings.xml"},
344 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800345 overlayFiles: map[string][]string{
Colin Crossbec85302019-02-13 13:15:46 -0800346 "foo": {
347 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800348 buildDir + "/.intermediates/lib/android_common/package-res.apk",
Anton Hansson53c88442019-03-18 15:53:16 +0000349 buildDir + "/.intermediates/lib3/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800350 "foo/res/res/values/strings.xml",
Colin Cross5c4791c2019-02-01 11:44:44 -0800351 "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
352 "device/vendor/blah/overlay/foo/res/values/strings.xml",
Anton Hansson53c88442019-03-18 15:53:16 +0000353 "product/vendor/blah/overlay/foo/res/values/strings.xml",
Colin Cross5c4791c2019-02-01 11:44:44 -0800354 },
Colin Crossbec85302019-02-13 13:15:46 -0800355 "bar": {
Colin Cross5c4791c2019-02-01 11:44:44 -0800356 "device/vendor/blah/static_overlay/bar/res/values/strings.xml",
357 "device/vendor/blah/overlay/bar/res/values/strings.xml",
358 },
Colin Crossbec85302019-02-13 13:15:46 -0800359 "lib": {
360 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
361 "lib/res/res/values/strings.xml",
362 "device/vendor/blah/overlay/lib/res/values/strings.xml",
363 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800364 },
365 rroDirs: map[string][]string{
366 "foo": nil,
367 "bar": nil,
368 },
369 },
370 {
371 name: "enforce RRO on foo",
372 enforceRROTargets: []string{"foo"},
373 enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
Colin Crossbec85302019-02-13 13:15:46 -0800374 resourceFiles: map[string][]string{
375 "foo": nil,
376 "bar": {"bar/res/res/values/strings.xml"},
377 "lib": nil,
378 "lib2": {"lib2/res/res/values/strings.xml"},
379 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800380 overlayFiles: map[string][]string{
Colin Crossbec85302019-02-13 13:15:46 -0800381 "foo": {
382 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800383 buildDir + "/.intermediates/lib/android_common/package-res.apk",
Anton Hansson53c88442019-03-18 15:53:16 +0000384 buildDir + "/.intermediates/lib3/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800385 "foo/res/res/values/strings.xml",
386 "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
387 },
Colin Crossbec85302019-02-13 13:15:46 -0800388 "bar": {
Colin Cross5c4791c2019-02-01 11:44:44 -0800389 "device/vendor/blah/static_overlay/bar/res/values/strings.xml",
390 "device/vendor/blah/overlay/bar/res/values/strings.xml",
391 },
Colin Crossbec85302019-02-13 13:15:46 -0800392 "lib": {
393 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
394 "lib/res/res/values/strings.xml",
395 "device/vendor/blah/overlay/lib/res/values/strings.xml",
396 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800397 },
Colin Crossc1c37552019-01-31 11:42:41 -0800398
Colin Cross5c4791c2019-02-01 11:44:44 -0800399 rroDirs: map[string][]string{
Colin Crossbec85302019-02-13 13:15:46 -0800400 "foo": {
Anton Hansson53c88442019-03-18 15:53:16 +0000401 "device:device/vendor/blah/overlay/foo/res",
Colin Crossc1c37552019-01-31 11:42:41 -0800402 // Enforce RRO on "foo" could imply RRO on static dependencies, but for now it doesn't.
403 // "device/vendor/blah/overlay/lib/res",
Anton Hansson53c88442019-03-18 15:53:16 +0000404 "product:product/vendor/blah/overlay/foo/res",
Colin Crossc1c37552019-01-31 11:42:41 -0800405 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800406 "bar": nil,
Colin Crossbec85302019-02-13 13:15:46 -0800407 "lib": nil,
Colin Cross5c4791c2019-02-01 11:44:44 -0800408 },
409 },
410 {
411 name: "enforce RRO on all",
412 enforceRROTargets: []string{"*"},
413 enforceRROExcludedOverlays: []string{
414 // Excluding specific apps/res directories also allowed.
415 "device/vendor/blah/static_overlay/foo",
416 "device/vendor/blah/static_overlay/bar/res",
417 },
Colin Crossbec85302019-02-13 13:15:46 -0800418 resourceFiles: map[string][]string{
419 "foo": nil,
420 "bar": {"bar/res/res/values/strings.xml"},
421 "lib": nil,
422 "lib2": {"lib2/res/res/values/strings.xml"},
423 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800424 overlayFiles: map[string][]string{
Colin Crossbec85302019-02-13 13:15:46 -0800425 "foo": {
426 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800427 buildDir + "/.intermediates/lib/android_common/package-res.apk",
Anton Hansson53c88442019-03-18 15:53:16 +0000428 buildDir + "/.intermediates/lib3/android_common/package-res.apk",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800429 "foo/res/res/values/strings.xml",
430 "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
431 },
Colin Crossbec85302019-02-13 13:15:46 -0800432 "bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
433 "lib": {
434 buildDir + "/.intermediates/lib2/android_common/package-res.apk",
435 "lib/res/res/values/strings.xml",
436 },
Colin Cross5c4791c2019-02-01 11:44:44 -0800437 },
438 rroDirs: map[string][]string{
Colin Crossbec85302019-02-13 13:15:46 -0800439 "foo": {
Anton Hansson53c88442019-03-18 15:53:16 +0000440 "device:device/vendor/blah/overlay/foo/res",
441 "product:product/vendor/blah/overlay/foo/res",
442 // Lib dep comes after the direct deps
443 "device:device/vendor/blah/overlay/lib/res",
Colin Crossc1c37552019-01-31 11:42:41 -0800444 },
Anton Hansson53c88442019-03-18 15:53:16 +0000445 "bar": {"device:device/vendor/blah/overlay/bar/res"},
446 "lib": {"device:device/vendor/blah/overlay/lib/res"},
Colin Cross5c4791c2019-02-01 11:44:44 -0800447 },
448 },
449 }
450
Anton Hansson53c88442019-03-18 15:53:16 +0000451 deviceResourceOverlays := []string{
Colin Cross890ff552017-11-30 20:13:19 -0800452 "device/vendor/blah/overlay",
453 "device/vendor/blah/overlay2",
454 "device/vendor/blah/static_overlay",
455 }
456
Anton Hansson53c88442019-03-18 15:53:16 +0000457 productResourceOverlays := []string{
458 "product/vendor/blah/overlay",
459 }
460
Colin Cross890ff552017-11-30 20:13:19 -0800461 fs := map[string][]byte{
462 "foo/res/res/values/strings.xml": nil,
463 "bar/res/res/values/strings.xml": nil,
Colin Cross6ed7dea2019-01-31 14:44:30 -0800464 "lib/res/res/values/strings.xml": nil,
Colin Crossbec85302019-02-13 13:15:46 -0800465 "lib2/res/res/values/strings.xml": nil,
Colin Cross890ff552017-11-30 20:13:19 -0800466 "device/vendor/blah/overlay/foo/res/values/strings.xml": nil,
467 "device/vendor/blah/overlay/bar/res/values/strings.xml": nil,
Colin Cross6ed7dea2019-01-31 14:44:30 -0800468 "device/vendor/blah/overlay/lib/res/values/strings.xml": nil,
Colin Cross890ff552017-11-30 20:13:19 -0800469 "device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil,
470 "device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil,
471 "device/vendor/blah/overlay2/res/values/strings.xml": nil,
Anton Hansson53c88442019-03-18 15:53:16 +0000472 "product/vendor/blah/overlay/foo/res/values/strings.xml": nil,
Colin Cross890ff552017-11-30 20:13:19 -0800473 }
474
475 bp := `
476 android_app {
477 name: "foo",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900478 sdk_version: "current",
Colin Cross890ff552017-11-30 20:13:19 -0800479 resource_dirs: ["foo/res"],
Anton Hansson53c88442019-03-18 15:53:16 +0000480 static_libs: ["lib", "lib3"],
Colin Cross890ff552017-11-30 20:13:19 -0800481 }
482
483 android_app {
484 name: "bar",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900485 sdk_version: "current",
Colin Cross890ff552017-11-30 20:13:19 -0800486 resource_dirs: ["bar/res"],
487 }
Colin Cross6ed7dea2019-01-31 14:44:30 -0800488
489 android_library {
490 name: "lib",
Jeongik Cha75b83b02019-11-01 15:28:00 +0900491 sdk_version: "current",
Colin Cross6ed7dea2019-01-31 14:44:30 -0800492 resource_dirs: ["lib/res"],
Colin Crossbec85302019-02-13 13:15:46 -0800493 static_libs: ["lib2"],
494 }
495
496 android_library {
497 name: "lib2",
Jeongik Cha75b83b02019-11-01 15:28:00 +0900498 sdk_version: "current",
Colin Crossbec85302019-02-13 13:15:46 -0800499 resource_dirs: ["lib2/res"],
Colin Cross6ed7dea2019-01-31 14:44:30 -0800500 }
Anton Hansson53c88442019-03-18 15:53:16 +0000501
502 // This library has the same resources as lib (should not lead to dupe RROs)
503 android_library {
504 name: "lib3",
Jeongik Cha75b83b02019-11-01 15:28:00 +0900505 sdk_version: "current",
Anton Hansson53c88442019-03-18 15:53:16 +0000506 resource_dirs: ["lib/res"]
507 }
Colin Cross890ff552017-11-30 20:13:19 -0800508 `
509
Colin Cross5c4791c2019-02-01 11:44:44 -0800510 for _, testCase := range testCases {
Colin Cross890ff552017-11-30 20:13:19 -0800511 t.Run(testCase.name, func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800512 config := testAppConfig(nil, bp, fs)
Anton Hansson53c88442019-03-18 15:53:16 +0000513 config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays
514 config.TestProductVariables.ProductResourceOverlays = productResourceOverlays
Colin Cross890ff552017-11-30 20:13:19 -0800515 if testCase.enforceRROTargets != nil {
Colin Crossa74ca042019-01-31 14:31:51 -0800516 config.TestProductVariables.EnforceRROTargets = testCase.enforceRROTargets
Colin Cross890ff552017-11-30 20:13:19 -0800517 }
518 if testCase.enforceRROExcludedOverlays != nil {
Colin Crossa74ca042019-01-31 14:31:51 -0800519 config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
Colin Cross890ff552017-11-30 20:13:19 -0800520 }
521
Colin Cross98be1bb2019-12-13 20:41:13 -0800522 ctx := testContext()
Colin Cross890ff552017-11-30 20:13:19 -0800523 run(t, ctx, config)
524
Colin Crossbec85302019-02-13 13:15:46 -0800525 resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
526 for _, o := range list {
527 res := module.MaybeOutput(o)
528 if res.Rule != nil {
529 // If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
530 // verify the inputs to the .arsc.flat rule.
531 files = append(files, res.Inputs.Strings()...)
532 } else {
533 // Otherwise, verify the full path to the output of the other module
534 files = append(files, o)
Anton Hansson94c93f32019-01-30 16:03:37 +0000535 }
Colin Cross890ff552017-11-30 20:13:19 -0800536 }
Colin Crossbec85302019-02-13 13:15:46 -0800537 return files
Colin Cross890ff552017-11-30 20:13:19 -0800538 }
539
Colin Crossbec85302019-02-13 13:15:46 -0800540 getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
541 module := ctx.ModuleForTests(moduleName, "android_common")
542 resourceList := module.MaybeOutput("aapt2/res.list")
543 if resourceList.Rule != nil {
544 resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings())
Anton Hansson0375a4f2019-01-24 14:39:19 +0000545 }
Colin Crossbec85302019-02-13 13:15:46 -0800546 overlayList := module.MaybeOutput("aapt2/overlay.list")
547 if overlayList.Rule != nil {
548 overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings())
549 }
550
Anton Hansson53c88442019-03-18 15:53:16 +0000551 for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() {
552 var prefix string
553 if d.overlayType == device {
554 prefix = "device:"
555 } else if d.overlayType == product {
556 prefix = "product:"
557 } else {
558 t.Fatalf("Unexpected overlayType %d", d.overlayType)
559 }
560 rroDirs = append(rroDirs, prefix+d.path.String())
561 }
Colin Crossbec85302019-02-13 13:15:46 -0800562
563 return resourceFiles, overlayFiles, rroDirs
564 }
565
566 modules := []string{"foo", "bar", "lib", "lib2"}
567 for _, module := range modules {
568 resourceFiles, overlayFiles, rroDirs := getResources(module)
569
570 if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) {
571 t.Errorf("expected %s resource files:\n %#v\n got:\n %#v",
572 module, testCase.resourceFiles[module], resourceFiles)
573 }
574 if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) {
575 t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v",
576 module, testCase.overlayFiles[module], overlayFiles)
577 }
578 if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) {
Anton Hansson0375a4f2019-01-24 14:39:19 +0000579 t.Errorf("expected %s rroDirs: %#v\n got:\n %#v",
Colin Crossbec85302019-02-13 13:15:46 -0800580 module, testCase.rroDirs[module], rroDirs)
Anton Hansson0375a4f2019-01-24 14:39:19 +0000581 }
Colin Cross890ff552017-11-30 20:13:19 -0800582 }
Colin Cross890ff552017-11-30 20:13:19 -0800583 })
584 }
585}
Colin Crossd09b0b62018-04-18 11:06:47 -0700586
587func TestAppSdkVersion(t *testing.T) {
588 testCases := []struct {
589 name string
590 sdkVersion string
591 platformSdkInt int
592 platformSdkCodename string
593 platformSdkFinal bool
594 expectedMinSdkVersion string
Jeongik Cha538c0d02019-07-11 15:54:27 +0900595 platformApis bool
Colin Crossd09b0b62018-04-18 11:06:47 -0700596 }{
597 {
598 name: "current final SDK",
599 sdkVersion: "current",
600 platformSdkInt: 27,
601 platformSdkCodename: "REL",
602 platformSdkFinal: true,
603 expectedMinSdkVersion: "27",
604 },
605 {
606 name: "current non-final SDK",
607 sdkVersion: "current",
608 platformSdkInt: 27,
609 platformSdkCodename: "OMR1",
610 platformSdkFinal: false,
611 expectedMinSdkVersion: "OMR1",
612 },
613 {
614 name: "default final SDK",
615 sdkVersion: "",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900616 platformApis: true,
Colin Crossd09b0b62018-04-18 11:06:47 -0700617 platformSdkInt: 27,
618 platformSdkCodename: "REL",
619 platformSdkFinal: true,
620 expectedMinSdkVersion: "27",
621 },
622 {
623 name: "default non-final SDK",
624 sdkVersion: "",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900625 platformApis: true,
Colin Crossd09b0b62018-04-18 11:06:47 -0700626 platformSdkInt: 27,
627 platformSdkCodename: "OMR1",
628 platformSdkFinal: false,
629 expectedMinSdkVersion: "OMR1",
630 },
631 {
632 name: "14",
633 sdkVersion: "14",
634 expectedMinSdkVersion: "14",
635 },
636 }
637
638 for _, moduleType := range []string{"android_app", "android_library"} {
639 for _, test := range testCases {
640 t.Run(moduleType+" "+test.name, func(t *testing.T) {
Jeongik Cha538c0d02019-07-11 15:54:27 +0900641 platformApiProp := ""
642 if test.platformApis {
643 platformApiProp = "platform_apis: true,"
644 }
Colin Crossd09b0b62018-04-18 11:06:47 -0700645 bp := fmt.Sprintf(`%s {
646 name: "foo",
647 srcs: ["a.java"],
648 sdk_version: "%s",
Jeongik Cha538c0d02019-07-11 15:54:27 +0900649 %s
650 }`, moduleType, test.sdkVersion, platformApiProp)
Colin Crossd09b0b62018-04-18 11:06:47 -0700651
Colin Cross98be1bb2019-12-13 20:41:13 -0800652 config := testAppConfig(nil, bp, nil)
Colin Crossd09b0b62018-04-18 11:06:47 -0700653 config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
654 config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
655 config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
656
Colin Cross98be1bb2019-12-13 20:41:13 -0800657 ctx := testContext()
Colin Crossd09b0b62018-04-18 11:06:47 -0700658
659 run(t, ctx, config)
660
661 foo := ctx.ModuleForTests("foo", "android_common")
662 link := foo.Output("package-res.apk")
663 linkFlags := strings.Split(link.Args["flags"], " ")
664 min := android.IndexList("--min-sdk-version", linkFlags)
665 target := android.IndexList("--target-sdk-version", linkFlags)
666
667 if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 {
668 t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags)
669 }
670
671 gotMinSdkVersion := linkFlags[min+1]
672 gotTargetSdkVersion := linkFlags[target+1]
673
674 if gotMinSdkVersion != test.expectedMinSdkVersion {
675 t.Errorf("incorrect --min-sdk-version, expected %q got %q",
676 test.expectedMinSdkVersion, gotMinSdkVersion)
677 }
678
679 if gotTargetSdkVersion != test.expectedMinSdkVersion {
680 t.Errorf("incorrect --target-sdk-version, expected %q got %q",
681 test.expectedMinSdkVersion, gotTargetSdkVersion)
682 }
683 })
684 }
685 }
686}
Colin Crossa4f08812018-10-02 22:03:40 -0700687
Paul Duffin50c217c2019-06-12 13:25:22 +0100688func TestJNIABI(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -0700689 ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
Paul Duffin50c217c2019-06-12 13:25:22 +0100690 cc_library {
691 name: "libjni",
692 system_shared_libs: [],
693 stl: "none",
694 }
695
696 android_test {
697 name: "test",
698 sdk_version: "core_platform",
699 jni_libs: ["libjni"],
700 }
701
702 android_test {
703 name: "test_first",
704 sdk_version: "core_platform",
705 compile_multilib: "first",
706 jni_libs: ["libjni"],
707 }
708
709 android_test {
710 name: "test_both",
711 sdk_version: "core_platform",
712 compile_multilib: "both",
713 jni_libs: ["libjni"],
714 }
715
716 android_test {
717 name: "test_32",
718 sdk_version: "core_platform",
719 compile_multilib: "32",
720 jni_libs: ["libjni"],
721 }
722
723 android_test {
724 name: "test_64",
725 sdk_version: "core_platform",
726 compile_multilib: "64",
727 jni_libs: ["libjni"],
728 }
729 `)
730
731 testCases := []struct {
732 name string
733 abis []string
734 }{
735 {"test", []string{"arm64-v8a"}},
736 {"test_first", []string{"arm64-v8a"}},
737 {"test_both", []string{"arm64-v8a", "armeabi-v7a"}},
738 {"test_32", []string{"armeabi-v7a"}},
739 {"test_64", []string{"arm64-v8a"}},
740 }
741
742 for _, test := range testCases {
743 t.Run(test.name, func(t *testing.T) {
744 app := ctx.ModuleForTests(test.name, "android_common")
745 jniLibZip := app.Output("jnilibs.zip")
746 var abis []string
747 args := strings.Fields(jniLibZip.Args["jarArgs"])
748 for i := 0; i < len(args); i++ {
749 if args[i] == "-P" {
750 abis = append(abis, filepath.Base(args[i+1]))
751 i++
752 }
753 }
754 if !reflect.DeepEqual(abis, test.abis) {
755 t.Errorf("want abis %v, got %v", test.abis, abis)
756 }
757 })
758 }
759}
760
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900761func TestAppSdkVersionByPartition(t *testing.T) {
762 testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
763 android_app {
764 name: "foo",
765 srcs: ["a.java"],
766 vendor: true,
767 platform_apis: true,
768 }
769 `)
770
771 testJava(t, `
772 android_app {
773 name: "bar",
774 srcs: ["b.java"],
775 platform_apis: true,
776 }
777 `)
778
779 for _, enforce := range []bool{true, false} {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900780 bp := `
781 android_app {
782 name: "foo",
783 srcs: ["a.java"],
784 product_specific: true,
785 platform_apis: true,
786 }
787 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800788
789 config := testAppConfig(nil, bp, nil)
790 config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900791 if enforce {
Colin Cross98be1bb2019-12-13 20:41:13 -0800792 testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config)
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900793 } else {
Colin Cross98be1bb2019-12-13 20:41:13 -0800794 testJavaWithConfig(t, config)
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900795 }
796 }
797}
798
Paul Duffin50c217c2019-06-12 13:25:22 +0100799func TestJNIPackaging(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -0700800 ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
Paul Duffin50c217c2019-06-12 13:25:22 +0100801 cc_library {
802 name: "libjni",
803 system_shared_libs: [],
804 stl: "none",
805 }
806
807 android_app {
808 name: "app",
809 jni_libs: ["libjni"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900810 sdk_version: "current",
Paul Duffin50c217c2019-06-12 13:25:22 +0100811 }
812
813 android_app {
814 name: "app_noembed",
815 jni_libs: ["libjni"],
816 use_embedded_native_libs: false,
Jeongik Cha538c0d02019-07-11 15:54:27 +0900817 sdk_version: "current",
Paul Duffin50c217c2019-06-12 13:25:22 +0100818 }
819
820 android_app {
821 name: "app_embed",
822 jni_libs: ["libjni"],
823 use_embedded_native_libs: true,
Jeongik Cha538c0d02019-07-11 15:54:27 +0900824 sdk_version: "current",
Paul Duffin50c217c2019-06-12 13:25:22 +0100825 }
826
827 android_test {
828 name: "test",
829 sdk_version: "core_platform",
830 jni_libs: ["libjni"],
831 }
832
833 android_test {
834 name: "test_noembed",
835 sdk_version: "core_platform",
836 jni_libs: ["libjni"],
837 use_embedded_native_libs: false,
838 }
839
840 android_test_helper_app {
841 name: "test_helper",
842 sdk_version: "core_platform",
843 jni_libs: ["libjni"],
844 }
845
846 android_test_helper_app {
847 name: "test_helper_noembed",
848 sdk_version: "core_platform",
849 jni_libs: ["libjni"],
850 use_embedded_native_libs: false,
851 }
852 `)
853
854 testCases := []struct {
855 name string
856 packaged bool
857 compressed bool
858 }{
859 {"app", false, false},
860 {"app_noembed", false, false},
861 {"app_embed", true, false},
862 {"test", true, false},
863 {"test_noembed", true, true},
864 {"test_helper", true, false},
865 {"test_helper_noembed", true, true},
866 }
867
868 for _, test := range testCases {
869 t.Run(test.name, func(t *testing.T) {
870 app := ctx.ModuleForTests(test.name, "android_common")
871 jniLibZip := app.MaybeOutput("jnilibs.zip")
872 if g, w := (jniLibZip.Rule != nil), test.packaged; g != w {
873 t.Errorf("expected jni packaged %v, got %v", w, g)
874 }
875
876 if jniLibZip.Rule != nil {
877 if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w {
878 t.Errorf("expected jni compressed %v, got %v", w, g)
879 }
880 }
881 })
882 }
Colin Cross47fa9d32019-03-26 10:51:39 -0700883}
884
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800885func TestCertificates(t *testing.T) {
886 testCases := []struct {
887 name string
888 bp string
889 certificateOverride string
890 expected string
891 }{
892 {
893 name: "default",
894 bp: `
895 android_app {
896 name: "foo",
897 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900898 sdk_version: "current",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800899 }
900 `,
901 certificateOverride: "",
Dan Willemsen412160e2019-04-09 21:36:26 -0700902 expected: "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800903 },
904 {
905 name: "module certificate property",
906 bp: `
907 android_app {
908 name: "foo",
909 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900910 certificate: ":new_certificate",
911 sdk_version: "current",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800912 }
913
914 android_app_certificate {
915 name: "new_certificate",
916 certificate: "cert/new_cert",
917 }
918 `,
919 certificateOverride: "",
920 expected: "cert/new_cert.x509.pem cert/new_cert.pk8",
921 },
922 {
923 name: "path certificate property",
924 bp: `
925 android_app {
926 name: "foo",
927 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900928 certificate: "expiredkey",
929 sdk_version: "current",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800930 }
931 `,
932 certificateOverride: "",
Dan Willemsen412160e2019-04-09 21:36:26 -0700933 expected: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800934 },
935 {
936 name: "certificate overrides",
937 bp: `
938 android_app {
939 name: "foo",
940 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900941 certificate: "expiredkey",
942 sdk_version: "current",
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800943 }
944
945 android_app_certificate {
946 name: "new_certificate",
947 certificate: "cert/new_cert",
948 }
949 `,
950 certificateOverride: "foo:new_certificate",
951 expected: "cert/new_cert.x509.pem cert/new_cert.pk8",
952 },
953 }
954
955 for _, test := range testCases {
956 t.Run(test.name, func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800957 config := testAppConfig(nil, test.bp, nil)
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800958 if test.certificateOverride != "" {
959 config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride}
960 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800961 ctx := testContext()
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800962
963 run(t, ctx, config)
964 foo := ctx.ModuleForTests("foo", "android_common")
965
966 signapk := foo.Output("foo.apk")
967 signFlags := signapk.Args["certificates"]
968 if test.expected != signFlags {
969 t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expected, signFlags)
970 }
971 })
972 }
973}
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800974
975func TestPackageNameOverride(t *testing.T) {
976 testCases := []struct {
977 name string
978 bp string
979 packageNameOverride string
980 expected []string
981 }{
982 {
983 name: "default",
984 bp: `
985 android_app {
986 name: "foo",
987 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +0900988 sdk_version: "current",
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800989 }
990 `,
991 packageNameOverride: "",
992 expected: []string{
993 buildDir + "/.intermediates/foo/android_common/foo.apk",
994 buildDir + "/target/product/test_device/system/app/foo/foo.apk",
995 },
996 },
997 {
998 name: "overridden",
999 bp: `
1000 android_app {
1001 name: "foo",
1002 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001003 sdk_version: "current",
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001004 }
1005 `,
1006 packageNameOverride: "foo:bar",
1007 expected: []string{
1008 // The package apk should be still be the original name for test dependencies.
Jaewoong Jung5a498812019-11-07 14:14:38 -08001009 buildDir + "/.intermediates/foo/android_common/bar.apk",
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001010 buildDir + "/target/product/test_device/system/app/bar/bar.apk",
1011 },
1012 },
1013 }
1014
1015 for _, test := range testCases {
1016 t.Run(test.name, func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08001017 config := testAppConfig(nil, test.bp, nil)
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001018 if test.packageNameOverride != "" {
1019 config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride}
1020 }
Colin Cross98be1bb2019-12-13 20:41:13 -08001021 ctx := testContext()
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001022
1023 run(t, ctx, config)
1024 foo := ctx.ModuleForTests("foo", "android_common")
1025
1026 outputs := foo.AllOutputs()
1027 outputMap := make(map[string]bool)
1028 for _, o := range outputs {
1029 outputMap[o] = true
1030 }
1031 for _, e := range test.expected {
1032 if _, exist := outputMap[e]; !exist {
1033 t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs)
1034 }
1035 }
1036 })
1037 }
1038}
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001039
1040func TestInstrumentationTargetOverridden(t *testing.T) {
1041 bp := `
1042 android_app {
1043 name: "foo",
1044 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001045 sdk_version: "current",
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001046 }
1047
1048 android_test {
1049 name: "bar",
1050 instrumentation_for: "foo",
Jeongik Cha538c0d02019-07-11 15:54:27 +09001051 sdk_version: "current",
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001052 }
1053 `
Colin Cross98be1bb2019-12-13 20:41:13 -08001054 config := testAppConfig(nil, bp, nil)
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001055 config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
Colin Cross98be1bb2019-12-13 20:41:13 -08001056 ctx := testContext()
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001057
1058 run(t, ctx, config)
1059
1060 bar := ctx.ModuleForTests("bar", "android_common")
1061 res := bar.Output("package-res.apk")
1062 aapt2Flags := res.Args["flags"]
1063 e := "--rename-instrumentation-target-package org.dandroid.bp"
1064 if !strings.Contains(aapt2Flags, e) {
1065 t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
1066 }
1067}
Jaewoong Jung525443a2019-02-28 15:35:54 -08001068
1069func TestOverrideAndroidApp(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001070 ctx, _ := testJava(t, `
Jaewoong Jung525443a2019-02-28 15:35:54 -08001071 android_app {
1072 name: "foo",
1073 srcs: ["a.java"],
Jaewoong Junga641ee92019-03-27 11:17:14 -07001074 certificate: "expiredkey",
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001075 overrides: ["qux"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001076 sdk_version: "current",
Jaewoong Jung525443a2019-02-28 15:35:54 -08001077 }
1078
1079 override_android_app {
1080 name: "bar",
1081 base: "foo",
1082 certificate: ":new_certificate",
1083 }
1084
1085 android_app_certificate {
1086 name: "new_certificate",
1087 certificate: "cert/new_cert",
1088 }
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001089
1090 override_android_app {
1091 name: "baz",
1092 base: "foo",
1093 package_name: "org.dandroid.bp",
1094 }
Jaewoong Jung525443a2019-02-28 15:35:54 -08001095 `)
1096
1097 expectedVariants := []struct {
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001098 moduleName string
Jaewoong Jung525443a2019-02-28 15:35:54 -08001099 variantName string
1100 apkName string
1101 apkPath string
1102 signFlag string
1103 overrides []string
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001104 aaptFlag string
Jaewoong Jung525443a2019-02-28 15:35:54 -08001105 }{
1106 {
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001107 moduleName: "foo",
Jaewoong Jung525443a2019-02-28 15:35:54 -08001108 variantName: "android_common",
1109 apkPath: "/target/product/test_device/system/app/foo/foo.apk",
Dan Willemsen412160e2019-04-09 21:36:26 -07001110 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001111 overrides: []string{"qux"},
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001112 aaptFlag: "",
Jaewoong Jung525443a2019-02-28 15:35:54 -08001113 },
1114 {
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001115 moduleName: "bar",
1116 variantName: "android_common_bar",
Jaewoong Jung525443a2019-02-28 15:35:54 -08001117 apkPath: "/target/product/test_device/system/app/bar/bar.apk",
1118 signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001119 overrides: []string{"qux", "foo"},
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001120 aaptFlag: "",
1121 },
1122 {
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001123 moduleName: "baz",
1124 variantName: "android_common_baz",
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001125 apkPath: "/target/product/test_device/system/app/baz/baz.apk",
Dan Willemsen412160e2019-04-09 21:36:26 -07001126 signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001127 overrides: []string{"qux", "foo"},
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001128 aaptFlag: "--rename-manifest-package org.dandroid.bp",
Jaewoong Jung525443a2019-02-28 15:35:54 -08001129 },
1130 }
1131 for _, expected := range expectedVariants {
1132 variant := ctx.ModuleForTests("foo", expected.variantName)
1133
1134 // Check the final apk name
1135 outputs := variant.AllOutputs()
1136 expectedApkPath := buildDir + expected.apkPath
1137 found := false
1138 for _, o := range outputs {
1139 if o == expectedApkPath {
1140 found = true
1141 break
1142 }
1143 }
1144 if !found {
1145 t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs)
1146 }
1147
1148 // Check the certificate paths
Jaewoong Jung5a498812019-11-07 14:14:38 -08001149 signapk := variant.Output(expected.moduleName + ".apk")
Jaewoong Jung525443a2019-02-28 15:35:54 -08001150 signFlag := signapk.Args["certificates"]
1151 if expected.signFlag != signFlag {
1152 t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.signFlag, signFlag)
1153 }
1154
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001155 // Check if the overrides field values are correctly aggregated.
Jaewoong Jung525443a2019-02-28 15:35:54 -08001156 mod := variant.Module().(*AndroidApp)
1157 if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) {
1158 t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
1159 expected.overrides, mod.appProperties.Overrides)
1160 }
Jaewoong Jung6f373f62019-03-13 10:13:24 -07001161
1162 // Check the package renaming flag, if exists.
1163 res := variant.Output("package-res.apk")
1164 aapt2Flags := res.Args["flags"]
1165 if !strings.Contains(aapt2Flags, expected.aaptFlag) {
1166 t.Errorf("package renaming flag, %q is missing in aapt2 link flags, %q", expected.aaptFlag, aapt2Flags)
1167 }
Jaewoong Jung525443a2019-02-28 15:35:54 -08001168 }
1169}
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001170
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001171func TestOverrideAndroidAppDependency(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001172 ctx, _ := testJava(t, `
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001173 android_app {
1174 name: "foo",
1175 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001176 sdk_version: "current",
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001177 }
1178
1179 override_android_app {
1180 name: "bar",
1181 base: "foo",
1182 package_name: "org.dandroid.bp",
1183 }
1184
1185 android_test {
1186 name: "baz",
1187 srcs: ["b.java"],
1188 instrumentation_for: "foo",
1189 }
1190
1191 android_test {
1192 name: "qux",
1193 srcs: ["b.java"],
1194 instrumentation_for: "bar",
1195 }
1196 `)
1197
1198 // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg.
1199 javac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
1200 fooTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar")
1201 if !strings.Contains(javac.Args["classpath"], fooTurbine) {
1202 t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine)
1203 }
1204
1205 // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg.
1206 javac = ctx.ModuleForTests("qux", "android_common").Rule("javac")
1207 barTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common_bar", "turbine-combined", "foo.jar")
1208 if !strings.Contains(javac.Args["classpath"], barTurbine) {
1209 t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
1210 }
1211}
1212
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001213func TestOverrideAndroidTest(t *testing.T) {
1214 ctx, _ := testJava(t, `
1215 android_app {
1216 name: "foo",
1217 srcs: ["a.java"],
1218 package_name: "com.android.foo",
1219 sdk_version: "current",
1220 }
1221
1222 override_android_app {
1223 name: "bar",
1224 base: "foo",
1225 package_name: "com.android.bar",
1226 }
1227
1228 android_test {
1229 name: "foo_test",
1230 srcs: ["b.java"],
1231 instrumentation_for: "foo",
1232 }
1233
1234 override_android_test {
1235 name: "bar_test",
1236 base: "foo_test",
1237 package_name: "com.android.bar.test",
1238 instrumentation_for: "bar",
1239 instrumentation_target_package: "com.android.bar",
1240 }
1241 `)
1242
1243 expectedVariants := []struct {
1244 moduleName string
1245 variantName string
1246 apkPath string
1247 overrides []string
1248 targetVariant string
1249 packageFlag string
1250 targetPackageFlag string
1251 }{
1252 {
1253 variantName: "android_common",
Jaewoong Jung326a9412019-11-21 10:41:00 -08001254 apkPath: "/target/product/test_device/testcases/foo_test/arm64/foo_test.apk",
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001255 overrides: nil,
1256 targetVariant: "android_common",
1257 packageFlag: "",
1258 targetPackageFlag: "",
1259 },
1260 {
1261 variantName: "android_common_bar_test",
Jaewoong Jung326a9412019-11-21 10:41:00 -08001262 apkPath: "/target/product/test_device/testcases/bar_test/arm64/bar_test.apk",
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001263 overrides: []string{"foo_test"},
1264 targetVariant: "android_common_bar",
1265 packageFlag: "com.android.bar.test",
1266 targetPackageFlag: "com.android.bar",
1267 },
1268 }
1269 for _, expected := range expectedVariants {
1270 variant := ctx.ModuleForTests("foo_test", expected.variantName)
1271
1272 // Check the final apk name
1273 outputs := variant.AllOutputs()
1274 expectedApkPath := buildDir + expected.apkPath
1275 found := false
1276 for _, o := range outputs {
1277 if o == expectedApkPath {
1278 found = true
1279 break
1280 }
1281 }
1282 if !found {
1283 t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs)
1284 }
1285
1286 // Check if the overrides field values are correctly aggregated.
1287 mod := variant.Module().(*AndroidTest)
1288 if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) {
1289 t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
1290 expected.overrides, mod.appProperties.Overrides)
1291 }
1292
1293 // Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides.
1294 javac := variant.Rule("javac")
1295 turbine := filepath.Join(buildDir, ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar")
1296 if !strings.Contains(javac.Args["classpath"], turbine) {
1297 t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine)
1298 }
1299
1300 // Check aapt2 flags.
1301 res := variant.Output("package-res.apk")
1302 aapt2Flags := res.Args["flags"]
1303 checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag)
1304 checkAapt2LinkFlag(t, aapt2Flags, "rename-instrumentation-target-package", expected.targetPackageFlag)
1305 }
1306}
1307
Jaewoong Jung39982342020-01-14 10:27:18 -08001308func TestAndroidTest_FixTestConfig(t *testing.T) {
1309 ctx, _ := testJava(t, `
1310 android_app {
1311 name: "foo",
1312 srcs: ["a.java"],
1313 package_name: "com.android.foo",
1314 sdk_version: "current",
1315 }
1316
1317 android_test {
1318 name: "foo_test",
1319 srcs: ["b.java"],
1320 instrumentation_for: "foo",
1321 }
1322
1323 android_test {
1324 name: "bar_test",
1325 srcs: ["b.java"],
1326 package_name: "com.android.bar.test",
1327 instrumentation_for: "foo",
1328 }
1329
1330 override_android_test {
1331 name: "baz_test",
1332 base: "foo_test",
1333 package_name: "com.android.baz.test",
1334 }
1335 `)
1336
1337 testCases := []struct {
1338 moduleName string
1339 variantName string
1340 expectedFlags []string
1341 }{
1342 {
1343 moduleName: "foo_test",
1344 variantName: "android_common",
1345 },
1346 {
1347 moduleName: "bar_test",
1348 variantName: "android_common",
1349 expectedFlags: []string{
1350 "--manifest " + buildDir + "/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
1351 "--package-name com.android.bar.test",
1352 },
1353 },
1354 {
1355 moduleName: "foo_test",
1356 variantName: "android_common_baz_test",
1357 expectedFlags: []string{
1358 "--manifest " + buildDir +
1359 "/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
1360 "--package-name com.android.baz.test",
1361 "--test-file-name baz_test.apk",
1362 },
1363 },
1364 }
1365
1366 for _, test := range testCases {
1367 variant := ctx.ModuleForTests(test.moduleName, test.variantName)
1368 params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml")
1369
1370 if len(test.expectedFlags) > 0 {
1371 if params.Rule == nil {
1372 t.Errorf("test_config_fixer was expected to run, but didn't")
1373 } else {
1374 for _, flag := range test.expectedFlags {
1375 if !strings.Contains(params.RuleParams.Command, flag) {
1376 t.Errorf("Flag %q was not found in command: %q", flag, params.RuleParams.Command)
1377 }
1378 }
1379 }
1380 } else {
1381 if params.Rule != nil {
1382 t.Errorf("test_config_fixer was not expected to run, but did: %q", params.RuleParams.Command)
1383 }
1384 }
1385
1386 }
1387}
1388
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001389func TestAndroidAppImport(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001390 ctx, _ := testJava(t, `
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001391 android_app_import {
1392 name: "foo",
1393 apk: "prebuilts/apk/app.apk",
1394 certificate: "platform",
1395 dex_preopt: {
1396 enabled: true,
1397 },
1398 }
1399 `)
1400
1401 variant := ctx.ModuleForTests("foo", "android_common")
1402
1403 // Check dexpreopt outputs.
1404 if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
1405 variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
1406 t.Errorf("can't find dexpreopt outputs")
1407 }
1408
1409 // Check cert signing flag.
1410 signedApk := variant.Output("signed/foo.apk")
1411 signingFlag := signedApk.Args["certificates"]
1412 expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8"
1413 if expected != signingFlag {
1414 t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
1415 }
1416}
1417
1418func TestAndroidAppImport_NoDexPreopt(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001419 ctx, _ := testJava(t, `
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001420 android_app_import {
1421 name: "foo",
1422 apk: "prebuilts/apk/app.apk",
1423 certificate: "platform",
1424 dex_preopt: {
1425 enabled: false,
1426 },
1427 }
1428 `)
1429
1430 variant := ctx.ModuleForTests("foo", "android_common")
1431
1432 // Check dexpreopt outputs. They shouldn't exist.
1433 if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule != nil ||
1434 variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule != nil {
1435 t.Errorf("dexpreopt shouldn't have run.")
1436 }
1437}
1438
1439func TestAndroidAppImport_Presigned(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001440 ctx, _ := testJava(t, `
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001441 android_app_import {
1442 name: "foo",
1443 apk: "prebuilts/apk/app.apk",
1444 presigned: true,
1445 dex_preopt: {
1446 enabled: true,
1447 },
1448 }
1449 `)
1450
1451 variant := ctx.ModuleForTests("foo", "android_common")
1452
1453 // Check dexpreopt outputs.
1454 if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
1455 variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
1456 t.Errorf("can't find dexpreopt outputs")
1457 }
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +01001458 // Make sure signing was skipped and aligning was done.
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001459 if variant.MaybeOutput("signed/foo.apk").Rule != nil {
1460 t.Errorf("signing rule shouldn't be included.")
1461 }
1462 if variant.MaybeOutput("zip-aligned/foo.apk").Rule == nil {
1463 t.Errorf("can't find aligning rule")
1464 }
1465}
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001466
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001467func TestAndroidAppImport_DefaultDevCert(t *testing.T) {
1468 ctx, _ := testJava(t, `
1469 android_app_import {
1470 name: "foo",
1471 apk: "prebuilts/apk/app.apk",
1472 default_dev_cert: true,
1473 dex_preopt: {
1474 enabled: true,
1475 },
1476 }
1477 `)
1478
1479 variant := ctx.ModuleForTests("foo", "android_common")
1480
1481 // Check dexpreopt outputs.
1482 if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
1483 variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
1484 t.Errorf("can't find dexpreopt outputs")
1485 }
1486
1487 // Check cert signing flag.
1488 signedApk := variant.Output("signed/foo.apk")
1489 signingFlag := signedApk.Args["certificates"]
1490 expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8"
1491 if expected != signingFlag {
1492 t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
1493 }
1494}
1495
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001496func TestAndroidAppImport_DpiVariants(t *testing.T) {
1497 bp := `
1498 android_app_import {
1499 name: "foo",
1500 apk: "prebuilts/apk/app.apk",
1501 dpi_variants: {
1502 xhdpi: {
1503 apk: "prebuilts/apk/app_xhdpi.apk",
1504 },
1505 xxhdpi: {
1506 apk: "prebuilts/apk/app_xxhdpi.apk",
1507 },
1508 },
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001509 presigned: true,
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001510 dex_preopt: {
1511 enabled: true,
1512 },
1513 }
1514 `
1515 testCases := []struct {
1516 name string
1517 aaptPreferredConfig *string
1518 aaptPrebuiltDPI []string
1519 expected string
1520 }{
1521 {
1522 name: "no preferred",
1523 aaptPreferredConfig: nil,
1524 aaptPrebuiltDPI: []string{},
1525 expected: "prebuilts/apk/app.apk",
1526 },
1527 {
1528 name: "AAPTPreferredConfig matches",
1529 aaptPreferredConfig: proptools.StringPtr("xhdpi"),
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001530 aaptPrebuiltDPI: []string{"xxhdpi", "ldpi"},
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001531 expected: "prebuilts/apk/app_xhdpi.apk",
1532 },
1533 {
1534 name: "AAPTPrebuiltDPI matches",
1535 aaptPreferredConfig: proptools.StringPtr("mdpi"),
1536 aaptPrebuiltDPI: []string{"xxhdpi", "xhdpi"},
1537 expected: "prebuilts/apk/app_xxhdpi.apk",
1538 },
1539 {
1540 name: "non-first AAPTPrebuiltDPI matches",
1541 aaptPreferredConfig: proptools.StringPtr("mdpi"),
1542 aaptPrebuiltDPI: []string{"ldpi", "xhdpi"},
1543 expected: "prebuilts/apk/app_xhdpi.apk",
1544 },
1545 {
1546 name: "no matches",
1547 aaptPreferredConfig: proptools.StringPtr("mdpi"),
1548 aaptPrebuiltDPI: []string{"ldpi", "xxxhdpi"},
1549 expected: "prebuilts/apk/app.apk",
1550 },
1551 }
1552
1553 jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)")
1554 for _, test := range testCases {
Colin Cross98be1bb2019-12-13 20:41:13 -08001555 config := testAppConfig(nil, bp, nil)
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001556 config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig
1557 config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
Colin Cross98be1bb2019-12-13 20:41:13 -08001558 ctx := testContext()
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001559
1560 run(t, ctx, config)
1561
1562 variant := ctx.ModuleForTests("foo", "android_common")
1563 jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
1564 matches := jniRuleRe.FindStringSubmatch(jniRuleCommand)
1565 if len(matches) != 2 {
1566 t.Errorf("failed to extract the src apk path from %q", jniRuleCommand)
1567 }
1568 if test.expected != matches[1] {
1569 t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1])
1570 }
1571 }
1572}
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001573
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001574func TestAndroidAppImport_Filename(t *testing.T) {
1575 ctx, config := testJava(t, `
1576 android_app_import {
1577 name: "foo",
1578 apk: "prebuilts/apk/app.apk",
1579 presigned: true,
1580 }
1581
1582 android_app_import {
1583 name: "bar",
1584 apk: "prebuilts/apk/app.apk",
1585 presigned: true,
1586 filename: "bar_sample.apk"
1587 }
1588 `)
1589
1590 testCases := []struct {
1591 name string
1592 expected string
1593 }{
1594 {
1595 name: "foo",
1596 expected: "foo.apk",
1597 },
1598 {
1599 name: "bar",
1600 expected: "bar_sample.apk",
1601 },
1602 }
1603
1604 for _, test := range testCases {
1605 variant := ctx.ModuleForTests(test.name, "android_common")
1606 if variant.MaybeOutput(test.expected).Rule == nil {
1607 t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs())
1608 }
1609
1610 a := variant.Module().(*AndroidAppImport)
1611 expectedValues := []string{test.expected}
1612 actualValues := android.AndroidMkEntriesForTest(
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001613 t, config, "", a)[0].EntryMap["LOCAL_INSTALLED_MODULE_STEM"]
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001614 if !reflect.DeepEqual(actualValues, expectedValues) {
1615 t.Errorf("Incorrect LOCAL_INSTALLED_MODULE_STEM value '%s', expected '%s'",
1616 actualValues, expectedValues)
1617 }
1618 }
1619}
1620
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001621func TestAndroidAppImport_ArchVariants(t *testing.T) {
1622 // The test config's target arch is ARM64.
1623 testCases := []struct {
1624 name string
1625 bp string
1626 expected string
1627 }{
1628 {
1629 name: "matching arch",
1630 bp: `
1631 android_app_import {
1632 name: "foo",
1633 apk: "prebuilts/apk/app.apk",
1634 arch: {
1635 arm64: {
1636 apk: "prebuilts/apk/app_arm64.apk",
1637 },
1638 },
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001639 presigned: true,
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001640 dex_preopt: {
1641 enabled: true,
1642 },
1643 }
1644 `,
1645 expected: "prebuilts/apk/app_arm64.apk",
1646 },
1647 {
1648 name: "no matching arch",
1649 bp: `
1650 android_app_import {
1651 name: "foo",
1652 apk: "prebuilts/apk/app.apk",
1653 arch: {
1654 arm: {
1655 apk: "prebuilts/apk/app_arm.apk",
1656 },
1657 },
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001658 presigned: true,
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001659 dex_preopt: {
1660 enabled: true,
1661 },
1662 }
1663 `,
1664 expected: "prebuilts/apk/app.apk",
1665 },
1666 }
1667
1668 jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)")
1669 for _, test := range testCases {
1670 ctx, _ := testJava(t, test.bp)
1671
1672 variant := ctx.ModuleForTests("foo", "android_common")
1673 jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
1674 matches := jniRuleRe.FindStringSubmatch(jniRuleCommand)
1675 if len(matches) != 2 {
1676 t.Errorf("failed to extract the src apk path from %q", jniRuleCommand)
1677 }
1678 if test.expected != matches[1] {
1679 t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1])
1680 }
1681 }
1682}
1683
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001684func TestAndroidTestImport(t *testing.T) {
1685 ctx, config := testJava(t, `
1686 android_test_import {
1687 name: "foo",
1688 apk: "prebuilts/apk/app.apk",
1689 presigned: true,
1690 data: [
1691 "testdata/data",
1692 ],
1693 }
1694 `)
1695
1696 test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport)
1697
1698 // Check android mks.
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001699 entries := android.AndroidMkEntriesForTest(t, config, "", test)[0]
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001700 expected := []string{"tests"}
1701 actual := entries.EntryMap["LOCAL_MODULE_TAGS"]
1702 if !reflect.DeepEqual(expected, actual) {
1703 t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual)
1704 }
1705 expected = []string{"testdata/data:testdata/data"}
1706 actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
1707 if !reflect.DeepEqual(expected, actual) {
1708 t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
1709 }
1710}
1711
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001712func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) {
1713 ctx, _ := testJava(t, `
1714 android_test_import {
1715 name: "foo",
1716 apk: "prebuilts/apk/app.apk",
1717 certificate: "cert/new_cert",
1718 data: [
1719 "testdata/data",
1720 ],
1721 }
1722
1723 android_test_import {
1724 name: "foo_presigned",
1725 apk: "prebuilts/apk/app.apk",
1726 presigned: true,
1727 data: [
1728 "testdata/data",
1729 ],
1730 }
1731 `)
1732
1733 variant := ctx.ModuleForTests("foo", "android_common")
1734 jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
1735 if !strings.HasPrefix(jniRule, "if (zipinfo") {
1736 t.Errorf("Unexpected JNI uncompress rule command: " + jniRule)
1737 }
1738
1739 variant = ctx.ModuleForTests("foo_presigned", "android_common")
1740 jniRule = variant.Output("jnis-uncompressed/foo_presigned.apk").BuildParams.Rule.String()
1741 if jniRule != android.Cp.String() {
1742 t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
1743 }
1744}
1745
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001746func TestStl(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07001747 ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001748 cc_library {
Peter Collingbournead84f972019-12-17 16:46:18 -08001749 name: "ndk_libunwind",
1750 sdk_version: "current",
1751 stl: "none",
1752 system_shared_libs: [],
1753 }
1754
1755 cc_library {
1756 name: "libc.ndk.current",
1757 sdk_version: "current",
1758 stl: "none",
1759 system_shared_libs: [],
1760 }
1761
1762 cc_library {
1763 name: "libm.ndk.current",
1764 sdk_version: "current",
1765 stl: "none",
1766 system_shared_libs: [],
1767 }
1768
1769 cc_library {
1770 name: "libdl.ndk.current",
1771 sdk_version: "current",
1772 stl: "none",
1773 system_shared_libs: [],
1774 }
1775
1776 cc_object {
1777 name: "ndk_crtbegin_so.27",
1778 }
1779
1780 cc_object {
1781 name: "ndk_crtend_so.27",
1782 }
1783
1784 cc_library {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001785 name: "libjni",
Peter Collingbournead84f972019-12-17 16:46:18 -08001786 sdk_version: "current",
1787 stl: "c++_shared",
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001788 }
1789
1790 android_test {
1791 name: "stl",
1792 jni_libs: ["libjni"],
1793 compile_multilib: "both",
1794 sdk_version: "current",
1795 stl: "c++_shared",
1796 }
1797
1798 android_test {
1799 name: "system",
1800 jni_libs: ["libjni"],
1801 compile_multilib: "both",
1802 sdk_version: "current",
1803 }
Jaewoong Jung710756a2019-06-04 11:53:47 -07001804
1805 ndk_prebuilt_shared_stl {
1806 name: "ndk_libc++_shared",
1807 }
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001808 `)
1809
1810 testCases := []struct {
1811 name string
1812 jnis []string
1813 }{
1814 {"stl",
1815 []string{
1816 "libjni.so",
Jaewoong Jung710756a2019-06-04 11:53:47 -07001817 "libc++_shared.so",
Jaewoong Jungbc625cd2019-05-06 15:48:44 -07001818 },
1819 },
1820 {"system",
1821 []string{
1822 "libjni.so",
1823 },
1824 },
1825 }
1826
1827 for _, test := range testCases {
1828 t.Run(test.name, func(t *testing.T) {
1829 app := ctx.ModuleForTests(test.name, "android_common")
1830 jniLibZip := app.Output("jnilibs.zip")
1831 var jnis []string
1832 args := strings.Fields(jniLibZip.Args["jarArgs"])
1833 for i := 0; i < len(args); i++ {
1834 if args[i] == "-f" {
1835 jnis = append(jnis, args[i+1])
1836 i += 1
1837 }
1838 }
1839 jnisJoined := strings.Join(jnis, " ")
1840 for _, jni := range test.jnis {
1841 if !strings.Contains(jnisJoined, jni) {
1842 t.Errorf("missing jni %q in %q", jni, jnis)
1843 }
1844 }
1845 })
1846 }
1847}
Colin Cross50ddcc42019-05-16 12:28:22 -07001848
1849func TestUsesLibraries(t *testing.T) {
1850 bp := `
1851 java_sdk_library {
1852 name: "foo",
1853 srcs: ["a.java"],
1854 api_packages: ["foo"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001855 sdk_version: "current",
Colin Cross50ddcc42019-05-16 12:28:22 -07001856 }
1857
1858 java_sdk_library {
1859 name: "bar",
1860 srcs: ["a.java"],
1861 api_packages: ["bar"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001862 sdk_version: "current",
Colin Cross50ddcc42019-05-16 12:28:22 -07001863 }
1864
1865 android_app {
1866 name: "app",
1867 srcs: ["a.java"],
1868 uses_libs: ["foo"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001869 sdk_version: "current",
Colin Cross50ddcc42019-05-16 12:28:22 -07001870 optional_uses_libs: [
1871 "bar",
1872 "baz",
1873 ],
1874 }
1875
1876 android_app_import {
1877 name: "prebuilt",
1878 apk: "prebuilts/apk/app.apk",
1879 certificate: "platform",
1880 uses_libs: ["foo"],
1881 optional_uses_libs: [
1882 "bar",
1883 "baz",
1884 ],
1885 }
1886 `
1887
Colin Cross98be1bb2019-12-13 20:41:13 -08001888 config := testAppConfig(nil, bp, nil)
Colin Cross50ddcc42019-05-16 12:28:22 -07001889 config.TestProductVariables.MissingUsesLibraries = []string{"baz"}
1890
Colin Cross98be1bb2019-12-13 20:41:13 -08001891 ctx := testContext()
Colin Cross50ddcc42019-05-16 12:28:22 -07001892
1893 run(t, ctx, config)
1894
1895 app := ctx.ModuleForTests("app", "android_common")
1896 prebuilt := ctx.ModuleForTests("prebuilt", "android_common")
1897
1898 // Test that all libraries are verified
1899 cmd := app.Rule("verify_uses_libraries").RuleParams.Command
1900 if w := "--uses-library foo"; !strings.Contains(cmd, w) {
1901 t.Errorf("wanted %q in %q", w, cmd)
1902 }
1903
1904 if w := "--optional-uses-library bar --optional-uses-library baz"; !strings.Contains(cmd, w) {
1905 t.Errorf("wanted %q in %q", w, cmd)
1906 }
1907
1908 cmd = prebuilt.Rule("verify_uses_libraries").RuleParams.Command
1909
1910 if w := `uses_library_names="foo"`; !strings.Contains(cmd, w) {
1911 t.Errorf("wanted %q in %q", w, cmd)
1912 }
1913
1914 if w := `optional_uses_library_names="bar baz"`; !strings.Contains(cmd, w) {
1915 t.Errorf("wanted %q in %q", w, cmd)
1916 }
1917
1918 // Test that only present libraries are preopted
1919 cmd = app.Rule("dexpreopt").RuleParams.Command
1920
1921 if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) {
1922 t.Errorf("wanted %q in %q", w, cmd)
1923 }
1924
1925 cmd = prebuilt.Rule("dexpreopt").RuleParams.Command
1926
1927 if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) {
1928 t.Errorf("wanted %q in %q", w, cmd)
1929 }
1930}
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001931
1932func TestCodelessApp(t *testing.T) {
1933 testCases := []struct {
1934 name string
1935 bp string
1936 noCode bool
1937 }{
1938 {
1939 name: "normal",
1940 bp: `
1941 android_app {
1942 name: "foo",
1943 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001944 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001945 }
1946 `,
1947 noCode: false,
1948 },
1949 {
1950 name: "app without sources",
1951 bp: `
1952 android_app {
1953 name: "foo",
Jeongik Cha538c0d02019-07-11 15:54:27 +09001954 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001955 }
1956 `,
1957 noCode: true,
1958 },
1959 {
1960 name: "app with libraries",
1961 bp: `
1962 android_app {
1963 name: "foo",
1964 static_libs: ["lib"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001965 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001966 }
1967
1968 java_library {
1969 name: "lib",
1970 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001971 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001972 }
1973 `,
1974 noCode: false,
1975 },
1976 {
1977 name: "app with sourceless libraries",
1978 bp: `
1979 android_app {
1980 name: "foo",
1981 static_libs: ["lib"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09001982 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001983 }
1984
1985 java_library {
1986 name: "lib",
Jeongik Cha538c0d02019-07-11 15:54:27 +09001987 sdk_version: "current",
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001988 }
1989 `,
1990 // TODO(jungjw): this should probably be true
1991 noCode: false,
1992 },
1993 }
1994
1995 for _, test := range testCases {
1996 t.Run(test.name, func(t *testing.T) {
1997 ctx := testApp(t, test.bp)
1998
1999 foo := ctx.ModuleForTests("foo", "android_common")
2000 manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
2001 if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode {
2002 t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs)
2003 }
2004 })
2005 }
2006}
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002007
2008func TestEmbedNotice(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -07002009 ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002010 android_app {
2011 name: "foo",
2012 srcs: ["a.java"],
2013 static_libs: ["javalib"],
2014 jni_libs: ["libjni"],
2015 notice: "APP_NOTICE",
2016 embed_notices: true,
Jeongik Cha538c0d02019-07-11 15:54:27 +09002017 sdk_version: "current",
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002018 }
2019
2020 // No embed_notice flag
2021 android_app {
2022 name: "bar",
2023 srcs: ["a.java"],
2024 jni_libs: ["libjni"],
2025 notice: "APP_NOTICE",
Jeongik Cha538c0d02019-07-11 15:54:27 +09002026 sdk_version: "current",
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002027 }
2028
2029 // No NOTICE files
2030 android_app {
2031 name: "baz",
2032 srcs: ["a.java"],
2033 embed_notices: true,
Jeongik Cha538c0d02019-07-11 15:54:27 +09002034 sdk_version: "current",
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002035 }
2036
2037 cc_library {
2038 name: "libjni",
2039 system_shared_libs: [],
2040 stl: "none",
2041 notice: "LIB_NOTICE",
2042 }
2043
2044 java_library {
2045 name: "javalib",
2046 srcs: [
2047 ":gen",
2048 ],
Jeongik Cha538c0d02019-07-11 15:54:27 +09002049 sdk_version: "current",
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002050 }
2051
2052 genrule {
2053 name: "gen",
2054 tools: ["gentool"],
2055 out: ["gen.java"],
2056 notice: "GENRULE_NOTICE",
2057 }
2058
2059 java_binary_host {
2060 name: "gentool",
2061 srcs: ["b.java"],
2062 notice: "TOOL_NOTICE",
2063 }
2064 `)
2065
2066 // foo has NOTICE files to process, and embed_notices is true.
2067 foo := ctx.ModuleForTests("foo", "android_common")
2068 // verify merge notices rule.
2069 mergeNotices := foo.Rule("mergeNoticesRule")
2070 noticeInputs := mergeNotices.Inputs.Strings()
2071 // TOOL_NOTICE should be excluded as it's a host module.
2072 if len(mergeNotices.Inputs) != 3 {
2073 t.Errorf("number of input notice files: expected = 3, actual = %q", noticeInputs)
2074 }
2075 if !inList("APP_NOTICE", noticeInputs) {
2076 t.Errorf("APP_NOTICE is missing from notice files, %q", noticeInputs)
2077 }
2078 if !inList("LIB_NOTICE", noticeInputs) {
2079 t.Errorf("LIB_NOTICE is missing from notice files, %q", noticeInputs)
2080 }
2081 if !inList("GENRULE_NOTICE", noticeInputs) {
2082 t.Errorf("GENRULE_NOTICE is missing from notice files, %q", noticeInputs)
2083 }
2084 // aapt2 flags should include -A <NOTICE dir> so that its contents are put in the APK's /assets.
2085 res := foo.Output("package-res.apk")
2086 aapt2Flags := res.Args["flags"]
2087 e := "-A " + buildDir + "/.intermediates/foo/android_common/NOTICE"
2088 if !strings.Contains(aapt2Flags, e) {
2089 t.Errorf("asset dir flag for NOTICE, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
2090 }
2091
2092 // bar has NOTICE files to process, but embed_notices is not set.
2093 bar := ctx.ModuleForTests("bar", "android_common")
Jaewoong Jung98772792019-07-01 17:15:13 -07002094 res = bar.Output("package-res.apk")
2095 aapt2Flags = res.Args["flags"]
2096 e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE"
2097 if strings.Contains(aapt2Flags, e) {
2098 t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e)
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002099 }
2100
2101 // baz's embed_notice is true, but it doesn't have any NOTICE files.
2102 baz := ctx.ModuleForTests("baz", "android_common")
Jaewoong Jung98772792019-07-01 17:15:13 -07002103 res = baz.Output("package-res.apk")
2104 aapt2Flags = res.Args["flags"]
2105 e = "-A " + buildDir + "/.intermediates/baz/android_common/NOTICE"
2106 if strings.Contains(aapt2Flags, e) {
2107 t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e)
Jaewoong Jung5b425e22019-06-17 17:40:56 -07002108 }
2109}
Colin Cross53a87f52019-06-25 13:35:30 -07002110
2111func TestUncompressDex(t *testing.T) {
2112 testCases := []struct {
2113 name string
2114 bp string
2115
2116 uncompressedPlatform bool
2117 uncompressedUnbundled bool
2118 }{
2119 {
2120 name: "normal",
2121 bp: `
2122 android_app {
2123 name: "foo",
2124 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09002125 sdk_version: "current",
Colin Cross53a87f52019-06-25 13:35:30 -07002126 }
2127 `,
2128 uncompressedPlatform: true,
2129 uncompressedUnbundled: false,
2130 },
2131 {
2132 name: "use_embedded_dex",
2133 bp: `
2134 android_app {
2135 name: "foo",
2136 use_embedded_dex: true,
2137 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09002138 sdk_version: "current",
Colin Cross53a87f52019-06-25 13:35:30 -07002139 }
2140 `,
2141 uncompressedPlatform: true,
2142 uncompressedUnbundled: true,
2143 },
2144 {
2145 name: "privileged",
2146 bp: `
2147 android_app {
2148 name: "foo",
2149 privileged: true,
2150 srcs: ["a.java"],
Jeongik Cha538c0d02019-07-11 15:54:27 +09002151 sdk_version: "current",
Colin Cross53a87f52019-06-25 13:35:30 -07002152 }
2153 `,
2154 uncompressedPlatform: true,
2155 uncompressedUnbundled: true,
2156 },
2157 }
2158
2159 test := func(t *testing.T, bp string, want bool, unbundled bool) {
2160 t.Helper()
2161
Colin Cross98be1bb2019-12-13 20:41:13 -08002162 config := testAppConfig(nil, bp, nil)
Colin Cross53a87f52019-06-25 13:35:30 -07002163 if unbundled {
2164 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
2165 }
2166
Colin Cross98be1bb2019-12-13 20:41:13 -08002167 ctx := testContext()
Colin Cross53a87f52019-06-25 13:35:30 -07002168
2169 run(t, ctx, config)
2170
2171 foo := ctx.ModuleForTests("foo", "android_common")
2172 dex := foo.Rule("r8")
2173 uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0")
2174 aligned := foo.MaybeRule("zipalign").Rule != nil
2175
2176 if uncompressedInDexJar != want {
2177 t.Errorf("want uncompressed in dex %v, got %v", want, uncompressedInDexJar)
2178 }
2179
2180 if aligned != want {
2181 t.Errorf("want aligned %v, got %v", want, aligned)
2182 }
2183 }
2184
2185 for _, tt := range testCases {
2186 t.Run(tt.name, func(t *testing.T) {
2187 t.Run("platform", func(t *testing.T) {
2188 test(t, tt.bp, tt.uncompressedPlatform, false)
2189 })
2190 t.Run("unbundled", func(t *testing.T) {
2191 test(t, tt.bp, tt.uncompressedUnbundled, true)
2192 })
2193 })
2194 }
2195}
Jaewoong Jung26dedd32019-06-06 08:45:58 -07002196
2197func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string) {
2198 if expectedValue != "" {
2199 expectedFlag := "--" + flagName + " " + expectedValue
2200 if !strings.Contains(aapt2Flags, expectedFlag) {
2201 t.Errorf("%q is missing in aapt2 link flags, %q", expectedFlag, aapt2Flags)
2202 }
2203 } else {
2204 unexpectedFlag := "--" + flagName
2205 if strings.Contains(aapt2Flags, unexpectedFlag) {
2206 t.Errorf("unexpected flag, %q is found in aapt2 link flags, %q", unexpectedFlag, aapt2Flags)
2207 }
2208 }
2209}
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08002210
2211func TestRuntimeResourceOverlay(t *testing.T) {
2212 ctx, config := testJava(t, `
2213 runtime_resource_overlay {
2214 name: "foo",
2215 certificate: "platform",
2216 product_specific: true,
Jaewoong Jungf0f747c2020-01-24 10:30:02 -08002217 aaptflags: ["--keep-raw-values"],
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08002218 }
2219
2220 runtime_resource_overlay {
2221 name: "foo_themed",
2222 certificate: "platform",
2223 product_specific: true,
2224 theme: "faza",
2225 }
2226 `)
2227
2228 m := ctx.ModuleForTests("foo", "android_common")
2229
Jaewoong Jungf0f747c2020-01-24 10:30:02 -08002230 // Check AAPT2 link flags.
2231 aapt2Flags := m.Output("package-res.apk").Args["flags"]
2232 expectedFlags := []string{"--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"}
2233 absentFlags := android.RemoveListFromList(expectedFlags, strings.Split(aapt2Flags, " "))
2234 if len(absentFlags) > 0 {
2235 t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags)
2236 }
2237
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08002238 // Check cert signing flag.
2239 signedApk := m.Output("signed/foo.apk")
2240 signingFlag := signedApk.Args["certificates"]
2241 expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8"
2242 if expected != signingFlag {
2243 t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
2244 }
2245
2246 // Check device location.
2247 path := android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
2248 expectedPath := []string{"/tmp/target/product/test_device/product/overlay"}
2249 if !reflect.DeepEqual(path, expectedPath) {
2250 t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
2251 }
2252
2253 // A themed module has a different device location
2254 m = ctx.ModuleForTests("foo_themed", "android_common")
2255 path = android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
2256 expectedPath = []string{"/tmp/target/product/test_device/product/overlay/faza"}
2257 if !reflect.DeepEqual(path, expectedPath) {
2258 t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
2259 }
2260}