2021-01-20 16:16:56 +01: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 java
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-03-24 00:13:53 +01:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
2021-01-20 16:16:56 +01:00
|
|
|
)
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Contains some simple tests for bootclasspath_fragment logic, additional tests can be found in
|
|
|
|
// apex/bootclasspath_fragment_test.go as the ART boot image requires modules from the ART apex.
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
|
2021-03-24 00:13:53 +01:00
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
dexpreopt.PrepareForTestByEnablingDexpreopt,
|
|
|
|
)
|
|
|
|
|
2021-05-21 20:28:09 +02:00
|
|
|
func TestBootclasspathFragment_UnknownImageName(t *testing.T) {
|
2021-04-23 15:25:28 +02:00
|
|
|
prepareForTestWithBootclasspathFragment.
|
2021-03-24 00:13:53 +01:00
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
2021-05-21 20:28:09 +02:00
|
|
|
`\Qimage_name: unknown image name "unknown", expected "art"\E`)).
|
2021-03-24 00:13:53 +01:00
|
|
|
RunTestWithBp(t, `
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "unknown-bootclasspath-fragment",
|
2021-03-24 00:13:53 +01:00
|
|
|
image_name: "unknown",
|
2021-05-21 20:28:09 +02:00
|
|
|
contents: ["foo"],
|
2021-03-24 00:13:53 +01:00
|
|
|
}
|
|
|
|
`)
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
2021-03-10 16:00:46 +01:00
|
|
|
|
2021-05-21 20:28:09 +02:00
|
|
|
func TestPrebuiltBootclasspathFragment_UnknownImageName(t *testing.T) {
|
2021-04-23 15:25:28 +02:00
|
|
|
prepareForTestWithBootclasspathFragment.
|
2021-03-29 12:02:53 +02:00
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
2021-05-21 20:28:09 +02:00
|
|
|
`\Qimage_name: unknown image name "unknown", expected "art"\E`)).
|
2021-03-24 00:13:53 +01:00
|
|
|
RunTestWithBp(t, `
|
2021-04-23 15:25:28 +02:00
|
|
|
prebuilt_bootclasspath_fragment {
|
|
|
|
name: "unknown-bootclasspath-fragment",
|
2021-03-24 00:13:53 +01:00
|
|
|
image_name: "unknown",
|
2021-05-21 20:28:09 +02:00
|
|
|
contents: ["foo"],
|
2021-03-24 00:13:53 +01:00
|
|
|
}
|
|
|
|
`)
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func TestBootclasspathFragmentInconsistentArtConfiguration_Platform(t *testing.T) {
|
2021-03-24 00:21:59 +01:00
|
|
|
android.GroupFixturePreparers(
|
2021-04-23 15:25:28 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-03-24 00:21:59 +01:00
|
|
|
dexpreopt.FixtureSetArtBootJars("platform:foo", "apex:bar"),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
|
|
|
`\QArtApexJars is invalid as it requests a platform variant of "foo"\E`)).
|
|
|
|
RunTestWithBp(t, `
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "bootclasspath-fragment",
|
2021-03-24 00:21:59 +01:00
|
|
|
image_name: "art",
|
2021-05-21 20:28:09 +02:00
|
|
|
contents: ["foo", "bar"],
|
2021-03-24 00:21:59 +01:00
|
|
|
apex_available: [
|
|
|
|
"apex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testing.T) {
|
2021-03-24 00:21:59 +01:00
|
|
|
android.GroupFixturePreparers(
|
2021-04-23 15:25:28 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-03-24 00:21:59 +01:00
|
|
|
dexpreopt.FixtureSetArtBootJars("apex1:foo", "apex2:bar"),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
|
|
|
`\QArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex "apex1" and "apex2"\E`)).
|
|
|
|
RunTestWithBp(t, `
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "bootclasspath-fragment",
|
2021-03-24 00:21:59 +01:00
|
|
|
image_name: "art",
|
2021-05-21 20:28:09 +02:00
|
|
|
contents: ["foo", "bar"],
|
2021-03-24 00:21:59 +01:00
|
|
|
apex_available: [
|
|
|
|
"apex1",
|
|
|
|
"apex2",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
2021-03-24 02:34:57 +01:00
|
|
|
|
2021-04-23 14:55:49 +02:00
|
|
|
func TestBootclasspathFragment_Coverage(t *testing.T) {
|
|
|
|
prepareForTestWithFrameworkCoverage := android.FixtureMergeEnv(map[string]string{
|
|
|
|
"EMMA_INSTRUMENT": "true",
|
|
|
|
"EMMA_INSTRUMENT_FRAMEWORK": "true",
|
|
|
|
})
|
|
|
|
|
|
|
|
prepareWithBp := android.FixtureWithRootAndroidBp(`
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "myfragment",
|
|
|
|
contents: [
|
|
|
|
"mybootlib",
|
|
|
|
],
|
2021-04-25 14:40:15 +02:00
|
|
|
api: {
|
|
|
|
stub_libs: [
|
|
|
|
"mysdklibrary",
|
|
|
|
],
|
|
|
|
},
|
2021-04-23 14:55:49 +02:00
|
|
|
coverage: {
|
|
|
|
contents: [
|
|
|
|
"coveragelib",
|
|
|
|
],
|
2021-04-25 14:40:15 +02:00
|
|
|
api: {
|
|
|
|
stub_libs: [
|
|
|
|
"mycoveragestubs",
|
|
|
|
],
|
|
|
|
},
|
2021-04-23 14:55:49 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "mybootlib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "coveragelib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
}
|
2021-04-25 14:40:15 +02:00
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "mysdklibrary",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
compile_dex: true,
|
|
|
|
public: {enabled: true},
|
|
|
|
system: {enabled: true},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "mycoveragestubs",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
compile_dex: true,
|
|
|
|
public: {enabled: true},
|
|
|
|
}
|
2021-04-23 14:55:49 +02:00
|
|
|
`)
|
|
|
|
|
|
|
|
checkContents := func(t *testing.T, result *android.TestResult, expected ...string) {
|
|
|
|
module := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule)
|
|
|
|
android.AssertArrayString(t, "contents property", expected, module.properties.Contents)
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:40:15 +02:00
|
|
|
preparer := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithBootclasspathFragment,
|
|
|
|
PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"),
|
2021-08-06 18:49:46 +02:00
|
|
|
FixtureConfigureApexBootJars("someapex:mybootlib"),
|
2021-04-25 14:40:15 +02:00
|
|
|
prepareWithBp,
|
|
|
|
)
|
|
|
|
|
2021-04-23 14:55:49 +02:00
|
|
|
t.Run("without coverage", func(t *testing.T) {
|
2021-04-25 14:40:15 +02:00
|
|
|
result := preparer.RunTest(t)
|
2021-04-23 14:55:49 +02:00
|
|
|
checkContents(t, result, "mybootlib")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with coverage", func(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithFrameworkCoverage,
|
2021-04-25 14:40:15 +02:00
|
|
|
preparer,
|
2021-04-23 14:55:49 +02:00
|
|
|
).RunTest(t)
|
|
|
|
checkContents(t, result, "mybootlib", "coveragelib")
|
|
|
|
})
|
|
|
|
}
|
2021-04-25 11:13:54 +02:00
|
|
|
|
|
|
|
func TestBootclasspathFragment_StubLibs(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithBootclasspathFragment,
|
|
|
|
PrepareForTestWithJavaSdkLibraryFiles,
|
2021-05-13 22:25:05 +02:00
|
|
|
FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
|
2021-08-06 18:49:46 +02:00
|
|
|
FixtureConfigureApexBootJars("someapex:mysdklibrary"),
|
2021-04-25 11:13:54 +02:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "myfragment",
|
|
|
|
contents: ["mysdklibrary"],
|
|
|
|
api: {
|
|
|
|
stub_libs: [
|
|
|
|
"mystublib",
|
2021-05-13 22:25:05 +02:00
|
|
|
"myothersdklibrary",
|
2021-04-25 11:13:54 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
core_platform_api: {
|
2021-06-30 19:25:36 +02:00
|
|
|
stub_libs: ["mycoreplatform.stubs"],
|
2021-04-25 11:13:54 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "mystublib",
|
|
|
|
srcs: ["Test.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "mysdklibrary",
|
|
|
|
srcs: ["a.java"],
|
2021-05-13 23:34:45 +02:00
|
|
|
shared_library: false,
|
2021-04-25 11:13:54 +02:00
|
|
|
public: {enabled: true},
|
|
|
|
system: {enabled: true},
|
|
|
|
}
|
|
|
|
|
2021-05-13 22:25:05 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "myothersdklibrary",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
shared_library: false,
|
|
|
|
public: {enabled: true},
|
|
|
|
}
|
|
|
|
|
2021-04-25 11:13:54 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "mycoreplatform",
|
|
|
|
srcs: ["a.java"],
|
2021-05-13 23:34:45 +02:00
|
|
|
shared_library: false,
|
2021-04-25 11:13:54 +02:00
|
|
|
public: {enabled: true},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
fragment := result.Module("myfragment", "android_common")
|
2021-05-21 23:46:59 +02:00
|
|
|
info := result.ModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo)
|
2021-04-25 11:13:54 +02:00
|
|
|
|
|
|
|
stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar"
|
|
|
|
|
2021-05-13 22:25:05 +02:00
|
|
|
// Stubs jars for mysdklibrary
|
2021-04-25 11:13:54 +02:00
|
|
|
publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar"
|
|
|
|
systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.system/android_common/dex/mysdklibrary.stubs.system.jar"
|
|
|
|
|
2021-05-13 22:25:05 +02:00
|
|
|
// Stubs jars for myothersdklibrary
|
|
|
|
otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar"
|
|
|
|
|
|
|
|
// Check that SdkPublic uses public stubs for all sdk libraries.
|
2021-06-27 21:28:29 +02:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(PublicHiddenAPIScope))
|
2021-05-13 22:25:05 +02:00
|
|
|
|
|
|
|
// Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary
|
|
|
|
// as it does not provide system stubs.
|
2021-06-27 21:28:29 +02:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(SystemHiddenAPIScope))
|
2021-05-13 22:25:05 +02:00
|
|
|
|
|
|
|
// Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs
|
|
|
|
// and public stubs for myothersdklibrary as it does not provide test stubs either.
|
2021-06-27 21:28:29 +02:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(TestHiddenAPIScope))
|
2021-04-25 11:13:54 +02:00
|
|
|
|
|
|
|
// Check that SdkCorePlatform uses public stubs from the mycoreplatform library.
|
|
|
|
corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar"
|
2021-06-27 21:28:29 +02:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(CorePlatformHiddenAPIScope))
|
2021-06-27 21:53:39 +02:00
|
|
|
|
2021-06-27 21:28:29 +02:00
|
|
|
// Check the widest stubs.. The list contains the widest stub dex jar provided by each module.
|
|
|
|
expectedWidestPaths := []string{
|
|
|
|
// mycoreplatform's widest API is core platform.
|
|
|
|
corePlatformStubsJar,
|
|
|
|
|
|
|
|
// myothersdklibrary's widest API is public.
|
|
|
|
otherPublicStubsJar,
|
|
|
|
|
|
|
|
// sdklibrary's widest API is system.
|
|
|
|
systemStubsJar,
|
|
|
|
|
|
|
|
// mystublib's only provides one API and so it must be the widest.
|
|
|
|
stubsJar,
|
|
|
|
}
|
|
|
|
|
|
|
|
android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope())
|
2021-04-25 11:13:54 +02:00
|
|
|
}
|