Update cts expectations to be sorted by bug first.

- Run format on the current expectations file to make it up to date.
- It's a lot easier to read the failures when they are grouped by the bug.

Change-Id: I333a0b237ccd405d204e47809eb7ab723824fddd
No-Try: True
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98241
Auto-Submit: Loko Kung <lokokung@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung
2022-08-09 16:40:32 +00:00
committed by Dawn LUCI CQ
parent d794342ed5
commit eaca2ebd4c
4 changed files with 61 additions and 42 deletions

View File

@@ -23,6 +23,7 @@ import (
"io"
"io/ioutil"
"os"
"sort"
"strings"
"dawn.googlesource.com/dawn/tools/src/cts/result"
@@ -39,7 +40,7 @@ type Content struct {
// expectation to a line-comment.
type Chunk struct {
Comments []string // Line comments at the top of the chunk
Expectations []Expectation // Expectations for the chunk
Expectations Expectations // Expectations for the chunk
}
// Tags holds the tag information parsed in the comments between the
@@ -80,6 +81,8 @@ type Expectation struct {
Comment string // Optional comment at end of line
}
type Expectations []Expectation
// Load loads the expectation file at 'path', returning a Content.
func Load(path string) (Content, error) {
content, err := ioutil.ReadFile(path)
@@ -228,3 +231,36 @@ func (e Expectation) Clone() Expectation {
}
return out
}
// Compare compares the relative order of a and b, returning:
// -1 if a should come before b
// 1 if a should come after b
// 0 if a and b are identical
// Note: Only comparing bug, query, and tags (in that order).
func (a Expectation) Compare(b Expectation) int {
switch strings.Compare(a.Bug, b.Bug) {
case -1:
return -1
case 1:
return 1
}
switch strings.Compare(a.Query, b.Query) {
case -1:
return -1
case 1:
return 1
}
aTag := result.TagsToString(a.Tags)
bTag := result.TagsToString(b.Tags)
switch strings.Compare(aTag, bTag) {
case -1:
return -1
case 1:
return 1
}
return 0
}
func (l Expectations) Sort() {
sort.Slice(l, func(i, j int) bool { return l[i].Compare(l[j]) < 0 })
}

View File

@@ -55,6 +55,7 @@ func Parse(body string) (Content, error) {
// flush completes the current chunk, appending it to 'content'
flush := func() {
parseTags(&content.Tags, pending.Comments)
pending.Expectations.Sort()
content.Chunks = append(content.Chunks, pending)
pending = Chunk{}
}

View File

@@ -17,7 +17,6 @@ package expectations
import (
"errors"
"fmt"
"sort"
"strings"
"time"
@@ -271,24 +270,7 @@ func (u *updater) chunk(in Chunk) Chunk {
}
// Sort the expectations to keep things clean and tidy.
sort.Slice(out.Expectations, func(i, j int) bool {
switch {
case out.Expectations[i].Query < out.Expectations[j].Query:
return true
case out.Expectations[i].Query > out.Expectations[j].Query:
return false
}
a := result.TagsToString(out.Expectations[i].Tags)
b := result.TagsToString(out.Expectations[j].Tags)
switch {
case a < b:
return true
case a > b:
return false
}
return false
})
out.Expectations.Sort()
return out
}