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

Commit 31029217 authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Automerger Merge Worker
Browse files

Merge "Refactor test to use Go subtests idiom." am: 56b92cf1

Change-Id: Ia9d181d43b8edacf023636ab561ccf8e4e7fc10a
parents df88e6fd 56b92cf1
Loading
Loading
Loading
Loading
+131 −122
Original line number Diff line number Diff line
@@ -4508,10 +4508,78 @@ func TestAppBundle(t *testing.T) {
	ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
}

func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) {
func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) {
	t.Helper()

	bp = bp + `
	bp := `
		java_library {
			name: "some-updatable-apex-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			apex_available: [
				"some-updatable-apex",
			],
		}

		java_library {
			name: "some-non-updatable-apex-lib",
			srcs: ["a.java"],
			apex_available: [
				"some-non-updatable-apex",
			],
		}

		java_library {
			name: "some-platform-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			installable: true,
		}

		java_library {
			name: "some-art-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			apex_available: [
				"com.android.art.something",
			],
			hostdex: true,
		}

		apex {
			name: "some-updatable-apex",
			key: "some-updatable-apex.key",
			java_libs: ["some-updatable-apex-lib"],
			updatable: true,
			min_sdk_version: "current",
		}

		apex {
			name: "some-non-updatable-apex",
			key: "some-non-updatable-apex.key",
			java_libs: ["some-non-updatable-apex-lib"],
		}

		apex_key {
			name: "some-updatable-apex.key",
		}

		apex_key {
			name: "some-non-updatable-apex.key",
		}

		apex {
			name: "com.android.art.something",
			key: "com.android.art.something.key",
			java_libs: ["some-art-lib"],
			updatable: true,
			min_sdk_version: "current",
		}

		apex_key {
			name: "com.android.art.something.key",
		}

		filegroup {
			name: "some-updatable-apex-file_contexts",
			srcs: [
@@ -4598,145 +4666,86 @@ func TestUpdatable_should_set_min_sdk_version(t *testing.T) {
}

func TestNoUpdatableJarsInBootImage(t *testing.T) {
	bp := `
		java_library {
			name: "some-updatable-apex-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			apex_available: [
				"some-updatable-apex",
			],
		}

		java_library {
			name: "some-non-updatable-apex-lib",
			srcs: ["a.java"],
			apex_available: [
				"some-non-updatable-apex",
			],
		}

		java_library {
			name: "some-platform-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			installable: true,
		}

		java_library {
			name: "some-art-lib",
			srcs: ["a.java"],
			sdk_version: "current",
			apex_available: [
				"com.android.art.something",
			],
			hostdex: true,
		}

		apex {
			name: "some-updatable-apex",
			key: "some-updatable-apex.key",
			java_libs: ["some-updatable-apex-lib"],
			updatable: true,
			min_sdk_version: "current",
		}

		apex {
			name: "some-non-updatable-apex",
			key: "some-non-updatable-apex.key",
			java_libs: ["some-non-updatable-apex-lib"],
		}

		apex_key {
			name: "some-updatable-apex.key",
		}

		apex_key {
			name: "some-non-updatable-apex.key",
		}

		apex {
			name: "com.android.art.something",
			key: "com.android.art.something.key",
			java_libs: ["some-art-lib"],
			updatable: true,
			min_sdk_version: "current",
		}

		apex_key {
			name: "com.android.art.something.key",
		}
	`

	var error string
	var transform func(*dexpreopt.GlobalConfig)

	// updatable jar from ART apex in the ART boot image => ok
	t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = []string{"com.android.art.something:some-art-lib"}
		}
	testNoUpdatableJarsInBootImage(t, "", bp, transform)
		testNoUpdatableJarsInBootImage(t, "", transform)
	})

	// updatable jar from ART apex in the framework boot image => error
	t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) {
		error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = []string{"com.android.art.something:some-art-lib"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// updatable jar from some other apex in the ART boot image => error
	t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
		error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = []string{"some-updatable-apex:some-updatable-apex-lib"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// non-updatable jar from some other apex in the ART boot image => error
	t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
		error = "module 'some-non-updatable-apex-lib' is not allowed in the ART boot image"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// updatable jar from some other apex in the framework boot image => error
	t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) {
		error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = []string{"some-updatable-apex:some-updatable-apex-lib"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// non-updatable jar from some other apex in the framework boot image => ok
	t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}
		}
	testNoUpdatableJarsInBootImage(t, "", bp, transform)
		testNoUpdatableJarsInBootImage(t, "", transform)
	})

	// nonexistent jar in the ART boot image => error
	t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) {
		error = "failed to find a dex jar path for module 'nonexistent'"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = []string{"platform:nonexistent"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// nonexistent jar in the framework boot image => error
	t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) {
		error = "failed to find a dex jar path for module 'nonexistent'"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = []string{"platform:nonexistent"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// platform jar in the ART boot image => error
	t.Run("platform jar in the ART boot image => error", func(t *testing.T) {
		error = "module 'some-platform-lib' is not allowed in the ART boot image"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = []string{"platform:some-platform-lib"}
		}
	testNoUpdatableJarsInBootImage(t, error, bp, transform)
		testNoUpdatableJarsInBootImage(t, error, transform)
	})

	// platform jar in the framework boot image => ok
	t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = []string{"platform:some-platform-lib"}
		}
	testNoUpdatableJarsInBootImage(t, "", bp, transform)
		testNoUpdatableJarsInBootImage(t, "", transform)
	})
}

func TestTestFor(t *testing.T) {