aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-03-23 03:52:15 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-23 03:52:15 +0000
commitb495d92d85eda5fd755343d7e0eff58307fe3520 (patch)
treeb51df7301b68175496f533d354899b07e05ae426
parentc3eb43535c7e46a3647402bdf2135ba817b785d6 (diff)
parentdd5f8b67a4d3e9a3d4e59ffbb6e810088babd570 (diff)
downloadcsuite-b495d92d85eda5fd755343d7e0eff58307fe3520.tar.gz
Merge "Add support for custom test plans" am: dd5f8b67a4
Original change: https://android-review.googlesource.com/c/platform/test/app_compat/csuite/+/1633264 Change-Id: I6e122526a3c2e58dfef27261e3bfc353545bdfbe
-rw-r--r--tools/csuite_test/csuite_test.go43
-rw-r--r--tools/csuite_test/csuite_test_test.go109
2 files changed, 108 insertions, 44 deletions
diff --git a/tools/csuite_test/csuite_test.go b/tools/csuite_test/csuite_test.go
index b34226a..74373f2 100644
--- a/tools/csuite_test/csuite_test.go
+++ b/tools/csuite_test/csuite_test.go
@@ -32,6 +32,9 @@ type csuiteTestProperties struct {
// Local path to a module template xml file.
// The content of the template will be used to generate test modules at runtime.
Test_config_template *string `android:"path"`
+
+ // Local path to a test plan config xml to be included in the generated plan.
+ Test_plan_include *string `android:"path"`
}
type CSuiteTest struct {
@@ -40,38 +43,46 @@ type CSuiteTest struct {
// C-Suite test properties struct.
csuiteTestProperties csuiteTestProperties
-
- // Local path to a xml config file to be included in the test plan.
- Test_plan_include *string `android:"path"`
}
-func (cSuiteTest *CSuiteTest) generateTestConfigTemplate(rule *android.RuleBuilder, ctx android.ModuleContext) android.ModuleGenPath {
+func (cSuiteTest *CSuiteTest) buildCopyConfigTemplateCommand(ctx android.ModuleContext, rule *android.RuleBuilder) string {
if cSuiteTest.csuiteTestProperties.Test_config_template == nil {
ctx.ModuleErrorf(`'test_config_template' is missing.`)
}
inputPath := android.PathForModuleSrc(ctx, *cSuiteTest.csuiteTestProperties.Test_config_template)
genPath := android.PathForModuleGen(ctx, planConfigDirName, ctx.ModuleName()+configTemplateFileExtension)
rule.Command().Textf("cp").Input(inputPath).Output(genPath)
- return genPath
+ cSuiteTest.AddExtraResource(genPath)
+ return genPath.Rel()
}
-func (cSuiteTest *CSuiteTest) generatePlanConfig(templatePathString string, ctx android.ModuleContext) android.ModuleGenPath {
+func (cSuiteTest *CSuiteTest) buildCopyPlanIncludeCommand(ctx android.ModuleContext, rule *android.RuleBuilder) string {
+ if cSuiteTest.csuiteTestProperties.Test_plan_include == nil {
+ return emptyPlanIncludePath
+ }
+ inputPath := android.PathForModuleSrc(ctx, *cSuiteTest.csuiteTestProperties.Test_plan_include)
+ genPath := android.PathForModuleGen(ctx, planConfigDirName, "includes", ctx.ModuleName()+".xml")
+ rule.Command().Textf("cp").Input(inputPath).Output(genPath)
+ cSuiteTest.AddExtraResource(genPath)
+ return strings.Replace(genPath.Rel(), "config/", "", -1)
+}
+
+func (cSuiteTest *CSuiteTest) buildWritePlanConfigRule(ctx android.ModuleContext, configTemplatePath string, planIncludePath string) {
planName := ctx.ModuleName()
+ content := strings.Replace(planTemplate, "{planName}", planName, -1)
+ content = strings.Replace(content, "{templatePath}", configTemplatePath, -1)
+ content = strings.Replace(content, "{planInclude}", planIncludePath, -1)
genPath := android.PathForModuleGen(ctx, planConfigDirName, planName+planFileExtension)
- content := strings.Replace(planTemplateContent, "{planName}", planName, -1)
- content = strings.Replace(content, "{templatePath}", templatePathString, -1)
android.WriteFileRule(ctx, genPath, content)
- return genPath
+ cSuiteTest.AddExtraResource(genPath)
}
func (cSuiteTest *CSuiteTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule := android.NewRuleBuilder(pctx, ctx)
- configTemplateOutputPath := cSuiteTest.generateTestConfigTemplate(rule, ctx)
- cSuiteTest.AddExtraResource(configTemplateOutputPath)
-
- planOutputFile := cSuiteTest.generatePlanConfig(configTemplateOutputPath.Rel(), ctx)
- cSuiteTest.AddExtraResource(planOutputFile)
+ configTemplatePath := cSuiteTest.buildCopyConfigTemplateCommand(ctx, rule)
+ planIncludePath := cSuiteTest.buildCopyPlanIncludeCommand(ctx, rule)
+ cSuiteTest.buildWritePlanConfigRule(ctx, configTemplatePath, planIncludePath)
rule.Build("CSuite", "generate C-Suite config files")
cSuiteTest.TestHost.GenerateAndroidBuildActions(ctx)
@@ -90,10 +101,11 @@ func CSuiteTestFactory() android.Module {
}
const (
+ emptyPlanIncludePath = `empty`
planConfigDirName = `config`
configTemplateFileExtension = `.xml.template`
planFileExtension = `.xml`
- planTemplateContent = `<?xml version="1.0" encoding="utf-8"?>
+ planTemplate = `<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
@@ -113,6 +125,7 @@ const (
<option name="template" value="{templatePath}" />
</test>
<include name="csuite-base" />
+ <include name="{planInclude}" />
<option name="plan" value="{planName}" />
</configuration>
`
diff --git a/tools/csuite_test/csuite_test_test.go b/tools/csuite_test/csuite_test_test.go
index 0223da1..daf07b0 100644
--- a/tools/csuite_test/csuite_test_test.go
+++ b/tools/csuite_test/csuite_test_test.go
@@ -24,19 +24,6 @@ import (
var buildDir string
-func TestValidBpDoesNotThrowError(t *testing.T) {
- ctx, config := createContextAndConfig(t, `
- csuite_test {
- name: "plan_name",
- test_config_template: "test_config.xml.template"
- }
- `)
-
- _, errs := ctx.PrepareBuildActions(config)
-
- android.FailIfErrored(t, errs)
-}
-
func TestBpContainsTestHostPropsThrowsError(t *testing.T) {
ctx, _ := createContextAndConfig(t, `
csuite_test {
@@ -90,6 +77,34 @@ func TestBpMissingTemplatePathThrowsError(t *testing.T) {
android.FailIfNoMatchingErrors(t, `'test_config_template' is missing`, errs)
}
+func TestValidBpMissingPlanIncludeDoesNotThrowError(t *testing.T) {
+ ctx, config := createContextAndConfig(t, `
+ csuite_test {
+ name: "plan_name",
+ test_config_template: "test_config.xml.template"
+ }
+ `)
+
+ parseBpAndBuild(t, ctx, config)
+}
+
+func TestValidBpMissingPlanIncludeGeneratesPlanXmlWithoutPlaceholders(t *testing.T) {
+ ctx, config := createContextAndConfig(t, `
+ csuite_test {
+ name: "plan_name",
+ test_config_template: "test_config.xml.template"
+ }
+ `)
+
+ parseBpAndBuild(t, ctx, config)
+
+ module := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common")
+ content := android.ContentFromFileRuleForTests(t, module.Output("config/plan_name.xml"))
+ if strings.Contains(content, "{") || strings.Contains(content, "}") {
+ t.Errorf("The generated plan name contains a placeholder: %s", content)
+ }
+}
+
func TestGeneratedTestPlanContainsPlanName(t *testing.T) {
ctx, config := createContextAndConfig(t, `
csuite_test {
@@ -98,11 +113,8 @@ func TestGeneratedTestPlanContainsPlanName(t *testing.T) {
}
`)
- _, parsingErrs := ctx.ParseBlueprintsFiles("Android.bp")
- _, buildErrs := ctx.PrepareBuildActions(config)
+ parseBpAndBuild(t, ctx, config)
- android.FailIfErrored(t, parsingErrs)
- android.FailIfErrored(t, buildErrs)
module := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common")
content := android.ContentFromFileRuleForTests(t, module.Output("config/plan_name.xml"))
if !strings.Contains(content, "plan_name") {
@@ -118,11 +130,8 @@ func TestGeneratedTestPlanContainsTemplatePath(t *testing.T) {
}
`)
- _, parsingErrs := ctx.ParseBlueprintsFiles("Android.bp")
- _, buildErrs := ctx.PrepareBuildActions(config)
+ parseBpAndBuild(t, ctx, config)
- android.FailIfErrored(t, parsingErrs)
- android.FailIfErrored(t, buildErrs)
module := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common")
content := android.ContentFromFileRuleForTests(t, module.Output("config/plan_name.xml"))
if !strings.Contains(content, "config/plan_name.xml.template") {
@@ -138,19 +147,45 @@ func TestTemplateFileCopyRuleExists(t *testing.T) {
}
`)
- _, parsingErrs := ctx.ParseBlueprintsFiles("Android.bp")
- _, buildErrs := ctx.PrepareBuildActions(config)
+ parseBpAndBuild(t, ctx, config)
- android.FailIfErrored(t, parsingErrs)
- android.FailIfErrored(t, buildErrs)
params := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common").Rule("CSuite")
- assertPathsContains(t, getAllInputPaths(params), "test_config.xml.template")
- assertWritablePathsContainsRel(t, getAllOutputPaths(params), "config/plan_name.xml.template")
- if !strings.HasPrefix(params.RuleParams.Command, "cp") {
- t.Errorf("'cp' command is missing.")
+ assertFileCopyRuleExists(t, params, "test_config.xml.template", "config/plan_name.xml.template")
+}
+
+func TestGeneratedTestPlanContainsPlanInclude(t *testing.T) {
+ ctx, config := createContextAndConfig(t, `
+ csuite_test {
+ name: "plan_name",
+ test_config_template: "test_config.xml.template",
+ test_plan_include: "include.xml"
+ }
+ `)
+
+ parseBpAndBuild(t, ctx, config)
+
+ module := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common")
+ content := android.ContentFromFileRuleForTests(t, module.Output("config/plan_name.xml"))
+ if !strings.Contains(content, `"includes/plan_name.xml"`) {
+ t.Errorf("The plan include path is missing from the generated plan: %s", content)
}
}
+func TestPlanIncludeFileCopyRuleExists(t *testing.T) {
+ ctx, config := createContextAndConfig(t, `
+ csuite_test {
+ name: "plan_name",
+ test_config_template: "test_config.xml.template",
+ test_plan_include: "include.xml"
+ }
+ `)
+
+ parseBpAndBuild(t, ctx, config)
+
+ params := ctx.ModuleForTests("plan_name", android.BuildOs.String()+"_common").Rule("CSuite")
+ assertFileCopyRuleExists(t, params, "include.xml", "config/includes/plan_name.xml")
+}
+
func TestMain(m *testing.M) {
run := func() int {
setUp()
@@ -162,6 +197,22 @@ func TestMain(m *testing.M) {
os.Exit(run())
}
+func parseBpAndBuild(t *testing.T, ctx *android.TestContext, config android.Config) {
+ _, parsingErrs := ctx.ParseBlueprintsFiles("Android.bp")
+ _, buildErrs := ctx.PrepareBuildActions(config)
+
+ android.FailIfErrored(t, parsingErrs)
+ android.FailIfErrored(t, buildErrs)
+}
+
+func assertFileCopyRuleExists(t *testing.T, params android.TestingBuildParams, src string, dst string) {
+ assertPathsContains(t, getAllInputPaths(params), src)
+ assertWritablePathsContainsRel(t, getAllOutputPaths(params), dst)
+ if !strings.HasPrefix(params.RuleParams.Command, "cp") {
+ t.Errorf("'cp' command is missing.")
+ }
+}
+
func assertPathsContains(t *testing.T, paths android.Paths, path string) {
for _, p := range paths {
if p.String() == path {