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

Commit 7c47515c authored by Paul Duffin's avatar Paul Duffin
Browse files

Make bootclasspath_fragment_sdk_test.go tests more realistic

In the input test fixture this makes sure that every
bootclasspath_fragment is part of an apex and every content module for
the fragment is listed in the appropriate boot jars config property. It
also adds a platform_bootclasspath fragment that references the
fragment.

In the snapshot test fixtures this adds a prebuilt_apex that exports
the fragment so that the platform_bootclasspath has access to the dex
implementation files.

Bug: 177892522
Test: m nothing
Change-Id: I6c73651a359052858232b06229b4433799dd94db
parent dc3f9566
Loading
Loading
Loading
Loading
+102 −41
Original line number Original line Diff line number Diff line
@@ -15,12 +15,53 @@
package sdk
package sdk


import (
import (
	"fmt"
	"path/filepath"
	"testing"
	"testing"


	"android/soong/android"
	"android/soong/android"
	"android/soong/java"
	"android/soong/java"
)
)


// fixtureAddPlatformBootclasspathForBootclasspathFragment adds a platform_bootclasspath module that
// references the bootclasspath fragment.
func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
	return android.GroupFixturePreparers(
		// Add a platform_bootclasspath module.
		android.FixtureAddTextFile("frameworks/base/boot/Android.bp", fmt.Sprintf(`
			platform_bootclasspath {
				name: "platform-bootclasspath",
				fragments: [
					{
						apex: "%s",
						module: "%s",
					},
				],
			}
		`, apex, fragment)),
		android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),
	)
}

// fixtureAddPrebuiltApexForBootclasspathFragment adds a prebuilt_apex that exports the fragment.
func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
	apexFile := fmt.Sprintf("%s.apex", apex)
	dir := "prebuilts/apex"
	return android.GroupFixturePreparers(
		// A preparer to add a prebuilt apex to the test fixture.
		android.FixtureAddTextFile(filepath.Join(dir, "Android.bp"), fmt.Sprintf(`
			prebuilt_apex {
				name: "%s",
				src: "%s",
				exported_bootclasspath_fragments: [
					"%s",
				],
			}
		`, apex, apexFile, fragment)),
		android.FixtureAddFile(filepath.Join(dir, apexFile), nil),
	)
}

func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
	result := android.GroupFixturePreparers(
	result := android.GroupFixturePreparers(
		prepareForSdkTestWithJava,
		prepareForSdkTestWithJava,
@@ -34,20 +75,8 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
			"system/sepolicy/apex/com.android.art-file_contexts": nil,
			"system/sepolicy/apex/com.android.art-file_contexts": nil,
		}),
		}),


		// platform_bootclasspath that depends on the fragment.
		// Add a platform_bootclasspath that depends on the fragment.
		android.FixtureAddTextFile("frameworks/base/boot/Android.bp", `
		fixtureAddPlatformBootclasspathForBootclasspathFragment("com.android.art", "mybootclasspathfragment"),
			platform_bootclasspath {
				name: "platform-bootclasspath",
				fragments: [
					{
						apex: "com.android.art",
						module: "mybootclasspathfragment",
					},
				],
			}
		`),
		// Needed for platform_bootclasspath
		android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),


		java.FixtureConfigureBootJars("com.android.art:mybootlib"),
		java.FixtureConfigureBootJars("com.android.art:mybootlib"),
		android.FixtureWithRootAndroidBp(`
		android.FixtureWithRootAndroidBp(`
@@ -89,19 +118,8 @@ func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
		`),
		`),
	).RunTest(t)
	).RunTest(t)


	// A preparer to add a prebuilt apex to the test fixture.
	// A preparer to update the test fixture used when processing an unpackage snapshot.
	prepareWithPrebuiltApex := android.GroupFixturePreparers(
	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment")
		android.FixtureAddTextFile("prebuilts/apex/Android.bp", `
				prebuilt_apex {
					name: "com.android.art",
					src: "art.apex",
					exported_bootclasspath_fragments: [
						"mybootclasspathfragment",
					],
				}
			`),
		android.FixtureAddFile("prebuilts/apex/art.apex", nil),
	)


	CheckSnapshot(t, result, "mysdk", "",
	CheckSnapshot(t, result, "mysdk", "",
		checkUnversionedAndroidBpContents(`
		checkUnversionedAndroidBpContents(`
@@ -154,9 +172,9 @@ sdk_snapshot {
		checkAllCopyRules(`
		checkAllCopyRules(`
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
`),
`),
		snapshotTestPreparer(checkSnapshotWithoutSource, prepareWithPrebuiltApex),
		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotWithSourcePreferred, prepareWithPrebuiltApex),
		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotPreferredWithSource, prepareWithPrebuiltApex),
		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
	)
	)
}
}


