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

Commit 2df9ebf9 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes from topics "bp-bionic-cts-tests", "cts-per-testcase-directory"

* changes:
  Add data_bins property
  Support per-testcase directories in all test suites
  Add environment variables to cc_genrule commands
parents d7d5b72e c8caa06a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -394,6 +394,8 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
		if Bool(test.Properties.Test_options.Unit_test) {
			entries.SetBool("LOCAL_IS_UNIT_TEST", true)
		}

		entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
	})

	AndroidMkWriteTestData(test.data, entries)
+4 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ type Deps struct {

	// Used for data dependencies adjacent to tests
	DataLibs []string
	DataBins []string

	// Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
	SystemSharedLibs []string
@@ -718,6 +719,7 @@ var (
	staticVariantTag      = dependencyTag{name: "static variant"}
	vndkExtDepTag         = dependencyTag{name: "vndk extends"}
	dataLibDepTag         = dependencyTag{name: "data lib"}
	dataBinDepTag         = dependencyTag{name: "data bin"}
	runtimeDepTag         = installDependencyTag{name: "runtime lib"}
	testPerSrcDepTag      = dependencyTag{name: "test_per_src"}
	stubImplDepTag        = dependencyTag{name: "stub_impl"}
@@ -2274,6 +2276,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
		{Mutator: "link", Variation: "shared"},
	}, dataLibDepTag, deps.DataLibs...)

	actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)

	actx.AddVariationDependencies([]blueprint.Variation{
		{Mutator: "link", Variation: "shared"},
	}, runtimeDepTag, deps.RuntimeLibs...)
+20 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
package cc

import (
	"fmt"

	"android/soong/android"
	"android/soong/genrule"
	"android/soong/snapshot"
@@ -36,13 +38,23 @@ type GenruleExtraProperties struct {

// cc_genrule is a genrule that can depend on other cc_* objects.
// The cmd may be run multiple times, once for each of the different arch/etc
// variations.
// variations.  The following environment variables will be set when the command
// execute:
//
//   CC_ARCH           the name of the architecture the command is being executed for
//
//   CC_MULTILIB       "lib32" if the architecture the command is being executed for is 32-bit,
//                     "lib64" if it is 64-bit.
//
//   CC_NATIVE_BRIDGE  the name of the subdirectory that native bridge libraries are stored in if
//                     the architecture has native bridge enabled, empty if it is disabled.
func GenRuleFactory() android.Module {
	module := genrule.NewGenRule()

	extra := &GenruleExtraProperties{}
	module.Extra = extra
	module.ImageInterface = extra
	module.CmdModifier = genruleCmdModifier
	module.AddProperties(module.Extra)

	android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
@@ -53,6 +65,13 @@ func GenRuleFactory() android.Module {
	return module
}

func genruleCmdModifier(ctx android.ModuleContext, cmd string) string {
	target := ctx.Target()
	arch := target.Arch.ArchType
	return fmt.Sprintf("CC_ARCH=%s CC_NATIVE_BRIDGE=%s CC_MULTILIB=%s && %s",
		arch.Name, target.NativeBridgeRelativePath, arch.Multilib, cmd)
}

var _ android.ImageInterface = (*GenruleExtraProperties)(nil)

func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+72 −0
Original line number Diff line number Diff line
@@ -115,3 +115,75 @@ func TestLibraryGenruleCmd(t *testing.T) {
		t.Errorf(`want inputs %v, got %v`, expected, got)
	}
}

func TestCmdPrefix(t *testing.T) {
	bp := `
		cc_genrule {
			name: "gen",
			cmd: "echo foo",
			out: ["out"],
			native_bridge_supported: true,
		}
		`

	testCases := []struct {
		name     string
		variant  string
		preparer android.FixturePreparer

		arch         string
		nativeBridge string
		multilib     string
	}{
		{
			name:     "arm",
			variant:  "android_arm_armv7-a-neon",
			arch:     "arm",
			multilib: "lib32",
		},
		{
			name:     "arm64",
			variant:  "android_arm64_armv8-a",
			arch:     "arm64",
			multilib: "lib64",
		},
		{
			name:    "nativebridge",
			variant: "android_native_bridge_arm_armv7-a-neon",
			preparer: android.FixtureModifyConfig(func(config android.Config) {
				config.Targets[android.Android] = []android.Target{
					{
						Os:           android.Android,
						Arch:         android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}},
						NativeBridge: android.NativeBridgeDisabled,
					},
					{
						Os:                       android.Android,
						Arch:                     android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}},
						NativeBridge:             android.NativeBridgeEnabled,
						NativeBridgeHostArchName: "x86",
						NativeBridgeRelativePath: "arm",
					},
				}
			}),
			arch:         "arm",
			multilib:     "lib32",
			nativeBridge: "arm",
		},
	}

	for _, tt := range testCases {
		t.Run(tt.name, func(t *testing.T) {
			result := android.GroupFixturePreparers(
				PrepareForIntegrationTestWithCc,
				android.OptionalFixturePreparer(tt.preparer),
			).RunTestWithBp(t, bp)
			gen := result.ModuleForTests("gen", tt.variant)
			sboxProto := android.RuleBuilderSboxProtoForTests(t, 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+" ")
			android.AssertStringDoesContain(t, "incorrect CC_MULTILIB", cmd, "CC_MULTILIB="+tt.multilib+" ")
		})
	}
}
+19 −0
Original line number Diff line number Diff line
@@ -80,6 +80,9 @@ type TestBinaryProperties struct {
	// list of shared library modules that should be installed alongside the test
	Data_libs []string `android:"arch_variant"`

	// list of binary modules that should be installed alongside the test
	Data_bins []string `android:"arch_variant"`

	// list of compatibility suites (for example "cts", "vts") that the module should be
	// installed into.
	Test_suites []string `android:"arch_variant"`
@@ -115,6 +118,9 @@ type TestBinaryProperties struct {
	// Add parameterized mainline modules to auto generated test config. The options will be
	// handled by TradeFed to download and install the specified modules on the device.
	Test_mainline_modules []string

	// Install the test into a folder named for the module in all test suites.
	Per_testcase_directory *bool
}

func init() {
@@ -347,6 +353,7 @@ func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
	deps = test.testDecorator.linkerDeps(ctx, deps)
	deps = test.binaryDecorator.linkerDeps(ctx, deps)
	deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
	deps.DataBins = append(deps.DataBins, test.Properties.Data_bins...)
	return deps
}

@@ -386,6 +393,18 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
					RelativeInstallPath: ccModule.installer.relativeInstallPath()})
		}
	})
	ctx.VisitDirectDepsWithTag(dataBinDepTag, func(dep android.Module) {
		depName := ctx.OtherModuleName(dep)
		ccModule, ok := dep.(*Module)
		if !ok {
			ctx.ModuleErrorf("data_bin %q is not a cc module", depName)
		}
		if ccModule.OutputFile().Valid() {
			test.data = append(test.data,
				android.DataPath{SrcPath: ccModule.OutputFile().Path(),
					RelativeInstallPath: ccModule.installer.relativeInstallPath()})
		}
	})

	var configs []tradefed.Config
	for _, module := range test.Properties.Test_mainline_modules {
Loading