Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2998c33d authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge "Add TestContext parameter to ContentFromFileRuleForTests" into main

parents bee01f7d f61d03d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ func shellUnescape(s string) string {

// ContentFromFileRuleForTests returns the content that was passed to a WriteFileRule for use
// in tests.
func ContentFromFileRuleForTests(t *testing.T, params TestingBuildParams) string {
func ContentFromFileRuleForTests(t *testing.T, ctx *TestContext, params TestingBuildParams) string {
	t.Helper()
	if g, w := params.Rule, writeFile; g != w {
		t.Errorf("expected params.Rule to be %q, was %q", w, g)
+2 −2
Original line number Diff line number Diff line
@@ -1341,9 +1341,9 @@ func (c *RuleBuilderCommand) String() string {

// RuleBuilderSboxProtoForTests takes the BuildParams for the manifest passed to RuleBuilder.Sbox()
// and returns sbox testproto generated by the RuleBuilder.
func RuleBuilderSboxProtoForTests(t *testing.T, params TestingBuildParams) *sbox_proto.Manifest {
func RuleBuilderSboxProtoForTests(t *testing.T, ctx *TestContext, params TestingBuildParams) *sbox_proto.Manifest {
	t.Helper()
	content := ContentFromFileRuleForTests(t, params)
	content := ContentFromFileRuleForTests(t, ctx, params)
	manifest := sbox_proto.Manifest{}
	err := prototext.Unmarshal([]byte(content), &manifest)
	if err != nil {
+2 −2
Original line number Diff line number Diff line
@@ -683,7 +683,7 @@ func TestRuleBuilder_Build(t *testing.T) {
			t.Errorf("want Deps = %q, got %q", blueprint.DepsGCC, params.Deps)
		}

		rspFile2Content := ContentFromFileRuleForTests(t, rspFile2Params)
		rspFile2Content := ContentFromFileRuleForTests(t, result.TestContext, rspFile2Params)
		AssertStringEquals(t, "rspFile2 content", "rsp_in2\n", rspFile2Content)
	}

@@ -797,7 +797,7 @@ func TestRuleBuilderHashInputs(t *testing.T) {
		t.Run(test.name, func(t *testing.T) {
			t.Run("sbox", func(t *testing.T) {
				gen := result.ModuleForTests(test.name+"_sbox", "")
				manifest := RuleBuilderSboxProtoForTests(t, gen.Output("sbox.textproto"))
				manifest := RuleBuilderSboxProtoForTests(t, result.TestContext, gen.Output("sbox.textproto"))
				hash := manifest.Commands[0].GetInputHash()

				AssertStringEquals(t, "hash", test.expectedHash, hash)
+17 −10
Original line number Diff line number Diff line
@@ -597,13 +597,15 @@ func TestBasicApex(t *testing.T) {
		t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
	}

	fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
	fullDepsInfo := strings.Split(android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex", "android_common_myapex").Output("depsinfo/fulllist.txt")), "\n")
	ensureListContains(t, fullDepsInfo, "  myjar(minSdkVersion:(no version)) <- myapex")
	ensureListContains(t, fullDepsInfo, "  mylib2(minSdkVersion:(no version)) <- mylib")
	ensureListContains(t, fullDepsInfo, "  myotherjar(minSdkVersion:(no version)) <- myjar")
	ensureListContains(t, fullDepsInfo, "  mysharedjar(minSdkVersion:(no version)) (external) <- myjar")

	flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
	flatDepsInfo := strings.Split(android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex", "android_common_myapex").Output("depsinfo/flatlist.txt")), "\n")
	ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))")
	ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))")
	ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))")
@@ -1283,10 +1285,12 @@ func TestApexWithExplicitStubsDependency(t *testing.T) {
	// Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
	ensureNotContains(t, libFooStubsLdFlags, "libbar.so")

	fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
	fullDepsInfo := strings.Split(android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex2", "android_common_myapex2").Output("depsinfo/fulllist.txt")), "\n")
	ensureListContains(t, fullDepsInfo, "  libfoo(minSdkVersion:(no version)) (external) <- mylib")

	flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
	flatDepsInfo := strings.Split(android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex2", "android_common_myapex2").Output("depsinfo/flatlist.txt")), "\n")
	ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)")
}

@@ -2032,7 +2036,8 @@ func TestTrackAllowedDeps(t *testing.T) {
		"out/soong/.intermediates/myapex2/android_common_myapex2/depsinfo/flatlist.txt")

	myapex := ctx.ModuleForTests("myapex", "android_common_myapex")
	flatlist := strings.Split(myapex.Output("depsinfo/flatlist.txt").BuildParams.Args["content"], "\\n")
	flatlist := strings.Split(android.ContentFromFileRuleForTests(t, ctx,
		myapex.Output("depsinfo/flatlist.txt")), "\n")
	android.AssertStringListContains(t, "deps with stubs should be tracked in depsinfo as external dep",
		flatlist, "libbar(minSdkVersion:(no version)) (external)")
	android.AssertStringListDoesNotContain(t, "do not track if not available for platform",
@@ -8156,7 +8161,7 @@ func TestAppBundle(t *testing.T) {
		`, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))

	bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex").Output("bundle_config.json")
	content := bundleConfigRule.Args["content"]
	content := android.ContentFromFileRuleForTests(t, ctx, bundleConfigRule)

	ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
	ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo@TEST.BUILD_ID/AppFoo.apk"}]}`)
@@ -8183,7 +8188,7 @@ func TestAppSetBundle(t *testing.T) {
		}`)
	mod := ctx.ModuleForTests("myapex", "android_common_myapex")
	bundleConfigRule := mod.Output("bundle_config.json")
	content := bundleConfigRule.Args["content"]
	content := android.ContentFromFileRuleForTests(t, ctx, bundleConfigRule)
	ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
	s := mod.Rule("apexRule").Args["copy_commands"]
	copyCmds := regexp.MustCompile(" *&& *").Split(s, -1)
@@ -9128,7 +9133,7 @@ func TestApexKeysTxt(t *testing.T) {
	`)

	myapex := ctx.ModuleForTests("myapex", "android_common_myapex")
	content := myapex.Output("apexkeys.txt").BuildParams.Args["content"]
	content := android.ContentFromFileRuleForTests(t, ctx, myapex.Output("apexkeys.txt"))
	ensureContains(t, content, `name="myapex.apex" public_key="vendor/foo/devkeys/testkey.avbpubkey" private_key="vendor/foo/devkeys/testkey.pem" container_certificate="vendor/foo/devkeys/test.x509.pem" container_private_key="vendor/foo/devkeys/test.pk8" partition="system" sign_tool="sign_myapex"`)
}

@@ -9168,9 +9173,11 @@ func TestApexKeysTxtOverrides(t *testing.T) {
		}
	`)

	content := ctx.ModuleForTests("myapex", "android_common_myapex").Output("apexkeys.txt").BuildParams.Args["content"]
	content := android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex", "android_common_myapex").Output("apexkeys.txt"))
	ensureContains(t, content, `name="myapex.apex" public_key="vendor/foo/devkeys/testkey.avbpubkey" private_key="vendor/foo/devkeys/testkey.pem" container_certificate="vendor/foo/devkeys/test.x509.pem" container_private_key="vendor/foo/devkeys/test.pk8" partition="system" sign_tool="sign_myapex"`)
	content = ctx.ModuleForTests("myapex_set", "android_common_myapex_set").Output("apexkeys.txt").BuildParams.Args["content"]
	content = android.ContentFromFileRuleForTests(t, ctx,
		ctx.ModuleForTests("myapex_set", "android_common_myapex_set").Output("apexkeys.txt"))
	ensureContains(t, content, `name="myapex_set.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`)
}

+6 −6
Original line number Diff line number Diff line
@@ -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) {
Loading