@@ -166,6 +184,12 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
		java.PrepareForTestWithJavaDefaultModules,
		java.PrepareForTestWithJavaDefaultModules,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
		java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
		java.FixtureConfigureUpdatableBootJars("myapex:mybootlib", "myapex:myothersdklibrary"),
		prepareForSdkTestWithApex,

		// Add a platform_bootclasspath that depends on the fragment.
		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),

		android.FixtureWithRootAndroidBp(`
		android.FixtureWithRootAndroidBp(`
			sdk {
			sdk {
				name: "mysdk",
				name: "mysdk",
@@ -179,8 +203,16 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
				],
				],
			}
			}


			apex {
				name: "myapex",
				key: "myapex.key",
				min_sdk_version: "2",
				bootclasspath_fragments: ["mybootclasspathfragment"],
			}

			bootclasspath_fragment {
			bootclasspath_fragment {
				name: "mybootclasspathfragment",
				name: "mybootclasspathfragment",
				apex_available: ["myapex"],
				contents: [
				contents: [
					// This should be automatically added to the sdk_snapshot as a java_boot_libs module.
					// This should be automatically added to the sdk_snapshot as a java_boot_libs module.
					"mybootlib",
					"mybootlib",
@@ -198,35 +230,48 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {


			java_library {
			java_library {
				name: "mybootlib",
				name: "mybootlib",
				apex_available: ["myapex"],
				srcs: ["Test.java"],
				srcs: ["Test.java"],
				system_modules: "none",
				system_modules: "none",
				sdk_version: "none",
				sdk_version: "none",
				min_sdk_version: "2",
				compile_dex: true,
				compile_dex: true,
				permitted_packages: ["mybootlib"],
			}
			}


			java_sdk_library {
			java_sdk_library {
				name: "mysdklibrary",
				name: "mysdklibrary",
				apex_available: ["myapex"],
				srcs: ["Test.java"],
				srcs: ["Test.java"],
				shared_library: false,
				shared_library: false,
				public: {enabled: true},
				public: {enabled: true},
				min_sdk_version: "2",
			}
			}


			java_sdk_library {
			java_sdk_library {
				name: "myothersdklibrary",
				name: "myothersdklibrary",
				apex_available: ["myapex"],
				srcs: ["Test.java"],
				srcs: ["Test.java"],
				shared_library: false,
				shared_library: false,
				public: {enabled: true},
				public: {enabled: true},
				min_sdk_version: "2",
				permitted_packages: ["myothersdklibrary"],
			}
			}


			java_sdk_library {
			java_sdk_library {
				name: "mycoreplatform",
				name: "mycoreplatform",
				apex_available: ["myapex"],
				srcs: ["Test.java"],
				srcs: ["Test.java"],
				shared_library: false,
				shared_library: false,
				public: {enabled: true},
				public: {enabled: true},
				min_sdk_version: "2",
			}
			}
		`),
		`),
	).RunTest(t)
	).RunTest(t)


	// A preparer to update the test fixture used when processing an unpackage snapshot.
	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")

	CheckSnapshot(t, result, "mysdk", "",
	CheckSnapshot(t, result, "mysdk", "",
		checkUnversionedAndroidBpContents(`
		checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
// This is auto-generated. DO NOT EDIT.
@@ -235,7 +280,7 @@ prebuilt_bootclasspath_fragment {
    name: "mybootclasspathfragment",
    name: "mybootclasspathfragment",
    prefer: false,
    prefer: false,
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    contents: [
    contents: [
        "mybootlib",
        "mybootlib",
        "myothersdklibrary",
        "myothersdklibrary",
@@ -259,7 +304,7 @@ java_import {
    name: "mybootlib",
    name: "mybootlib",
    prefer: false,
    prefer: false,
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    jars: ["java/mybootlib.jar"],
    jars: ["java/mybootlib.jar"],
}
}


@@ -267,7 +312,7 @@ java_sdk_library_import {
    name: "myothersdklibrary",
    name: "myothersdklibrary",
    prefer: false,
    prefer: false,
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
        jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
@@ -282,7 +327,7 @@ java_sdk_library_import {
    name: "mysdklibrary",
    name: "mysdklibrary",
    prefer: false,
    prefer: false,
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
@@ -297,7 +342,7 @@ java_sdk_library_import {
    name: "mycoreplatform",
    name: "mycoreplatform",
    prefer: false,
    prefer: false,
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
@@ -315,7 +360,7 @@ prebuilt_bootclasspath_fragment {
    name: "mysdk_mybootclasspathfragment@current",
    name: "mysdk_mybootclasspathfragment@current",
    sdk_member_name: "mybootclasspathfragment",
    sdk_member_name: "mybootclasspathfragment",
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    contents: [
    contents: [
        "mysdk_mybootlib@current",
        "mysdk_mybootlib@current",
        "mysdk_myothersdklibrary@current",
        "mysdk_myothersdklibrary@current",
@@ -339,7 +384,7 @@ java_import {
    name: "mysdk_mybootlib@current",
    name: "mysdk_mybootlib@current",
    sdk_member_name: "mybootlib",
    sdk_member_name: "mybootlib",
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    jars: ["java/mybootlib.jar"],
    jars: ["java/mybootlib.jar"],
}
}


@@ -347,7 +392,7 @@ java_sdk_library_import {
    name: "mysdk_myothersdklibrary@current",
    name: "mysdk_myothersdklibrary@current",
    sdk_member_name: "myothersdklibrary",
    sdk_member_name: "myothersdklibrary",
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
        jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
@@ -362,7 +407,7 @@ java_sdk_library_import {
    name: "mysdk_mysdklibrary@current",
    name: "mysdk_mysdklibrary@current",
    sdk_member_name: "mysdklibrary",
    sdk_member_name: "mysdklibrary",
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
@@ -377,7 +422,7 @@ java_sdk_library_import {
    name: "mysdk_mycoreplatform@current",
    name: "mysdk_mycoreplatform@current",
    sdk_member_name: "mycoreplatform",
    sdk_member_name: "mycoreplatform",
    visibility: ["//visibility:public"],
    visibility: ["//visibility:public"],
    apex_available: ["//apex_available:platform"],
    apex_available: ["myapex"],
    shared_library: false,
    shared_library: false,
    public: {
    public: {
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
@@ -416,7 +461,11 @@ sdk_snapshot {
.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar
.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
`))
`),
		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
	)
}
}


// Test that bootclasspath_fragment works with sdk.
// Test that bootclasspath_fragment works with sdk.
@@ -482,7 +531,12 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
		java.PrepareForTestWithJavaDefaultModules,
		java.PrepareForTestWithJavaDefaultModules,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.FixtureWithLastReleaseApis("mysdklibrary"),
		java.FixtureWithLastReleaseApis("mysdklibrary"),
		java.FixtureConfigureUpdatableBootJars("myapex:mybootlib"),
		prepareForSdkTestWithApex,
		prepareForSdkTestWithApex,

		// Add a platform_bootclasspath that depends on the fragment.
		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),

		android.MockFS{
		android.MockFS{
			"my-blocked.txt":                   nil,
			"my-blocked.txt":                   nil,
			"my-max-target-o-low-priority.txt": nil,
			"my-max-target-o-low-priority.txt": nil,
@@ -549,6 +603,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
				sdk_version: "none",
				sdk_version: "none",
				min_sdk_version: "1",
				min_sdk_version: "1",
				compile_dex: true,
				compile_dex: true,
				permitted_packages: ["mybootlib"],
			}
			}


			java_sdk_library {
			java_sdk_library {
@@ -560,6 +615,9 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
		`),
		`),
	).RunTest(t)
	).RunTest(t)


	// A preparer to update the test fixture used when processing an unpackage snapshot.
	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")

	CheckSnapshot(t, result, "mysdk", "",
	CheckSnapshot(t, result, "mysdk", "",
		checkUnversionedAndroidBpContents(`
		checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
// This is auto-generated. DO NOT EDIT.
@@ -633,5 +691,8 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
`),
`),
		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
	)
	)
}
}