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, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 90 | NoCreateAppImage: false, |
| 91 | ForceCreateAppImage: false, |
| 92 | PresignedPrebuilt: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 93 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func TestDexPreopt(t *testing.T) { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 97 | config := android.TestConfig("out", nil, "", nil) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 98 | ctx := android.BuilderContextForTesting(config) |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 99 | globalSoong := globalSoongConfigForTests() |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 100 | global := GlobalConfigForTests(ctx) |
| 101 | module := testSystemModuleConfig(ctx, "test") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 102 | productPackages := android.PathForTesting("product_packages.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 103 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 104 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 105 | if err != nil { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 106 | t.Fatal(err) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Colin Cross | deabb94 | 2019-02-11 14:11:09 -0800 | [diff] [blame] | 109 | wantInstalls := android.RuleBuilderInstalls{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 110 | {android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"}, |
| 111 | {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] | 112 | } |
| 113 | |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 114 | if rule.Installs().String() != wantInstalls.String() { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 115 | t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | func TestDexPreoptSystemOther(t *testing.T) { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 120 | config := android.TestConfig("out", nil, "", nil) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 121 | ctx := android.BuilderContextForTesting(config) |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 122 | globalSoong := globalSoongConfigForTests() |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 123 | global := GlobalConfigForTests(ctx) |
| 124 | systemModule := testSystemModuleConfig(ctx, "Stest") |
| 125 | systemProductModule := testSystemProductModuleConfig(ctx, "SPtest") |
| 126 | productModule := testProductModuleConfig(ctx, "Ptest") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 127 | productPackages := android.PathForTesting("product_packages.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 128 | |
| 129 | global.HasSystemOther = true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 130 | |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 131 | type moduleTest struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 132 | module *ModuleConfig |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 133 | expectedPartition string |
| 134 | } |
| 135 | tests := []struct { |
| 136 | patterns []string |
| 137 | moduleTests []moduleTest |
| 138 | }{ |
| 139 | { |
| 140 | patterns: []string{"app/%"}, |
| 141 | moduleTests: []moduleTest{ |
Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 142 | {module: systemModule, expectedPartition: "system_other/system"}, |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 143 | {module: systemProductModule, expectedPartition: "system/product"}, |
| 144 | {module: productModule, expectedPartition: "product"}, |
| 145 | }, |
| 146 | }, |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 147 | // product/app/% only applies to product apps inside the system partition |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 148 | { |
| 149 | patterns: []string{"app/%", "product/app/%"}, |
| 150 | moduleTests: []moduleTest{ |
Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 151 | {module: systemModule, expectedPartition: "system_other/system"}, |
| 152 | {module: systemProductModule, expectedPartition: "system_other/system/product"}, |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 153 | {module: productModule, expectedPartition: "product"}, |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 154 | }, |
| 155 | }, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 158 | for _, test := range tests { |
| 159 | global.PatternsOnSystemOther = test.patterns |
| 160 | for _, mt := range test.moduleTests { |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 161 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages) |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 162 | if err != nil { |
| 163 | t.Fatal(err) |
| 164 | } |
| 165 | |
| 166 | name := mt.module.Name |
| 167 | wantInstalls := android.RuleBuilderInstalls{ |
| 168 | {android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)}, |
| 169 | {android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)}, |
| 170 | } |
| 171 | |
| 172 | if rule.Installs().String() != wantInstalls.String() { |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 173 | t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 174 | } |
| 175 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 180 | func TestDexPreoptApexSystemServerJars(t *testing.T) { |
| 181 | config := android.TestConfig("out", nil, "", nil) |
| 182 | ctx := android.BuilderContextForTesting(config) |
| 183 | globalSoong := globalSoongConfigForTests() |
| 184 | global := GlobalConfigForTests(ctx) |
| 185 | module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 186 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 187 | |
| 188 | global.ApexSystemServerJars = android.CreateTestConfiguredJarList( |
| 189 | []string{"com.android.apex1:service-A"}) |
| 190 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 191 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 192 | if err != nil { |
| 193 | t.Fatal(err) |
| 194 | } |
| 195 | |
| 196 | wantInstalls := android.RuleBuilderInstalls{ |
| 197 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, |
| 198 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, |
| 199 | } |
| 200 | |
| 201 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 202 | } |
| 203 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 204 | func TestDexPreoptStandaloneSystemServerJars(t *testing.T) { |
| 205 | config := android.TestConfig("out", nil, "", nil) |
| 206 | ctx := android.BuilderContextForTesting(config) |
| 207 | globalSoong := globalSoongConfigForTests() |
| 208 | global := GlobalConfigForTests(ctx) |
| 209 | module := testPlatformSystemServerModuleConfig(ctx, "service-A") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 210 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 211 | |
| 212 | global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 213 | []string{"platform:service-A"}) |
| 214 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 215 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 216 | if err != nil { |
| 217 | t.Fatal(err) |
| 218 | } |
| 219 | |
| 220 | wantInstalls := android.RuleBuilderInstalls{ |
| 221 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/service-A.odex"}, |
| 222 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/service-A.vdex"}, |
| 223 | } |
| 224 | |
| 225 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 226 | } |
| 227 | |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 228 | func TestDexPreoptSystemExtSystemServerJars(t *testing.T) { |
| 229 | config := android.TestConfig("out", nil, "", nil) |
| 230 | ctx := android.BuilderContextForTesting(config) |
| 231 | globalSoong := globalSoongConfigForTests() |
| 232 | global := GlobalConfigForTests(ctx) |
| 233 | module := testSystemExtSystemServerModuleConfig(ctx, "service-A") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 234 | productPackages := android.PathForTesting("product_packages.txt") |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 235 | |
| 236 | global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 237 | []string{"system_ext:service-A"}) |
| 238 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 239 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 240 | if err != nil { |
| 241 | t.Fatal(err) |
| 242 | } |
| 243 | |
| 244 | wantInstalls := android.RuleBuilderInstalls{ |
| 245 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system_ext/framework/oat/arm/service-A.odex"}, |
| 246 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system_ext/framework/oat/arm/service-A.vdex"}, |
| 247 | } |
| 248 | |
| 249 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 250 | } |
| 251 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 252 | func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) { |
| 253 | config := android.TestConfig("out", nil, "", nil) |
| 254 | ctx := android.BuilderContextForTesting(config) |
| 255 | globalSoong := globalSoongConfigForTests() |
| 256 | global := GlobalConfigForTests(ctx) |
| 257 | module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 258 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 259 | |
| 260 | global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 261 | []string{"com.android.apex1:service-A"}) |
| 262 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 263 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 264 | if err != nil { |
| 265 | t.Fatal(err) |
| 266 | } |
| 267 | |
| 268 | wantInstalls := android.RuleBuilderInstalls{ |
| 269 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, |
| 270 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, |
| 271 | } |
| 272 | |
| 273 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 274 | } |
| 275 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 276 | func TestDexPreoptProfile(t *testing.T) { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 277 | config := android.TestConfig("out", nil, "", nil) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 278 | ctx := android.BuilderContextForTesting(config) |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 279 | globalSoong := globalSoongConfigForTests() |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 280 | global := GlobalConfigForTests(ctx) |
| 281 | module := testSystemModuleConfig(ctx, "test") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 282 | productPackages := android.PathForTesting("product_packages.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 283 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 284 | module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile")) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 285 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 286 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 287 | if err != nil { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 288 | t.Fatal(err) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Colin Cross | deabb94 | 2019-02-11 14:11:09 -0800 | [diff] [blame] | 291 | wantInstalls := android.RuleBuilderInstalls{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 292 | {android.PathForOutput(ctx, "test/profile.prof"), "/system/app/test/test.apk.prof"}, |
| 293 | {android.PathForOutput(ctx, "test/oat/arm/package.art"), "/system/app/test/oat/arm/test.art"}, |
| 294 | {android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"}, |
| 295 | {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] | 296 | } |
| 297 | |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 298 | if rule.Installs().String() != wantInstalls.String() { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 299 | t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) |
| 300 | } |
| 301 | } |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 302 | |
| 303 | func TestDexPreoptConfigToJson(t *testing.T) { |
| 304 | config := android.TestConfig("out", nil, "", nil) |
| 305 | ctx := android.BuilderContextForTesting(config) |
| 306 | module := testSystemModuleConfig(ctx, "test") |
| 307 | data, err := moduleConfigToJSON(module) |
| 308 | if err != nil { |
| 309 | t.Errorf("Failed to convert module config data to JSON, %v", err) |
| 310 | } |
| 311 | parsed, err := ParseModuleConfig(ctx, data) |
| 312 | if err != nil { |
| 313 | t.Errorf("Failed to parse JSON, %v", err) |
| 314 | } |
| 315 | before := fmt.Sprintf("%v", module) |
| 316 | after := fmt.Sprintf("%v", parsed) |
| 317 | android.AssertStringEquals(t, "The result must be the same as the original after marshalling and unmarshalling it.", before, after) |
| 318 | } |