Move sharding functions for reuse

Move shardPaths and shardTests to android.ShardPaths and
android.ShardStrings for reuse in other packages.

Test: m checkbuild
Change-Id: I868802872c73616b80f56cbf11f959c01a8b793a
This commit is contained in:
Colin Cross
2019-09-23 14:33:09 -07:00
parent 852116a061
commit 0a2f719bca
7 changed files with 137 additions and 123 deletions

View File

@@ -123,25 +123,6 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext)
}
}
func shardTests(paths []string, shards int) [][]string {
if shards > len(paths) {
shards = len(paths)
}
if shards == 0 {
return nil
}
ret := make([][]string, 0, shards)
shardSize := (len(paths) + shards - 1) / shards
for len(paths) > shardSize {
ret = append(ret, paths[0:shardSize])
paths = paths[shardSize:]
}
if len(paths) > 0 {
ret = append(ret, paths)
}
return ret
}
func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, instrumentedApp *AndroidApp) {
manifest := instrumentedApp.mergedManifestFile
resourceApk := instrumentedApp.outputFile
@@ -183,7 +164,9 @@ func (r *robolectricTest) AndroidMkEntries() android.AndroidMkEntries {
entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
if s := r.robolectricProperties.Test_options.Shards; s != nil && *s > 1 {
shards := shardTests(r.tests, int(*s))
numShards := int(*s)
shardSize := (len(r.tests) + numShards - 1) / numShards
shards := android.ShardStrings(r.tests, shardSize)
for i, shard := range shards {
r.writeTestRunner(w, name, "Run"+name+strconv.Itoa(i), shard)
}