aboutsummaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-03-19 14:05:33 -0700
committerColin Cross <ccross@android.com>2015-03-19 14:05:33 -0700
commit6b29069d42c7084b948a1670230c2807014e41cc (patch)
treef03f57b60aac6f71d7f4a83028208aab21481589 /cc
parented9f868f494df2176e953ac825db7213a18a9f0d (diff)
downloadbuild_soong-6b29069d42c7084b948a1670230c2807014e41cc.tar.gz
build_soong-6b29069d42c7084b948a1670230c2807014e41cc.tar.bz2
build_soong-6b29069d42c7084b948a1670230c2807014e41cc.zip
Allow cc_test to build a test per source file
Some cc_test modules want a test per source file, for example when there is global state that needs to be reset between each test suite, but no way to reset it. Allow them to specify test_per_src: true, which will cause a separate test to be built for each source file. Change-Id: I3dbf1202fb070437cb0109f195dc11a6440061ee
Diffstat (limited to 'cc')
-rw-r--r--cc/cc.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/cc/cc.go b/cc/cc.go
index d27bdd0d..46274401 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1192,6 +1192,12 @@ func (c *ccBinary) installModule(ctx common.AndroidModuleContext, flags ccFlags)
type ccTest struct {
ccBinary
+
+ testProperties struct {
+ // test_per_src: Create a separate test for each source file. Useful when there is
+ // global state that can not be torn down and reset between each test suite.
+ Test_per_src bool
+ }
}
var (
@@ -1234,7 +1240,23 @@ func (c *ccTest) installModule(ctx common.AndroidModuleContext, flags ccFlags) {
func NewCCTest() (blueprint.Module, []interface{}) {
module := &ccTest{}
return newCCDynamic(&module.ccDynamic, module, common.HostAndDeviceSupported,
- common.MultilibFirst, &module.binaryProperties)
+ common.MultilibFirst, &module.binaryProperties, &module.testProperties)
+}
+
+func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) {
+ if test, ok := mctx.Module().(*ccTest); ok {
+ if test.testProperties.Test_per_src {
+ testNames := make([]string, len(test.properties.Srcs))
+ for i, src := range test.properties.Srcs {
+ testNames[i] = strings.TrimSuffix(src, filepath.Ext(src))
+ }
+ tests := mctx.CreateLocalVariations(testNames...)
+ for i, src := range test.properties.Srcs {
+ tests[i].(*ccTest).properties.Srcs = []string{src}
+ tests[i].(*ccTest).binaryProperties.Stem = testNames[i]
+ }
+ }
+ }
}
//