| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. | 
 | 2 | // | 
 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 4 | // you may not use this file except in compliance with the License. | 
 | 5 | // You may obtain a copy of the License at | 
 | 6 | // | 
 | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
 | 8 | // | 
 | 9 | // Unless required by applicable law or agreed to in writing, software | 
 | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 12 | // See the License for the specific language governing permissions and | 
 | 13 | // limitations under the License. | 
 | 14 |  | 
 | 15 | package dexpreopt | 
 | 16 |  | 
 | 17 | import ( | 
| Colin Cross | feec25b | 2019-01-30 17:32:39 -0800 | [diff] [blame] | 18 | 	"android/soong/android" | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 19 | 	"fmt" | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 20 | 	"testing" | 
 | 21 | ) | 
 | 22 |  | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 23 | func testSystemModuleConfig(ctx android.PathContext, name string) *ModuleConfig { | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 24 | 	return testModuleConfig(ctx, name, "system") | 
 | 25 | } | 
 | 26 |  | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 27 | func testSystemProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig { | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 28 | 	return testModuleConfig(ctx, name, "system/product") | 
 | 29 | } | 
 | 30 |  | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 31 | func testProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig { | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 32 | 	return testModuleConfig(ctx, name, "product") | 
 | 33 | } | 
 | 34 |  | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 35 | func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleConfig { | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 36 | 	return createTestModuleConfig( | 
 | 37 | 		name, | 
 | 38 | 		fmt.Sprintf("/%s/app/test/%s.apk", partition, name), | 
 | 39 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)), | 
 | 40 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/dex/%s.jar", name, name)), | 
 | 41 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) | 
 | 42 | } | 
 | 43 |  | 
 | 44 | func testApexModuleConfig(ctx android.PathContext, name, apexName string) *ModuleConfig { | 
 | 45 | 	return createTestModuleConfig( | 
 | 46 | 		name, | 
 | 47 | 		fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, name), | 
 | 48 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)), | 
 | 49 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)), | 
 | 50 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) | 
 | 51 | } | 
 | 52 |  | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 53 | func testPlatformSystemServerModuleConfig(ctx android.PathContext, name string) *ModuleConfig { | 
 | 54 | 	return createTestModuleConfig( | 
 | 55 | 		name, | 
 | 56 | 		fmt.Sprintf("/system/framework/%s.jar", name), | 
 | 57 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)), | 
 | 58 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)), | 
 | 59 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) | 
 | 60 | } | 
 | 61 |  | 
| liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 62 | func testSystemExtSystemServerModuleConfig(ctx android.PathContext, name string) *ModuleConfig { | 
 | 63 | 	return createTestModuleConfig( | 
 | 64 | 		name, | 
 | 65 | 		fmt.Sprintf("/system_ext/framework/%s.jar", name), | 
 | 66 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)), | 
 | 67 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)), | 
 | 68 | 		android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) | 
 | 69 | } | 
 | 70 |  | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 71 | func createTestModuleConfig(name, dexLocation string, buildPath, dexPath, enforceUsesLibrariesStatusFile android.OutputPath) *ModuleConfig { | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 72 | 	return &ModuleConfig{ | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 73 | 		Name:                            name, | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 74 | 		DexLocation:                     dexLocation, | 
 | 75 | 		BuildPath:                       buildPath, | 
 | 76 | 		DexPath:                         dexPath, | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 77 | 		UncompressedDex:                 false, | 
 | 78 | 		HasApkLibraries:                 false, | 
 | 79 | 		PreoptFlags:                     nil, | 
 | 80 | 		ProfileClassListing:             android.OptionalPath{}, | 
 | 81 | 		ProfileIsTextListing:            false, | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 82 | 		EnforceUsesLibrariesStatusFile:  enforceUsesLibrariesStatusFile, | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 83 | 		EnforceUsesLibraries:            false, | 
| Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 84 | 		ClassLoaderContexts:             nil, | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 85 | 		Archs:                           []android.ArchType{android.Arm}, | 
| Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 86 | 		DexPreoptImagesDeps:             []android.OutputPaths{android.OutputPaths{}}, | 
| Jeongik Cha | a596909 | 2021-05-07 18:53:21 +0900 | [diff] [blame] | 87 | 		DexPreoptImageLocationsOnHost:   []string{}, | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 88 | 		PreoptBootClassPathDexFiles:     nil, | 
 | 89 | 		PreoptBootClassPathDexLocations: nil, | 
 | 90 | 		PreoptExtractedApk:              false, | 
 | 91 | 		NoCreateAppImage:                false, | 
 | 92 | 		ForceCreateAppImage:             false, | 
 | 93 | 		PresignedPrebuilt:               false, | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 94 | 	} | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 95 | } | 
 | 96 |  | 
 | 97 | func TestDexPreopt(t *testing.T) { | 
| Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 98 | 	config := android.TestConfig("out", nil, "", nil) | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 99 | 	ctx := android.BuilderContextForTesting(config) | 
| Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 100 | 	globalSoong := globalSoongConfigForTests() | 
| Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 101 | 	global := GlobalConfigForTests(ctx) | 
 | 102 | 	module := testSystemModuleConfig(ctx, "test") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 103 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 104 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 105 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 106 | 	if err != nil { | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 107 | 		t.Fatal(err) | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 108 | 	} | 
 | 109 |  | 
| Colin Cross | deabb94 | 2019-02-11 14:11:09 -0800 | [diff] [blame] | 110 | 	wantInstalls := android.RuleBuilderInstalls{ | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 111 | 		{android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"}, | 
 | 112 | 		{android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system/app/test/oat/arm/test.vdex"}, | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 113 | 	} | 
 | 114 |  | 
| Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 115 | 	if rule.Installs().String() != wantInstalls.String() { | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 116 | 		t.Errorf("\nwant installs:\n   %v\ngot:\n   %v", wantInstalls, rule.Installs()) | 
 | 117 | 	} | 
 | 118 | } | 
 | 119 |  | 
 | 120 | func TestDexPreoptSystemOther(t *testing.T) { | 
| Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 121 | 	config := android.TestConfig("out", nil, "", nil) | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 122 | 	ctx := android.BuilderContextForTesting(config) | 
| Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 123 | 	globalSoong := globalSoongConfigForTests() | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 124 | 	global := GlobalConfigForTests(ctx) | 
 | 125 | 	systemModule := testSystemModuleConfig(ctx, "Stest") | 
 | 126 | 	systemProductModule := testSystemProductModuleConfig(ctx, "SPtest") | 
 | 127 | 	productModule := testProductModuleConfig(ctx, "Ptest") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 128 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 129 |  | 
 | 130 | 	global.HasSystemOther = true | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 131 |  | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 132 | 	type moduleTest struct { | 
| Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 133 | 		module            *ModuleConfig | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 134 | 		expectedPartition string | 
 | 135 | 	} | 
 | 136 | 	tests := []struct { | 
 | 137 | 		patterns    []string | 
 | 138 | 		moduleTests []moduleTest | 
 | 139 | 	}{ | 
 | 140 | 		{ | 
 | 141 | 			patterns: []string{"app/%"}, | 
 | 142 | 			moduleTests: []moduleTest{ | 
| Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 143 | 				{module: systemModule, expectedPartition: "system_other/system"}, | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 144 | 				{module: systemProductModule, expectedPartition: "system/product"}, | 
 | 145 | 				{module: productModule, expectedPartition: "product"}, | 
 | 146 | 			}, | 
 | 147 | 		}, | 
| Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 148 | 		// product/app/% only applies to product apps inside the system partition | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 149 | 		{ | 
 | 150 | 			patterns: []string{"app/%", "product/app/%"}, | 
 | 151 | 			moduleTests: []moduleTest{ | 
| Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 152 | 				{module: systemModule, expectedPartition: "system_other/system"}, | 
 | 153 | 				{module: systemProductModule, expectedPartition: "system_other/system/product"}, | 
| Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 154 | 				{module: productModule, expectedPartition: "product"}, | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 155 | 			}, | 
 | 156 | 		}, | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 157 | 	} | 
 | 158 |  | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 159 | 	for _, test := range tests { | 
 | 160 | 		global.PatternsOnSystemOther = test.patterns | 
 | 161 | 		for _, mt := range test.moduleTests { | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 162 | 			rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages) | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 163 | 			if err != nil { | 
 | 164 | 				t.Fatal(err) | 
 | 165 | 			} | 
 | 166 |  | 
 | 167 | 			name := mt.module.Name | 
 | 168 | 			wantInstalls := android.RuleBuilderInstalls{ | 
 | 169 | 				{android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)}, | 
 | 170 | 				{android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)}, | 
 | 171 | 			} | 
 | 172 |  | 
 | 173 | 			if rule.Installs().String() != wantInstalls.String() { | 
| Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 174 | 				t.Errorf("\nwant installs:\n   %v\ngot:\n   %v", wantInstalls, rule.Installs()) | 
| Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 175 | 			} | 
 | 176 | 		} | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 177 | 	} | 
 | 178 |  | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 179 | } | 
 | 180 |  | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 181 | func TestDexPreoptApexSystemServerJars(t *testing.T) { | 
 | 182 | 	config := android.TestConfig("out", nil, "", nil) | 
 | 183 | 	ctx := android.BuilderContextForTesting(config) | 
 | 184 | 	globalSoong := globalSoongConfigForTests() | 
 | 185 | 	global := GlobalConfigForTests(ctx) | 
 | 186 | 	module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 187 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 188 |  | 
 | 189 | 	global.ApexSystemServerJars = android.CreateTestConfiguredJarList( | 
 | 190 | 		[]string{"com.android.apex1:service-A"}) | 
 | 191 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 192 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 193 | 	if err != nil { | 
 | 194 | 		t.Fatal(err) | 
 | 195 | 	} | 
 | 196 |  | 
 | 197 | 	wantInstalls := android.RuleBuilderInstalls{ | 
 | 198 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, | 
 | 199 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, | 
 | 200 | 	} | 
 | 201 |  | 
 | 202 | 	android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) | 
 | 203 | } | 
 | 204 |  | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 205 | func TestDexPreoptStandaloneSystemServerJars(t *testing.T) { | 
 | 206 | 	config := android.TestConfig("out", nil, "", nil) | 
 | 207 | 	ctx := android.BuilderContextForTesting(config) | 
 | 208 | 	globalSoong := globalSoongConfigForTests() | 
 | 209 | 	global := GlobalConfigForTests(ctx) | 
 | 210 | 	module := testPlatformSystemServerModuleConfig(ctx, "service-A") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 211 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 212 |  | 
 | 213 | 	global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( | 
 | 214 | 		[]string{"platform:service-A"}) | 
 | 215 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 216 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 217 | 	if err != nil { | 
 | 218 | 		t.Fatal(err) | 
 | 219 | 	} | 
 | 220 |  | 
 | 221 | 	wantInstalls := android.RuleBuilderInstalls{ | 
 | 222 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/service-A.odex"}, | 
 | 223 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/service-A.vdex"}, | 
 | 224 | 	} | 
 | 225 |  | 
 | 226 | 	android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) | 
 | 227 | } | 
 | 228 |  | 
| liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 229 | func TestDexPreoptSystemExtSystemServerJars(t *testing.T) { | 
 | 230 | 	config := android.TestConfig("out", nil, "", nil) | 
 | 231 | 	ctx := android.BuilderContextForTesting(config) | 
 | 232 | 	globalSoong := globalSoongConfigForTests() | 
 | 233 | 	global := GlobalConfigForTests(ctx) | 
 | 234 | 	module := testSystemExtSystemServerModuleConfig(ctx, "service-A") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 235 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 236 |  | 
 | 237 | 	global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( | 
 | 238 | 		[]string{"system_ext:service-A"}) | 
 | 239 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 240 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 241 | 	if err != nil { | 
 | 242 | 		t.Fatal(err) | 
 | 243 | 	} | 
 | 244 |  | 
 | 245 | 	wantInstalls := android.RuleBuilderInstalls{ | 
 | 246 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system_ext/framework/oat/arm/service-A.odex"}, | 
 | 247 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system_ext/framework/oat/arm/service-A.vdex"}, | 
 | 248 | 	} | 
 | 249 |  | 
 | 250 | 	android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) | 
 | 251 | } | 
 | 252 |  | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 253 | func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) { | 
 | 254 | 	config := android.TestConfig("out", nil, "", nil) | 
 | 255 | 	ctx := android.BuilderContextForTesting(config) | 
 | 256 | 	globalSoong := globalSoongConfigForTests() | 
 | 257 | 	global := GlobalConfigForTests(ctx) | 
 | 258 | 	module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 259 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 260 |  | 
 | 261 | 	global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList( | 
 | 262 | 		[]string{"com.android.apex1:service-A"}) | 
 | 263 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 264 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 265 | 	if err != nil { | 
 | 266 | 		t.Fatal(err) | 
 | 267 | 	} | 
 | 268 |  | 
 | 269 | 	wantInstalls := android.RuleBuilderInstalls{ | 
 | 270 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, | 
 | 271 | 		{android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, | 
 | 272 | 	} | 
 | 273 |  | 
 | 274 | 	android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) | 
 | 275 | } | 
 | 276 |  | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 277 | func TestDexPreoptProfile(t *testing.T) { | 
| Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 278 | 	config := android.TestConfig("out", nil, "", nil) | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 279 | 	ctx := android.BuilderContextForTesting(config) | 
| Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 280 | 	globalSoong := globalSoongConfigForTests() | 
| Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 281 | 	global := GlobalConfigForTests(ctx) | 
 | 282 | 	module := testSystemModuleConfig(ctx, "test") | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 283 | 	productPackages := android.PathForTesting("product_packages.txt") | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 284 |  | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 285 | 	module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile")) | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 286 |  | 
| Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 287 | 	rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 288 | 	if err != nil { | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 289 | 		t.Fatal(err) | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 290 | 	} | 
 | 291 |  | 
| Colin Cross | deabb94 | 2019-02-11 14:11:09 -0800 | [diff] [blame] | 292 | 	wantInstalls := android.RuleBuilderInstalls{ | 
| Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 293 | 		{android.PathForOutput(ctx, "test/profile.prof"), "/system/app/test/test.apk.prof"}, | 
 | 294 | 		{android.PathForOutput(ctx, "test/oat/arm/package.art"), "/system/app/test/oat/arm/test.art"}, | 
 | 295 | 		{android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"}, | 
 | 296 | 		{android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system/app/test/oat/arm/test.vdex"}, | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 297 | 	} | 
 | 298 |  | 
| Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 299 | 	if rule.Installs().String() != wantInstalls.String() { | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 300 | 		t.Errorf("\nwant installs:\n   %v\ngot:\n   %v", wantInstalls, rule.Installs()) | 
 | 301 | 	} | 
 | 302 | } | 
| Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 303 |  | 
 | 304 | func TestDexPreoptConfigToJson(t *testing.T) { | 
 | 305 | 	config := android.TestConfig("out", nil, "", nil) | 
 | 306 | 	ctx := android.BuilderContextForTesting(config) | 
 | 307 | 	module := testSystemModuleConfig(ctx, "test") | 
 | 308 | 	data, err := moduleConfigToJSON(module) | 
 | 309 | 	if err != nil { | 
 | 310 | 		t.Errorf("Failed to convert module config data to JSON, %v", err) | 
 | 311 | 	} | 
 | 312 | 	parsed, err := ParseModuleConfig(ctx, data) | 
 | 313 | 	if err != nil { | 
 | 314 | 		t.Errorf("Failed to parse JSON, %v", err) | 
 | 315 | 	} | 
 | 316 | 	before := fmt.Sprintf("%v", module) | 
 | 317 | 	after := fmt.Sprintf("%v", parsed) | 
 | 318 | 	android.AssertStringEquals(t, "The result must be the same as the original after marshalling and unmarshalling it.", before, after) | 
 | 319 | } |