diff options
| author | 2019-10-03 11:01:03 +0000 | |
|---|---|---|
| committer | 2019-10-03 11:01:03 +0000 | |
| commit | a9e13f785f47b630f73af25603d80183a0444bf2 (patch) | |
| tree | 09627277554bbd8d43b8594e5b18774b358503df | |
| parent | 62be1e3e3360bda8b242625cf8d7bec8cb43c4ab (diff) | |
| parent | 4ec91dd47dfea0e2bb1faee7faf8ba929c93f397 (diff) | |
Merge "Beef up system_other odex tests"
| -rw-r--r-- | dexpreopt/dexpreopt_test.go | 93 |
1 files changed, 71 insertions, 22 deletions
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go index 7f1fe4276..78f2f3fb5 100644 --- a/dexpreopt/dexpreopt_test.go +++ b/dexpreopt/dexpreopt_test.go @@ -16,17 +16,30 @@ package dexpreopt import ( "android/soong/android" + "fmt" "reflect" "strings" "testing" ) -func testModuleConfig(ctx android.PathContext) ModuleConfig { +func testSystemModuleConfig(ctx android.PathContext, name string) ModuleConfig { + return testModuleConfig(ctx, name, "system") +} + +func testSystemProductModuleConfig(ctx android.PathContext, name string) ModuleConfig { + return testModuleConfig(ctx, name, "system/product") +} + +func testProductModuleConfig(ctx android.PathContext, name string) ModuleConfig { + return testModuleConfig(ctx, name, "product") +} + +func testModuleConfig(ctx android.PathContext, name, partition string) ModuleConfig { return ModuleConfig{ - Name: "test", - DexLocation: "/system/app/test/test.apk", - BuildPath: android.PathForOutput(ctx, "test/test.apk"), - DexPath: android.PathForOutput(ctx, "test/dex/test.jar"), + Name: name, + DexLocation: fmt.Sprintf("/%s/app/test/%s.apk", partition, name), + BuildPath: android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)), + DexPath: android.PathForOutput(ctx, fmt.Sprintf("%s/dex/%s.jar", name, name)), UncompressedDex: false, HasApkLibraries: false, PreoptFlags: nil, @@ -46,14 +59,14 @@ func testModuleConfig(ctx android.PathContext) ModuleConfig { ForceCreateAppImage: false, PresignedPrebuilt: false, NoStripping: false, - StripInputPath: android.PathForOutput(ctx, "unstripped/test.apk"), - StripOutputPath: android.PathForOutput(ctx, "stripped/test.apk"), + StripInputPath: android.PathForOutput(ctx, fmt.Sprintf("unstripped/%s.apk", name)), + StripOutputPath: android.PathForOutput(ctx, fmt.Sprintf("stripped/%s.apk", name)), } } func TestDexPreopt(t *testing.T) { ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil) - global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx) + global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test") rule, err := GenerateDexpreoptRule(ctx, global, module) if err != nil { @@ -73,7 +86,7 @@ func TestDexPreopt(t *testing.T) { func TestDexPreoptStrip(t *testing.T) { // Test that we panic if we strip in a configuration where stripping is not allowed. ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil) - global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx) + global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test") global.NeverAllowStripping = true module.NoStripping = false @@ -86,29 +99,65 @@ func TestDexPreoptStrip(t *testing.T) { func TestDexPreoptSystemOther(t *testing.T) { ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil) - global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx) + global := GlobalConfigForTests(ctx) + systemModule := testSystemModuleConfig(ctx, "Stest") + systemProductModule := testSystemProductModuleConfig(ctx, "SPtest") + productModule := testProductModuleConfig(ctx, "Ptest") global.HasSystemOther = true - global.PatternsOnSystemOther = []string{"app/%"} - rule, err := GenerateDexpreoptRule(ctx, global, module) - if err != nil { - t.Fatal(err) + type moduleTest struct { + module ModuleConfig + expectedPartition string } - - wantInstalls := android.RuleBuilderInstalls{ - {android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system_other/app/test/oat/arm/test.odex"}, - {android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system_other/app/test/oat/arm/test.vdex"}, + tests := []struct { + patterns []string + moduleTests []moduleTest + }{ + { + patterns: []string{"app/%"}, + moduleTests: []moduleTest{ + {module: systemModule, expectedPartition: "system_other"}, + {module: systemProductModule, expectedPartition: "system/product"}, + {module: productModule, expectedPartition: "product"}, + }, + }, + // product/app/% only applies to product apps inside the system partition + { + patterns: []string{"app/%", "product/app/%"}, + moduleTests: []moduleTest{ + {module: systemModule, expectedPartition: "system_other"}, + {module: systemProductModule, expectedPartition: "system_other/product"}, + {module: productModule, expectedPartition: "product"}, + }, + }, } - if rule.Installs().String() != wantInstalls.String() { - t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) + for _, test := range tests { + global.PatternsOnSystemOther = test.patterns + for _, mt := range test.moduleTests { + rule, err := GenerateDexpreoptRule(ctx, global, mt.module) + if err != nil { + t.Fatal(err) + } + + name := mt.module.Name + wantInstalls := android.RuleBuilderInstalls{ + {android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)}, + {android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)}, + } + + if rule.Installs().String() != wantInstalls.String() { + t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs()) + } + } } + } func TestDexPreoptProfile(t *testing.T) { ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil) - global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx) + global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test") module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile")) @@ -156,7 +205,7 @@ func TestStripDex(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil) - global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx) + global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test") test.setup(&global, &module) |