Merge "Switch CheckSnapshot from a testSdkResult method to a function" am: 982c550855

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1628640

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I42cc27f727be41ac6595acc6c8abd4251450d0d0
This commit is contained in:
Paul Duffin 2021-03-11 17:53:46 +00:00 committed by Automerger Merge Worker
commit 8337c02b38
5 changed files with 62 additions and 62 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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`),
)
}

View File

@ -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)