2018-11-12 19:13:39 +01:00
|
|
|
// Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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 dexpreopt
|
|
|
|
|
|
|
|
import (
|
2019-01-31 02:32:39 +01:00
|
|
|
"android/soong/android"
|
2019-10-02 18:42:44 +02:00
|
|
|
"fmt"
|
2018-11-12 19:13:39 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func testSystemModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
|
2019-10-02 18:42:44 +02:00
|
|
|
return testModuleConfig(ctx, name, "system")
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func testSystemProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
|
2019-10-02 18:42:44 +02:00
|
|
|
return testModuleConfig(ctx, name, "system/product")
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func testProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
|
2019-10-02 18:42:44 +02:00
|
|
|
return testModuleConfig(ctx, name, "product")
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleConfig {
|
2021-09-16 08:15:39 +02:00
|
|
|
return createTestModuleConfig(
|
|
|
|
name,
|
|
|
|
fmt.Sprintf("/%s/app/test/%s.apk", partition, name),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/dex/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testApexModuleConfig(ctx android.PathContext, name, apexName string) *ModuleConfig {
|
|
|
|
return createTestModuleConfig(
|
|
|
|
name,
|
|
|
|
fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, name),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name)))
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
func testPlatformSystemServerModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
|
|
|
|
return createTestModuleConfig(
|
|
|
|
name,
|
|
|
|
fmt.Sprintf("/system/framework/%s.jar", name),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name)))
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:40:13 +02:00
|
|
|
func testSystemExtSystemServerModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
|
|
|
|
return createTestModuleConfig(
|
|
|
|
name,
|
|
|
|
fmt.Sprintf("/system_ext/framework/%s.jar", name),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)),
|
|
|
|
android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name)))
|
|
|
|
}
|
|
|
|
|
2021-09-16 08:15:39 +02:00
|
|
|
func createTestModuleConfig(name, dexLocation string, buildPath, dexPath, enforceUsesLibrariesStatusFile android.OutputPath) *ModuleConfig {
|
2020-01-31 18:44:54 +01:00
|
|
|
return &ModuleConfig{
|
2019-10-02 18:42:44 +02:00
|
|
|
Name: name,
|
2021-09-16 08:15:39 +02:00
|
|
|
DexLocation: dexLocation,
|
|
|
|
BuildPath: buildPath,
|
|
|
|
DexPath: dexPath,
|
2019-02-15 19:39:37 +01:00
|
|
|
UncompressedDex: false,
|
|
|
|
HasApkLibraries: false,
|
|
|
|
PreoptFlags: nil,
|
|
|
|
ProfileClassListing: android.OptionalPath{},
|
|
|
|
ProfileIsTextListing: false,
|
2021-09-16 08:15:39 +02:00
|
|
|
EnforceUsesLibrariesStatusFile: enforceUsesLibrariesStatusFile,
|
2019-02-15 19:39:37 +01:00
|
|
|
EnforceUsesLibraries: false,
|
2020-11-03 16:15:46 +01:00
|
|
|
ClassLoaderContexts: nil,
|
2019-02-15 19:39:37 +01:00
|
|
|
Archs: []android.ArchType{android.Arm},
|
2019-11-08 11:54:21 +01:00
|
|
|
DexPreoptImagesDeps: []android.OutputPaths{android.OutputPaths{}},
|
2021-05-07 11:53:21 +02:00
|
|
|
DexPreoptImageLocationsOnHost: []string{},
|
2019-02-15 19:39:37 +01:00
|
|
|
PreoptBootClassPathDexFiles: nil,
|
|
|
|
PreoptBootClassPathDexLocations: nil,
|
|
|
|
PreoptExtractedApk: false,
|
|
|
|
NoCreateAppImage: false,
|
|
|
|
ForceCreateAppImage: false,
|
|
|
|
PresignedPrebuilt: false,
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDexPreopt(t *testing.T) {
|
2020-01-10 21:32:59 +01:00
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
2020-11-17 02:32:30 +01:00
|
|
|
ctx := android.BuilderContextForTesting(config)
|
2021-01-21 16:05:11 +01:00
|
|
|
globalSoong := globalSoongConfigForTests()
|
2020-01-10 21:32:59 +01:00
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testSystemModuleConfig(ctx, "test")
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2020-01-10 21:32:59 +01:00
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
2018-11-12 19:13:39 +01:00
|
|
|
if err != nil {
|
2019-02-15 19:39:37 +01:00
|
|
|
t.Fatal(err)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-11 23:11:09 +01:00
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
2019-02-15 19:39:37 +01:00
|
|
|
{android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"},
|
|
|
|
{android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system/app/test/oat/arm/test.vdex"},
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 19:25:24 +01:00
|
|
|
if rule.Installs().String() != wantInstalls.String() {
|
2018-11-12 19:13:39 +01:00
|
|
|
t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDexPreoptSystemOther(t *testing.T) {
|
2020-01-10 21:32:59 +01:00
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
2020-11-17 02:32:30 +01:00
|
|
|
ctx := android.BuilderContextForTesting(config)
|
2021-01-21 16:05:11 +01:00
|
|
|
globalSoong := globalSoongConfigForTests()
|
2019-10-02 18:42:44 +02:00
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
systemModule := testSystemModuleConfig(ctx, "Stest")
|
|
|
|
systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
|
|
|
|
productModule := testProductModuleConfig(ctx, "Ptest")
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
global.HasSystemOther = true
|
|
|
|
|
2019-10-02 18:42:44 +02:00
|
|
|
type moduleTest struct {
|
2020-01-31 18:44:54 +01:00
|
|
|
module *ModuleConfig
|
2019-10-02 18:42:44 +02:00
|
|
|
expectedPartition string
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2019-10-02 18:42:44 +02:00
|
|
|
tests := []struct {
|
|
|
|
patterns []string
|
|
|
|
moduleTests []moduleTest
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
patterns: []string{"app/%"},
|
|
|
|
moduleTests: []moduleTest{
|
2019-10-03 15:18:45 +02:00
|
|
|
{module: systemModule, expectedPartition: "system_other/system"},
|
2019-10-02 18:42:44 +02:00
|
|
|
{module: systemProductModule, expectedPartition: "system/product"},
|
|
|
|
{module: productModule, expectedPartition: "product"},
|
|
|
|
},
|
|
|
|
},
|
2020-09-15 11:28:55 +02:00
|
|
|
// product/app/% only applies to product apps inside the system partition
|
2019-10-02 18:42:44 +02:00
|
|
|
{
|
|
|
|
patterns: []string{"app/%", "product/app/%"},
|
|
|
|
moduleTests: []moduleTest{
|
2019-10-03 15:18:45 +02:00
|
|
|
{module: systemModule, expectedPartition: "system_other/system"},
|
|
|
|
{module: systemProductModule, expectedPartition: "system_other/system/product"},
|
2020-09-15 11:28:55 +02:00
|
|
|
{module: productModule, expectedPartition: "product"},
|
2019-10-02 18:42:44 +02:00
|
|
|
},
|
|
|
|
},
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-10-02 18:42:44 +02:00
|
|
|
for _, test := range tests {
|
|
|
|
global.PatternsOnSystemOther = test.patterns
|
|
|
|
for _, mt := range test.moduleTests {
|
2020-01-10 21:32:59 +01:00
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module)
|
2019-10-02 18:42:44 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := mt.module.Name
|
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
|
|
|
{android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)},
|
|
|
|
{android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)},
|
|
|
|
}
|
|
|
|
|
|
|
|
if rule.Installs().String() != wantInstalls.String() {
|
2020-09-15 11:28:55 +02:00
|
|
|
t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
|
2019-10-02 18:42:44 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2019-10-02 18:42:44 +02:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2021-09-16 08:15:39 +02:00
|
|
|
func TestDexPreoptApexSystemServerJars(t *testing.T) {
|
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
|
|
|
ctx := android.BuilderContextForTesting(config)
|
|
|
|
globalSoong := globalSoongConfigForTests()
|
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testApexModuleConfig(ctx, "service-A", "com.android.apex1")
|
|
|
|
|
|
|
|
global.ApexSystemServerJars = android.CreateTestConfiguredJarList(
|
|
|
|
[]string{"com.android.apex1:service-A"})
|
|
|
|
|
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"},
|
2021-12-14 19:54:06 +01:00
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"},
|
|
|
|
}
|
|
|
|
|
|
|
|
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
|
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
|
|
|
ctx := android.BuilderContextForTesting(config)
|
|
|
|
globalSoong := globalSoongConfigForTests()
|
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testPlatformSystemServerModuleConfig(ctx, "service-A")
|
|
|
|
|
|
|
|
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
|
|
|
|
[]string{"platform:service-A"})
|
|
|
|
|
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/service-A.odex"},
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/service-A.vdex"},
|
|
|
|
}
|
|
|
|
|
|
|
|
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:40:13 +02:00
|
|
|
func TestDexPreoptSystemExtSystemServerJars(t *testing.T) {
|
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
|
|
|
ctx := android.BuilderContextForTesting(config)
|
|
|
|
globalSoong := globalSoongConfigForTests()
|
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testSystemExtSystemServerModuleConfig(ctx, "service-A")
|
|
|
|
|
|
|
|
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
|
|
|
|
[]string{"system_ext:service-A"})
|
|
|
|
|
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system_ext/framework/oat/arm/service-A.odex"},
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system_ext/framework/oat/arm/service-A.vdex"},
|
|
|
|
}
|
|
|
|
|
|
|
|
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) {
|
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
|
|
|
ctx := android.BuilderContextForTesting(config)
|
|
|
|
globalSoong := globalSoongConfigForTests()
|
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testApexModuleConfig(ctx, "service-A", "com.android.apex1")
|
|
|
|
|
|
|
|
global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(
|
|
|
|
[]string{"com.android.apex1:service-A"})
|
|
|
|
|
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"},
|
2021-09-16 08:15:39 +02:00
|
|
|
{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"},
|
|
|
|
}
|
|
|
|
|
|
|
|
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
func TestDexPreoptProfile(t *testing.T) {
|
2020-01-10 21:32:59 +01:00
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
2020-11-17 02:32:30 +01:00
|
|
|
ctx := android.BuilderContextForTesting(config)
|
2021-01-21 16:05:11 +01:00
|
|
|
globalSoong := globalSoongConfigForTests()
|
2020-01-10 21:32:59 +01:00
|
|
|
global := GlobalConfigForTests(ctx)
|
|
|
|
module := testSystemModuleConfig(ctx, "test")
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2020-01-10 21:32:59 +01:00
|
|
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
2018-11-12 19:13:39 +01:00
|
|
|
if err != nil {
|
2019-02-15 19:39:37 +01:00
|
|
|
t.Fatal(err)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-11 23:11:09 +01:00
|
|
|
wantInstalls := android.RuleBuilderInstalls{
|
2019-02-15 19:39:37 +01:00
|
|
|
{android.PathForOutput(ctx, "test/profile.prof"), "/system/app/test/test.apk.prof"},
|
|
|
|
{android.PathForOutput(ctx, "test/oat/arm/package.art"), "/system/app/test/oat/arm/test.art"},
|
|
|
|
{android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"},
|
|
|
|
{android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system/app/test/oat/arm/test.vdex"},
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 19:25:24 +01:00
|
|
|
if rule.Installs().String() != wantInstalls.String() {
|
2018-11-12 19:13:39 +01:00
|
|
|
t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 17:00:19 +02:00
|
|
|
|
|
|
|
func TestDexPreoptConfigToJson(t *testing.T) {
|
|
|
|
config := android.TestConfig("out", nil, "", nil)
|
|
|
|
ctx := android.BuilderContextForTesting(config)
|
|
|
|
module := testSystemModuleConfig(ctx, "test")
|
|
|
|
data, err := moduleConfigToJSON(module)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to convert module config data to JSON, %v", err)
|
|
|
|
}
|
|
|
|
parsed, err := ParseModuleConfig(ctx, data)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to parse JSON, %v", err)
|
|
|
|
}
|
|
|
|
before := fmt.Sprintf("%v", module)
|
|
|
|
after := fmt.Sprintf("%v", parsed)
|
|
|
|
android.AssertStringEquals(t, "The result must be the same as the original after marshalling and unmarshalling it.", before, after)
|
|
|
|
}
|