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"
|
|
|
|
"sort"
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
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-03-01 00:45:28 +08:00
|
|
|
Command: "sed 's&{MODULE}&${name}&g;s&{EXTRA_OPTIONS}&'${extraOptions}'&g' $template > $out",
|
2018-08-08 07:49:25 +08:00
|
|
|
CommandDeps: []string{"$template"},
|
2019-03-01 00:45:28 +08:00
|
|
|
}, "name", "template", "extraOptions")
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2019-02-13 21:45:47 +08:00
|
|
|
func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string) (path android.Path, autogenPath android.WritablePath) {
|
2018-08-08 07:49:25 +08:00
|
|
|
if p := getTestConfig(ctx, prop); p != nil {
|
|
|
|
return p, nil
|
2019-02-13 21:45:47 +08:00
|
|
|
} else if !android.InList("cts", testSuites) {
|
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
|
|
|
|
// explicitly created using AndroidTest.xml
|
|
|
|
// TODO(b/112602712): remove the path check
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 00:45:28 +08:00
|
|
|
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, optionsMap map[string]string) {
|
|
|
|
// If no test option found, delete {EXTRA_OPTIONS} line.
|
|
|
|
var options []string
|
|
|
|
for optionName, value := range optionsMap {
|
|
|
|
if value != "" {
|
|
|
|
options = append(options, fmt.Sprintf(`<option name="%s" value="%s" />`, optionName, value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(options)
|
|
|
|
extraOptions := strings.Join(options, "\n ")
|
2019-03-01 03:00:01 +08:00
|
|
|
extraOptions = proptools.NinjaAndShellEscape(extraOptions)
|
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-03-01 00:45:28 +08:00
|
|
|
"name": ctx.ModuleName(),
|
|
|
|
"template": template,
|
|
|
|
"extraOptions": extraOptions,
|
2018-08-08 07:49:25 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
2019-03-01 00:45:28 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string,
|
|
|
|
optionsMap map[string]string) android.Path {
|
2019-02-13 21:45:47 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
|
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(), optionsMap)
|
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, "${NativeTestConfigTemplate}",
|
|
|
|
optionsMap)
|
2018-09-19 17:21:28 +08:00
|
|
|
} else {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}",
|
|
|
|
optionsMap)
|
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-02-13 21:45:47 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string) android.Path {
|
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
|
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-09-19 17:21:28 +08:00
|
|
|
} else {
|
2019-03-01 00:45:28 +08:00
|
|
|
autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", nil)
|
2018-09-19 17:21:28 +08:00
|
|
|
}
|
|
|
|
return autogenPath
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:45:47 +08:00
|
|
|
func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, testSuites []string) android.Path {
|
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
|
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-02-13 21:45:47 +08:00
|
|
|
testConfigTemplateProp *string, testSuites []string) android.Path {
|
2018-11-06 11:49:55 +08:00
|
|
|
|
2019-02-13 21:45:47 +08:00
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{
|
2018-09-19 17:21:28 +08:00
|
|
|
Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template",
|
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
|
|
|
},
|
2018-09-19 17:21:28 +08:00
|
|
|
}, "name", "template")
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2019-02-13 21:45:47 +08:00
|
|
|
func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, manifest android.Path, testSuites []string) android.Path {
|
|
|
|
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
|
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()
|
|
|
|
}
|
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{
|
2018-09-19 17:21:28 +08:00
|
|
|
"name": ctx.ModuleName(),
|
|
|
|
"template": template,
|
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
|
|
|
|
}
|