| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 18 | "fmt" | 
| Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 19 | "path/filepath" | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 20 | "reflect" | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 21 | "regexp" | 
| Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 22 | "sort" | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 23 | "strings" | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 24 | "testing" | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | "github.com/google/blueprint/proptools" | 
|  | 27 |  | 
|  | 28 | "android/soong/android" | 
|  | 29 | "android/soong/cc" | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 30 | ) | 
|  | 31 |  | 
|  | 32 | var ( | 
|  | 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 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 46 | func testAppContext(bp string, fs map[string][]byte) *android.TestContext { | 
| Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 47 | appFS := map[string][]byte{} | 
|  | 48 | for k, v := range fs { | 
|  | 49 | appFS[k] = v | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 50 | } | 
|  | 51 |  | 
| Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 52 | for _, file := range resourceFiles { | 
|  | 53 | appFS[file] = nil | 
|  | 54 | } | 
|  | 55 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 56 | return testContext(bp, appFS) | 
| Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | func testApp(t *testing.T, bp string) *android.TestContext { | 
|  | 60 | config := testConfig(nil) | 
|  | 61 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 62 | ctx := testAppContext(bp, nil) | 
| Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 63 |  | 
|  | 64 | run(t, ctx, config) | 
|  | 65 |  | 
|  | 66 | return ctx | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 67 | } | 
|  | 68 |  | 
|  | 69 | func TestApp(t *testing.T) { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 70 | 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 Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 75 | sdk_version: "current" | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 76 | } | 
|  | 77 | `) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 78 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 79 | foo := ctx.ModuleForTests("foo", "android_common") | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 80 |  | 
| Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 81 | var expectedLinkImplicits []string | 
|  | 82 |  | 
|  | 83 | manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml") | 
|  | 84 | expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String()) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 85 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 86 | frameworkRes := ctx.ModuleForTests("framework-res", "android_common") | 
|  | 87 | expectedLinkImplicits = append(expectedLinkImplicits, | 
|  | 88 | frameworkRes.Output("package-res.apk").Output.String()) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 89 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 90 | // 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 Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 96 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 97 | compiledResourceOutputs := compile.Outputs.Strings() | 
|  | 98 | sort.Strings(compiledResourceOutputs) | 
| Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 99 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 100 | expectedLinkImplicits = append(expectedLinkImplicits, compiledResourceOutputs...) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 101 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 102 | list := foo.Output("aapt2/res.list") | 
|  | 103 | expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 104 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 105 | // 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 Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 112 | } | 
|  | 113 | } | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 114 |  | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 115 | func 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 Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 121 | sdk_version: "current" | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 122 | }`) | 
|  | 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 Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 135 | 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 Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 141 | } | 
|  | 142 | } | 
|  | 143 |  | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 144 | func 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 |  | 
| Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 178 | func TestResourceDirs(t *testing.T) { | 
|  | 179 | testCases := []struct { | 
|  | 180 | name      string | 
|  | 181 | prop      string | 
|  | 182 | resources []string | 
|  | 183 | }{ | 
|  | 184 | { | 
|  | 185 | name:      "no resource_dirs", | 
|  | 186 | prop:      "", | 
|  | 187 | resources: []string{"res/res/values/strings.xml"}, | 
|  | 188 | }, | 
|  | 189 | { | 
|  | 190 | name:      "resource_dirs", | 
|  | 191 | prop:      `resource_dirs: ["res"]`, | 
|  | 192 | resources: []string{"res/res/values/strings.xml"}, | 
|  | 193 | }, | 
|  | 194 | { | 
|  | 195 | name:      "empty resource_dirs", | 
|  | 196 | prop:      `resource_dirs: []`, | 
|  | 197 | resources: nil, | 
|  | 198 | }, | 
|  | 199 | } | 
|  | 200 |  | 
|  | 201 | fs := map[string][]byte{ | 
|  | 202 | "res/res/values/strings.xml": nil, | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | bp := ` | 
|  | 206 | android_app { | 
|  | 207 | name: "foo", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 208 | sdk_version: "current", | 
| Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 209 | %s | 
|  | 210 | } | 
|  | 211 | ` | 
|  | 212 |  | 
|  | 213 | for _, testCase := range testCases { | 
|  | 214 | t.Run(testCase.name, func(t *testing.T) { | 
|  | 215 | config := testConfig(nil) | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 216 | ctx := testContext(fmt.Sprintf(bp, testCase.prop), fs) | 
| Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 217 | run(t, ctx, config) | 
|  | 218 |  | 
|  | 219 | module := ctx.ModuleForTests("foo", "android_common") | 
|  | 220 | resourceList := module.MaybeOutput("aapt2/res.list") | 
|  | 221 |  | 
|  | 222 | var resources []string | 
|  | 223 | if resourceList.Rule != nil { | 
|  | 224 | for _, compiledResource := range resourceList.Inputs.Strings() { | 
|  | 225 | resources = append(resources, module.Output(compiledResource).Inputs.Strings()...) | 
|  | 226 | } | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | if !reflect.DeepEqual(resources, testCase.resources) { | 
|  | 230 | t.Errorf("expected resource files %q, got %q", | 
|  | 231 | testCase.resources, resources) | 
|  | 232 | } | 
|  | 233 | }) | 
|  | 234 | } | 
|  | 235 | } | 
|  | 236 |  | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 237 | func TestAndroidResources(t *testing.T) { | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 238 | testCases := []struct { | 
|  | 239 | name                       string | 
|  | 240 | enforceRROTargets          []string | 
|  | 241 | enforceRROExcludedOverlays []string | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 242 | resourceFiles              map[string][]string | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 243 | overlayFiles               map[string][]string | 
|  | 244 | rroDirs                    map[string][]string | 
|  | 245 | }{ | 
|  | 246 | { | 
|  | 247 | name:                       "no RRO", | 
|  | 248 | enforceRROTargets:          nil, | 
|  | 249 | enforceRROExcludedOverlays: nil, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 250 | resourceFiles: map[string][]string{ | 
|  | 251 | "foo":  nil, | 
|  | 252 | "bar":  {"bar/res/res/values/strings.xml"}, | 
|  | 253 | "lib":  nil, | 
|  | 254 | "lib2": {"lib2/res/res/values/strings.xml"}, | 
|  | 255 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 256 | overlayFiles: map[string][]string{ | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 257 | "foo": { | 
|  | 258 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 259 | buildDir + "/.intermediates/lib/android_common/package-res.apk", | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 260 | buildDir + "/.intermediates/lib3/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 261 | "foo/res/res/values/strings.xml", | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 262 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", | 
|  | 263 | "device/vendor/blah/overlay/foo/res/values/strings.xml", | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 264 | "product/vendor/blah/overlay/foo/res/values/strings.xml", | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 265 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 266 | "bar": { | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 267 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", | 
|  | 268 | "device/vendor/blah/overlay/bar/res/values/strings.xml", | 
|  | 269 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 270 | "lib": { | 
|  | 271 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
|  | 272 | "lib/res/res/values/strings.xml", | 
|  | 273 | "device/vendor/blah/overlay/lib/res/values/strings.xml", | 
|  | 274 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 275 | }, | 
|  | 276 | rroDirs: map[string][]string{ | 
|  | 277 | "foo": nil, | 
|  | 278 | "bar": nil, | 
|  | 279 | }, | 
|  | 280 | }, | 
|  | 281 | { | 
|  | 282 | name:                       "enforce RRO on foo", | 
|  | 283 | enforceRROTargets:          []string{"foo"}, | 
|  | 284 | enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"}, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 285 | resourceFiles: map[string][]string{ | 
|  | 286 | "foo":  nil, | 
|  | 287 | "bar":  {"bar/res/res/values/strings.xml"}, | 
|  | 288 | "lib":  nil, | 
|  | 289 | "lib2": {"lib2/res/res/values/strings.xml"}, | 
|  | 290 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 291 | overlayFiles: map[string][]string{ | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 292 | "foo": { | 
|  | 293 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 294 | buildDir + "/.intermediates/lib/android_common/package-res.apk", | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 295 | buildDir + "/.intermediates/lib3/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 296 | "foo/res/res/values/strings.xml", | 
|  | 297 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", | 
|  | 298 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 299 | "bar": { | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 300 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", | 
|  | 301 | "device/vendor/blah/overlay/bar/res/values/strings.xml", | 
|  | 302 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 303 | "lib": { | 
|  | 304 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
|  | 305 | "lib/res/res/values/strings.xml", | 
|  | 306 | "device/vendor/blah/overlay/lib/res/values/strings.xml", | 
|  | 307 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 308 | }, | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 309 |  | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 310 | rroDirs: map[string][]string{ | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 311 | "foo": { | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 312 | "device:device/vendor/blah/overlay/foo/res", | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 313 | // Enforce RRO on "foo" could imply RRO on static dependencies, but for now it doesn't. | 
|  | 314 | // "device/vendor/blah/overlay/lib/res", | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 315 | "product:product/vendor/blah/overlay/foo/res", | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 316 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 317 | "bar": nil, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 318 | "lib": nil, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 319 | }, | 
|  | 320 | }, | 
|  | 321 | { | 
|  | 322 | name:              "enforce RRO on all", | 
|  | 323 | enforceRROTargets: []string{"*"}, | 
|  | 324 | enforceRROExcludedOverlays: []string{ | 
|  | 325 | // Excluding specific apps/res directories also allowed. | 
|  | 326 | "device/vendor/blah/static_overlay/foo", | 
|  | 327 | "device/vendor/blah/static_overlay/bar/res", | 
|  | 328 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 329 | resourceFiles: map[string][]string{ | 
|  | 330 | "foo":  nil, | 
|  | 331 | "bar":  {"bar/res/res/values/strings.xml"}, | 
|  | 332 | "lib":  nil, | 
|  | 333 | "lib2": {"lib2/res/res/values/strings.xml"}, | 
|  | 334 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 335 | overlayFiles: map[string][]string{ | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 336 | "foo": { | 
|  | 337 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 338 | buildDir + "/.intermediates/lib/android_common/package-res.apk", | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 339 | buildDir + "/.intermediates/lib3/android_common/package-res.apk", | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 340 | "foo/res/res/values/strings.xml", | 
|  | 341 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", | 
|  | 342 | }, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 343 | "bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"}, | 
|  | 344 | "lib": { | 
|  | 345 | buildDir + "/.intermediates/lib2/android_common/package-res.apk", | 
|  | 346 | "lib/res/res/values/strings.xml", | 
|  | 347 | }, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 348 | }, | 
|  | 349 | rroDirs: map[string][]string{ | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 350 | "foo": { | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 351 | "device:device/vendor/blah/overlay/foo/res", | 
|  | 352 | "product:product/vendor/blah/overlay/foo/res", | 
|  | 353 | // Lib dep comes after the direct deps | 
|  | 354 | "device:device/vendor/blah/overlay/lib/res", | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 355 | }, | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 356 | "bar": {"device:device/vendor/blah/overlay/bar/res"}, | 
|  | 357 | "lib": {"device:device/vendor/blah/overlay/lib/res"}, | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 358 | }, | 
|  | 359 | }, | 
|  | 360 | } | 
|  | 361 |  | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 362 | deviceResourceOverlays := []string{ | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 363 | "device/vendor/blah/overlay", | 
|  | 364 | "device/vendor/blah/overlay2", | 
|  | 365 | "device/vendor/blah/static_overlay", | 
|  | 366 | } | 
|  | 367 |  | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 368 | productResourceOverlays := []string{ | 
|  | 369 | "product/vendor/blah/overlay", | 
|  | 370 | } | 
|  | 371 |  | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 372 | fs := map[string][]byte{ | 
|  | 373 | "foo/res/res/values/strings.xml":                               nil, | 
|  | 374 | "bar/res/res/values/strings.xml":                               nil, | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 375 | "lib/res/res/values/strings.xml":                               nil, | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 376 | "lib2/res/res/values/strings.xml":                              nil, | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 377 | "device/vendor/blah/overlay/foo/res/values/strings.xml":        nil, | 
|  | 378 | "device/vendor/blah/overlay/bar/res/values/strings.xml":        nil, | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 379 | "device/vendor/blah/overlay/lib/res/values/strings.xml":        nil, | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 380 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil, | 
|  | 381 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil, | 
|  | 382 | "device/vendor/blah/overlay2/res/values/strings.xml":           nil, | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 383 | "product/vendor/blah/overlay/foo/res/values/strings.xml":       nil, | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 384 | } | 
|  | 385 |  | 
|  | 386 | bp := ` | 
|  | 387 | android_app { | 
|  | 388 | name: "foo", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 389 | sdk_version: "current", | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 390 | resource_dirs: ["foo/res"], | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 391 | static_libs: ["lib", "lib3"], | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 392 | } | 
|  | 393 |  | 
|  | 394 | android_app { | 
|  | 395 | name: "bar", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 396 | sdk_version: "current", | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 397 | resource_dirs: ["bar/res"], | 
|  | 398 | } | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 399 |  | 
|  | 400 | android_library { | 
|  | 401 | name: "lib", | 
|  | 402 | resource_dirs: ["lib/res"], | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 403 | static_libs: ["lib2"], | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | android_library { | 
|  | 407 | name: "lib2", | 
|  | 408 | resource_dirs: ["lib2/res"], | 
| Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 409 | } | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 410 |  | 
|  | 411 | // This library has the same resources as lib (should not lead to dupe RROs) | 
|  | 412 | android_library { | 
|  | 413 | name: "lib3", | 
|  | 414 | resource_dirs: ["lib/res"] | 
|  | 415 | } | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 416 | ` | 
|  | 417 |  | 
| Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 418 | for _, testCase := range testCases { | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 419 | t.Run(testCase.name, func(t *testing.T) { | 
|  | 420 | config := testConfig(nil) | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 421 | config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays | 
|  | 422 | config.TestProductVariables.ProductResourceOverlays = productResourceOverlays | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 423 | if testCase.enforceRROTargets != nil { | 
| Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 424 | config.TestProductVariables.EnforceRROTargets = testCase.enforceRROTargets | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 425 | } | 
|  | 426 | if testCase.enforceRROExcludedOverlays != nil { | 
| Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 427 | config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 428 | } | 
|  | 429 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 430 | ctx := testAppContext(bp, fs) | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 431 | run(t, ctx, config) | 
|  | 432 |  | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 433 | resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { | 
|  | 434 | for _, o := range list { | 
|  | 435 | res := module.MaybeOutput(o) | 
|  | 436 | if res.Rule != nil { | 
|  | 437 | // If the overlay is compiled as part of this module (i.e. a .arsc.flat file), | 
|  | 438 | // verify the inputs to the .arsc.flat rule. | 
|  | 439 | files = append(files, res.Inputs.Strings()...) | 
|  | 440 | } else { | 
|  | 441 | // Otherwise, verify the full path to the output of the other module | 
|  | 442 | files = append(files, o) | 
| Anton Hansson | 94c93f3 | 2019-01-30 16:03:37 +0000 | [diff] [blame] | 443 | } | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 444 | } | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 445 | return files | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 446 | } | 
|  | 447 |  | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 448 | getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) { | 
|  | 449 | module := ctx.ModuleForTests(moduleName, "android_common") | 
|  | 450 | resourceList := module.MaybeOutput("aapt2/res.list") | 
|  | 451 | if resourceList.Rule != nil { | 
|  | 452 | resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings()) | 
| Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 453 | } | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 454 | overlayList := module.MaybeOutput("aapt2/overlay.list") | 
|  | 455 | if overlayList.Rule != nil { | 
|  | 456 | overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings()) | 
|  | 457 | } | 
|  | 458 |  | 
| Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 459 | for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() { | 
|  | 460 | var prefix string | 
|  | 461 | if d.overlayType == device { | 
|  | 462 | prefix = "device:" | 
|  | 463 | } else if d.overlayType == product { | 
|  | 464 | prefix = "product:" | 
|  | 465 | } else { | 
|  | 466 | t.Fatalf("Unexpected overlayType %d", d.overlayType) | 
|  | 467 | } | 
|  | 468 | rroDirs = append(rroDirs, prefix+d.path.String()) | 
|  | 469 | } | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 470 |  | 
|  | 471 | return resourceFiles, overlayFiles, rroDirs | 
|  | 472 | } | 
|  | 473 |  | 
|  | 474 | modules := []string{"foo", "bar", "lib", "lib2"} | 
|  | 475 | for _, module := range modules { | 
|  | 476 | resourceFiles, overlayFiles, rroDirs := getResources(module) | 
|  | 477 |  | 
|  | 478 | if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) { | 
|  | 479 | t.Errorf("expected %s resource files:\n  %#v\n got:\n  %#v", | 
|  | 480 | module, testCase.resourceFiles[module], resourceFiles) | 
|  | 481 | } | 
|  | 482 | if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) { | 
|  | 483 | t.Errorf("expected %s overlay files:\n  %#v\n got:\n  %#v", | 
|  | 484 | module, testCase.overlayFiles[module], overlayFiles) | 
|  | 485 | } | 
|  | 486 | if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) { | 
| Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 487 | t.Errorf("expected %s rroDirs:  %#v\n got:\n  %#v", | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 488 | module, testCase.rroDirs[module], rroDirs) | 
| Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 489 | } | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 490 | } | 
| Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 491 | }) | 
|  | 492 | } | 
|  | 493 | } | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 494 |  | 
|  | 495 | func TestAppSdkVersion(t *testing.T) { | 
|  | 496 | testCases := []struct { | 
|  | 497 | name                  string | 
|  | 498 | sdkVersion            string | 
|  | 499 | platformSdkInt        int | 
|  | 500 | platformSdkCodename   string | 
|  | 501 | platformSdkFinal      bool | 
|  | 502 | expectedMinSdkVersion string | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 503 | platformApis          bool | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 504 | }{ | 
|  | 505 | { | 
|  | 506 | name:                  "current final SDK", | 
|  | 507 | sdkVersion:            "current", | 
|  | 508 | platformSdkInt:        27, | 
|  | 509 | platformSdkCodename:   "REL", | 
|  | 510 | platformSdkFinal:      true, | 
|  | 511 | expectedMinSdkVersion: "27", | 
|  | 512 | }, | 
|  | 513 | { | 
|  | 514 | name:                  "current non-final SDK", | 
|  | 515 | sdkVersion:            "current", | 
|  | 516 | platformSdkInt:        27, | 
|  | 517 | platformSdkCodename:   "OMR1", | 
|  | 518 | platformSdkFinal:      false, | 
|  | 519 | expectedMinSdkVersion: "OMR1", | 
|  | 520 | }, | 
|  | 521 | { | 
|  | 522 | name:                  "default final SDK", | 
|  | 523 | sdkVersion:            "", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 524 | platformApis:          true, | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 525 | platformSdkInt:        27, | 
|  | 526 | platformSdkCodename:   "REL", | 
|  | 527 | platformSdkFinal:      true, | 
|  | 528 | expectedMinSdkVersion: "27", | 
|  | 529 | }, | 
|  | 530 | { | 
|  | 531 | name:                  "default non-final SDK", | 
|  | 532 | sdkVersion:            "", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 533 | platformApis:          true, | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 534 | platformSdkInt:        27, | 
|  | 535 | platformSdkCodename:   "OMR1", | 
|  | 536 | platformSdkFinal:      false, | 
|  | 537 | expectedMinSdkVersion: "OMR1", | 
|  | 538 | }, | 
|  | 539 | { | 
|  | 540 | name:                  "14", | 
|  | 541 | sdkVersion:            "14", | 
|  | 542 | expectedMinSdkVersion: "14", | 
|  | 543 | }, | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 | for _, moduleType := range []string{"android_app", "android_library"} { | 
|  | 547 | for _, test := range testCases { | 
|  | 548 | t.Run(moduleType+" "+test.name, func(t *testing.T) { | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 549 | platformApiProp := "" | 
|  | 550 | if test.platformApis { | 
|  | 551 | platformApiProp = "platform_apis: true," | 
|  | 552 | } | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 553 | bp := fmt.Sprintf(`%s { | 
|  | 554 | name: "foo", | 
|  | 555 | srcs: ["a.java"], | 
|  | 556 | sdk_version: "%s", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 557 | %s | 
|  | 558 | }`, moduleType, test.sdkVersion, platformApiProp) | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 559 |  | 
|  | 560 | config := testConfig(nil) | 
|  | 561 | config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt | 
|  | 562 | config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename | 
|  | 563 | config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal | 
|  | 564 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 565 | ctx := testAppContext(bp, nil) | 
| Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 566 |  | 
|  | 567 | run(t, ctx, config) | 
|  | 568 |  | 
|  | 569 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 570 | link := foo.Output("package-res.apk") | 
|  | 571 | linkFlags := strings.Split(link.Args["flags"], " ") | 
|  | 572 | min := android.IndexList("--min-sdk-version", linkFlags) | 
|  | 573 | target := android.IndexList("--target-sdk-version", linkFlags) | 
|  | 574 |  | 
|  | 575 | if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 { | 
|  | 576 | t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags) | 
|  | 577 | } | 
|  | 578 |  | 
|  | 579 | gotMinSdkVersion := linkFlags[min+1] | 
|  | 580 | gotTargetSdkVersion := linkFlags[target+1] | 
|  | 581 |  | 
|  | 582 | if gotMinSdkVersion != test.expectedMinSdkVersion { | 
|  | 583 | t.Errorf("incorrect --min-sdk-version, expected %q got %q", | 
|  | 584 | test.expectedMinSdkVersion, gotMinSdkVersion) | 
|  | 585 | } | 
|  | 586 |  | 
|  | 587 | if gotTargetSdkVersion != test.expectedMinSdkVersion { | 
|  | 588 | t.Errorf("incorrect --target-sdk-version, expected %q got %q", | 
|  | 589 | test.expectedMinSdkVersion, gotTargetSdkVersion) | 
|  | 590 | } | 
|  | 591 | }) | 
|  | 592 | } | 
|  | 593 | } | 
|  | 594 | } | 
| Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 595 |  | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 596 | func TestJNIABI(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 597 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 598 | cc_library { | 
|  | 599 | name: "libjni", | 
|  | 600 | system_shared_libs: [], | 
|  | 601 | stl: "none", | 
|  | 602 | } | 
|  | 603 |  | 
|  | 604 | android_test { | 
|  | 605 | name: "test", | 
|  | 606 | sdk_version: "core_platform", | 
|  | 607 | jni_libs: ["libjni"], | 
|  | 608 | } | 
|  | 609 |  | 
|  | 610 | android_test { | 
|  | 611 | name: "test_first", | 
|  | 612 | sdk_version: "core_platform", | 
|  | 613 | compile_multilib: "first", | 
|  | 614 | jni_libs: ["libjni"], | 
|  | 615 | } | 
|  | 616 |  | 
|  | 617 | android_test { | 
|  | 618 | name: "test_both", | 
|  | 619 | sdk_version: "core_platform", | 
|  | 620 | compile_multilib: "both", | 
|  | 621 | jni_libs: ["libjni"], | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | android_test { | 
|  | 625 | name: "test_32", | 
|  | 626 | sdk_version: "core_platform", | 
|  | 627 | compile_multilib: "32", | 
|  | 628 | jni_libs: ["libjni"], | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | android_test { | 
|  | 632 | name: "test_64", | 
|  | 633 | sdk_version: "core_platform", | 
|  | 634 | compile_multilib: "64", | 
|  | 635 | jni_libs: ["libjni"], | 
|  | 636 | } | 
|  | 637 | `) | 
|  | 638 |  | 
|  | 639 | testCases := []struct { | 
|  | 640 | name string | 
|  | 641 | abis []string | 
|  | 642 | }{ | 
|  | 643 | {"test", []string{"arm64-v8a"}}, | 
|  | 644 | {"test_first", []string{"arm64-v8a"}}, | 
|  | 645 | {"test_both", []string{"arm64-v8a", "armeabi-v7a"}}, | 
|  | 646 | {"test_32", []string{"armeabi-v7a"}}, | 
|  | 647 | {"test_64", []string{"arm64-v8a"}}, | 
|  | 648 | } | 
|  | 649 |  | 
|  | 650 | for _, test := range testCases { | 
|  | 651 | t.Run(test.name, func(t *testing.T) { | 
|  | 652 | app := ctx.ModuleForTests(test.name, "android_common") | 
|  | 653 | jniLibZip := app.Output("jnilibs.zip") | 
|  | 654 | var abis []string | 
|  | 655 | args := strings.Fields(jniLibZip.Args["jarArgs"]) | 
|  | 656 | for i := 0; i < len(args); i++ { | 
|  | 657 | if args[i] == "-P" { | 
|  | 658 | abis = append(abis, filepath.Base(args[i+1])) | 
|  | 659 | i++ | 
|  | 660 | } | 
|  | 661 | } | 
|  | 662 | if !reflect.DeepEqual(abis, test.abis) { | 
|  | 663 | t.Errorf("want abis %v, got %v", test.abis, abis) | 
|  | 664 | } | 
|  | 665 | }) | 
|  | 666 | } | 
|  | 667 | } | 
|  | 668 |  | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 669 | func TestJNIPackaging(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 670 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 671 | cc_library { | 
|  | 672 | name: "libjni", | 
|  | 673 | system_shared_libs: [], | 
|  | 674 | stl: "none", | 
|  | 675 | } | 
|  | 676 |  | 
|  | 677 | android_app { | 
|  | 678 | name: "app", | 
|  | 679 | jni_libs: ["libjni"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 680 | sdk_version: "current", | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 681 | } | 
|  | 682 |  | 
|  | 683 | android_app { | 
|  | 684 | name: "app_noembed", | 
|  | 685 | jni_libs: ["libjni"], | 
|  | 686 | use_embedded_native_libs: false, | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 687 | sdk_version: "current", | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 688 | } | 
|  | 689 |  | 
|  | 690 | android_app { | 
|  | 691 | name: "app_embed", | 
|  | 692 | jni_libs: ["libjni"], | 
|  | 693 | use_embedded_native_libs: true, | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 694 | sdk_version: "current", | 
| Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 695 | } | 
|  | 696 |  | 
|  | 697 | android_test { | 
|  | 698 | name: "test", | 
|  | 699 | sdk_version: "core_platform", | 
|  | 700 | jni_libs: ["libjni"], | 
|  | 701 | } | 
|  | 702 |  | 
|  | 703 | android_test { | 
|  | 704 | name: "test_noembed", | 
|  | 705 | sdk_version: "core_platform", | 
|  | 706 | jni_libs: ["libjni"], | 
|  | 707 | use_embedded_native_libs: false, | 
|  | 708 | } | 
|  | 709 |  | 
|  | 710 | android_test_helper_app { | 
|  | 711 | name: "test_helper", | 
|  | 712 | sdk_version: "core_platform", | 
|  | 713 | jni_libs: ["libjni"], | 
|  | 714 | } | 
|  | 715 |  | 
|  | 716 | android_test_helper_app { | 
|  | 717 | name: "test_helper_noembed", | 
|  | 718 | sdk_version: "core_platform", | 
|  | 719 | jni_libs: ["libjni"], | 
|  | 720 | use_embedded_native_libs: false, | 
|  | 721 | } | 
|  | 722 | `) | 
|  | 723 |  | 
|  | 724 | testCases := []struct { | 
|  | 725 | name       string | 
|  | 726 | packaged   bool | 
|  | 727 | compressed bool | 
|  | 728 | }{ | 
|  | 729 | {"app", false, false}, | 
|  | 730 | {"app_noembed", false, false}, | 
|  | 731 | {"app_embed", true, false}, | 
|  | 732 | {"test", true, false}, | 
|  | 733 | {"test_noembed", true, true}, | 
|  | 734 | {"test_helper", true, false}, | 
|  | 735 | {"test_helper_noembed", true, true}, | 
|  | 736 | } | 
|  | 737 |  | 
|  | 738 | for _, test := range testCases { | 
|  | 739 | t.Run(test.name, func(t *testing.T) { | 
|  | 740 | app := ctx.ModuleForTests(test.name, "android_common") | 
|  | 741 | jniLibZip := app.MaybeOutput("jnilibs.zip") | 
|  | 742 | if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { | 
|  | 743 | t.Errorf("expected jni packaged %v, got %v", w, g) | 
|  | 744 | } | 
|  | 745 |  | 
|  | 746 | if jniLibZip.Rule != nil { | 
|  | 747 | if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w { | 
|  | 748 | t.Errorf("expected jni compressed %v, got %v", w, g) | 
|  | 749 | } | 
|  | 750 | } | 
|  | 751 | }) | 
|  | 752 | } | 
| Colin Cross | 47fa9d3 | 2019-03-26 10:51:39 -0700 | [diff] [blame] | 753 | } | 
|  | 754 |  | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 755 | func TestCertificates(t *testing.T) { | 
|  | 756 | testCases := []struct { | 
|  | 757 | name                string | 
|  | 758 | bp                  string | 
|  | 759 | certificateOverride string | 
|  | 760 | expected            string | 
|  | 761 | }{ | 
|  | 762 | { | 
|  | 763 | name: "default", | 
|  | 764 | bp: ` | 
|  | 765 | android_app { | 
|  | 766 | name: "foo", | 
|  | 767 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 768 | sdk_version: "current", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 769 | } | 
|  | 770 | `, | 
|  | 771 | certificateOverride: "", | 
| Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 772 | expected:            "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 773 | }, | 
|  | 774 | { | 
|  | 775 | name: "module certificate property", | 
|  | 776 | bp: ` | 
|  | 777 | android_app { | 
|  | 778 | name: "foo", | 
|  | 779 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 780 | certificate: ":new_certificate", | 
|  | 781 | sdk_version: "current", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 782 | } | 
|  | 783 |  | 
|  | 784 | android_app_certificate { | 
|  | 785 | name: "new_certificate", | 
|  | 786 | certificate: "cert/new_cert", | 
|  | 787 | } | 
|  | 788 | `, | 
|  | 789 | certificateOverride: "", | 
|  | 790 | expected:            "cert/new_cert.x509.pem cert/new_cert.pk8", | 
|  | 791 | }, | 
|  | 792 | { | 
|  | 793 | name: "path certificate property", | 
|  | 794 | bp: ` | 
|  | 795 | android_app { | 
|  | 796 | name: "foo", | 
|  | 797 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 798 | certificate: "expiredkey", | 
|  | 799 | sdk_version: "current", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 800 | } | 
|  | 801 | `, | 
|  | 802 | certificateOverride: "", | 
| Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 803 | expected:            "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 804 | }, | 
|  | 805 | { | 
|  | 806 | name: "certificate overrides", | 
|  | 807 | bp: ` | 
|  | 808 | android_app { | 
|  | 809 | name: "foo", | 
|  | 810 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 811 | certificate: "expiredkey", | 
|  | 812 | sdk_version: "current", | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 813 | } | 
|  | 814 |  | 
|  | 815 | android_app_certificate { | 
|  | 816 | name: "new_certificate", | 
|  | 817 | certificate: "cert/new_cert", | 
|  | 818 | } | 
|  | 819 | `, | 
|  | 820 | certificateOverride: "foo:new_certificate", | 
|  | 821 | expected:            "cert/new_cert.x509.pem cert/new_cert.pk8", | 
|  | 822 | }, | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | for _, test := range testCases { | 
|  | 826 | t.Run(test.name, func(t *testing.T) { | 
|  | 827 | config := testConfig(nil) | 
|  | 828 | if test.certificateOverride != "" { | 
|  | 829 | config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride} | 
|  | 830 | } | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 831 | ctx := testAppContext(test.bp, nil) | 
| Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 832 |  | 
|  | 833 | run(t, ctx, config) | 
|  | 834 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 835 |  | 
|  | 836 | signapk := foo.Output("foo.apk") | 
|  | 837 | signFlags := signapk.Args["certificates"] | 
|  | 838 | if test.expected != signFlags { | 
|  | 839 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expected, signFlags) | 
|  | 840 | } | 
|  | 841 | }) | 
|  | 842 | } | 
|  | 843 | } | 
| Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 844 |  | 
|  | 845 | func TestPackageNameOverride(t *testing.T) { | 
|  | 846 | testCases := []struct { | 
|  | 847 | name                string | 
|  | 848 | bp                  string | 
|  | 849 | packageNameOverride string | 
|  | 850 | expected            []string | 
|  | 851 | }{ | 
|  | 852 | { | 
|  | 853 | name: "default", | 
|  | 854 | bp: ` | 
|  | 855 | android_app { | 
|  | 856 | name: "foo", | 
|  | 857 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 858 | sdk_version: "current", | 
| Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 859 | } | 
|  | 860 | `, | 
|  | 861 | packageNameOverride: "", | 
|  | 862 | expected: []string{ | 
|  | 863 | buildDir + "/.intermediates/foo/android_common/foo.apk", | 
|  | 864 | buildDir + "/target/product/test_device/system/app/foo/foo.apk", | 
|  | 865 | }, | 
|  | 866 | }, | 
|  | 867 | { | 
|  | 868 | name: "overridden", | 
|  | 869 | bp: ` | 
|  | 870 | android_app { | 
|  | 871 | name: "foo", | 
|  | 872 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 873 | sdk_version: "current", | 
| Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 874 | } | 
|  | 875 | `, | 
|  | 876 | packageNameOverride: "foo:bar", | 
|  | 877 | expected: []string{ | 
|  | 878 | // The package apk should be still be the original name for test dependencies. | 
|  | 879 | buildDir + "/.intermediates/foo/android_common/foo.apk", | 
|  | 880 | buildDir + "/target/product/test_device/system/app/bar/bar.apk", | 
|  | 881 | }, | 
|  | 882 | }, | 
|  | 883 | } | 
|  | 884 |  | 
|  | 885 | for _, test := range testCases { | 
|  | 886 | t.Run(test.name, func(t *testing.T) { | 
|  | 887 | config := testConfig(nil) | 
|  | 888 | if test.packageNameOverride != "" { | 
|  | 889 | config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride} | 
|  | 890 | } | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 891 | ctx := testAppContext(test.bp, nil) | 
| Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 892 |  | 
|  | 893 | run(t, ctx, config) | 
|  | 894 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 895 |  | 
|  | 896 | outputs := foo.AllOutputs() | 
|  | 897 | outputMap := make(map[string]bool) | 
|  | 898 | for _, o := range outputs { | 
|  | 899 | outputMap[o] = true | 
|  | 900 | } | 
|  | 901 | for _, e := range test.expected { | 
|  | 902 | if _, exist := outputMap[e]; !exist { | 
|  | 903 | t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs) | 
|  | 904 | } | 
|  | 905 | } | 
|  | 906 | }) | 
|  | 907 | } | 
|  | 908 | } | 
| Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 909 |  | 
|  | 910 | func TestInstrumentationTargetOverridden(t *testing.T) { | 
|  | 911 | bp := ` | 
|  | 912 | android_app { | 
|  | 913 | name: "foo", | 
|  | 914 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 915 | sdk_version: "current", | 
| Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 916 | } | 
|  | 917 |  | 
|  | 918 | android_test { | 
|  | 919 | name: "bar", | 
|  | 920 | instrumentation_for: "foo", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 921 | sdk_version: "current", | 
| Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 922 | } | 
|  | 923 | ` | 
|  | 924 | config := testConfig(nil) | 
|  | 925 | config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 926 | ctx := testAppContext(bp, nil) | 
| Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 927 |  | 
|  | 928 | run(t, ctx, config) | 
|  | 929 |  | 
|  | 930 | bar := ctx.ModuleForTests("bar", "android_common") | 
|  | 931 | res := bar.Output("package-res.apk") | 
|  | 932 | aapt2Flags := res.Args["flags"] | 
|  | 933 | e := "--rename-instrumentation-target-package org.dandroid.bp" | 
|  | 934 | if !strings.Contains(aapt2Flags, e) { | 
|  | 935 | t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags) | 
|  | 936 | } | 
|  | 937 | } | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 938 |  | 
|  | 939 | func TestOverrideAndroidApp(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 940 | ctx, _ := testJava(t, ` | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 941 | android_app { | 
|  | 942 | name: "foo", | 
|  | 943 | srcs: ["a.java"], | 
| Jaewoong Jung | a641ee9 | 2019-03-27 11:17:14 -0700 | [diff] [blame] | 944 | certificate: "expiredkey", | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 945 | overrides: ["qux"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 946 | sdk_version: "current", | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 947 | } | 
|  | 948 |  | 
|  | 949 | override_android_app { | 
|  | 950 | name: "bar", | 
|  | 951 | base: "foo", | 
|  | 952 | certificate: ":new_certificate", | 
|  | 953 | } | 
|  | 954 |  | 
|  | 955 | android_app_certificate { | 
|  | 956 | name: "new_certificate", | 
|  | 957 | certificate: "cert/new_cert", | 
|  | 958 | } | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 959 |  | 
|  | 960 | override_android_app { | 
|  | 961 | name: "baz", | 
|  | 962 | base: "foo", | 
|  | 963 | package_name: "org.dandroid.bp", | 
|  | 964 | } | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 965 | `) | 
|  | 966 |  | 
|  | 967 | expectedVariants := []struct { | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 968 | moduleName  string | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 969 | variantName string | 
|  | 970 | apkName     string | 
|  | 971 | apkPath     string | 
|  | 972 | signFlag    string | 
|  | 973 | overrides   []string | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 974 | aaptFlag    string | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 975 | }{ | 
|  | 976 | { | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 977 | moduleName:  "foo", | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 978 | variantName: "android_common", | 
|  | 979 | apkPath:     "/target/product/test_device/system/app/foo/foo.apk", | 
| Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 980 | signFlag:    "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 981 | overrides:   []string{"qux"}, | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 982 | aaptFlag:    "", | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 983 | }, | 
|  | 984 | { | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 985 | moduleName:  "bar", | 
|  | 986 | variantName: "android_common_bar", | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 987 | apkPath:     "/target/product/test_device/system/app/bar/bar.apk", | 
|  | 988 | signFlag:    "cert/new_cert.x509.pem cert/new_cert.pk8", | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 989 | overrides:   []string{"qux", "foo"}, | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 990 | aaptFlag:    "", | 
|  | 991 | }, | 
|  | 992 | { | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 993 | moduleName:  "baz", | 
|  | 994 | variantName: "android_common_baz", | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 995 | apkPath:     "/target/product/test_device/system/app/baz/baz.apk", | 
| Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 996 | signFlag:    "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 997 | overrides:   []string{"qux", "foo"}, | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 998 | aaptFlag:    "--rename-manifest-package org.dandroid.bp", | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 999 | }, | 
|  | 1000 | } | 
|  | 1001 | for _, expected := range expectedVariants { | 
|  | 1002 | variant := ctx.ModuleForTests("foo", expected.variantName) | 
|  | 1003 |  | 
|  | 1004 | // Check the final apk name | 
|  | 1005 | outputs := variant.AllOutputs() | 
|  | 1006 | expectedApkPath := buildDir + expected.apkPath | 
|  | 1007 | found := false | 
|  | 1008 | for _, o := range outputs { | 
|  | 1009 | if o == expectedApkPath { | 
|  | 1010 | found = true | 
|  | 1011 | break | 
|  | 1012 | } | 
|  | 1013 | } | 
|  | 1014 | if !found { | 
|  | 1015 | t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs) | 
|  | 1016 | } | 
|  | 1017 |  | 
|  | 1018 | // Check the certificate paths | 
|  | 1019 | signapk := variant.Output("foo.apk") | 
|  | 1020 | signFlag := signapk.Args["certificates"] | 
|  | 1021 | if expected.signFlag != signFlag { | 
|  | 1022 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.signFlag, signFlag) | 
|  | 1023 | } | 
|  | 1024 |  | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1025 | // Check if the overrides field values are correctly aggregated. | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1026 | mod := variant.Module().(*AndroidApp) | 
|  | 1027 | if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) { | 
|  | 1028 | t.Errorf("Incorrect overrides property value, expected: %q, got: %q", | 
|  | 1029 | expected.overrides, mod.appProperties.Overrides) | 
|  | 1030 | } | 
| Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1031 |  | 
|  | 1032 | // Check the package renaming flag, if exists. | 
|  | 1033 | res := variant.Output("package-res.apk") | 
|  | 1034 | aapt2Flags := res.Args["flags"] | 
|  | 1035 | if !strings.Contains(aapt2Flags, expected.aaptFlag) { | 
|  | 1036 | t.Errorf("package renaming flag, %q is missing in aapt2 link flags, %q", expected.aaptFlag, aapt2Flags) | 
|  | 1037 | } | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1038 | } | 
|  | 1039 | } | 
| Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1040 |  | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 1041 | func TestOverrideAndroidAppDependency(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1042 | ctx, _ := testJava(t, ` | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 1043 | android_app { | 
|  | 1044 | name: "foo", | 
|  | 1045 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1046 | sdk_version: "current", | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 1047 | } | 
|  | 1048 |  | 
|  | 1049 | override_android_app { | 
|  | 1050 | name: "bar", | 
|  | 1051 | base: "foo", | 
|  | 1052 | package_name: "org.dandroid.bp", | 
|  | 1053 | } | 
|  | 1054 |  | 
|  | 1055 | android_test { | 
|  | 1056 | name: "baz", | 
|  | 1057 | srcs: ["b.java"], | 
|  | 1058 | instrumentation_for: "foo", | 
|  | 1059 | } | 
|  | 1060 |  | 
|  | 1061 | android_test { | 
|  | 1062 | name: "qux", | 
|  | 1063 | srcs: ["b.java"], | 
|  | 1064 | instrumentation_for: "bar", | 
|  | 1065 | } | 
|  | 1066 | `) | 
|  | 1067 |  | 
|  | 1068 | // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. | 
|  | 1069 | javac := ctx.ModuleForTests("baz", "android_common").Rule("javac") | 
|  | 1070 | fooTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") | 
|  | 1071 | if !strings.Contains(javac.Args["classpath"], fooTurbine) { | 
|  | 1072 | t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. | 
|  | 1076 | javac = ctx.ModuleForTests("qux", "android_common").Rule("javac") | 
|  | 1077 | barTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common_bar", "turbine-combined", "foo.jar") | 
|  | 1078 | if !strings.Contains(javac.Args["classpath"], barTurbine) { | 
|  | 1079 | t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) | 
|  | 1080 | } | 
|  | 1081 | } | 
|  | 1082 |  | 
| Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1083 | func TestAndroidAppImport(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1084 | ctx, _ := testJava(t, ` | 
| Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1085 | android_app_import { | 
|  | 1086 | name: "foo", | 
|  | 1087 | apk: "prebuilts/apk/app.apk", | 
|  | 1088 | certificate: "platform", | 
|  | 1089 | dex_preopt: { | 
|  | 1090 | enabled: true, | 
|  | 1091 | }, | 
|  | 1092 | } | 
|  | 1093 | `) | 
|  | 1094 |  | 
|  | 1095 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1096 |  | 
|  | 1097 | // Check dexpreopt outputs. | 
|  | 1098 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || | 
|  | 1099 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { | 
|  | 1100 | t.Errorf("can't find dexpreopt outputs") | 
|  | 1101 | } | 
|  | 1102 |  | 
|  | 1103 | // Check cert signing flag. | 
|  | 1104 | signedApk := variant.Output("signed/foo.apk") | 
|  | 1105 | signingFlag := signedApk.Args["certificates"] | 
|  | 1106 | expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8" | 
|  | 1107 | if expected != signingFlag { | 
|  | 1108 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) | 
|  | 1109 | } | 
|  | 1110 | } | 
|  | 1111 |  | 
|  | 1112 | func TestAndroidAppImport_NoDexPreopt(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1113 | ctx, _ := testJava(t, ` | 
| Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1114 | android_app_import { | 
|  | 1115 | name: "foo", | 
|  | 1116 | apk: "prebuilts/apk/app.apk", | 
|  | 1117 | certificate: "platform", | 
|  | 1118 | dex_preopt: { | 
|  | 1119 | enabled: false, | 
|  | 1120 | }, | 
|  | 1121 | } | 
|  | 1122 | `) | 
|  | 1123 |  | 
|  | 1124 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1125 |  | 
|  | 1126 | // Check dexpreopt outputs. They shouldn't exist. | 
|  | 1127 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule != nil || | 
|  | 1128 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule != nil { | 
|  | 1129 | t.Errorf("dexpreopt shouldn't have run.") | 
|  | 1130 | } | 
|  | 1131 | } | 
|  | 1132 |  | 
|  | 1133 | func TestAndroidAppImport_Presigned(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1134 | ctx, _ := testJava(t, ` | 
| Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1135 | android_app_import { | 
|  | 1136 | name: "foo", | 
|  | 1137 | apk: "prebuilts/apk/app.apk", | 
|  | 1138 | presigned: true, | 
|  | 1139 | dex_preopt: { | 
|  | 1140 | enabled: true, | 
|  | 1141 | }, | 
|  | 1142 | } | 
|  | 1143 | `) | 
|  | 1144 |  | 
|  | 1145 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1146 |  | 
|  | 1147 | // Check dexpreopt outputs. | 
|  | 1148 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || | 
|  | 1149 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { | 
|  | 1150 | t.Errorf("can't find dexpreopt outputs") | 
|  | 1151 | } | 
|  | 1152 | // Make sure stripping wasn't done. | 
|  | 1153 | stripRule := variant.Output("dexpreopt/foo.apk") | 
|  | 1154 | if !strings.HasPrefix(stripRule.RuleParams.Command, "cp -f") { | 
|  | 1155 | t.Errorf("unexpected, non-skipping strip command: %q", stripRule.RuleParams.Command) | 
|  | 1156 | } | 
|  | 1157 |  | 
|  | 1158 | // Make sure signing was skipped and aligning was done instead. | 
|  | 1159 | if variant.MaybeOutput("signed/foo.apk").Rule != nil { | 
|  | 1160 | t.Errorf("signing rule shouldn't be included.") | 
|  | 1161 | } | 
|  | 1162 | if variant.MaybeOutput("zip-aligned/foo.apk").Rule == nil { | 
|  | 1163 | t.Errorf("can't find aligning rule") | 
|  | 1164 | } | 
|  | 1165 | } | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 1166 |  | 
| Jaewoong Jung | 961d4fd | 2019-08-22 14:25:58 -0700 | [diff] [blame] | 1167 | func TestAndroidAppImport_DefaultDevCert(t *testing.T) { | 
|  | 1168 | ctx, _ := testJava(t, ` | 
|  | 1169 | android_app_import { | 
|  | 1170 | name: "foo", | 
|  | 1171 | apk: "prebuilts/apk/app.apk", | 
|  | 1172 | default_dev_cert: true, | 
|  | 1173 | dex_preopt: { | 
|  | 1174 | enabled: true, | 
|  | 1175 | }, | 
|  | 1176 | } | 
|  | 1177 | `) | 
|  | 1178 |  | 
|  | 1179 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1180 |  | 
|  | 1181 | // Check dexpreopt outputs. | 
|  | 1182 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || | 
|  | 1183 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { | 
|  | 1184 | t.Errorf("can't find dexpreopt outputs") | 
|  | 1185 | } | 
|  | 1186 |  | 
|  | 1187 | // Check cert signing flag. | 
|  | 1188 | signedApk := variant.Output("signed/foo.apk") | 
|  | 1189 | signingFlag := signedApk.Args["certificates"] | 
|  | 1190 | expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8" | 
|  | 1191 | if expected != signingFlag { | 
|  | 1192 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) | 
|  | 1193 | } | 
|  | 1194 | } | 
|  | 1195 |  | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 1196 | func TestAndroidAppImport_DpiVariants(t *testing.T) { | 
|  | 1197 | bp := ` | 
|  | 1198 | android_app_import { | 
|  | 1199 | name: "foo", | 
|  | 1200 | apk: "prebuilts/apk/app.apk", | 
|  | 1201 | dpi_variants: { | 
|  | 1202 | xhdpi: { | 
|  | 1203 | apk: "prebuilts/apk/app_xhdpi.apk", | 
|  | 1204 | }, | 
|  | 1205 | xxhdpi: { | 
|  | 1206 | apk: "prebuilts/apk/app_xxhdpi.apk", | 
|  | 1207 | }, | 
|  | 1208 | }, | 
| Jaewoong Jung | 961d4fd | 2019-08-22 14:25:58 -0700 | [diff] [blame] | 1209 | presigned: true, | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 1210 | dex_preopt: { | 
|  | 1211 | enabled: true, | 
|  | 1212 | }, | 
|  | 1213 | } | 
|  | 1214 | ` | 
|  | 1215 | testCases := []struct { | 
|  | 1216 | name                string | 
|  | 1217 | aaptPreferredConfig *string | 
|  | 1218 | aaptPrebuiltDPI     []string | 
|  | 1219 | expected            string | 
|  | 1220 | }{ | 
|  | 1221 | { | 
|  | 1222 | name:                "no preferred", | 
|  | 1223 | aaptPreferredConfig: nil, | 
|  | 1224 | aaptPrebuiltDPI:     []string{}, | 
|  | 1225 | expected:            "prebuilts/apk/app.apk", | 
|  | 1226 | }, | 
|  | 1227 | { | 
|  | 1228 | name:                "AAPTPreferredConfig matches", | 
|  | 1229 | aaptPreferredConfig: proptools.StringPtr("xhdpi"), | 
| Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 1230 | aaptPrebuiltDPI:     []string{"xxhdpi", "ldpi"}, | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 1231 | expected:            "prebuilts/apk/app_xhdpi.apk", | 
|  | 1232 | }, | 
|  | 1233 | { | 
|  | 1234 | name:                "AAPTPrebuiltDPI matches", | 
|  | 1235 | aaptPreferredConfig: proptools.StringPtr("mdpi"), | 
|  | 1236 | aaptPrebuiltDPI:     []string{"xxhdpi", "xhdpi"}, | 
|  | 1237 | expected:            "prebuilts/apk/app_xxhdpi.apk", | 
|  | 1238 | }, | 
|  | 1239 | { | 
|  | 1240 | name:                "non-first AAPTPrebuiltDPI matches", | 
|  | 1241 | aaptPreferredConfig: proptools.StringPtr("mdpi"), | 
|  | 1242 | aaptPrebuiltDPI:     []string{"ldpi", "xhdpi"}, | 
|  | 1243 | expected:            "prebuilts/apk/app_xhdpi.apk", | 
|  | 1244 | }, | 
|  | 1245 | { | 
|  | 1246 | name:                "no matches", | 
|  | 1247 | aaptPreferredConfig: proptools.StringPtr("mdpi"), | 
|  | 1248 | aaptPrebuiltDPI:     []string{"ldpi", "xxxhdpi"}, | 
|  | 1249 | expected:            "prebuilts/apk/app.apk", | 
|  | 1250 | }, | 
|  | 1251 | } | 
|  | 1252 |  | 
|  | 1253 | jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") | 
|  | 1254 | for _, test := range testCases { | 
|  | 1255 | config := testConfig(nil) | 
|  | 1256 | config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig | 
|  | 1257 | config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1258 | ctx := testAppContext(bp, nil) | 
| Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 1259 |  | 
|  | 1260 | run(t, ctx, config) | 
|  | 1261 |  | 
|  | 1262 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1263 | jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command | 
|  | 1264 | matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) | 
|  | 1265 | if len(matches) != 2 { | 
|  | 1266 | t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) | 
|  | 1267 | } | 
|  | 1268 | if test.expected != matches[1] { | 
|  | 1269 | t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) | 
|  | 1270 | } | 
|  | 1271 | } | 
|  | 1272 | } | 
| Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 1273 |  | 
| Jaewoong Jung | 8aae22e | 2019-07-17 10:21:49 -0700 | [diff] [blame] | 1274 | func TestAndroidAppImport_Filename(t *testing.T) { | 
|  | 1275 | ctx, config := testJava(t, ` | 
|  | 1276 | android_app_import { | 
|  | 1277 | name: "foo", | 
|  | 1278 | apk: "prebuilts/apk/app.apk", | 
|  | 1279 | presigned: true, | 
|  | 1280 | } | 
|  | 1281 |  | 
|  | 1282 | android_app_import { | 
|  | 1283 | name: "bar", | 
|  | 1284 | apk: "prebuilts/apk/app.apk", | 
|  | 1285 | presigned: true, | 
|  | 1286 | filename: "bar_sample.apk" | 
|  | 1287 | } | 
|  | 1288 | `) | 
|  | 1289 |  | 
|  | 1290 | testCases := []struct { | 
|  | 1291 | name     string | 
|  | 1292 | expected string | 
|  | 1293 | }{ | 
|  | 1294 | { | 
|  | 1295 | name:     "foo", | 
|  | 1296 | expected: "foo.apk", | 
|  | 1297 | }, | 
|  | 1298 | { | 
|  | 1299 | name:     "bar", | 
|  | 1300 | expected: "bar_sample.apk", | 
|  | 1301 | }, | 
|  | 1302 | } | 
|  | 1303 |  | 
|  | 1304 | for _, test := range testCases { | 
|  | 1305 | variant := ctx.ModuleForTests(test.name, "android_common") | 
|  | 1306 | if variant.MaybeOutput(test.expected).Rule == nil { | 
|  | 1307 | t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs()) | 
|  | 1308 | } | 
|  | 1309 |  | 
|  | 1310 | a := variant.Module().(*AndroidAppImport) | 
|  | 1311 | expectedValues := []string{test.expected} | 
|  | 1312 | actualValues := android.AndroidMkEntriesForTest( | 
|  | 1313 | t, config, "", a).EntryMap["LOCAL_INSTALLED_MODULE_STEM"] | 
|  | 1314 | if !reflect.DeepEqual(actualValues, expectedValues) { | 
|  | 1315 | t.Errorf("Incorrect LOCAL_INSTALLED_MODULE_STEM value '%s', expected '%s'", | 
|  | 1316 | actualValues, expectedValues) | 
|  | 1317 | } | 
|  | 1318 | } | 
|  | 1319 | } | 
|  | 1320 |  | 
| Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 1321 | func TestAndroidAppImport_ArchVariants(t *testing.T) { | 
|  | 1322 | // The test config's target arch is ARM64. | 
|  | 1323 | testCases := []struct { | 
|  | 1324 | name     string | 
|  | 1325 | bp       string | 
|  | 1326 | expected string | 
|  | 1327 | }{ | 
|  | 1328 | { | 
|  | 1329 | name: "matching arch", | 
|  | 1330 | bp: ` | 
|  | 1331 | android_app_import { | 
|  | 1332 | name: "foo", | 
|  | 1333 | apk: "prebuilts/apk/app.apk", | 
|  | 1334 | arch: { | 
|  | 1335 | arm64: { | 
|  | 1336 | apk: "prebuilts/apk/app_arm64.apk", | 
|  | 1337 | }, | 
|  | 1338 | }, | 
| Jaewoong Jung | 961d4fd | 2019-08-22 14:25:58 -0700 | [diff] [blame] | 1339 | presigned: true, | 
| Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 1340 | dex_preopt: { | 
|  | 1341 | enabled: true, | 
|  | 1342 | }, | 
|  | 1343 | } | 
|  | 1344 | `, | 
|  | 1345 | expected: "prebuilts/apk/app_arm64.apk", | 
|  | 1346 | }, | 
|  | 1347 | { | 
|  | 1348 | name: "no matching arch", | 
|  | 1349 | bp: ` | 
|  | 1350 | android_app_import { | 
|  | 1351 | name: "foo", | 
|  | 1352 | apk: "prebuilts/apk/app.apk", | 
|  | 1353 | arch: { | 
|  | 1354 | arm: { | 
|  | 1355 | apk: "prebuilts/apk/app_arm.apk", | 
|  | 1356 | }, | 
|  | 1357 | }, | 
| Jaewoong Jung | 961d4fd | 2019-08-22 14:25:58 -0700 | [diff] [blame] | 1358 | presigned: true, | 
| Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 1359 | dex_preopt: { | 
|  | 1360 | enabled: true, | 
|  | 1361 | }, | 
|  | 1362 | } | 
|  | 1363 | `, | 
|  | 1364 | expected: "prebuilts/apk/app.apk", | 
|  | 1365 | }, | 
|  | 1366 | } | 
|  | 1367 |  | 
|  | 1368 | jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") | 
|  | 1369 | for _, test := range testCases { | 
|  | 1370 | ctx, _ := testJava(t, test.bp) | 
|  | 1371 |  | 
|  | 1372 | variant := ctx.ModuleForTests("foo", "android_common") | 
|  | 1373 | jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command | 
|  | 1374 | matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) | 
|  | 1375 | if len(matches) != 2 { | 
|  | 1376 | t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) | 
|  | 1377 | } | 
|  | 1378 | if test.expected != matches[1] { | 
|  | 1379 | t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) | 
|  | 1380 | } | 
|  | 1381 | } | 
|  | 1382 | } | 
|  | 1383 |  | 
| Jaewoong Jung | b28eb5f | 2019-08-27 15:01:50 -0700 | [diff] [blame] | 1384 | func TestAndroidTestImport(t *testing.T) { | 
|  | 1385 | ctx, config := testJava(t, ` | 
|  | 1386 | android_test_import { | 
|  | 1387 | name: "foo", | 
|  | 1388 | apk: "prebuilts/apk/app.apk", | 
|  | 1389 | presigned: true, | 
|  | 1390 | data: [ | 
|  | 1391 | "testdata/data", | 
|  | 1392 | ], | 
|  | 1393 | } | 
|  | 1394 | `) | 
|  | 1395 |  | 
|  | 1396 | test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport) | 
|  | 1397 |  | 
|  | 1398 | // Check android mks. | 
|  | 1399 | entries := android.AndroidMkEntriesForTest(t, config, "", test) | 
|  | 1400 | expected := []string{"tests"} | 
|  | 1401 | actual := entries.EntryMap["LOCAL_MODULE_TAGS"] | 
|  | 1402 | if !reflect.DeepEqual(expected, actual) { | 
|  | 1403 | t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual) | 
|  | 1404 | } | 
|  | 1405 | expected = []string{"testdata/data:testdata/data"} | 
|  | 1406 | actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] | 
|  | 1407 | if !reflect.DeepEqual(expected, actual) { | 
|  | 1408 | t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual) | 
|  | 1409 | } | 
|  | 1410 | } | 
|  | 1411 |  | 
| Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 1412 | func TestStl(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1413 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` | 
| Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 1414 | cc_library { | 
|  | 1415 | name: "libjni", | 
|  | 1416 | } | 
|  | 1417 |  | 
|  | 1418 | android_test { | 
|  | 1419 | name: "stl", | 
|  | 1420 | jni_libs: ["libjni"], | 
|  | 1421 | compile_multilib: "both", | 
|  | 1422 | sdk_version: "current", | 
|  | 1423 | stl: "c++_shared", | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | android_test { | 
|  | 1427 | name: "system", | 
|  | 1428 | jni_libs: ["libjni"], | 
|  | 1429 | compile_multilib: "both", | 
|  | 1430 | sdk_version: "current", | 
|  | 1431 | } | 
| Jaewoong Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 1432 |  | 
|  | 1433 | ndk_prebuilt_shared_stl { | 
|  | 1434 | name: "ndk_libc++_shared", | 
|  | 1435 | } | 
| Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 1436 | `) | 
|  | 1437 |  | 
|  | 1438 | testCases := []struct { | 
|  | 1439 | name string | 
|  | 1440 | jnis []string | 
|  | 1441 | }{ | 
|  | 1442 | {"stl", | 
|  | 1443 | []string{ | 
|  | 1444 | "libjni.so", | 
| Jaewoong Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 1445 | "libc++_shared.so", | 
| Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 1446 | }, | 
|  | 1447 | }, | 
|  | 1448 | {"system", | 
|  | 1449 | []string{ | 
|  | 1450 | "libjni.so", | 
|  | 1451 | }, | 
|  | 1452 | }, | 
|  | 1453 | } | 
|  | 1454 |  | 
|  | 1455 | for _, test := range testCases { | 
|  | 1456 | t.Run(test.name, func(t *testing.T) { | 
|  | 1457 | app := ctx.ModuleForTests(test.name, "android_common") | 
|  | 1458 | jniLibZip := app.Output("jnilibs.zip") | 
|  | 1459 | var jnis []string | 
|  | 1460 | args := strings.Fields(jniLibZip.Args["jarArgs"]) | 
|  | 1461 | for i := 0; i < len(args); i++ { | 
|  | 1462 | if args[i] == "-f" { | 
|  | 1463 | jnis = append(jnis, args[i+1]) | 
|  | 1464 | i += 1 | 
|  | 1465 | } | 
|  | 1466 | } | 
|  | 1467 | jnisJoined := strings.Join(jnis, " ") | 
|  | 1468 | for _, jni := range test.jnis { | 
|  | 1469 | if !strings.Contains(jnisJoined, jni) { | 
|  | 1470 | t.Errorf("missing jni %q in %q", jni, jnis) | 
|  | 1471 | } | 
|  | 1472 | } | 
|  | 1473 | }) | 
|  | 1474 | } | 
|  | 1475 | } | 
| Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1476 |  | 
|  | 1477 | func TestUsesLibraries(t *testing.T) { | 
|  | 1478 | bp := ` | 
|  | 1479 | java_sdk_library { | 
|  | 1480 | name: "foo", | 
|  | 1481 | srcs: ["a.java"], | 
|  | 1482 | api_packages: ["foo"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1483 | sdk_version: "current", | 
| Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1484 | } | 
|  | 1485 |  | 
|  | 1486 | java_sdk_library { | 
|  | 1487 | name: "bar", | 
|  | 1488 | srcs: ["a.java"], | 
|  | 1489 | api_packages: ["bar"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1490 | sdk_version: "current", | 
| Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1491 | } | 
|  | 1492 |  | 
|  | 1493 | android_app { | 
|  | 1494 | name: "app", | 
|  | 1495 | srcs: ["a.java"], | 
|  | 1496 | uses_libs: ["foo"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1497 | sdk_version: "current", | 
| Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1498 | optional_uses_libs: [ | 
|  | 1499 | "bar", | 
|  | 1500 | "baz", | 
|  | 1501 | ], | 
|  | 1502 | } | 
|  | 1503 |  | 
|  | 1504 | android_app_import { | 
|  | 1505 | name: "prebuilt", | 
|  | 1506 | apk: "prebuilts/apk/app.apk", | 
|  | 1507 | certificate: "platform", | 
|  | 1508 | uses_libs: ["foo"], | 
|  | 1509 | optional_uses_libs: [ | 
|  | 1510 | "bar", | 
|  | 1511 | "baz", | 
|  | 1512 | ], | 
|  | 1513 | } | 
|  | 1514 | ` | 
|  | 1515 |  | 
|  | 1516 | config := testConfig(nil) | 
|  | 1517 | config.TestProductVariables.MissingUsesLibraries = []string{"baz"} | 
|  | 1518 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1519 | ctx := testAppContext(bp, nil) | 
| Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1520 |  | 
|  | 1521 | run(t, ctx, config) | 
|  | 1522 |  | 
|  | 1523 | app := ctx.ModuleForTests("app", "android_common") | 
|  | 1524 | prebuilt := ctx.ModuleForTests("prebuilt", "android_common") | 
|  | 1525 |  | 
|  | 1526 | // Test that all libraries are verified | 
|  | 1527 | cmd := app.Rule("verify_uses_libraries").RuleParams.Command | 
|  | 1528 | if w := "--uses-library foo"; !strings.Contains(cmd, w) { | 
|  | 1529 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1530 | } | 
|  | 1531 |  | 
|  | 1532 | if w := "--optional-uses-library bar --optional-uses-library baz"; !strings.Contains(cmd, w) { | 
|  | 1533 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1534 | } | 
|  | 1535 |  | 
|  | 1536 | cmd = prebuilt.Rule("verify_uses_libraries").RuleParams.Command | 
|  | 1537 |  | 
|  | 1538 | if w := `uses_library_names="foo"`; !strings.Contains(cmd, w) { | 
|  | 1539 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1540 | } | 
|  | 1541 |  | 
|  | 1542 | if w := `optional_uses_library_names="bar baz"`; !strings.Contains(cmd, w) { | 
|  | 1543 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1544 | } | 
|  | 1545 |  | 
|  | 1546 | // Test that only present libraries are preopted | 
|  | 1547 | cmd = app.Rule("dexpreopt").RuleParams.Command | 
|  | 1548 |  | 
|  | 1549 | if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) { | 
|  | 1550 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1551 | } | 
|  | 1552 |  | 
|  | 1553 | cmd = prebuilt.Rule("dexpreopt").RuleParams.Command | 
|  | 1554 |  | 
|  | 1555 | if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) { | 
|  | 1556 | t.Errorf("wanted %q in %q", w, cmd) | 
|  | 1557 | } | 
|  | 1558 | } | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1559 |  | 
|  | 1560 | func TestCodelessApp(t *testing.T) { | 
|  | 1561 | testCases := []struct { | 
|  | 1562 | name   string | 
|  | 1563 | bp     string | 
|  | 1564 | noCode bool | 
|  | 1565 | }{ | 
|  | 1566 | { | 
|  | 1567 | name: "normal", | 
|  | 1568 | bp: ` | 
|  | 1569 | android_app { | 
|  | 1570 | name: "foo", | 
|  | 1571 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1572 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1573 | } | 
|  | 1574 | `, | 
|  | 1575 | noCode: false, | 
|  | 1576 | }, | 
|  | 1577 | { | 
|  | 1578 | name: "app without sources", | 
|  | 1579 | bp: ` | 
|  | 1580 | android_app { | 
|  | 1581 | name: "foo", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1582 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1583 | } | 
|  | 1584 | `, | 
|  | 1585 | noCode: true, | 
|  | 1586 | }, | 
|  | 1587 | { | 
|  | 1588 | name: "app with libraries", | 
|  | 1589 | bp: ` | 
|  | 1590 | android_app { | 
|  | 1591 | name: "foo", | 
|  | 1592 | static_libs: ["lib"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1593 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1594 | } | 
|  | 1595 |  | 
|  | 1596 | java_library { | 
|  | 1597 | name: "lib", | 
|  | 1598 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1599 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1600 | } | 
|  | 1601 | `, | 
|  | 1602 | noCode: false, | 
|  | 1603 | }, | 
|  | 1604 | { | 
|  | 1605 | name: "app with sourceless libraries", | 
|  | 1606 | bp: ` | 
|  | 1607 | android_app { | 
|  | 1608 | name: "foo", | 
|  | 1609 | static_libs: ["lib"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1610 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
|  | 1613 | java_library { | 
|  | 1614 | name: "lib", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1615 | sdk_version: "current", | 
| Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1616 | } | 
|  | 1617 | `, | 
|  | 1618 | // TODO(jungjw): this should probably be true | 
|  | 1619 | noCode: false, | 
|  | 1620 | }, | 
|  | 1621 | } | 
|  | 1622 |  | 
|  | 1623 | for _, test := range testCases { | 
|  | 1624 | t.Run(test.name, func(t *testing.T) { | 
|  | 1625 | ctx := testApp(t, test.bp) | 
|  | 1626 |  | 
|  | 1627 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 1628 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] | 
|  | 1629 | if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode { | 
|  | 1630 | t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs) | 
|  | 1631 | } | 
|  | 1632 | }) | 
|  | 1633 | } | 
|  | 1634 | } | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1635 |  | 
|  | 1636 | func TestEmbedNotice(t *testing.T) { | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1637 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1638 | android_app { | 
|  | 1639 | name: "foo", | 
|  | 1640 | srcs: ["a.java"], | 
|  | 1641 | static_libs: ["javalib"], | 
|  | 1642 | jni_libs: ["libjni"], | 
|  | 1643 | notice: "APP_NOTICE", | 
|  | 1644 | embed_notices: true, | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1645 | sdk_version: "current", | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1646 | } | 
|  | 1647 |  | 
|  | 1648 | // No embed_notice flag | 
|  | 1649 | android_app { | 
|  | 1650 | name: "bar", | 
|  | 1651 | srcs: ["a.java"], | 
|  | 1652 | jni_libs: ["libjni"], | 
|  | 1653 | notice: "APP_NOTICE", | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1654 | sdk_version: "current", | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | // No NOTICE files | 
|  | 1658 | android_app { | 
|  | 1659 | name: "baz", | 
|  | 1660 | srcs: ["a.java"], | 
|  | 1661 | embed_notices: true, | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1662 | sdk_version: "current", | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1663 | } | 
|  | 1664 |  | 
|  | 1665 | cc_library { | 
|  | 1666 | name: "libjni", | 
|  | 1667 | system_shared_libs: [], | 
|  | 1668 | stl: "none", | 
|  | 1669 | notice: "LIB_NOTICE", | 
|  | 1670 | } | 
|  | 1671 |  | 
|  | 1672 | java_library { | 
|  | 1673 | name: "javalib", | 
|  | 1674 | srcs: [ | 
|  | 1675 | ":gen", | 
|  | 1676 | ], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1677 | sdk_version: "current", | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1678 | } | 
|  | 1679 |  | 
|  | 1680 | genrule { | 
|  | 1681 | name: "gen", | 
|  | 1682 | tools: ["gentool"], | 
|  | 1683 | out: ["gen.java"], | 
|  | 1684 | notice: "GENRULE_NOTICE", | 
|  | 1685 | } | 
|  | 1686 |  | 
|  | 1687 | java_binary_host { | 
|  | 1688 | name: "gentool", | 
|  | 1689 | srcs: ["b.java"], | 
|  | 1690 | notice: "TOOL_NOTICE", | 
|  | 1691 | } | 
|  | 1692 | `) | 
|  | 1693 |  | 
|  | 1694 | // foo has NOTICE files to process, and embed_notices is true. | 
|  | 1695 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 1696 | // verify merge notices rule. | 
|  | 1697 | mergeNotices := foo.Rule("mergeNoticesRule") | 
|  | 1698 | noticeInputs := mergeNotices.Inputs.Strings() | 
|  | 1699 | // TOOL_NOTICE should be excluded as it's a host module. | 
|  | 1700 | if len(mergeNotices.Inputs) != 3 { | 
|  | 1701 | t.Errorf("number of input notice files: expected = 3, actual = %q", noticeInputs) | 
|  | 1702 | } | 
|  | 1703 | if !inList("APP_NOTICE", noticeInputs) { | 
|  | 1704 | t.Errorf("APP_NOTICE is missing from notice files, %q", noticeInputs) | 
|  | 1705 | } | 
|  | 1706 | if !inList("LIB_NOTICE", noticeInputs) { | 
|  | 1707 | t.Errorf("LIB_NOTICE is missing from notice files, %q", noticeInputs) | 
|  | 1708 | } | 
|  | 1709 | if !inList("GENRULE_NOTICE", noticeInputs) { | 
|  | 1710 | t.Errorf("GENRULE_NOTICE is missing from notice files, %q", noticeInputs) | 
|  | 1711 | } | 
|  | 1712 | // aapt2 flags should include -A <NOTICE dir> so that its contents are put in the APK's /assets. | 
|  | 1713 | res := foo.Output("package-res.apk") | 
|  | 1714 | aapt2Flags := res.Args["flags"] | 
|  | 1715 | e := "-A " + buildDir + "/.intermediates/foo/android_common/NOTICE" | 
|  | 1716 | if !strings.Contains(aapt2Flags, e) { | 
|  | 1717 | t.Errorf("asset dir flag for NOTICE, %q is missing in aapt2 link flags, %q", e, aapt2Flags) | 
|  | 1718 | } | 
|  | 1719 |  | 
|  | 1720 | // bar has NOTICE files to process, but embed_notices is not set. | 
|  | 1721 | bar := ctx.ModuleForTests("bar", "android_common") | 
| Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame] | 1722 | res = bar.Output("package-res.apk") | 
|  | 1723 | aapt2Flags = res.Args["flags"] | 
|  | 1724 | e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE" | 
|  | 1725 | if strings.Contains(aapt2Flags, e) { | 
|  | 1726 | t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e) | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1727 | } | 
|  | 1728 |  | 
|  | 1729 | // baz's embed_notice is true, but it doesn't have any NOTICE files. | 
|  | 1730 | baz := ctx.ModuleForTests("baz", "android_common") | 
| Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame] | 1731 | res = baz.Output("package-res.apk") | 
|  | 1732 | aapt2Flags = res.Args["flags"] | 
|  | 1733 | e = "-A " + buildDir + "/.intermediates/baz/android_common/NOTICE" | 
|  | 1734 | if strings.Contains(aapt2Flags, e) { | 
|  | 1735 | t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e) | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 1736 | } | 
|  | 1737 | } | 
| Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 1738 |  | 
|  | 1739 | func TestUncompressDex(t *testing.T) { | 
|  | 1740 | testCases := []struct { | 
|  | 1741 | name string | 
|  | 1742 | bp   string | 
|  | 1743 |  | 
|  | 1744 | uncompressedPlatform  bool | 
|  | 1745 | uncompressedUnbundled bool | 
|  | 1746 | }{ | 
|  | 1747 | { | 
|  | 1748 | name: "normal", | 
|  | 1749 | bp: ` | 
|  | 1750 | android_app { | 
|  | 1751 | name: "foo", | 
|  | 1752 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1753 | sdk_version: "current", | 
| Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 1754 | } | 
|  | 1755 | `, | 
|  | 1756 | uncompressedPlatform:  true, | 
|  | 1757 | uncompressedUnbundled: false, | 
|  | 1758 | }, | 
|  | 1759 | { | 
|  | 1760 | name: "use_embedded_dex", | 
|  | 1761 | bp: ` | 
|  | 1762 | android_app { | 
|  | 1763 | name: "foo", | 
|  | 1764 | use_embedded_dex: true, | 
|  | 1765 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1766 | sdk_version: "current", | 
| Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 1767 | } | 
|  | 1768 | `, | 
|  | 1769 | uncompressedPlatform:  true, | 
|  | 1770 | uncompressedUnbundled: true, | 
|  | 1771 | }, | 
|  | 1772 | { | 
|  | 1773 | name: "privileged", | 
|  | 1774 | bp: ` | 
|  | 1775 | android_app { | 
|  | 1776 | name: "foo", | 
|  | 1777 | privileged: true, | 
|  | 1778 | srcs: ["a.java"], | 
| Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1779 | sdk_version: "current", | 
| Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 1780 | } | 
|  | 1781 | `, | 
|  | 1782 | uncompressedPlatform:  true, | 
|  | 1783 | uncompressedUnbundled: true, | 
|  | 1784 | }, | 
|  | 1785 | } | 
|  | 1786 |  | 
|  | 1787 | test := func(t *testing.T, bp string, want bool, unbundled bool) { | 
|  | 1788 | t.Helper() | 
|  | 1789 |  | 
|  | 1790 | config := testConfig(nil) | 
|  | 1791 | if unbundled { | 
|  | 1792 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) | 
|  | 1793 | } | 
|  | 1794 |  | 
| Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1795 | ctx := testAppContext(bp, nil) | 
| Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 1796 |  | 
|  | 1797 | run(t, ctx, config) | 
|  | 1798 |  | 
|  | 1799 | foo := ctx.ModuleForTests("foo", "android_common") | 
|  | 1800 | dex := foo.Rule("r8") | 
|  | 1801 | uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0") | 
|  | 1802 | aligned := foo.MaybeRule("zipalign").Rule != nil | 
|  | 1803 |  | 
|  | 1804 | if uncompressedInDexJar != want { | 
|  | 1805 | t.Errorf("want uncompressed in dex %v, got %v", want, uncompressedInDexJar) | 
|  | 1806 | } | 
|  | 1807 |  | 
|  | 1808 | if aligned != want { | 
|  | 1809 | t.Errorf("want aligned %v, got %v", want, aligned) | 
|  | 1810 | } | 
|  | 1811 | } | 
|  | 1812 |  | 
|  | 1813 | for _, tt := range testCases { | 
|  | 1814 | t.Run(tt.name, func(t *testing.T) { | 
|  | 1815 | t.Run("platform", func(t *testing.T) { | 
|  | 1816 | test(t, tt.bp, tt.uncompressedPlatform, false) | 
|  | 1817 | }) | 
|  | 1818 | t.Run("unbundled", func(t *testing.T) { | 
|  | 1819 | test(t, tt.bp, tt.uncompressedUnbundled, true) | 
|  | 1820 | }) | 
|  | 1821 | }) | 
|  | 1822 | } | 
|  | 1823 | } |