Stricten TestUsesLibrary check.

- Verify argument order for manifest_fixer args verify_uses_libraries.
- Rewrite manifest_fixer test so that it reveals arguments that should
  not be there, add a TODO to remove them.

Bug: 132357300
Test: m nothing
Change-Id: I910e13b84f0464fc06b5b98395ddb45bf4120223
This commit is contained in:
Ulya Trafimovich
2021-02-26 12:05:11 +00:00
parent 30e3e9d21d
commit 2eaf5c5256

View File

@@ -2286,35 +2286,44 @@ func TestUsesLibraries(t *testing.T) {
prebuilt := ctx.ModuleForTests("prebuilt", "android_common")
// Test that implicit dependencies on java_sdk_library instances are passed to the manifest.
manifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
for _, w := range []string{"qux", "quuz", "runtime-library"} {
if !strings.Contains(manifestFixerArgs, "--uses-library "+w) {
t.Errorf("unexpected manifest_fixer args: wanted %q in %q", w, manifestFixerArgs)
}
// This should not include explicit `uses_libs`/`optional_uses_libs` entries.
actualManifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
expectManifestFixerArgs := `--extract-native-libs=true ` +
`--uses-library qux ` +
`--uses-library quuz ` +
`--uses-library foo ` + // TODO(b/132357300): "foo" should not be passed to manifest_fixer
`--uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer
`--uses-library runtime-library`
if actualManifestFixerArgs != expectManifestFixerArgs {
t.Errorf("unexpected manifest_fixer args:\n\texpect: %q\n\tactual: %q",
expectManifestFixerArgs, actualManifestFixerArgs)
}
// Test that all libraries are verified
cmd := app.Rule("verify_uses_libraries").RuleParams.Command
if w := "--uses-library foo"; !strings.Contains(cmd, w) {
t.Errorf("wanted %q in %q", w, cmd)
// Test that all libraries are verified (library order matters).
verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command
verifyArgs := `--uses-library foo ` +
`--uses-library qux ` +
`--uses-library quuz ` +
`--uses-library runtime-library ` +
`--optional-uses-library bar ` +
`--optional-uses-library baz `
if !strings.Contains(verifyCmd, verifyArgs) {
t.Errorf("wanted %q in %q", verifyArgs, verifyCmd)
}
if w := "--optional-uses-library bar --optional-uses-library baz"; !strings.Contains(cmd, w) {
t.Errorf("wanted %q in %q", w, cmd)
// Test that all libraries are verified for an APK (library order matters).
verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command
verifyApkReqLibs := `uses_library_names="foo android.test.runner"`
verifyApkOptLibs := `optional_uses_library_names="bar baz"`
if !strings.Contains(verifyApkCmd, verifyApkReqLibs) {
t.Errorf("wanted %q in %q", verifyApkReqLibs, verifyApkCmd)
}
cmd = prebuilt.Rule("verify_uses_libraries").RuleParams.Command
if w := `uses_library_names="foo android.test.runner"`; !strings.Contains(cmd, w) {
t.Errorf("wanted %q in %q", w, cmd)
}
if w := `optional_uses_library_names="bar baz"`; !strings.Contains(cmd, w) {
t.Errorf("wanted %q in %q", w, cmd)
if !strings.Contains(verifyApkCmd, verifyApkOptLibs) {
t.Errorf("wanted %q in %q", verifyApkOptLibs, verifyApkCmd)
}
// Test that all present libraries are preopted, including implicit SDK dependencies, possibly stubs
cmd = app.Rule("dexpreopt").RuleParams.Command
cmd := app.Rule("dexpreopt").RuleParams.Command
w := `--target-context-for-sdk any ` +
`PCL[/system/framework/qux.jar]#` +
`PCL[/system/framework/quuz.jar]#` +