From ecadfc111b4242ada83b87007bd65e5d0ca5855f Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 4 Aug 2021 20:02:15 +0000 Subject: [PATCH] tools: Support adding tint flags to the test cases Starting a test case with `// flags: ` will append the 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 Reviewed-by: James Price Commit-Queue: James Price Kokoro: Kokoro Auto-Submit: Ben Clayton --- tools/src/cmd/test-runner/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/src/cmd/test-runner/main.go b/tools/src/cmd/test-runner/main.go index ce87b2e489..d480db04f9 100644 --- a/tools/src/cmd/test-runner/main.go +++ b/tools/src/cmd/test-runner/main.go @@ -23,6 +23,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "runtime" "sort" "strings" @@ -230,9 +231,11 @@ func run() error { go func() { for i, file := range files { // For each test file... file := filepath.Join(dir, file) + flags := parseFlags(file) for _, format := range formats { // For each output format... pendingJobs <- job{ file: file, + flags: flags, format: format, result: results[i][format], } @@ -472,6 +475,7 @@ type status struct { type job struct { file string + flags []string format outputFormat 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... start := time.Now() ok, out := invoke(wd, exe, args...) @@ -703,6 +709,24 @@ func invoke(wd, exe string, args ...string) (ok bool, output string) { 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 { sec := int(d.Seconds()) min := int(sec) / 60