Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55f72d70 authored by Ulya Trafimovich's avatar Ulya Trafimovich
Browse files

Add tests for uncompressed dex for `android_app_import`.

Some of the test cases for privileged apps currently produce incorrect
results (e.g. with DONT_UNCOMPRESS_PRIV_APPS_DEXS := true); they are
marked with TODO and will be fixed in a follow-up CL.

Bug: 194504107
Test: m nothing
Change-Id: Ic0cd24113a27850a967afa0b3deb4a6324f95347
parent b37a92cc
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package java

import (
	"fmt"
	"reflect"
	"regexp"
	"strings"
@@ -656,3 +657,74 @@ func TestAndroidTestImport_Preprocessed(t *testing.T) {
		}
	}
}

func TestAndroidTestImport_UncompressDex(t *testing.T) {
	testCases := []struct {
		name string
		bp   string
	}{
		{
			name: "normal",
			bp: `
				android_app_import {
					name: "foo",
					presigned: true,
					apk: "prebuilts/apk/app.apk",
				}
			`,
		},
		{
			name: "privileged",
			bp: `
				android_app_import {
					name: "foo",
					presigned: true,
					privileged: true,
					apk: "prebuilts/apk/app.apk",
				}
			`,
		},
	}

	test := func(t *testing.T, bp string, unbundled bool, dontUncompressPrivAppDexs bool) {
		t.Helper()

		result := android.GroupFixturePreparers(
			prepareForJavaTest,
			android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
				if unbundled {
					variables.Unbundled_build = proptools.BoolPtr(true)
				}
				variables.UncompressPrivAppDex = proptools.BoolPtr(!dontUncompressPrivAppDexs)
			}),
		).RunTestWithBp(t, bp)

		foo := result.ModuleForTests("foo", "android_common")
		actual := foo.MaybeRule("uncompress-dex").Rule != nil

		expect := !unbundled
		if strings.Contains(bp, "privileged: true") {
			if dontUncompressPrivAppDexs {
				// TODO(b/194504107): DONT_UNCOMPRESS_PRIV_APPS_DEXS should disable uncompression of priv-apps no matter what.
				// expect = false
			} else {
				// TODO(b/194504107): shouldn't priv-apps be always uncompressed unless DONT_UNCOMPRESS_PRIV_APPS_DEXS is true?
				// expect = true
			}
		}

		android.AssertBoolEquals(t, "uncompress dex", expect, actual)
	}

	for _, unbundled := range []bool{false, true} {
		for _, dontUncompressPrivAppDexs := range []bool{false, true} {
			for _, tt := range testCases {
				name := fmt.Sprintf("%s,unbundled:%t,dontUncompressPrivAppDexs:%t",
					tt.name, unbundled, dontUncompressPrivAppDexs)
				t.Run(name, func(t *testing.T) {
					test(t, tt.bp, unbundled, dontUncompressPrivAppDexs)
				})
			}
		}
	}
}