From 1f4542c85bfadbac6cd0860057e401393231f2e5 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 15 Feb 2023 22:43:09 +0000 Subject: [PATCH] Add tests for the ignored "profile_guided: true" property. This is tricky and is worth some tests. Bug: 241823638 Test: m nothing Change-Id: I9c09451d075dca7563eb42c63812375cfd974fbf --- apex/systemserver_classpath_fragment_test.go | 61 ++++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go index c404a2e37..1803fcfb9 100644 --- a/apex/systemserver_classpath_fragment_test.go +++ b/apex/systemserver_classpath_fragment_test.go @@ -15,10 +15,11 @@ package apex import ( - "android/soong/dexpreopt" + "strings" "testing" "android/soong/android" + "android/soong/dexpreopt" "android/soong/java" ) @@ -31,7 +32,7 @@ func TestSystemserverclasspathFragmentContents(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithSystemserverclasspathFragment, prepareForTestWithMyapex, - dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar"), + dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"), ).RunTestWithBp(t, ` apex { name: "myapex", @@ -69,11 +70,24 @@ func TestSystemserverclasspathFragmentContents(t *testing.T) { ], } + java_library { + name: "baz", + srcs: ["d.java"], + installable: true, + dex_preopt: { + profile_guided: true, // ignored + }, + apex_available: [ + "myapex", + ], + } + systemserverclasspath_fragment { name: "mysystemserverclasspathfragment", contents: [ "foo", "bar", + "baz", ], apex_available: [ "myapex", @@ -81,17 +95,24 @@ func TestSystemserverclasspathFragmentContents(t *testing.T) { } `) - ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ + ctx := result.TestContext + + ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ "etc/classpaths/systemserverclasspath.pb", "javalib/foo.jar", "javalib/bar.jar", "javalib/bar.jar.prof", + "javalib/baz.jar", }) - java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ + java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex_image", []string{ `myapex.key`, `mysystemserverclasspathfragment`, }) + + assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false) + assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true) + assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false) } func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) { @@ -251,7 +272,7 @@ func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithSystemserverclasspathFragment, prepareForTestWithMyapex, - dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar"), + dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"), ).RunTestWithBp(t, ` apex { name: "myapex", @@ -289,11 +310,24 @@ func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) { ], } + java_library { + name: "baz", + srcs: ["d.java"], + dex_preopt: { + profile_guided: true, // ignored + }, + installable: true, + apex_available: [ + "myapex", + ], + } + systemserverclasspath_fragment { name: "mysystemserverclasspathfragment", standalone_contents: [ "foo", "bar", + "baz", ], apex_available: [ "myapex", @@ -301,12 +335,19 @@ func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) { } `) - ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ + ctx := result.TestContext + + ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ "etc/classpaths/systemserverclasspath.pb", "javalib/foo.jar", "javalib/bar.jar", "javalib/bar.jar.prof", + "javalib/baz.jar", }) + + assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false) + assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true) + assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false) } func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) { @@ -353,3 +394,11 @@ func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) { `prebuilt_foo`, }) } + +func assertProfileGuided(t *testing.T, ctx *android.TestContext, moduleName string, variant string, expected bool) { + dexpreopt := ctx.ModuleForTests(moduleName, variant).Rule("dexpreopt") + actual := strings.Contains(dexpreopt.RuleParams.Command, "--profile-file=") + if expected != actual { + t.Fatalf("Expected profile-guided to be %v, got %v", expected, actual) + } +}