summaryrefslogtreecommitdiff
path: root/java/app_test.go
diff options
context:
space:
mode:
author Jaewoong Jung <jungjw@google.com> 2020-12-28 17:50:44 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-12-28 17:50:44 +0000
commit8bfb63c5a9717ef50e7a10fcd85274b4fcd55df3 (patch)
treea84051d035c36ecf08a33e4f928db320fca4e046 /java/app_test.go
parent3d419e3b3d1dc313f33ee48833a96c6dd381c1be (diff)
parentf9b44657c81af46d409478e18fc88201f595d510 (diff)
Merge "Break up app.go."
Diffstat (limited to 'java/app_test.go')
-rw-r--r--java/app_test.go913
1 files changed, 0 insertions, 913 deletions
diff --git a/java/app_test.go b/java/app_test.go
index 6e0093e96..b1abe3db3 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -18,7 +18,6 @@ import (
"fmt"
"path/filepath"
"reflect"
- "regexp"
"sort"
"strings"
"testing"
@@ -141,99 +140,6 @@ func TestAppSplits(t *testing.T) {
}
}
-func TestAndroidAppSet(t *testing.T) {
- ctx, config := testJava(t, `
- android_app_set {
- name: "foo",
- set: "prebuilts/apks/app.apks",
- prerelease: true,
- }`)
- module := ctx.ModuleForTests("foo", "android_common")
- const packedSplitApks = "foo.zip"
- params := module.Output(packedSplitApks)
- if params.Rule == nil {
- t.Errorf("expected output %s is missing", packedSplitApks)
- }
- if s := params.Args["allow-prereleased"]; s != "true" {
- t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s)
- }
- if s := params.Args["partition"]; s != "system" {
- t.Errorf("wrong partition value: '%s', expected 'system'", s)
- }
- mkEntries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
- actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
- expectedInstallFile := []string{"foo.apk"}
- if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
- t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
- actualInstallFile, expectedInstallFile)
- }
-}
-
-func TestAndroidAppSet_Variants(t *testing.T) {
- bp := `
- android_app_set {
- name: "foo",
- set: "prebuilts/apks/app.apks",
- }`
- testCases := []struct {
- name string
- targets []android.Target
- aaptPrebuiltDPI []string
- sdkVersion int
- expected map[string]string
- }{
- {
- name: "One",
- targets: []android.Target{
- {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
- },
- aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"},
- sdkVersion: 29,
- expected: map[string]string{
- "abis": "X86",
- "allow-prereleased": "false",
- "screen-densities": "LDPI,XXHDPI",
- "sdk-version": "29",
- "stem": "foo",
- },
- },
- {
- name: "Two",
- targets: []android.Target{
- {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}},
- {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
- },
- aaptPrebuiltDPI: nil,
- sdkVersion: 30,
- expected: map[string]string{
- "abis": "X86_64,X86",
- "allow-prereleased": "false",
- "screen-densities": "all",
- "sdk-version": "30",
- "stem": "foo",
- },
- },
- }
-
- for _, test := range testCases {
- config := testAppConfig(nil, bp, nil)
- config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
- config.TestProductVariables.Platform_sdk_version = &test.sdkVersion
- config.Targets[android.Android] = test.targets
- ctx := testContext(config)
- run(t, ctx, config)
- module := ctx.ModuleForTests("foo", "android_common")
- const packedSplitApks = "foo.zip"
- params := module.Output(packedSplitApks)
- for k, v := range test.expected {
- if actual := params.Args[k]; actual != v {
- t.Errorf("%s: bad build arg value for '%s': '%s', expected '%s'",
- test.name, k, actual, v)
- }
- }
- }
-}
-
func TestPlatformAPIs(t *testing.T) {
testJava(t, `
android_app {
@@ -2226,475 +2132,6 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
}
}
-func TestAndroidAppImport(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- certificate: "platform",
- dex_preopt: {
- enabled: true,
- },
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
-
- // Check dexpreopt outputs.
- if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
- variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
- t.Errorf("can't find dexpreopt outputs")
- }
-
- // Check cert signing flag.
- signedApk := variant.Output("signed/foo.apk")
- signingFlag := signedApk.Args["certificates"]
- expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8"
- if expected != signingFlag {
- t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
- }
-}
-
-func TestAndroidAppImport_NoDexPreopt(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- certificate: "platform",
- dex_preopt: {
- enabled: false,
- },
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
-
- // Check dexpreopt outputs. They shouldn't exist.
- if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule != nil ||
- variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule != nil {
- t.Errorf("dexpreopt shouldn't have run.")
- }
-}
-
-func TestAndroidAppImport_Presigned(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
-
- // Check dexpreopt outputs.
- if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
- variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
- t.Errorf("can't find dexpreopt outputs")
- }
- // Make sure signing was skipped and aligning was done.
- if variant.MaybeOutput("signed/foo.apk").Rule != nil {
- t.Errorf("signing rule shouldn't be included.")
- }
- if variant.MaybeOutput("zip-aligned/foo.apk").Rule == nil {
- t.Errorf("can't find aligning rule")
- }
-}
-
-func TestAndroidAppImport_SigningLineage(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- certificate: "platform",
- lineage: "lineage.bin",
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
-
- // Check cert signing lineage flag.
- signedApk := variant.Output("signed/foo.apk")
- signingFlag := signedApk.Args["flags"]
- expected := "--lineage lineage.bin"
- if expected != signingFlag {
- t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
- }
-}
-
-func TestAndroidAppImport_DefaultDevCert(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- default_dev_cert: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
-
- // Check dexpreopt outputs.
- if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
- variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
- t.Errorf("can't find dexpreopt outputs")
- }
-
- // Check cert signing flag.
- signedApk := variant.Output("signed/foo.apk")
- signingFlag := signedApk.Args["certificates"]
- expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8"
- if expected != signingFlag {
- t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
- }
-}
-
-func TestAndroidAppImport_DpiVariants(t *testing.T) {
- bp := `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- dpi_variants: {
- xhdpi: {
- apk: "prebuilts/apk/app_xhdpi.apk",
- },
- xxhdpi: {
- apk: "prebuilts/apk/app_xxhdpi.apk",
- },
- },
- presigned: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `
- testCases := []struct {
- name string
- aaptPreferredConfig *string
- aaptPrebuiltDPI []string
- expected string
- }{
- {
- name: "no preferred",
- aaptPreferredConfig: nil,
- aaptPrebuiltDPI: []string{},
- expected: "prebuilts/apk/app.apk",
- },
- {
- name: "AAPTPreferredConfig matches",
- aaptPreferredConfig: proptools.StringPtr("xhdpi"),
- aaptPrebuiltDPI: []string{"xxhdpi", "ldpi"},
- expected: "prebuilts/apk/app_xhdpi.apk",
- },
- {
- name: "AAPTPrebuiltDPI matches",
- aaptPreferredConfig: proptools.StringPtr("mdpi"),
- aaptPrebuiltDPI: []string{"xxhdpi", "xhdpi"},
- expected: "prebuilts/apk/app_xxhdpi.apk",
- },
- {
- name: "non-first AAPTPrebuiltDPI matches",
- aaptPreferredConfig: proptools.StringPtr("mdpi"),
- aaptPrebuiltDPI: []string{"ldpi", "xhdpi"},
- expected: "prebuilts/apk/app_xhdpi.apk",
- },
- {
- name: "no matches",
- aaptPreferredConfig: proptools.StringPtr("mdpi"),
- aaptPrebuiltDPI: []string{"ldpi", "xxxhdpi"},
- expected: "prebuilts/apk/app.apk",
- },
- }
-
- jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)")
- for _, test := range testCases {
- config := testAppConfig(nil, bp, nil)
- config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig
- config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
- ctx := testContext(config)
-
- run(t, ctx, config)
-
- variant := ctx.ModuleForTests("foo", "android_common")
- jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
- matches := jniRuleRe.FindStringSubmatch(jniRuleCommand)
- if len(matches) != 2 {
- t.Errorf("failed to extract the src apk path from %q", jniRuleCommand)
- }
- if test.expected != matches[1] {
- t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1])
- }
- }
-}
-
-func TestAndroidAppImport_Filename(t *testing.T) {
- ctx, config := testJava(t, `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- }
-
- android_app_import {
- name: "bar",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- filename: "bar_sample.apk"
- }
- `)
-
- testCases := []struct {
- name string
- expected string
- }{
- {
- name: "foo",
- expected: "foo.apk",
- },
- {
- name: "bar",
- expected: "bar_sample.apk",
- },
- }
-
- for _, test := range testCases {
- variant := ctx.ModuleForTests(test.name, "android_common")
- if variant.MaybeOutput(test.expected).Rule == nil {
- t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs())
- }
-
- a := variant.Module().(*AndroidAppImport)
- expectedValues := []string{test.expected}
- actualValues := android.AndroidMkEntriesForTest(
- t, config, "", a)[0].EntryMap["LOCAL_INSTALLED_MODULE_STEM"]
- if !reflect.DeepEqual(actualValues, expectedValues) {
- t.Errorf("Incorrect LOCAL_INSTALLED_MODULE_STEM value '%s', expected '%s'",
- actualValues, expectedValues)
- }
- }
-}
-
-func TestAndroidAppImport_ArchVariants(t *testing.T) {
- // The test config's target arch is ARM64.
- testCases := []struct {
- name string
- bp string
- expected string
- }{
- {
- name: "matching arch",
- bp: `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- arch: {
- arm64: {
- apk: "prebuilts/apk/app_arm64.apk",
- },
- },
- presigned: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `,
- expected: "prebuilts/apk/app_arm64.apk",
- },
- {
- name: "no matching arch",
- bp: `
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- arch: {
- arm: {
- apk: "prebuilts/apk/app_arm.apk",
- },
- },
- presigned: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `,
- expected: "prebuilts/apk/app.apk",
- },
- {
- name: "no matching arch without default",
- bp: `
- android_app_import {
- name: "foo",
- arch: {
- arm: {
- apk: "prebuilts/apk/app_arm.apk",
- },
- },
- presigned: true,
- dex_preopt: {
- enabled: true,
- },
- }
- `,
- expected: "",
- },
- }
-
- jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)")
- for _, test := range testCases {
- ctx, _ := testJava(t, test.bp)
-
- variant := ctx.ModuleForTests("foo", "android_common")
- if test.expected == "" {
- if variant.Module().Enabled() {
- t.Error("module should have been disabled, but wasn't")
- }
- continue
- }
- jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
- matches := jniRuleRe.FindStringSubmatch(jniRuleCommand)
- if len(matches) != 2 {
- t.Errorf("failed to extract the src apk path from %q", jniRuleCommand)
- }
- if test.expected != matches[1] {
- t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1])
- }
- }
-}
-
-func TestAndroidAppImport_overridesDisabledAndroidApp(t *testing.T) {
- ctx, _ := testJava(t, `
- android_app {
- name: "foo",
- srcs: ["a.java"],
- enabled: false,
- }
-
- android_app_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- certificate: "platform",
- prefer: true,
- }
- `)
-
- variant := ctx.ModuleForTests("prebuilt_foo", "android_common")
- a := variant.Module().(*AndroidAppImport)
- // The prebuilt module should still be enabled and active even if the source-based counterpart
- // is disabled.
- if !a.prebuilt.UsePrebuilt() {
- t.Errorf("prebuilt foo module is not active")
- }
- if !a.Enabled() {
- t.Errorf("prebuilt foo module is disabled")
- }
-}
-
-func TestAndroidTestImport(t *testing.T) {
- ctx, config := testJava(t, `
- android_test_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- data: [
- "testdata/data",
- ],
- }
- `)
-
- test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport)
-
- // Check android mks.
- entries := android.AndroidMkEntriesForTest(t, config, "", test)[0]
- expected := []string{"tests"}
- actual := entries.EntryMap["LOCAL_MODULE_TAGS"]
- if !reflect.DeepEqual(expected, actual) {
- t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual)
- }
- expected = []string{"testdata/data:testdata/data"}
- actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
- if !reflect.DeepEqual(expected, actual) {
- t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
- }
-}
-
-func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) {
- ctx, _ := testJava(t, `
- android_test_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- certificate: "cert/new_cert",
- data: [
- "testdata/data",
- ],
- }
-
- android_test_import {
- name: "foo_presigned",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- data: [
- "testdata/data",
- ],
- }
- `)
-
- variant := ctx.ModuleForTests("foo", "android_common")
- jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
- if !strings.HasPrefix(jniRule, "if (zipinfo") {
- t.Errorf("Unexpected JNI uncompress rule command: " + jniRule)
- }
-
- variant = ctx.ModuleForTests("foo_presigned", "android_common")
- jniRule = variant.Output("jnis-uncompressed/foo_presigned.apk").BuildParams.Rule.String()
- if jniRule != android.Cp.String() {
- t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
- }
- if variant.MaybeOutput("zip-aligned/foo_presigned.apk").Rule == nil {
- t.Errorf("Presigned test apk should be aligned")
- }
-}
-
-func TestAndroidTestImport_Preprocessed(t *testing.T) {
- ctx, _ := testJava(t, `
- android_test_import {
- name: "foo",
- apk: "prebuilts/apk/app.apk",
- presigned: true,
- preprocessed: true,
- }
-
- android_test_import {
- name: "foo_cert",
- apk: "prebuilts/apk/app.apk",
- certificate: "cert/new_cert",
- preprocessed: true,
- }
- `)
-
- testModules := []string{"foo", "foo_cert"}
- for _, m := range testModules {
- apkName := m + ".apk"
- variant := ctx.ModuleForTests(m, "android_common")
- jniRule := variant.Output("jnis-uncompressed/" + apkName).BuildParams.Rule.String()
- if jniRule != android.Cp.String() {
- t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
- }
-
- // Make sure signing and aligning were skipped.
- if variant.MaybeOutput("signed/"+apkName).Rule != nil {
- t.Errorf("signing rule shouldn't be included for preprocessed.")
- }
- if variant.MaybeOutput("zip-aligned/"+apkName).Rule != nil {
- t.Errorf("aligning rule shouldn't be for preprocessed")
- }
- }
-}
-
func TestStl(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
cc_library {
@@ -3237,356 +2674,6 @@ func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string
}
}
-func TestRuntimeResourceOverlay(t *testing.T) {
- fs := map[string][]byte{
- "baz/res/res/values/strings.xml": nil,
- "bar/res/res/values/strings.xml": nil,
- }
- bp := `
- runtime_resource_overlay {
- name: "foo",
- certificate: "platform",
- lineage: "lineage.bin",
- product_specific: true,
- static_libs: ["bar"],
- resource_libs: ["baz"],
- aaptflags: ["--keep-raw-values"],
- }
-
- runtime_resource_overlay {
- name: "foo_themed",
- certificate: "platform",
- product_specific: true,
- theme: "faza",
- overrides: ["foo"],
- }
-
- android_library {
- name: "bar",
- resource_dirs: ["bar/res"],
- }
-
- android_app {
- name: "baz",
- sdk_version: "current",
- resource_dirs: ["baz/res"],
- }
- `
- config := testAppConfig(nil, bp, fs)
- ctx := testContext(config)
- run(t, ctx, config)
-
- m := ctx.ModuleForTests("foo", "android_common")
-
- // Check AAPT2 link flags.
- aapt2Flags := m.Output("package-res.apk").Args["flags"]
- expectedFlags := []string{"--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"}
- absentFlags := android.RemoveListFromList(expectedFlags, strings.Split(aapt2Flags, " "))
- if len(absentFlags) > 0 {
- t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags)
- }
-
- // Check overlay.list output for static_libs dependency.
- overlayList := m.Output("aapt2/overlay.list").Inputs.Strings()
- staticLibPackage := buildDir + "/.intermediates/bar/android_common/package-res.apk"
- if !inList(staticLibPackage, overlayList) {
- t.Errorf("Stactic lib res package %q missing in overlay list: %q", staticLibPackage, overlayList)
- }
-
- // Check AAPT2 link flags for resource_libs dependency.
- resourceLibFlag := "-I " + buildDir + "/.intermediates/baz/android_common/package-res.apk"
- if !strings.Contains(aapt2Flags, resourceLibFlag) {
- t.Errorf("Resource lib flag %q missing in aapt2 link flags: %q", resourceLibFlag, aapt2Flags)
- }
-
- // Check cert signing flag.
- signedApk := m.Output("signed/foo.apk")
- lineageFlag := signedApk.Args["flags"]
- expectedLineageFlag := "--lineage lineage.bin"
- if expectedLineageFlag != lineageFlag {
- t.Errorf("Incorrect signing lineage flags, expected: %q, got: %q", expectedLineageFlag, lineageFlag)
- }
- signingFlag := signedApk.Args["certificates"]
- expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8"
- if expected != signingFlag {
- t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
- }
- androidMkEntries := android.AndroidMkEntriesForTest(t, config, "", m.Module())[0]
- path := androidMkEntries.EntryMap["LOCAL_CERTIFICATE"]
- expectedPath := []string{"build/make/target/product/security/platform.x509.pem"}
- if !reflect.DeepEqual(path, expectedPath) {
- t.Errorf("Unexpected LOCAL_CERTIFICATE value: %v, expected: %v", path, expectedPath)
- }
-
- // Check device location.
- path = androidMkEntries.EntryMap["LOCAL_MODULE_PATH"]
- expectedPath = []string{"/tmp/target/product/test_device/product/overlay"}
- if !reflect.DeepEqual(path, expectedPath) {
- t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
- }
-
- // A themed module has a different device location
- m = ctx.ModuleForTests("foo_themed", "android_common")
- androidMkEntries = android.AndroidMkEntriesForTest(t, config, "", m.Module())[0]
- path = androidMkEntries.EntryMap["LOCAL_MODULE_PATH"]
- expectedPath = []string{"/tmp/target/product/test_device/product/overlay/faza"}
- if !reflect.DeepEqual(path, expectedPath) {
- t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
- }
-
- overrides := androidMkEntries.EntryMap["LOCAL_OVERRIDES_PACKAGES"]
- expectedOverrides := []string{"foo"}
- if !reflect.DeepEqual(overrides, expectedOverrides) {
- t.Errorf("Unexpected LOCAL_OVERRIDES_PACKAGES value: %v, expected: %v", overrides, expectedOverrides)
- }
-}
-
-func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) {
- ctx, config := testJava(t, `
- java_defaults {
- name: "rro_defaults",
- theme: "default_theme",
- product_specific: true,
- aaptflags: ["--keep-raw-values"],
- }
-
- runtime_resource_overlay {
- name: "foo_with_defaults",
- defaults: ["rro_defaults"],
- }
-
- runtime_resource_overlay {
- name: "foo_barebones",
- }
- `)
-
- //
- // RRO module with defaults
- //
- m := ctx.ModuleForTests("foo_with_defaults", "android_common")
-
- // Check AAPT2 link flags.
- aapt2Flags := strings.Split(m.Output("package-res.apk").Args["flags"], " ")
- expectedFlags := []string{"--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"}
- absentFlags := android.RemoveListFromList(expectedFlags, aapt2Flags)
- if len(absentFlags) > 0 {
- t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags)
- }
-
- // Check device location.
- path := android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
- expectedPath := []string{"/tmp/target/product/test_device/product/overlay/default_theme"}
- if !reflect.DeepEqual(path, expectedPath) {
- t.Errorf("Unexpected LOCAL_MODULE_PATH value: %q, expected: %q", path, expectedPath)
- }
-
- //
- // RRO module without defaults
- //
- m = ctx.ModuleForTests("foo_barebones", "android_common")
-
- // Check AAPT2 link flags.
- aapt2Flags = strings.Split(m.Output("package-res.apk").Args["flags"], " ")
- unexpectedFlags := "--keep-raw-values"
- if inList(unexpectedFlags, aapt2Flags) {
- t.Errorf("unexpected value, %q is present in aapt2 link flags, %q", unexpectedFlags, aapt2Flags)
- }
-
- // Check device location.
- path = android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
- expectedPath = []string{"/tmp/target/product/test_device/system/overlay"}
- if !reflect.DeepEqual(path, expectedPath) {
- t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
- }
-}
-
-func TestOverrideRuntimeResourceOverlay(t *testing.T) {
- ctx, _ := testJava(t, `
- runtime_resource_overlay {
- name: "foo_overlay",
- certificate: "platform",
- product_specific: true,
- sdk_version: "current",
- }
-
- override_runtime_resource_overlay {
- name: "bar_overlay",
- base: "foo_overlay",
- package_name: "com.android.bar.overlay",
- target_package_name: "com.android.bar",
- }
- `)
-
- expectedVariants := []struct {
- moduleName string
- variantName string
- apkPath string
- overrides []string
- targetVariant string
- packageFlag string
- targetPackageFlag string
- }{
- {
- variantName: "android_common",
- apkPath: "/target/product/test_device/product/overlay/foo_overlay.apk",
- overrides: nil,
- targetVariant: "android_common",
- packageFlag: "",
- targetPackageFlag: "",
- },
- {
- variantName: "android_common_bar_overlay",
- apkPath: "/target/product/test_device/product/overlay/bar_overlay.apk",
- overrides: []string{"foo_overlay"},
- targetVariant: "android_common_bar",
- packageFlag: "com.android.bar.overlay",
- targetPackageFlag: "com.android.bar",
- },
- }
- for _, expected := range expectedVariants {
- variant := ctx.ModuleForTests("foo_overlay", expected.variantName)
-
- // Check the final apk name
- outputs := variant.AllOutputs()
- expectedApkPath := buildDir + expected.apkPath
- found := false
- for _, o := range outputs {
- if o == expectedApkPath {
- found = true
- break
- }
- }
- if !found {
- t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs)
- }
-
- // Check if the overrides field values are correctly aggregated.
- mod := variant.Module().(*RuntimeResourceOverlay)
- if !reflect.DeepEqual(expected.overrides, mod.properties.Overrides) {
- t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
- expected.overrides, mod.properties.Overrides)
- }
-
- // Check aapt2 flags.
- res := variant.Output("package-res.apk")
- aapt2Flags := res.Args["flags"]
- checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag)
- checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", "")
- checkAapt2LinkFlag(t, aapt2Flags, "rename-overlay-target-package", expected.targetPackageFlag)
- }
-}
-
-func TestEnforceRRO_propagatesToDependencies(t *testing.T) {
- testCases := []struct {
- name string
- enforceRROTargets []string
- enforceRROExemptTargets []string
- rroDirs map[string][]string
- }{
- {
- name: "no RRO",
- enforceRROTargets: nil,
- enforceRROExemptTargets: nil,
- rroDirs: map[string][]string{
- "foo": nil,
- "bar": nil,
- },
- },
- {
- name: "enforce RRO on all",
- enforceRROTargets: []string{"*"},
- enforceRROExemptTargets: nil,
- rroDirs: map[string][]string{
- "foo": {"product/vendor/blah/overlay/lib2/res"},
- "bar": {"product/vendor/blah/overlay/lib2/res"},
- },
- },
- {
- name: "enforce RRO on foo",
- enforceRROTargets: []string{"foo"},
- enforceRROExemptTargets: nil,
- rroDirs: map[string][]string{
- "foo": {"product/vendor/blah/overlay/lib2/res"},
- "bar": {"product/vendor/blah/overlay/lib2/res"},
- },
- },
- {
- name: "enforce RRO on foo, bar exempted",
- enforceRROTargets: []string{"foo"},
- enforceRROExemptTargets: []string{"bar"},
- rroDirs: map[string][]string{
- "foo": {"product/vendor/blah/overlay/lib2/res"},
- "bar": nil,
- },
- },
- }
-
- productResourceOverlays := []string{
- "product/vendor/blah/overlay",
- }
-
- fs := map[string][]byte{
- "lib2/res/values/strings.xml": nil,
- "product/vendor/blah/overlay/lib2/res/values/strings.xml": nil,
- }
-
- bp := `
- android_app {
- name: "foo",
- sdk_version: "current",
- resource_dirs: [],
- static_libs: ["lib"],
- }
-
- android_app {
- name: "bar",
- sdk_version: "current",
- resource_dirs: [],
- static_libs: ["lib"],
- }
-
- android_library {
- name: "lib",
- sdk_version: "current",
- resource_dirs: [],
- static_libs: ["lib2"],
- }
-
- android_library {
- name: "lib2",
- sdk_version: "current",
- resource_dirs: ["lib2/res"],
- }
- `
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- config := testAppConfig(nil, bp, fs)
- config.TestProductVariables.ProductResourceOverlays = productResourceOverlays
- if testCase.enforceRROTargets != nil {
- config.TestProductVariables.EnforceRROTargets = testCase.enforceRROTargets
- }
- if testCase.enforceRROExemptTargets != nil {
- config.TestProductVariables.EnforceRROExemptedTargets = testCase.enforceRROExemptTargets
- }
-
- ctx := testContext(config)
- run(t, ctx, config)
-
- modules := []string{"foo", "bar"}
- for _, moduleName := range modules {
- module := ctx.ModuleForTests(moduleName, "android_common")
- mkEntries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
- actualRRODirs := mkEntries.EntryMap["LOCAL_SOONG_PRODUCT_RRO_DIRS"]
- if !reflect.DeepEqual(actualRRODirs, testCase.rroDirs[moduleName]) {
- t.Errorf("exected %s LOCAL_SOONG_PRODUCT_RRO_DIRS entry: %v\ngot:%q",
- moduleName, testCase.rroDirs[moduleName], actualRRODirs)
- }
- }
- })
- }
-}
-
func TestExportedProguardFlagFiles(t *testing.T) {
ctx, _ := testJava(t, `
android_app {