2021-05-17 22:35:26 +02:00
|
|
|
// Copyright (C) 2021 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package apex
|
|
|
|
|
|
|
|
import (
|
2023-02-15 23:43:09 +01:00
|
|
|
"strings"
|
2021-05-17 22:35:26 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2023-02-15 23:43:09 +01:00
|
|
|
"android/soong/dexpreopt"
|
2021-05-17 22:35:26 +02:00
|
|
|
"android/soong/java"
|
|
|
|
)
|
|
|
|
|
|
|
|
var prepareForTestWithSystemserverclasspathFragment = android.GroupFixturePreparers(
|
|
|
|
java.PrepareForTestWithDexpreopt,
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSystemserverclasspathFragmentContents(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
2023-02-15 23:43:09 +01:00
|
|
|
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"),
|
2021-05-17 22:35:26 +02:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
systemserverclasspath_fragments: [
|
|
|
|
"mysystemserverclasspathfragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-07 18:19:19 +01:00
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
installable: true,
|
|
|
|
dex_preopt: {
|
|
|
|
profile: "bar-art-profile",
|
|
|
|
},
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-15 23:43:09 +01:00
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["d.java"],
|
|
|
|
installable: true,
|
|
|
|
dex_preopt: {
|
|
|
|
profile_guided: true, // ignored
|
|
|
|
},
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-05-17 22:35:26 +02:00
|
|
|
systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
contents: [
|
|
|
|
"foo",
|
2023-02-07 18:19:19 +01:00
|
|
|
"bar",
|
2023-02-15 23:43:09 +01:00
|
|
|
"baz",
|
2021-05-17 22:35:26 +02:00
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2023-02-15 23:43:09 +01:00
|
|
|
ctx := result.TestContext
|
|
|
|
|
2023-08-23 06:12:50 +02:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
|
2021-05-20 22:35:06 +02:00
|
|
|
"etc/classpaths/systemserverclasspath.pb",
|
2021-05-17 22:35:26 +02:00
|
|
|
"javalib/foo.jar",
|
2023-02-07 18:19:19 +01:00
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/bar.jar.prof",
|
2023-02-15 23:43:09 +01:00
|
|
|
"javalib/baz.jar",
|
2021-05-17 22:35:26 +02:00
|
|
|
})
|
|
|
|
|
2023-08-23 06:12:50 +02:00
|
|
|
java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{
|
2021-05-17 22:35:26 +02:00
|
|
|
`myapex.key`,
|
|
|
|
`mysystemserverclasspathfragment`,
|
|
|
|
})
|
2023-02-15 23:43:09 +01:00
|
|
|
|
|
|
|
assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
|
|
|
|
assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
|
|
|
|
assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
|
2021-05-17 22:35:26 +02:00
|
|
|
}
|
2021-06-15 17:49:50 +02:00
|
|
|
|
|
|
|
func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
2021-08-06 18:49:46 +02:00
|
|
|
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
|
2021-06-15 17:49:50 +02:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
systemserverclasspath_fragments: [
|
|
|
|
"mysystemserverclasspathfragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
generate_classpaths_proto: false,
|
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2023-08-23 06:12:50 +02:00
|
|
|
ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex", []string{
|
2021-06-15 17:49:50 +02:00
|
|
|
"javalib/foo.jar",
|
|
|
|
})
|
|
|
|
|
2023-08-23 06:12:50 +02:00
|
|
|
java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{
|
2021-06-15 17:49:50 +02:00
|
|
|
`myapex.key`,
|
|
|
|
`mysystemserverclasspathfragment`,
|
|
|
|
})
|
|
|
|
}
|
2021-08-06 14:20:28 +02:00
|
|
|
|
|
|
|
func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) {
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
2021-10-04 16:42:53 +02:00
|
|
|
`in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS`)).
|
2021-08-06 14:20:28 +02:00
|
|
|
RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
systemserverclasspath_fragments: [
|
|
|
|
"mysystemserverclasspathfragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
"bar",
|
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
2021-09-26 05:52:19 +02:00
|
|
|
|
|
|
|
func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
2023-02-08 14:56:07 +01:00
|
|
|
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar"),
|
2021-09-26 05:52:19 +02:00
|
|
|
).RunTestWithBp(t, `
|
2021-09-26 05:54:25 +02:00
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
src: "myapex-arm64.apex",
|
|
|
|
},
|
|
|
|
arm: {
|
|
|
|
src: "myapex-arm.apex",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
|
|
|
|
}
|
|
|
|
|
2021-09-26 05:52:19 +02:00
|
|
|
java_import {
|
|
|
|
name: "foo",
|
|
|
|
jars: ["foo.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-08 14:56:07 +01:00
|
|
|
java_import {
|
|
|
|
name: "bar",
|
|
|
|
jars: ["bar.jar"],
|
|
|
|
dex_preopt: {
|
|
|
|
profile_guided: true,
|
|
|
|
},
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-09-26 05:52:19 +02:00
|
|
|
prebuilt_systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
prefer: true,
|
|
|
|
contents: [
|
|
|
|
"foo",
|
2023-02-08 14:56:07 +01:00
|
|
|
"bar",
|
2021-09-26 05:52:19 +02:00
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2023-02-08 14:56:07 +01:00
|
|
|
ctx := result.TestContext
|
|
|
|
|
|
|
|
java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{
|
2023-12-06 20:40:24 +01:00
|
|
|
`dex2oatd`,
|
2024-01-03 19:57:03 +01:00
|
|
|
`prebuilt_myapex.apex.selector`,
|
|
|
|
`prebuilt_myapex.deapexer`,
|
2021-09-26 05:54:25 +02:00
|
|
|
`prebuilt_mysystemserverclasspathfragment`,
|
|
|
|
})
|
|
|
|
|
2023-02-08 14:56:07 +01:00
|
|
|
java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
|
|
|
|
`prebuilt_bar`,
|
2021-09-26 05:52:19 +02:00
|
|
|
`prebuilt_foo`,
|
2024-01-03 19:57:03 +01:00
|
|
|
`prebuilt_myapex.deapexer`,
|
2021-09-26 05:52:19 +02:00
|
|
|
})
|
2023-02-08 14:56:07 +01:00
|
|
|
|
2024-01-03 19:57:03 +01:00
|
|
|
ensureExactDeapexedContents(t, ctx, "prebuilt_myapex", "android_common", []string{
|
2023-02-08 14:56:07 +01:00
|
|
|
"javalib/foo.jar",
|
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/bar.jar.prof",
|
|
|
|
})
|
|
|
|
|
|
|
|
assertProfileGuided(t, ctx, "foo", "android_common_myapex", false)
|
|
|
|
assertProfileGuided(t, ctx, "bar", "android_common_myapex", true)
|
2021-09-26 05:52:19 +02:00
|
|
|
}
|
2021-10-29 21:46:45 +02:00
|
|
|
|
|
|
|
func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
2023-02-15 23:43:09 +01:00
|
|
|
dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"),
|
2021-10-29 21:46:45 +02:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
systemserverclasspath_fragments: [
|
|
|
|
"mysystemserverclasspathfragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-07 18:19:19 +01:00
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
dex_preopt: {
|
|
|
|
profile: "bar-art-profile",
|
|
|
|
},
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-15 23:43:09 +01:00
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["d.java"],
|
|
|
|
dex_preopt: {
|
|
|
|
profile_guided: true, // ignored
|
|
|
|
},
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:46:45 +02:00
|
|
|
systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
standalone_contents: [
|
|
|
|
"foo",
|
2023-02-07 18:19:19 +01:00
|
|
|
"bar",
|
2023-02-15 23:43:09 +01:00
|
|
|
"baz",
|
2021-10-29 21:46:45 +02:00
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2023-02-15 23:43:09 +01:00
|
|
|
ctx := result.TestContext
|
|
|
|
|
2023-08-23 06:12:50 +02:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
|
2021-10-29 21:46:45 +02:00
|
|
|
"etc/classpaths/systemserverclasspath.pb",
|
|
|
|
"javalib/foo.jar",
|
2023-02-07 18:19:19 +01:00
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/bar.jar.prof",
|
2023-02-15 23:43:09 +01:00
|
|
|
"javalib/baz.jar",
|
2021-10-29 21:46:45 +02:00
|
|
|
})
|
2023-02-15 23:43:09 +01:00
|
|
|
|
|
|
|
assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
|
|
|
|
assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
|
|
|
|
assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
|
2021-10-29 21:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithSystemserverclasspathFragment,
|
|
|
|
prepareForTestWithMyapex,
|
2023-02-08 14:56:07 +01:00
|
|
|
dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar"),
|
2021-10-29 21:46:45 +02:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
src: "myapex-arm64.apex",
|
|
|
|
},
|
|
|
|
arm: {
|
|
|
|
src: "myapex-arm.apex",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "foo",
|
|
|
|
jars: ["foo.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2023-02-08 14:56:07 +01:00
|
|
|
java_import {
|
|
|
|
name: "bar",
|
|
|
|
jars: ["bar.jar"],
|
|
|
|
dex_preopt: {
|
|
|
|
profile_guided: true,
|
|
|
|
},
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:46:45 +02:00
|
|
|
prebuilt_systemserverclasspath_fragment {
|
|
|
|
name: "mysystemserverclasspathfragment",
|
|
|
|
prefer: true,
|
|
|
|
standalone_contents: [
|
|
|
|
"foo",
|
2023-02-08 14:56:07 +01:00
|
|
|
"bar",
|
2021-10-29 21:46:45 +02:00
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2023-02-08 14:56:07 +01:00
|
|
|
ctx := result.TestContext
|
|
|
|
|
|
|
|
java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
|
|
|
|
`prebuilt_bar`,
|
2021-10-29 21:46:45 +02:00
|
|
|
`prebuilt_foo`,
|
2024-01-03 19:57:03 +01:00
|
|
|
`prebuilt_myapex.deapexer`,
|
2021-10-29 21:46:45 +02:00
|
|
|
})
|
2023-02-08 14:56:07 +01:00
|
|
|
|
2024-01-03 19:57:03 +01:00
|
|
|
ensureExactDeapexedContents(t, ctx, "prebuilt_myapex", "android_common", []string{
|
2023-02-08 14:56:07 +01:00
|
|
|
"javalib/foo.jar",
|
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/bar.jar.prof",
|
|
|
|
})
|
|
|
|
|
|
|
|
assertProfileGuided(t, ctx, "foo", "android_common_myapex", false)
|
|
|
|
assertProfileGuided(t, ctx, "bar", "android_common_myapex", true)
|
2021-10-29 21:46:45 +02:00
|
|
|
}
|
2023-02-15 23:43:09 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|