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

Commit 32282f69 authored by Weijia He's avatar Weijia He
Browse files

Add boilerplates for test_suite module type to tradefed_modules

This CL adds a new module type: test_suite.
test_suite {
  name: "example-test-suite",
  description: "some example test suite"
  tests: [
    "ExampleTest1",
    "ExampleTest2",
  ],
}

test_suite allows users to define a suite of tests that can be run together. The test_suite module type takes a list of tests as input, and it will generate a single test module that can be run by tradefed.

This CL also adds a test for the test_suite module type. The test verifies that the test_suite module type can be used to define a suite of tests, and that the generated test module can be run by tradefed.

Change-Id: I1a8585899b29b0e96234a7abbd367de033d5f686
Bug: 372945132
parent 0ba7034b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13,9 +13,11 @@ bootstrap_go_package {
    ],
    srcs: [
        "test_module_config.go",
        "test_suite.go",
    ],
    testSrcs: [
        "test_module_config_test.go",
        "test_suite_test.go",
    ],
    pluginFor: ["soong_build"],
}
+56 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tradefed_modules

import (
	"android/soong/android"
)

func init() {
	RegisterTestSuiteBuildComponents(android.InitRegistrationContext)
}

func RegisterTestSuiteBuildComponents(ctx android.RegistrationContext) {
	ctx.RegisterModuleType("test_suite", TestSuiteFactory)
}

var PrepareForTestWithTestSuiteBuildComponents = android.GroupFixturePreparers(
	android.FixtureRegisterWithContext(RegisterTestSuiteBuildComponents),
)

type testSuiteProperties struct {
	Description string
	Tests []string `android:"path,arch_variant"`
}

type testSuiteModule struct {
	android.ModuleBase
	android.DefaultableModuleBase
	testSuiteProperties
}

func (t *testSuiteModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	// TODO(hwj): Implement this.
}

func TestSuiteFactory() android.Module {
	module := &testSuiteModule{}
	module.AddProperties(&module.testSuiteProperties)

	android.InitAndroidModule(module)
	android.InitDefaultableModule(module)

	return module
}
+47 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tradefed_modules

import (
	"android/soong/android"
	"android/soong/java"
	"testing"
)

func TestTestSuites(t *testing.T) {
	t.Parallel()
	android.GroupFixturePreparers(
		java.PrepareForTestWithJavaDefaultModules,
		android.FixtureRegisterWithContext(RegisterTestSuiteBuildComponents),
	).RunTestWithBp(t, `
		android_test {
			name: "TestModule1",
			sdk_version: "current",
		}

		android_test {
			name: "TestModule2",
			sdk_version: "current",
		}

		test_suite {
			name: "my-suite",
			description: "a test suite",
			tests: [
				"TestModule1",
				"TestModule2",
			]
		}
	`)
}