Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package tradefed |
| 16 | |
| 17 | import ( |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 18 | "github.com/google/blueprint" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 23 | func getTestConfigTemplate(ctx android.ModuleContext, prop *string) android.OptionalPath { |
| 24 | return ctx.ExpandOptionalSource(prop, "test_config_template") |
| 25 | } |
| 26 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 27 | func getTestConfig(ctx android.ModuleContext, prop *string) android.Path { |
| 28 | if p := ctx.ExpandOptionalSource(prop, "test_config"); p.Valid() { |
| 29 | return p.Path() |
| 30 | } else if p := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "AndroidTest.xml"); p.Valid() { |
| 31 | return p.Path() |
| 32 | } |
| 33 | return nil |
| 34 | } |
| 35 | |
| 36 | var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{ |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 37 | Command: "sed 's&{MODULE}&${name}&g' $template > $out", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 38 | CommandDeps: []string{"$template"}, |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 39 | }, "name", "template") |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 40 | |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 41 | func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string) (path android.Path, autogenPath android.WritablePath) { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 42 | if p := getTestConfig(ctx, prop); p != nil { |
| 43 | return p, nil |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 44 | } else if !android.InList("cts", testSuites) { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 45 | outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".config") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 46 | return nil, outputFile |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 47 | } else { |
| 48 | // CTS modules can be used for test data, so test config files must be |
| 49 | // explicitly created using AndroidTest.xml |
| 50 | // TODO(b/112602712): remove the path check |
| 51 | return nil, nil |
| 52 | } |
| 53 | } |
| 54 | |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 55 | func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string) { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 56 | ctx.Build(pctx, android.BuildParams{ |
| 57 | Rule: autogenTestConfig, |
| 58 | Description: "test config", |
| 59 | Output: output, |
| 60 | Args: map[string]string{ |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 61 | "name": ctx.ModuleName(), |
| 62 | "template": template, |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 63 | }, |
| 64 | }) |
| 65 | } |
| 66 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 67 | func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string, |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 68 | testConfigTemplateProp *string, testSuites []string) android.Path { |
| 69 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 70 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 71 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 72 | if templatePath.Valid() { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 73 | autogenTemplate(ctx, autogenPath, templatePath.String()) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 74 | } else { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 75 | if ctx.Device() { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 76 | autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 77 | } else { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 78 | autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 79 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 80 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 81 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 82 | } |
| 83 | return path |
| 84 | } |
| 85 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 86 | func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp *string, |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 87 | testConfigTemplateProp *string, testSuites []string) android.Path { |
| 88 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 89 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 90 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 91 | if templatePath.Valid() { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 92 | autogenTemplate(ctx, autogenPath, templatePath.String()) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 93 | } else { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 94 | autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 95 | } |
| 96 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 97 | } |
| 98 | return path |
| 99 | } |
| 100 | |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 101 | func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, testSuites []string) android.Path { |
| 102 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 103 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 104 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 105 | if templatePath.Valid() { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 106 | autogenTemplate(ctx, autogenPath, templatePath.String()) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 107 | } else { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 108 | if ctx.Device() { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 109 | autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 110 | } else { |
Bill Yang | fd18c42 | 2018-10-25 05:36:13 +0000 | [diff] [blame] | 111 | autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}") |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 112 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 113 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 114 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 115 | } |
| 116 | return path |
| 117 | } |
| 118 | |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 119 | func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string, |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 120 | testConfigTemplateProp *string, testSuites []string) android.Path { |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 121 | |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 122 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) |
yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 123 | if autogenPath != nil { |
| 124 | templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 125 | if templatePath.Valid() { |
| 126 | autogenTemplate(ctx, autogenPath, templatePath.String()) |
| 127 | } else { |
| 128 | autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}") |
| 129 | } |
| 130 | return autogenPath |
| 131 | } |
| 132 | return path |
| 133 | } |
| 134 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 135 | var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{ |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 136 | Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 137 | CommandDeps: []string{ |
| 138 | "${AutoGenTestConfigScript}", |
| 139 | "${EmptyTestConfig}", |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 140 | "$template", |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 141 | }, |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 142 | }, "name", "template") |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 143 | |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 144 | func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, manifest android.Path, testSuites []string) android.Path { |
| 145 | path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 146 | if autogenPath != nil { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 147 | template := "${InstrumentationTestConfigTemplate}" |
| 148 | moduleTemplate := getTestConfigTemplate(ctx, testConfigTemplateProp) |
| 149 | if moduleTemplate.Valid() { |
| 150 | template = moduleTemplate.String() |
| 151 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 152 | ctx.Build(pctx, android.BuildParams{ |
| 153 | Rule: autogenInstrumentationTest, |
| 154 | Description: "test config", |
| 155 | Input: manifest, |
| 156 | Output: autogenPath, |
| 157 | Args: map[string]string{ |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 158 | "name": ctx.ModuleName(), |
| 159 | "template": template, |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 160 | }, |
| 161 | }) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 162 | return autogenPath |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 163 | } |
| 164 | return path |
| 165 | } |