blob: eff2416e57a38061ce4f328a9cb068c92f7ae7e2 [file] [log] [blame]
Colin Cross43f08db2018-11-12 10:13:39 -08001// 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
15package dexpreopt
16
17import (
Colin Crossfeec25b2019-01-30 17:32:39 -080018 "android/soong/android"
Anton Hansson4ec91dd2019-10-02 17:42:44 +010019 "fmt"
Colin Cross43f08db2018-11-12 10:13:39 -080020 "testing"
21)
22
Martin Stjernholm8d80cee2020-01-31 17:44:54 +000023func testSystemModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
Anton Hansson4ec91dd2019-10-02 17:42:44 +010024 return testModuleConfig(ctx, name, "system")
25}
26
Martin Stjernholm8d80cee2020-01-31 17:44:54 +000027func testSystemProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
Anton Hansson4ec91dd2019-10-02 17:42:44 +010028 return testModuleConfig(ctx, name, "system/product")
29}
30
Martin Stjernholm8d80cee2020-01-31 17:44:54 +000031func testProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
Anton Hansson4ec91dd2019-10-02 17:42:44 +010032 return testModuleConfig(ctx, name, "product")
33}
34
Martin Stjernholm8d80cee2020-01-31 17:44:54 +000035func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleConfig {
Jiakai Zhang519c5c82021-09-16 06:15:39 +000036 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
44func 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 Zhang389a6472021-12-14 18:54:06 +000053func 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
liulvping76d56ee2022-05-07 14:40:13 +080062func 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 Zhang519c5c82021-09-16 06:15:39 +000071func createTestModuleConfig(name, dexLocation string, buildPath, dexPath, enforceUsesLibrariesStatusFile android.OutputPath) *ModuleConfig {
Martin Stjernholm8d80cee2020-01-31 17:44:54 +000072 return &ModuleConfig{
Anton Hansson4ec91dd2019-10-02 17:42:44 +010073 Name: name,
Jiakai Zhang519c5c82021-09-16 06:15:39 +000074 DexLocation: dexLocation,
75 BuildPath: buildPath,
76 DexPath: dexPath,
Colin Cross69f59a32019-02-15 10:39:37 -080077 UncompressedDex: false,
78 HasApkLibraries: false,
79 PreoptFlags: nil,
80 ProfileClassListing: android.OptionalPath{},
81 ProfileIsTextListing: false,
Jiakai Zhang519c5c82021-09-16 06:15:39 +000082 EnforceUsesLibrariesStatusFile: enforceUsesLibrariesStatusFile,
Colin Cross69f59a32019-02-15 10:39:37 -080083 EnforceUsesLibraries: false,
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +000084 ClassLoaderContexts: nil,
Colin Cross69f59a32019-02-15 10:39:37 -080085 Archs: []android.ArchType{android.Arm},
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000086 DexPreoptImagesDeps: []android.OutputPaths{android.OutputPaths{}},
Jeongik Chaa5969092021-05-07 18:53:21 +090087 DexPreoptImageLocationsOnHost: []string{},
Colin Cross69f59a32019-02-15 10:39:37 -080088 PreoptBootClassPathDexFiles: nil,
89 PreoptBootClassPathDexLocations: nil,
Colin Cross69f59a32019-02-15 10:39:37 -080090 NoCreateAppImage: false,
91 ForceCreateAppImage: false,
92 PresignedPrebuilt: false,
Colin Cross69f59a32019-02-15 10:39:37 -080093 }
Colin Cross43f08db2018-11-12 10:13:39 -080094}
95
96func TestDexPreopt(t *testing.T) {
Martin Stjernholm75a48d82020-01-10 20:32:59 +000097 config := android.TestConfig("out", nil, "", nil)
Colin Crossf1a035e2020-11-16 17:32:30 -080098 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +000099 globalSoong := globalSoongConfigForTests(ctx)
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000100 global := GlobalConfigForTests(ctx)
101 module := testSystemModuleConfig(ctx, "test")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100102 productPackages := android.PathForTesting("product_packages.txt")
Colin Cross43f08db2018-11-12 10:13:39 -0800103
Spandan Das5ae65ee2024-04-16 22:03:26 +0000104 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
Colin Cross43f08db2018-11-12 10:13:39 -0800105 if err != nil {
Colin Cross69f59a32019-02-15 10:39:37 -0800106 t.Fatal(err)
Colin Cross43f08db2018-11-12 10:13:39 -0800107 }
108
Colin Crossdeabb942019-02-11 14:11:09 -0800109 wantInstalls := android.RuleBuilderInstalls{
Colin Cross69f59a32019-02-15 10:39:37 -0800110 {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 Cross43f08db2018-11-12 10:13:39 -0800112 }
113
Colin Cross2cdd5df2019-02-25 10:25:24 -0800114 if rule.Installs().String() != wantInstalls.String() {
Colin Cross43f08db2018-11-12 10:13:39 -0800115 t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
116 }
Jiakai Zhang7d292222024-01-18 17:27:42 +0000117
118 android.AssertStringListContains(t, "", rule.Inputs().RelativeToTop().Strings(),
119 "out/soong/dexpreopt_test/uffd_gc_flag.txt")
Colin Cross43f08db2018-11-12 10:13:39 -0800120}
121
122func TestDexPreoptSystemOther(t *testing.T) {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000123 config := android.TestConfig("out", nil, "", nil)
Colin Crossf1a035e2020-11-16 17:32:30 -0800124 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000125 globalSoong := globalSoongConfigForTests(ctx)
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100126 global := GlobalConfigForTests(ctx)
127 systemModule := testSystemModuleConfig(ctx, "Stest")
128 systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
129 productModule := testProductModuleConfig(ctx, "Ptest")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100130 productPackages := android.PathForTesting("product_packages.txt")
Colin Cross43f08db2018-11-12 10:13:39 -0800131
132 global.HasSystemOther = true
Colin Cross43f08db2018-11-12 10:13:39 -0800133
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100134 type moduleTest struct {
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000135 module *ModuleConfig
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100136 expectedPartition string
137 }
138 tests := []struct {
139 patterns []string
140 moduleTests []moduleTest
141 }{
142 {
143 patterns: []string{"app/%"},
144 moduleTests: []moduleTest{
Anton Hansson43ab0bc2019-10-03 14:18:45 +0100145 {module: systemModule, expectedPartition: "system_other/system"},
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100146 {module: systemProductModule, expectedPartition: "system/product"},
147 {module: productModule, expectedPartition: "product"},
148 },
149 },
Anton Hanssonda4d9d92020-09-15 09:28:55 +0000150 // product/app/% only applies to product apps inside the system partition
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100151 {
152 patterns: []string{"app/%", "product/app/%"},
153 moduleTests: []moduleTest{
Anton Hansson43ab0bc2019-10-03 14:18:45 +0100154 {module: systemModule, expectedPartition: "system_other/system"},
155 {module: systemProductModule, expectedPartition: "system_other/system/product"},
Anton Hanssonda4d9d92020-09-15 09:28:55 +0000156 {module: productModule, expectedPartition: "product"},
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100157 },
158 },
Colin Cross43f08db2018-11-12 10:13:39 -0800159 }
160
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100161 for _, test := range tests {
162 global.PatternsOnSystemOther = test.patterns
163 for _, mt := range test.moduleTests {
Spandan Das5ae65ee2024-04-16 22:03:26 +0000164 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages, true)
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100165 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 Hanssonda4d9d92020-09-15 09:28:55 +0000176 t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
Anton Hansson4ec91dd2019-10-02 17:42:44 +0100177 }
178 }
Colin Cross43f08db2018-11-12 10:13:39 -0800179 }
180
Colin Cross43f08db2018-11-12 10:13:39 -0800181}
182
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000183func TestDexPreoptApexSystemServerJars(t *testing.T) {
Spandan Das5ae65ee2024-04-16 22:03:26 +0000184 // modify the global variable for test
185 var oldDexpreoptRunningInSoong = DexpreoptRunningInSoong
186 DexpreoptRunningInSoong = true
187
188 // test begin
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000189 config := android.TestConfig("out", nil, "", nil)
190 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000191 globalSoong := globalSoongConfigForTests(ctx)
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000192 global := GlobalConfigForTests(ctx)
193 module := testApexModuleConfig(ctx, "service-A", "com.android.apex1")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100194 productPackages := android.PathForTesting("product_packages.txt")
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000195
196 global.ApexSystemServerJars = android.CreateTestConfiguredJarList(
197 []string{"com.android.apex1:service-A"})
198
Spandan Das5ae65ee2024-04-16 22:03:26 +0000199 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000200 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 Das5ae65ee2024-04-16 22:03:26 +0000210
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 Zhang519c5c82021-09-16 06:15:39 +0000222}
223
Jiakai Zhang389a6472021-12-14 18:54:06 +0000224func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
225 config := android.TestConfig("out", nil, "", nil)
226 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000227 globalSoong := globalSoongConfigForTests(ctx)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000228 global := GlobalConfigForTests(ctx)
229 module := testPlatformSystemServerModuleConfig(ctx, "service-A")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100230 productPackages := android.PathForTesting("product_packages.txt")
Jiakai Zhang389a6472021-12-14 18:54:06 +0000231
232 global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
233 []string{"platform:service-A"})
234
Spandan Das5ae65ee2024-04-16 22:03:26 +0000235 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000236 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
liulvping76d56ee2022-05-07 14:40:13 +0800248func TestDexPreoptSystemExtSystemServerJars(t *testing.T) {
249 config := android.TestConfig("out", nil, "", nil)
250 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000251 globalSoong := globalSoongConfigForTests(ctx)
liulvping76d56ee2022-05-07 14:40:13 +0800252 global := GlobalConfigForTests(ctx)
253 module := testSystemExtSystemServerModuleConfig(ctx, "service-A")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100254 productPackages := android.PathForTesting("product_packages.txt")
liulvping76d56ee2022-05-07 14:40:13 +0800255
256 global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
257 []string{"system_ext:service-A"})
258
Spandan Das5ae65ee2024-04-16 22:03:26 +0000259 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
liulvping76d56ee2022-05-07 14:40:13 +0800260 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 Zhang389a6472021-12-14 18:54:06 +0000272func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) {
273 config := android.TestConfig("out", nil, "", nil)
274 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000275 globalSoong := globalSoongConfigForTests(ctx)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000276 global := GlobalConfigForTests(ctx)
277 module := testApexModuleConfig(ctx, "service-A", "com.android.apex1")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100278 productPackages := android.PathForTesting("product_packages.txt")
Jiakai Zhang389a6472021-12-14 18:54:06 +0000279
280 global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(
281 []string{"com.android.apex1:service-A"})
282
Spandan Das5ae65ee2024-04-16 22:03:26 +0000283 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000284 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 Cross43f08db2018-11-12 10:13:39 -0800296func TestDexPreoptProfile(t *testing.T) {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000297 config := android.TestConfig("out", nil, "", nil)
Colin Crossf1a035e2020-11-16 17:32:30 -0800298 ctx := android.BuilderContextForTesting(config)
Jiakai Zhang7d292222024-01-18 17:27:42 +0000299 globalSoong := globalSoongConfigForTests(ctx)
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000300 global := GlobalConfigForTests(ctx)
301 module := testSystemModuleConfig(ctx, "test")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100302 productPackages := android.PathForTesting("product_packages.txt")
Colin Cross43f08db2018-11-12 10:13:39 -0800303
Colin Cross69f59a32019-02-15 10:39:37 -0800304 module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
Colin Cross43f08db2018-11-12 10:13:39 -0800305
Spandan Das5ae65ee2024-04-16 22:03:26 +0000306 rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
Colin Cross43f08db2018-11-12 10:13:39 -0800307 if err != nil {
Colin Cross69f59a32019-02-15 10:39:37 -0800308 t.Fatal(err)
Colin Cross43f08db2018-11-12 10:13:39 -0800309 }
310
Colin Crossdeabb942019-02-11 14:11:09 -0800311 wantInstalls := android.RuleBuilderInstalls{
Colin Cross69f59a32019-02-15 10:39:37 -0800312 {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 Cross43f08db2018-11-12 10:13:39 -0800316 }
317
Colin Cross2cdd5df2019-02-25 10:25:24 -0800318 if rule.Installs().String() != wantInstalls.String() {
Colin Cross43f08db2018-11-12 10:13:39 -0800319 t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
320 }
321}
Jeongik Chac6246672021-04-08 00:00:19 +0900322
323func 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 Zhang7d292222024-01-18 17:27:42 +0000339
340func 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
357func 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
379func 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}