From 981b94b4609b34b880bc8b85fc51fed4daf94d17 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 11 Mar 2021 12:32:12 +0000 Subject: [PATCH] Switch CheckSnapshot from a testSdkResult method to a function This will allow the testSdkResult to be replaced with the TestResult when switching sdk package to use test fixtures. Bug: 181070625 Test: m nothing Change-Id: Ieca63f4c189f5e804102aeb4073289ea03143b6e --- sdk/cc_sdk_test.go | 52 ++++++++++++++++++++++---------------------- sdk/exports_test.go | 2 +- sdk/java_sdk_test.go | 40 +++++++++++++++++----------------- sdk/sdk_test.go | 4 ++-- sdk/testing.go | 26 +++++++++++----------- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 359177771..6da135a32 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -101,7 +101,7 @@ func TestSdkCompileMultilibOverride(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -353,7 +353,7 @@ func TestSnapshotWithObject(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -440,7 +440,7 @@ func TestSnapshotWithCcDuplicateHeaders(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h .intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so @@ -486,7 +486,7 @@ func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -556,7 +556,7 @@ func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -615,7 +615,7 @@ func TestSnapshotWithCcBinary(t *testing.T) { } `) - result.CheckSnapshot("mymodule_exports", "", + CheckSnapshot(result, "mymodule_exports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -700,7 +700,7 @@ func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -853,7 +853,7 @@ func TestSnapshotWithSingleHostOsType(t *testing.T) { result := runTests(t, ctx, config) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -991,7 +991,7 @@ func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) { } `) - result.CheckSnapshot("mymodule_exports", "", + CheckSnapshot(result, "mymodule_exports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1099,7 +1099,7 @@ func TestSnapshotWithCcSharedLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1200,7 +1200,7 @@ func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1297,7 +1297,7 @@ func TestHostSnapshotWithCcSharedLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1424,7 +1424,7 @@ func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1552,7 +1552,7 @@ func TestSnapshotWithCcStaticLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1615,7 +1615,7 @@ func TestHostSnapshotWithCcStaticLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1729,7 +1729,7 @@ func TestSnapshotWithCcLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1843,7 +1843,7 @@ func TestHostSnapshotWithMultiLib64(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1940,7 +1940,7 @@ func TestSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1978,7 +1978,7 @@ func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2080,7 +2080,7 @@ func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2193,7 +2193,7 @@ func TestSystemSharedLibPropagation(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2266,7 +2266,7 @@ cc_prebuilt_library_shared { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2377,7 +2377,7 @@ func TestStubsLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2430,7 +2430,7 @@ func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2543,7 +2543,7 @@ func TestUniqueHostSoname(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2658,7 +2658,7 @@ func TestNoSanitizerMembers(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/exports_test.go b/sdk/exports_test.go index 1c59244d8..54a40d272 100644 --- a/sdk/exports_test.go +++ b/sdk/exports_test.go @@ -42,7 +42,7 @@ func TestModuleExportsSnapshot(t *testing.T) { "package/Android.bp": []byte(packageBp), }) - result.CheckSnapshot("myexports", "package", + CheckSnapshot(result, "myexports", "package", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index f6d508d23..ef8e4a00d 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -127,7 +127,7 @@ func TestSdkDependsOnSourceEvenWhenPrebuiltPreferred(t *testing.T) { // Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember". java.CheckModuleDependencies(t, result.TestContext, "mysdk", "android_common", []string{"sdkmember"}) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT. java_import { @@ -255,7 +255,7 @@ func TestSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -312,7 +312,7 @@ func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -369,7 +369,7 @@ func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -440,7 +440,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -496,7 +496,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -551,7 +551,7 @@ func TestHostSnapshotWithJavaImplLibrary(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -607,7 +607,7 @@ func TestSnapshotWithJavaTest(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -662,7 +662,7 @@ func TestHostSnapshotWithJavaTest(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -731,7 +731,7 @@ func TestSnapshotWithJavaSystemModules(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -827,7 +827,7 @@ func TestHostSnapshotWithJavaSystemModules(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -918,7 +918,7 @@ func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) { } `) - result.CheckSnapshot("myexports", "", + CheckSnapshot(result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1032,7 +1032,7 @@ func TestSnapshotWithJavaSdkLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1133,7 +1133,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1202,7 +1202,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1274,7 +1274,7 @@ func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1367,7 +1367,7 @@ func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1475,7 +1475,7 @@ func TestSnapshotWithJavaSdkLibrary_SystemServer(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1563,7 +1563,7 @@ func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1639,7 +1639,7 @@ func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index a7acd0c5f..65a9001e6 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -169,7 +169,7 @@ func TestSnapshotVisibility(t *testing.T) { "package/Android.bp": []byte(packageBp), }) - result.CheckSnapshot("mysdk", "package", + CheckSnapshot(result, "mysdk", "package", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -317,7 +317,7 @@ func TestSdkInstall(t *testing.T) { ` result := testSdkWithFs(t, sdk, nil) - result.CheckSnapshot("mysdk", "", + CheckSnapshot(result, "mysdk", "", checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`), ) } diff --git a/sdk/testing.go b/sdk/testing.go index ea0fe77d8..fac2f8e8a 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -186,13 +186,17 @@ type testSdkResult struct { *android.TestContext } +func (result *testSdkResult) Module(name string, variant string) android.Module { + return result.ModuleForTests(name, variant).Module() +} + // Analyse the sdk build rules to extract information about what it is doing. // e.g. find the src/dest pairs from each cp command, the various zip files // generated, etc. -func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo { +func getSdkSnapshotBuildInfo(result *testSdkResult, sdk *sdk) *snapshotBuildInfo { info := &snapshotBuildInfo{ - r: r, + r: result, androidBpContents: sdk.GetAndroidBpContentsForTests(), androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(), @@ -235,7 +239,7 @@ func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo { info.intermediateZip = info.outputZip mergeInput := android.NormalizePathForTesting(bp.Input) if info.intermediateZip != mergeInput { - r.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", + result.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", info.intermediateZip, mergeInput) } @@ -254,24 +258,20 @@ func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo { return info } -func (r *testSdkResult) Module(name string, variant string) android.Module { - return r.ModuleForTests(name, variant).Module() -} - // Check the snapshot build rules. // // Takes a list of functions which check different facets of the snapshot build rules. // Allows each test to customize what is checked without duplicating lots of code // or proliferating check methods of different flavors. -func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snapshotBuildInfoChecker) { - r.Helper() +func CheckSnapshot(result *testSdkResult, name string, dir string, checkers ...snapshotBuildInfoChecker) { + result.Helper() // The sdk CommonOS variant is always responsible for generating the snapshot. variant := android.CommonOS.Name - sdk := r.Module(name, variant).(*sdk) + sdk := result.Module(name, variant).(*sdk) - snapshotBuildInfo := r.getSdkSnapshotBuildInfo(sdk) + snapshotBuildInfo := getSdkSnapshotBuildInfo(result, sdk) // Check state of the snapshot build. for _, checker := range checkers { @@ -283,7 +283,7 @@ func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snaps if dir != "" { dir = filepath.Clean(dir) + "/" } - r.AssertStringEquals("Snapshot zip file in wrong place", + result.AssertStringEquals("Snapshot zip file in wrong place", fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual) // Populate a mock filesystem with the files that would have been copied by @@ -294,7 +294,7 @@ func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snaps } // Process the generated bp file to make sure it is valid. - testSdkWithFs(r.T, snapshotBuildInfo.androidBpContents, fs) + testSdkWithFs(result.T, snapshotBuildInfo.androidBpContents, fs) } type snapshotBuildInfoChecker func(info *snapshotBuildInfo)