OSDN Git Service

Regres: Scan commit message for additional test lists.
authorBen Clayton <bclayton@google.com>
Fri, 8 Mar 2019 19:26:24 +0000 (19:26 +0000)
committerBen Clayton <bclayton@google.com>
Sat, 9 Mar 2019 08:03:13 +0000 (08:03 +0000)
Change-Id: Ib0beec96a6efafa0ee6fb8a43e15142206d3cd4d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26558
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
tests/regres/main.go
tests/regres/testlist/testlist.go

index 396cada..cd2b760 100644 (file)
@@ -290,6 +290,8 @@ func (r *regres) test(change *changeInfo) (string, error) {
        return msg, nil
 }
 
+var additionalTestsRE = regexp.MustCompile(`\n\s*Test[s]?:\s*([^\s]+)[^\n]*`)
+
 func (r *regres) testLatest(change *changeInfo) (*CommitTestResults, testlist.Lists, error) {
        // Get the test results for the latest patchset in the change.
        test := r.newTest(change.latest)
@@ -304,6 +306,29 @@ func (r *regres) testLatest(change *changeInfo) (*CommitTestResults, testlist.Li
                return nil, nil, cause.Wrap(err, "Failed to load '%s'", change.latest)
        }
 
+       if matches := additionalTestsRE.FindAllStringSubmatch(change.commitMessage, -1); len(matches) > 0 {
+               log.Println("Change description contains additional test patterns")
+
+               // Change specifies additional tests to try. Load the full test list.
+               fullTestLists, err := test.loadTestLists(fullTestListRelPath)
+               if err != nil {
+                       return nil, nil, cause.Wrap(err, "Failed to load '%s'", change.latest)
+               }
+
+               // Add any tests in the full list that match the pattern to the list to test.
+               for _, match := range matches {
+                       if len(match) > 1 {
+                               pattern := match[1]
+                               log.Printf("Adding custom tests with pattern '%s'\n", pattern)
+                               filtered := fullTestLists.Filter(func(name string) bool {
+                                       ok, _ := filepath.Match(pattern, name)
+                                       return ok
+                               })
+                               testlists = append(testlists, filtered...)
+                       }
+               }
+       }
+
        cachePath := test.resultsCachePath(testlists)
 
        if results, err := loadCommitTestResults(cachePath); err == nil {
index 5585200..d2da533 100644 (file)
@@ -48,9 +48,36 @@ type Group struct {
        Tests []string
 }
 
+// Filter returns a new Group that contains only tests that match the predicate.
+func (g Group) Filter(pred func(string) bool) Group {
+       out := Group{
+               Name: g.Name,
+               File: g.File,
+               API:  g.API,
+       }
+       for _, test := range g.Tests {
+               if pred(test) {
+                       out.Tests = append(out.Tests, test)
+               }
+       }
+       return out
+}
+
 // Lists is the full list of tests to be run.
 type Lists []Group
 
+// Filter returns a new Lists that contains only tests that match the predicate.
+func (l Lists) Filter(pred func(string) bool) Lists {
+       out := Lists{}
+       for _, group := range l {
+               filtered := group.Filter(pred)
+               if len(filtered.Tests) > 0 {
+                       out = append(out, filtered)
+               }
+       }
+       return out
+}
+
 // Hash returns a SHA1 hash of the set of tests.
 func (l Lists) Hash() string {
        h := sha1.New()