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) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 99 | globalSoong := globalSoongConfigForTests(ctx) |
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 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 104 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
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 | } |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 117 | |
| 118 | android.AssertStringListContains(t, "", rule.Inputs().RelativeToTop().Strings(), |
| 119 | "out/soong/dexpreopt_test/uffd_gc_flag.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | func TestDexPreoptSystemOther(t *testing.T) { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 123 | config := android.TestConfig("out", nil, "", nil) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 124 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 125 | globalSoong := globalSoongConfigForTests(ctx) |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 126 | global := GlobalConfigForTests(ctx) |
| 127 | systemModule := testSystemModuleConfig(ctx, "Stest") |
| 128 | systemProductModule := testSystemProductModuleConfig(ctx, "SPtest") |
| 129 | productModule := testProductModuleConfig(ctx, "Ptest") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 130 | productPackages := android.PathForTesting("product_packages.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 131 | |
| 132 | global.HasSystemOther = true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 133 | |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 134 | type moduleTest struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 135 | module *ModuleConfig |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 136 | expectedPartition string |
| 137 | } |
| 138 | tests := []struct { |
| 139 | patterns []string |
| 140 | moduleTests []moduleTest |
| 141 | }{ |
| 142 | { |
| 143 | patterns: []string{"app/%"}, |
| 144 | moduleTests: []moduleTest{ |
Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 145 | {module: systemModule, expectedPartition: "system_other/system"}, |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 146 | {module: systemProductModule, expectedPartition: "system/product"}, |
| 147 | {module: productModule, expectedPartition: "product"}, |
| 148 | }, |
| 149 | }, |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 150 | // product/app/% only applies to product apps inside the system partition |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 151 | { |
| 152 | patterns: []string{"app/%", "product/app/%"}, |
| 153 | moduleTests: []moduleTest{ |
Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 154 | {module: systemModule, expectedPartition: "system_other/system"}, |
| 155 | {module: systemProductModule, expectedPartition: "system_other/system/product"}, |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 156 | {module: productModule, expectedPartition: "product"}, |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 157 | }, |
| 158 | }, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 161 | for _, test := range tests { |
| 162 | global.PatternsOnSystemOther = test.patterns |
| 163 | for _, mt := range test.moduleTests { |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 164 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages, true) |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 165 | if err != nil { |
| 166 | t.Fatal(err) |
| 167 | } |
| 168 | |
| 169 | name := mt.module.Name |
| 170 | wantInstalls := android.RuleBuilderInstalls{ |
| 171 | {android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)}, |
| 172 | {android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)}, |
| 173 | } |
| 174 | |
| 175 | if rule.Installs().String() != wantInstalls.String() { |
Anton Hansson | da4d9d9 | 2020-09-15 09:28:55 +0000 | [diff] [blame] | 176 | t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) |
Anton Hansson | 4ec91dd | 2019-10-02 17:42:44 +0100 | [diff] [blame] | 177 | } |
| 178 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 183 | func TestDexPreoptApexSystemServerJars(t *testing.T) { |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 184 | // modify the global variable for test |
| 185 | var oldDexpreoptRunningInSoong = DexpreoptRunningInSoong |
| 186 | DexpreoptRunningInSoong = true |
| 187 | |
| 188 | // test begin |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 189 | config := android.TestConfig("out", nil, "", nil) |
| 190 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 191 | globalSoong := globalSoongConfigForTests(ctx) |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 192 | global := GlobalConfigForTests(ctx) |
| 193 | module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 194 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 195 | |
| 196 | global.ApexSystemServerJars = android.CreateTestConfiguredJarList( |
| 197 | []string{"com.android.apex1:service-A"}) |
| 198 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 199 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 200 | if err != nil { |
| 201 | t.Fatal(err) |
| 202 | } |
| 203 | |
| 204 | wantInstalls := android.RuleBuilderInstalls{ |
| 205 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, |
| 206 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, |
| 207 | } |
| 208 | |
| 209 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 210 | |
| 211 | android.AssertStringListContains(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar") |
| 212 | |
| 213 | // rule with apex sscp cp as false |
| 214 | rule, err = GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, false) |
| 215 | if err != nil { |
| 216 | t.Fatal(err) |
| 217 | } |
| 218 | android.AssertStringListDoesNotContain(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar") |
| 219 | |
| 220 | // cleanup the global variable for test |
| 221 | DexpreoptRunningInSoong = oldDexpreoptRunningInSoong |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 224 | func TestDexPreoptStandaloneSystemServerJars(t *testing.T) { |
| 225 | config := android.TestConfig("out", nil, "", nil) |
| 226 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 227 | globalSoong := globalSoongConfigForTests(ctx) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 228 | global := GlobalConfigForTests(ctx) |
| 229 | module := testPlatformSystemServerModuleConfig(ctx, "service-A") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 230 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 231 | |
| 232 | global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 233 | []string{"platform:service-A"}) |
| 234 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 235 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 236 | if err != nil { |
| 237 | t.Fatal(err) |
| 238 | } |
| 239 | |
| 240 | wantInstalls := android.RuleBuilderInstalls{ |
| 241 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/service-A.odex"}, |
| 242 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/service-A.vdex"}, |
| 243 | } |
| 244 | |
| 245 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 246 | } |
| 247 | |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 248 | func TestDexPreoptSystemExtSystemServerJars(t *testing.T) { |
| 249 | config := android.TestConfig("out", nil, "", nil) |
| 250 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 251 | globalSoong := globalSoongConfigForTests(ctx) |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 252 | global := GlobalConfigForTests(ctx) |
| 253 | module := testSystemExtSystemServerModuleConfig(ctx, "service-A") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 254 | productPackages := android.PathForTesting("product_packages.txt") |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 255 | |
| 256 | global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 257 | []string{"system_ext:service-A"}) |
| 258 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 259 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
liulvping | 76d56ee | 2022-05-07 14:40:13 +0800 | [diff] [blame] | 260 | if err != nil { |
| 261 | t.Fatal(err) |
| 262 | } |
| 263 | |
| 264 | wantInstalls := android.RuleBuilderInstalls{ |
| 265 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system_ext/framework/oat/arm/service-A.odex"}, |
| 266 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system_ext/framework/oat/arm/service-A.vdex"}, |
| 267 | } |
| 268 | |
| 269 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 270 | } |
| 271 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 272 | func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) { |
| 273 | config := android.TestConfig("out", nil, "", nil) |
| 274 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 275 | globalSoong := globalSoongConfigForTests(ctx) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 276 | global := GlobalConfigForTests(ctx) |
| 277 | module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 278 | productPackages := android.PathForTesting("product_packages.txt") |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 279 | |
| 280 | global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList( |
| 281 | []string{"com.android.apex1:service-A"}) |
| 282 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 283 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 284 | if err != nil { |
| 285 | t.Fatal(err) |
| 286 | } |
| 287 | |
| 288 | wantInstalls := android.RuleBuilderInstalls{ |
| 289 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, |
| 290 | {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, |
| 291 | } |
| 292 | |
| 293 | android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) |
| 294 | } |
| 295 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 296 | func TestDexPreoptProfile(t *testing.T) { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 297 | config := android.TestConfig("out", nil, "", nil) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 298 | ctx := android.BuilderContextForTesting(config) |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 299 | globalSoong := globalSoongConfigForTests(ctx) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 300 | global := GlobalConfigForTests(ctx) |
| 301 | module := testSystemModuleConfig(ctx, "test") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 302 | productPackages := android.PathForTesting("product_packages.txt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 303 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 304 | module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile")) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 305 | |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 306 | rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 307 | if err != nil { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 308 | t.Fatal(err) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Colin Cross | deabb94 | 2019-02-11 14:11:09 -0800 | [diff] [blame] | 311 | wantInstalls := android.RuleBuilderInstalls{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 312 | {android.PathForOutput(ctx, "test/profile.prof"), "/system/app/test/test.apk.prof"}, |
| 313 | {android.PathForOutput(ctx, "test/oat/arm/package.art"), "/system/app/test/oat/arm/test.art"}, |
| 314 | {android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system/app/test/oat/arm/test.odex"}, |
| 315 | {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] | 316 | } |
| 317 | |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 318 | if rule.Installs().String() != wantInstalls.String() { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 319 | t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) |
| 320 | } |
| 321 | } |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 322 | |
| 323 | func TestDexPreoptConfigToJson(t *testing.T) { |
| 324 | config := android.TestConfig("out", nil, "", nil) |
| 325 | ctx := android.BuilderContextForTesting(config) |
| 326 | module := testSystemModuleConfig(ctx, "test") |
| 327 | data, err := moduleConfigToJSON(module) |
| 328 | if err != nil { |
| 329 | t.Errorf("Failed to convert module config data to JSON, %v", err) |
| 330 | } |
| 331 | parsed, err := ParseModuleConfig(ctx, data) |
| 332 | if err != nil { |
| 333 | t.Errorf("Failed to parse JSON, %v", err) |
| 334 | } |
| 335 | before := fmt.Sprintf("%v", module) |
| 336 | after := fmt.Sprintf("%v", parsed) |
| 337 | android.AssertStringEquals(t, "The result must be the same as the original after marshalling and unmarshalling it.", before, after) |
| 338 | } |
Jiakai Zhang | 7d29222 | 2024-01-18 17:27:42 +0000 | [diff] [blame] | 339 | |
| 340 | func TestUffdGcFlagForce(t *testing.T) { |
| 341 | for _, enableUffdGc := range []string{"true", "false"} { |
| 342 | t.Run(enableUffdGc, func(t *testing.T) { |
| 343 | preparers := android.GroupFixturePreparers( |
| 344 | PrepareForTestWithFakeDex2oatd, |
| 345 | PrepareForTestWithDexpreoptConfig, |
| 346 | FixtureSetEnableUffdGc(enableUffdGc), |
| 347 | ) |
| 348 | |
| 349 | result := preparers.RunTest(t) |
| 350 | ctx := result.TestContext |
| 351 | |
| 352 | ctx.SingletonForTests("dexpreopt-soong-config").Output("out/soong/dexpreopt/uffd_gc_flag.txt") |
| 353 | }) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | func TestUffdGcFlagDefault(t *testing.T) { |
| 358 | preparers := android.GroupFixturePreparers( |
| 359 | PrepareForTestWithFakeDex2oatd, |
| 360 | PrepareForTestWithDexpreoptConfig, |
| 361 | FixtureSetEnableUffdGc("default"), |
| 362 | ) |
| 363 | |
| 364 | result := preparers.RunTest(t) |
| 365 | ctx := result.TestContext |
| 366 | config := ctx.Config() |
| 367 | |
| 368 | rule := ctx.SingletonForTests("dexpreopt-soong-config").Rule("dexpreopt_uffd_gc_flag") |
| 369 | |
| 370 | android.AssertStringDoesContain(t, "", rule.RuleParams.Command, "construct_uffd_gc_flag") |
| 371 | android.AssertStringPathsRelativeToTopEquals(t, "", config, []string{ |
| 372 | "out/soong/dexpreopt/uffd_gc_flag.txt", |
| 373 | }, rule.AllOutputs()) |
| 374 | android.AssertPathsRelativeToTopEquals(t, "", []string{ |
| 375 | "out/soong/dexpreopt/kernel_version_for_uffd_gc.txt", |
| 376 | }, rule.Implicits) |
| 377 | } |
| 378 | |
| 379 | func TestUffdGcFlagBogus(t *testing.T) { |
| 380 | preparers := android.GroupFixturePreparers( |
| 381 | PrepareForTestWithFakeDex2oatd, |
| 382 | PrepareForTestWithDexpreoptConfig, |
| 383 | FixtureSetEnableUffdGc("bogus"), |
| 384 | ) |
| 385 | |
| 386 | preparers. |
| 387 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 388 | "Unknown value of PRODUCT_ENABLE_UFFD_GC: bogus")). |
| 389 | RunTest(t) |
| 390 | } |