From db462dd9878e6d412139e853e2c1224caf7452a3 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Sun, 21 Mar 2021 22:01:55 +0000 Subject: [PATCH] Disallow non-existent paths in sdk package Test behavior was changed a while ago so that tests by default ignore non-existent source paths (unless they explicitly check for/rely on them). Prior to that CheckSnapshot() could detect when files were missing from the snapshot but it no longer can. This change disallows non-existent source files in all the sdk tests which means that they are disallowed when processing the snapshots as they use the same preparers as were used to process the sources. This caused a test failure which has been temporarily ignored and has a TODO and bug associated with it. Bug: 183184375 Test: m nothing Change-Id: I969d8515d20ef5ae515f2b5f93d8ed4e4f8ede75 --- apex/testing.go | 7 +++++++ cc/cc_test.go | 9 +++++++++ cc/testing.go | 15 +++++++++++++++ sdk/cc_sdk_test.go | 6 ++++++ sdk/java_sdk_test.go | 22 ++++++++++++++++++++-- sdk/testing.go | 14 ++++++++++---- 6 files changed, 67 insertions(+), 6 deletions(-) diff --git a/apex/testing.go b/apex/testing.go index e662cade3..926125f26 100644 --- a/apex/testing.go +++ b/apex/testing.go @@ -19,4 +19,11 @@ import "android/soong/android" var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( android.FixtureRegisterWithContext(registerApexBuildComponents), android.FixtureRegisterWithContext(registerApexKeyBuildComponents), + // Additional files needed in tests that disallow non-existent source files. + // This includes files that are needed by all, or at least most, instances of an apex module type. + android.MockFS{ + // Needed by apex. + "system/core/rootdir/etc/public.libraries.android.txt": nil, + "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, + }.AddToFixture(), ) diff --git a/cc/cc_test.go b/cc/cc_test.go index 719661598..8b3a6bdc6 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -166,6 +166,15 @@ const ( recoveryVariant = "android_recovery_arm64_armv8-a_shared" ) +// Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by +// running it in a fixture that requires all source files to exist. +func TestPrepareForTestWithCcDefaultModules(t *testing.T) { + android.GroupFixturePreparers( + PrepareForTestWithCcDefaultModules, + android.PrepareForTestDisallowNonExistentPaths, + ).RunTest(t) +} + func TestFuchsiaDeps(t *testing.T) { t.Helper() diff --git a/cc/testing.go b/cc/testing.go index d8adc6127..6e356557c 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -619,11 +619,26 @@ var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers( RegisterVndkLibraryTxtTypes(ctx) }), + + // Additional files needed in tests that disallow non-existent source files. + // This includes files that are needed by all, or at least most, instances of a cc module type. + android.MockFS{ + // Needed for ndk_prebuilt_(shared|static)_stl. + "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil, + }.AddToFixture(), ) // Preparer that will define default cc modules, e.g. standard prebuilt modules. var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers( PrepareForTestWithCcBuildComponents, + + // Additional files needed in tests that disallow non-existent source. + android.MockFS{ + "defaults/cc/common/libc.map.txt": nil, + "defaults/cc/common/libdl.map.txt": nil, + "defaults/cc/common/libm.map.txt": nil, + }.AddToFixture(), + // Place the default cc test modules that are common to all platforms in a location that will not // conflict with default test modules defined by other packages. android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()), diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 6c02bf755..a886a18ce 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -486,6 +486,9 @@ func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) { } `) + // TODO(b/183322862): Remove this and fix the issue. + errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module source path "snapshot/include_gen/generated_foo/gen/protos" does not exist`) + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -518,6 +521,9 @@ myinclude/Test.h -> include/myinclude/Test.h .intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so .intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so `), + snapshotTestErrorHandler(checkSnapshotWithoutSource, errorHandler), + snapshotTestErrorHandler(checkSnapshotWithSourcePreferred, errorHandler), + snapshotTestErrorHandler(checkSnapshotPreferredWithSource, errorHandler), ) } diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 6f78ded35..2bc248d22 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -24,6 +24,16 @@ import ( var prepareForSdkTestWithJava = android.GroupFixturePreparers( java.PrepareForTestWithJavaBuildComponents, PrepareForTestWithSdkBuildComponents, + + // Ensure that all source paths are provided. This helps ensure that the snapshot generation is + // consistent and all files referenced from the snapshot's Android.bp file have actually been + // copied into the snapshot. + android.PrepareForTestDisallowNonExistentPaths, + + // Files needs by most of the tests. + android.MockFS{ + "Test.java": nil, + }.AddToFixture(), ) var prepareForSdkTestWithJavaSdkLibrary = android.GroupFixturePreparers( @@ -339,6 +349,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil), + android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` module_exports { name: "myexports", @@ -394,7 +405,11 @@ aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl } func TestSnapshotWithJavaBootLibrary(t *testing.T) { - result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + android.FixtureAddFile("aidl", nil), + android.FixtureAddFile("resource.txt", nil), + ).RunTestWithBp(t, ` module_exports { name: "myexports", java_boot_libs: ["myjavalib"], @@ -1539,7 +1554,10 @@ sdk_snapshot { } func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { - result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` + result := android.GroupFixturePreparers( + prepareForSdkTestWithJavaSdkLibrary, + android.FixtureAddFile("docs/known_doctags", nil), + ).RunTestWithBp(t, ` sdk { name: "mysdk", java_sdk_libs: ["myjavalib"], diff --git a/sdk/testing.go b/sdk/testing.go index f2538145b..44970f756 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -48,10 +48,10 @@ var prepareForSdkTestWithApex = android.GroupFixturePreparers( "system/sepolicy/apex/myapex-file_contexts": nil, "system/sepolicy/apex/myapex2-file_contexts": nil, "system/sepolicy/apex/mysdkapex-file_contexts": nil, - "myapex.avbpubkey": nil, - "myapex.pem": nil, - "myapex.x509.pem": nil, - "myapex.pk8": nil, + "sdk/tests/myapex.avbpubkey": nil, + "sdk/tests/myapex.pem": nil, + "sdk/tests/myapex.x509.pem": nil, + "sdk/tests/myapex.pk8": nil, }), ) @@ -80,6 +80,12 @@ var prepareForSdkTest = android.GroupFixturePreparers( {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true}, } }), + + // Make sure that every test provides all the source files. + android.PrepareForTestDisallowNonExistentPaths, + android.MockFS{ + "Test.java": nil, + }.AddToFixture(), ) var PrepareForTestWithSdkBuildComponents = android.GroupFixturePreparers(