From 2eaf5c5256b9ce92e5d520c00efc2ea67ebd2bf2 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Fri, 26 Feb 2021 12:05:11 +0000 Subject: [PATCH] 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 --- java/app_test.go | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/java/app_test.go b/java/app_test.go index b1abe3db3..72a53e970 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -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]#` +