tools: Support adding tint flags to the test cases

Starting a test case with `// flags: <flags>` will
append the <flags> to the tint executable for that test case.

Let's you specify things like `// flags: --transform XXX`, which lets us
end-to-end test a particular set of transforms.

Change-Id: I181e9f7e7c1fba5e3a47cf58aee462b51e4b6e3b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60921
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-08-04 20:02:15 +00:00 committed by Tint LUCI CQ
parent 5c61d6d12c
commit ecadfc111b
1 changed files with 24 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
@ -230,9 +231,11 @@ func run() error {
go func() { go func() {
for i, file := range files { // For each test file... for i, file := range files { // For each test file...
file := filepath.Join(dir, file) file := filepath.Join(dir, file)
flags := parseFlags(file)
for _, format := range formats { // For each output format... for _, format := range formats { // For each output format...
pendingJobs <- job{ pendingJobs <- job{
file: file, file: file,
flags: flags,
format: format, format: format,
result: results[i][format], result: results[i][format],
} }
@ -472,6 +475,7 @@ type status struct {
type job struct { type job struct {
file string file string
flags []string
format outputFormat format outputFormat
result chan status result chan status
} }
@ -524,6 +528,8 @@ func (j job) run(wd, exe string, fxc bool, dxcPath, xcrunPath string, generateEx
} }
} }
args = append(args, j.flags...)
// Invoke the compiler... // Invoke the compiler...
start := time.Now() start := time.Now()
ok, out := invoke(wd, exe, args...) ok, out := invoke(wd, exe, args...)
@ -703,6 +709,24 @@ func invoke(wd, exe string, args ...string) (ok bool, output string) {
return true, str return true, str
} }
var reFlags = regexp.MustCompile(` *\/\/ *flags:(.*)\n`)
// parseFlags looks for a `// flags:` header at the start of the file with the
// given path, returning each of the space delimited tokens that follow for the
// line
func parseFlags(path string) []string {
content, err := ioutil.ReadFile(path)
if err != nil {
return nil
}
header := strings.SplitN(string(content), "\n", 1)[0]
m := reFlags.FindStringSubmatch(header)
if len(m) != 2 {
return nil
}
return strings.Split(m[1], " ")
}
func printDuration(d time.Duration) string { func printDuration(d time.Duration) string {
sec := int(d.Seconds()) sec := int(d.Seconds())
min := int(sec) / 60 min := int(sec) / 60