Add TestContext parameter to ContentFromFileRuleForTests

The next CL will need a TestContext parameter in
ContentFromFileRuleForTests in order to retrieve the file rule contents
from the Config.  Add it and update all the tests that use it in order
to simply review of the next CL.

Bug: 306029038
Test: go test ./...
Change-Id: Ia4b4c9854017ea3472fa2f8ba42cf7f72720496e
This commit is contained in:
Colin Cross
2023-11-02 16:56:39 -07:00
parent 5c1d5fb21b
commit f61d03d241
13 changed files with 53 additions and 45 deletions

View File

@@ -341,9 +341,9 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string
}
}
func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
func checkWriteFileOutput(t *testing.T, ctx *android.TestContext, params android.TestingBuildParams, expected []string) {
t.Helper()
content := android.ContentFromFileRuleForTests(t, params)
content := android.ContentFromFileRuleForTests(t, ctx, params)
actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
assertArrayString(t, actual, expected)
}
@@ -351,7 +351,7 @@ func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expec
func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
t.Helper()
vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
checkWriteFileOutput(t, ctx, vndkSnapshot.Output(output), expected)
}
func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
@@ -4302,7 +4302,7 @@ func TestAidlLibraryWithHeaders(t *testing.T) {
libfoo.Rule("aidl_library").Implicits,
)
manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl_library.sbox.textproto"))
manifest := android.RuleBuilderSboxProtoForTests(t, ctx, libfoo.Output("aidl_library.sbox.textproto"))
aidlCommand := manifest.Commands[0].GetCommand()
expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x"
@@ -4337,7 +4337,7 @@ func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
`)
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
manifest := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, libfoo.Output("aidl.sbox.textproto"))
aidlCommand := manifest.Commands[0].GetCommand()
expectedAidlFlag := "-Werror"
if !strings.Contains(aidlCommand, expectedAidlFlag) {
@@ -4388,7 +4388,7 @@ func TestAidlFlagsWithMinSdkVersion(t *testing.T) {
}
`)
libfoo := ctx.ModuleForTests("libfoo", tc.variant)
manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
manifest := android.RuleBuilderSboxProtoForTests(t, ctx, libfoo.Output("aidl.sbox.textproto"))
aidlCommand := manifest.Commands[0].GetCommand()
expectedAidlFlag := "--min_sdk_version=" + tc.expected
if !strings.Contains(aidlCommand, expectedAidlFlag) {

View File

@@ -67,7 +67,7 @@ func TestGen(t *testing.T) {
t.Errorf("missing aidl includes in global flags")
}
aidlCommand := android.RuleBuilderSboxProtoForTests(t, aidlManifest).Commands[0].GetCommand()
aidlCommand := android.RuleBuilderSboxProtoForTests(t, ctx, aidlManifest).Commands[0].GetCommand()
if !strings.Contains(aidlCommand, "-Isub") {
t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand)
}

View File

@@ -178,7 +178,7 @@ func TestCmdPrefix(t *testing.T) {
android.OptionalFixturePreparer(tt.preparer),
).RunTestWithBp(t, bp)
gen := result.ModuleForTests("gen", tt.variant)
sboxProto := android.RuleBuilderSboxProtoForTests(t, gen.Output("genrule.sbox.textproto"))
sboxProto := android.RuleBuilderSboxProtoForTests(t, result.TestContext, gen.Output("genrule.sbox.textproto"))
cmd := *sboxProto.Commands[0].Command
android.AssertStringDoesContain(t, "incorrect CC_ARCH", cmd, "CC_ARCH="+tt.arch+" ")
android.AssertStringDoesContain(t, "incorrect CC_NATIVE_BRIDGE", cmd, "CC_NATIVE_BRIDGE="+tt.nativeBridge+" ")

View File

@@ -797,7 +797,7 @@ func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext,
func checkOverrides(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, jsonPath string, expected []string) {
t.Helper()
out := singleton.MaybeOutput(jsonPath)
content := android.ContentFromFileRuleForTests(t, out)
content := android.ContentFromFileRuleForTests(t, ctx, out)
var flags snapshotJsonFlags
if err := json.Unmarshal([]byte(content), &flags); err != nil {

View File

@@ -23,13 +23,14 @@ import (
"testing"
)
func checkJsonContents(t *testing.T, ctx android.TestingSingleton, jsonPath string, key string, value string) {
jsonOut := ctx.MaybeOutput(jsonPath)
func checkJsonContents(t *testing.T, ctx *android.TestContext, snapshotSingleton android.TestingSingleton, jsonPath string, key string, value string) {
jsonOut := snapshotSingleton.MaybeOutput(jsonPath)
if jsonOut.Rule == nil {
t.Errorf("%q expected but not found", jsonPath)
return
}
if !strings.Contains(jsonOut.Args["content"], fmt.Sprintf("%q:%q", key, value)) {
content := android.ContentFromFileRuleForTests(t, ctx, jsonOut)
if !strings.Contains(content, fmt.Sprintf("%q:%q", key, value)) {
t.Errorf("%q must include %q:%q but it only has %v", jsonPath, key, value, jsonOut.Args["content"])
}
}
@@ -167,8 +168,8 @@ func TestVendorSnapshotCapture(t *testing.T) {
filepath.Join(staticDir, "libvendor_available.a.json"),
filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit")
checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29")
checkJsonContents(t, ctx, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit")
checkJsonContents(t, ctx, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29")
// For binary executables, all vendor:true and vendor_available modules are captured.
if archType == "arm64" {