Commit 313a6b67 by Ben Clayton

Regres: Simplify running of local tests

Add `filter` flag to run_testlist so that tests can be filtered by wildcard or regex. Update `run_testlist.sh` and `run_testlist.bat` to automatically use the vk-master.txt test list. Change-Id: I94ef1d2e9220f18bdf50555db8c291b3736ec3f3 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42089Reviewed-by: 's avatarPaul Thomson <paulthomson@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent ca10816d
...@@ -24,14 +24,14 @@ import ( ...@@ -24,14 +24,14 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "log"
"os" "os"
"path/filepath"
"regexp"
"runtime" "runtime"
"sort"
"strings" "strings"
"time" "time"
"../../cause"
"../../deqp" "../../deqp"
"../../shell" "../../shell"
"../../testlist" "../../testlist"
...@@ -43,27 +43,32 @@ var ( ...@@ -43,27 +43,32 @@ var (
numThreads = flag.Int("num-threads", runtime.NumCPU(), "number of parallel test runner processes") numThreads = flag.Int("num-threads", runtime.NumCPU(), "number of parallel test runner processes")
maxProcMemory = flag.Uint64("max-proc-mem", shell.MaxProcMemory, "maximum virtual memory per child process") maxProcMemory = flag.Uint64("max-proc-mem", shell.MaxProcMemory, "maximum virtual memory per child process")
output = flag.String("output", "results.json", "path to an output JSON results file") output = flag.String("output", "results.json", "path to an output JSON results file")
filter = flag.String("filter", "", "filter for test names. Start with a '/' to indicate regex")
) )
const testTimeout = time.Minute * 2 const testTimeout = time.Minute * 2
func runTests() error { func run() error {
tests, err := ioutil.ReadFile(*testList)
if err != nil {
return cause.Wrap(err, "Couldn't read '%s'", *testList)
}
group := testlist.Group{ group := testlist.Group{
Name: "", Name: "",
File: "", File: *testList,
API: testlist.Vulkan, API: testlist.Vulkan,
} }
for _, line := range strings.Split(string(tests), "\n") { if err := group.Load(); err != nil {
line = strings.TrimSpace(line) return err
if line != "" && !strings.HasPrefix(line, "#") { }
group.Tests = append(group.Tests, line)
if *filter != "" {
if strings.HasPrefix(*filter, "/") {
re := regexp.MustCompile((*filter)[1:])
group = group.Filter(re.MatchString)
} else {
group = group.Filter(func(name string) bool {
ok, _ := filepath.Match(*filter, name)
return ok
})
} }
} }
sort.Strings(group.Tests)
testLists := testlist.Lists{group} testLists := testlist.Lists{group}
...@@ -80,11 +85,23 @@ func runTests() error { ...@@ -80,11 +85,23 @@ func runTests() error {
TestTimeout: testTimeout, TestTimeout: testTimeout,
} }
log.Printf("Running %d tests...\n", len(group.Tests))
res, err := config.Run() res, err := config.Run()
if err != nil { if err != nil {
return err return err
} }
counts := map[testlist.Status]int{}
for _, r := range res.Tests {
counts[r.Status] = counts[r.Status] + 1
}
for _, s := range testlist.Statuses {
if count := counts[s]; count > 0 {
log.Printf("%s: %d\n", string(s), count)
}
}
err = res.Save(*output) err = res.Save(*output)
if err != nil { if err != nil {
return err return err
...@@ -96,7 +113,7 @@ func runTests() error { ...@@ -96,7 +113,7 @@ func runTests() error {
func main() { func main() {
flag.ErrHelp = errors.New("regres is a tool to detect regressions between versions of SwiftShader") flag.ErrHelp = errors.New("regres is a tool to detect regressions between versions of SwiftShader")
flag.Parse() flag.Parse()
if err := runTests(); err != nil { if err := run(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(-1) os.Exit(-1)
} }
......
go run %~dp0cmd\run_testlist\main.go %* go run %~dp0cmd\run_testlist\main.go --test-list=%~dp0testlists\vk-master.txt %*
\ No newline at end of file
#!/bin/bash
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
go run $ROOT_DIR/cmd/run_testlist/main.go --test-list=$ROOT_DIR/testlists/vk-master.txt $@
...@@ -48,6 +48,22 @@ type Group struct { ...@@ -48,6 +48,22 @@ type Group struct {
Tests []string Tests []string
} }
// Load loads the test list file and appends all tests to the Group.
func (g *Group) Load() error {
tests, err := ioutil.ReadFile(g.File)
if err != nil {
return cause.Wrap(err, "Couldn't read '%s'", tests)
}
for _, line := range strings.Split(string(tests), "\n") {
line = strings.TrimSpace(line)
if line != "" && !strings.HasPrefix(line, "#") {
g.Tests = append(g.Tests, line)
}
}
sort.Strings(g.Tests)
return nil
}
// Filter returns a new Group that contains only tests that match the predicate. // Filter returns a new Group that contains only tests that match the predicate.
func (g Group) Filter(pred func(string) bool) Group { func (g Group) Filter(pred func(string) bool) Group {
out := Group{ out := Group{
...@@ -117,27 +133,22 @@ func Load(root, jsonPath string) (Lists, error) { ...@@ -117,27 +133,22 @@ func Load(root, jsonPath string) (Lists, error) {
out := make(Lists, len(jsonGroups)) out := make(Lists, len(jsonGroups))
for i, jsonGroup := range jsonGroups { for i, jsonGroup := range jsonGroups {
path := filepath.Join(dir, jsonGroup.TestFile)
tests, err := ioutil.ReadFile(path)
if err != nil {
return nil, cause.Wrap(err, "Couldn't read '%s'", tests)
}
relPath, err := filepath.Rel(root, path)
if err != nil {
return nil, cause.Wrap(err, "Couldn't get relative path for '%s'", path)
}
group := Group{ group := Group{
Name: jsonGroup.Name, Name: jsonGroup.Name,
File: relPath, File: filepath.Join(dir, jsonGroup.TestFile),
API: API(jsonGroup.API), API: API(jsonGroup.API),
} }
for _, line := range strings.Split(string(tests), "\n") { if err := group.Load(); err != nil {
line = strings.TrimSpace(line) return nil, err
if line != "" && !strings.HasPrefix(line, "#") {
group.Tests = append(group.Tests, line)
}
} }
sort.Strings(group.Tests)
// Make the path relative before displaying it to the world.
relPath, err := filepath.Rel(root, group.File)
if err != nil {
return nil, cause.Wrap(err, "Couldn't get relative path for '%s'", group.File)
}
group.File = relPath
out[i] = group out[i] = group
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment