2018-08-08 07:49:25 +08:00
|
|
|
// Copyright 2018 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
|
|
|
|
|
|
|
|
import (
|
2019-03-01 00:45:28 +08:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
"github.com/google/blueprint"
|
2019-03-01 00:45:28 +08:00
|
|
|
"github.com/google/blueprint/proptools"
|
2018-08-08 07:49:25 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
2019-08-28 01:37:24 +08:00
|
|
|
const test_xml_indent = " "
|
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
func getTestConfigTemplate(ctx android.ModuleContext, prop *string) android.OptionalPath {
|
|
|
|
return ctx.ExpandOptionalSource(prop, "test_config_template")
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
func getTestConfig(ctx android.ModuleContext, prop *string) android.Path {
|
|
|
|
if p := ctx.ExpandOptionalSource(prop, "test_config"); p.Valid() {
|
|
|
|
return p.Path()
|
|
|
|
} else if p := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "AndroidTest.xml"); p.Valid() {
|
|
|
|
return p.Path()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{
|
2019-06-07 07:23:32 +08:00
|
|
|
Command: "sed 's&{MODULE}&${name}&g;s&{EXTRA_CONFIGS}&'${extraConfigs}'&g' $template > $out",
|
2018-08-08 07:49:25 +08:00
|
|
|
CommandDeps: []string{"$template"},
|
2019-06-07 07:23:32 +08:00
|
|
|
}, "name", "template", "extraConfigs")
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2020-02-14 17:27:56 +08:00
|
|
|
func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string, autoGenConfig *bool, testConfigTemplateProp *string) (path android.Path, autogenPath android.WritablePath) {
|
2019-09-27 02:41:36 +08:00
|
|
|
p := getTestConfig(ctx, prop)
|
|
|
|
if !Bool(autoGenConfig) && p != nil {
|
2018-08-08 07:49:25 +08:00
|
|
|
return p, nil
|
2020-02-14 17:27:56 +08:00
|
|
|
} else if BoolDefault(autoGenConfig, true) && (!android.InList("cts", testSuites) || testConfigTemplateProp != nil) {
|
2018-08-08 07:49:25 +08:00
|
|
|
outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".config")
|
2018-09-19 17:21:28 +08:00
|
|
|
return nil, outputFile
|
2018-08-08 07:49:25 +08:00
|
|
|
} else {
|
|
|
|
// CTS modules can be used for test data, so test config files must be
|
2020-02-14 17:27:56 +08:00
|
|
|
// explicitly created using AndroidTest.xml or test_config_template.
|
2018-08-08 07:49:25 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 07:23:32 +08:00
|
|
|
type Config interface {
|
|
|
|
Config() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option struct {
|
|
|
|
Name string
|
2020-04-30 10:08:33 +08:00
|
|
|
Key string
|
2019-06-07 07:23:32 +08:00
|
|
|
Value string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Config = Option{}
|
|
|
|
|
|
|
|
func (o Option) Config() string {
|
2020-04-30 10:08:33 +08:00
|
|
|
if o.Key != "" {
|
|
|
|
return fmt.Sprintf(`<option name="%s" key="%s" value="%s" />`, o.Name, o.Key, o.Value)
|
|
|
|
}
|
2019-06-07 07:23:32 +08:00
|
|
|
return fmt.Sprintf(`<option name="%s" value="%s" />`, o.Name, o.Value)
|
|
|
|
}
|
|
|
|
|
2019-09-17 16:35:23 +08:00
|
|
|
// It can be a template of object or target_preparer.
|
|
|
|
type Object struct {
|
|
|
|
// Set it as a target_preparer if object type == "target_preparer".
|
|
|
|
Type string
|
2019-08-28 01:37:24 +08:00
|
|
|
Class string
|
|
|
|
Options []Option
|
2019-06-07 07:23:32 +08:00
|
|
|
}
|
|
|
|
|
2019-09-17 16:35:23 +08:00
|
|
|
var _ Config = Object{}
|
2019-06-07 07:23:32 +08:00
|
|
|
|
2019-09-17 16:35:23 +08:00
|
|
|
func (ob Object) Config() string {
|
2019-08-28 01:37:24 +08:00
|
|
|
var optionStrings []string
|
2019-09-17 16:35:23 +08:00
|
|
|
for _, option := range ob.Options {
|
2019-08-28 01:37:24 +08:00
|
|
|
optionStrings = append(optionStrings, option.Config())
|
|
|
|
}
|
|
|
|
var options string
|
2019-09-17 16:35:23 +08:00
|
|
|
if len(ob.Options) == 0 {
|
2019-08-28 01:37:24 +08:00
|
|
|
options = ""
|
|
|
|
} else {
|
|
|
|
optionDelimiter := fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent)
|
|
|
|
options = optionDelimiter + strings.Join(optionStrings, optionDelimiter)
|
|
|
|
}
|
2019-09-17 16:35:23 +08:00
|
|
|
if ob.Type == "target_preparer" {
|
|
|
|
return fmt.Sprintf(`<target_preparer class="%s">%s\n%s</target_preparer>`, ob.Class, options, test_xml_indent)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf(`<object type="%s" class="%s">%s\n%s</object>`, ob.Type, ob.Class, options, test_xml_indent)
|
|
|
|
}
|
|
|
|
|
2019-06-07 07:23:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config) {
|
2019-11-01 11:56:47 +08:00
|
|
|
autogenTemplateWithName(ctx, ctx.ModuleName(), output, template, configs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func autogenTemplateWithName(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config) {
|
2019-06-07 07:23:32 +08:00
|
|
|
var configStrings []string
|
|
|
|
for _, config := range configs {
|
|
|
|
configStrings = append(configStrings, config.Config())
|
2019-03-01 00:45:28 +08:00
|
|
|
}
|
2019-08-28 01:37:24 +08:00
|
|
|
extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
|
2019-06-07 07:23:32 +08:00
|
|
|
extraConfigs = proptools.NinjaAndShellEscape(extraConfigs)
|
2019-03-01 00:45:28 +08:00
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: autogenTestConfig,
|
|
|
|
Description: "test config",
|
|
|
|
Output: output,
|
|
|
|
Args: map[string]string{
|
2019-11-01 11:56:47 +08:00
|
|
|
"name": name,
|
2019-03-01 00:45:28 +08:00
|
|
|
"template": template,
|
2019-06-07 07:23:32 +08:00
|
|
|
"extraConfigs": extraConfigs,
|
2018-08-08 07:49:25 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
2019-09-27 02:41:36 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool) android.Path {
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2018-08-08 07:49:25 +08:00
|
|
|
if autogenPath != nil {
|
2018-09-19 17:21:28 +08:00
|
|
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if templatePath.Valid() {
|
2019-06-07 07:23:32 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, templatePath.String(), config)
|
2018-08-08 07:49:25 +08:00
|
|
|
} else {
|
2018-09-19 17:21:28 +08:00
|
|
|
if ctx.Device() {
|
2019-06-07 07:23:32 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", config)
|
2018-09-19 17:21:28 +08:00
|
|
|
} else {
|
2019-06-07 07:23:32 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", config)
|
2018-09-19 17:21:28 +08:00
|
|
|
}
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
2018-09-19 17:21:28 +08:00
|
|
|
return autogenPath
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
2019-09-27 02:41:36 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string, configs []Config, autoGenConfig *bool) android.Path {
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2018-08-08 07:49:25 +08:00
|
|
|
if autogenPath != nil {
|
2018-09-19 17:21:28 +08:00
|
|
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if templatePath.Valid() {
|
2019-06-07 07:23:32 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, templatePath.String(), configs)
|
2018-09-19 17:21:28 +08:00
|
|
|
} else {
|
2019-06-07 07:23:32 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", configs)
|
2018-09-19 17:21:28 +08:00
|
|
|
}
|
|
|
|
return autogenPath
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2019-09-27 02:41:36 +08:00
|
|
|
func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string,
|
|
|
|
testSuites []string, autoGenConfig *bool) android.Path {
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2018-08-08 07:49:25 +08:00
|
|
|
if autogenPath != nil {
|
2018-09-19 17:21:28 +08:00
|
|
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if templatePath.Valid() {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
|
2018-08-08 07:49:25 +08:00
|
|
|
} else {
|
2018-09-19 17:21:28 +08:00
|
|
|
if ctx.Device() {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil)
|
2018-09-19 17:21:28 +08:00
|
|
|
} else {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil)
|
2018-09-19 17:21:28 +08:00
|
|
|
}
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
2018-09-19 17:21:28 +08:00
|
|
|
return autogenPath
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:49:55 +08:00
|
|
|
func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
2019-09-27 02:41:36 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path {
|
2018-11-06 11:49:55 +08:00
|
|
|
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2018-11-06 11:49:55 +08:00
|
|
|
if autogenPath != nil {
|
|
|
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if templatePath.Valid() {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
|
2018-11-06 11:49:55 +08:00
|
|
|
} else {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}", nil)
|
2018-11-06 11:49:55 +08:00
|
|
|
}
|
|
|
|
return autogenPath
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2019-11-23 12:22:35 +08:00
|
|
|
func AutoGenRustTestConfig(ctx android.ModuleContext, name string, testConfigProp *string,
|
2019-11-01 11:56:47 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path {
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2019-11-01 11:56:47 +08:00
|
|
|
if autogenPath != nil {
|
|
|
|
templatePathString := "${RustHostTestConfigTemplate}"
|
2019-11-23 12:22:35 +08:00
|
|
|
if ctx.Device() {
|
|
|
|
templatePathString = "${RustDeviceTestConfigTemplate}"
|
|
|
|
}
|
2019-11-01 11:56:47 +08:00
|
|
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if templatePath.Valid() {
|
|
|
|
templatePathString = templatePath.String()
|
|
|
|
}
|
|
|
|
autogenTemplateWithName(ctx, name, autogenPath, templatePathString, nil)
|
|
|
|
return autogenPath
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{
|
2020-04-30 14:57:06 +08:00
|
|
|
Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template ${extraConfigs}",
|
2018-08-08 07:49:25 +08:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${AutoGenTestConfigScript}",
|
|
|
|
"${EmptyTestConfig}",
|
2018-09-19 17:21:28 +08:00
|
|
|
"$template",
|
2018-08-08 07:49:25 +08:00
|
|
|
},
|
2020-04-30 14:57:06 +08:00
|
|
|
}, "name", "template", "extraConfigs")
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2019-09-27 02:41:36 +08:00
|
|
|
func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
2020-04-30 14:57:06 +08:00
|
|
|
testConfigTemplateProp *string, manifest android.Path, testSuites []string, autoGenConfig *bool, configs []Config) android.Path {
|
2020-02-14 17:27:56 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
|
2020-04-30 14:57:06 +08:00
|
|
|
var configStrings []string
|
2018-08-08 07:49:25 +08:00
|
|
|
if autogenPath != nil {
|
2018-09-19 17:21:28 +08:00
|
|
|
template := "${InstrumentationTestConfigTemplate}"
|
|
|
|
moduleTemplate := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
|
|
|
if moduleTemplate.Valid() {
|
|
|
|
template = moduleTemplate.String()
|
|
|
|
}
|
2020-04-30 14:57:06 +08:00
|
|
|
for _, config := range configs {
|
|
|
|
configStrings = append(configStrings, config.Config())
|
|
|
|
}
|
|
|
|
extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
|
|
|
|
extraConfigs = fmt.Sprintf("--extra-configs '%s'", extraConfigs)
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: autogenInstrumentationTest,
|
|
|
|
Description: "test config",
|
|
|
|
Input: manifest,
|
|
|
|
Output: autogenPath,
|
|
|
|
Args: map[string]string{
|
2020-04-30 14:57:06 +08:00
|
|
|
"name": ctx.ModuleName(),
|
|
|
|
"template": template,
|
|
|
|
"extraConfigs": extraConfigs,
|
2018-08-08 07:49:25 +08:00
|
|
|
},
|
|
|
|
})
|
2018-09-19 17:21:28 +08:00
|
|
|
return autogenPath
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
2019-09-27 02:41:36 +08:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|
|
|
|
var BoolDefault = proptools.BoolDefault
|