summaryrefslogtreecommitdiff
path: root/java/system_modules_test.go
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2021-03-11 08:10:19 +0000
committerPaul Duffin <paulduffin@google.com>2021-03-11 09:39:18 +0000
commitc52bea9555086692a7afc0dc5cf36b60ca430057 (patch)
treeda03e392f97bcb5a44cd959a8292832d54c3ef3e /java/system_modules_test.go
parentf23e346f6cff3162b3b9ca8e73ddea8ac2f4ca89 (diff)
Improve system modules tests
The previous approach of looking for substrings in the command that matched the base name of the jar could not differentiate between whether the jar was a prebuilt or a source as they both have the same base name. The tests also did not cover the case when there was both prebuilts and source modules. This change: 1. Checks that the inputs to the command come from the appropriate module. 2. Adds a mixed test. 3. Deduped the source and prebuilt module definitions. The new test reveals the buggy behavior which will be fixed in a follow up change. Bug: 182402568 Test: m nothing Change-Id: I384ecca097cbe3560e7589c23fb99c176a42fd9b
Diffstat (limited to 'java/system_modules_test.go')
-rw-r--r--java/system_modules_test.go76
1 files changed, 56 insertions, 20 deletions
diff --git a/java/system_modules_test.go b/java/system_modules_test.go
index d2fa2b152..a8d7b0210 100644
--- a/java/system_modules_test.go
+++ b/java/system_modules_test.go
@@ -16,10 +16,21 @@ package java
import (
"testing"
+
+ "android/soong/android"
)
-func TestJavaSystemModules(t *testing.T) {
- result := javaFixtureFactory.RunTestWithBp(t, `
+func normalizedPathsToHeaderJars(result *android.TestResult, moduleNames ...string) []string {
+ paths := []string{}
+ for _, moduleName := range moduleNames {
+ module := result.Module(moduleName, "android_common")
+ info := result.ModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ paths = append(paths, result.NormalizePathsForTesting(info.HeaderJars)...)
+ }
+ return paths
+}
+
+var addSourceSystemModules = android.FixtureAddTextFile("source/Android.bp", `
java_system_modules {
name: "system-modules",
libs: ["system-module1", "system-module2"],
@@ -36,21 +47,21 @@ func TestJavaSystemModules(t *testing.T) {
sdk_version: "none",
system_modules: "none",
}
- `)
+`)
- // check the existence of the module
- systemModules := result.ModuleForTests("system-modules", "android_common")
+func TestJavaSystemModules(t *testing.T) {
+ result := javaFixtureFactory.RunTest(t, addSourceSystemModules)
- cmd := systemModules.Rule("jarsTosystemModules")
+ // check the existence of the source module
+ sourceSystemModules := result.ModuleForTests("system-modules", "android_common")
+ sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
- // make sure the command compiles against the supplied modules.
- for _, module := range []string{"system-module1.jar", "system-module2.jar"} {
- result.AssertStringDoesContain("system modules classpath", cmd.Args["classpath"], module)
- }
+ // The expected paths are the header jars from the source input modules.
+ expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
}
-func TestJavaSystemModulesImport(t *testing.T) {
- result := javaFixtureFactory.RunTestWithBp(t, `
+var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", `
java_system_modules_import {
name: "system-modules",
libs: ["system-module1", "system-module2"],
@@ -63,15 +74,40 @@ func TestJavaSystemModulesImport(t *testing.T) {
name: "system-module2",
jars: ["b.jar"],
}
- `)
+`)
- // check the existence of the module
- systemModules := result.ModuleForTests("system-modules", "android_common")
+func TestJavaSystemModulesImport(t *testing.T) {
+ result := javaFixtureFactory.RunTest(t, addPrebuiltSystemModules)
- cmd := systemModules.Rule("jarsTosystemModules")
+ // check the existence of the renamed prebuilt module
+ prebuiltSystemModules := result.ModuleForTests("system-modules", "android_common")
+ prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
- // make sure the command compiles against the supplied modules.
- for _, module := range []string{"system-module1.jar", "system-module2.jar"} {
- result.AssertStringDoesContain("system modules classpath", cmd.Args["classpath"], module)
- }
+ // The expected paths are the header jars from the renamed prebuilt input modules.
+ expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ result.AssertArrayString("renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
+}
+
+func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
+ result := javaFixtureFactory.RunTest(t,
+ addSourceSystemModules,
+ addPrebuiltSystemModules,
+ )
+
+ // check the existence of the source module
+ sourceSystemModules := result.ModuleForTests("system-modules", "android_common")
+ sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
+
+ // The expected paths are the header jars from the source input modules.
+ expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
+
+ // check the existence of the renamed prebuilt module
+ prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common")
+ prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
+
+ // The expected paths are the header jars from the renamed prebuilt input modules.
+ // TODO(b/182402568) - these should be depending on the prebuilts
+ expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ result.AssertArrayString("prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
}