run-cts : default "cts" arg to third_party/webgpu-cts if found

Change-Id: Ia052e92d17be5ce2068a14d74b5cdc2c43cf625f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85160
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2022-03-30 18:42:19 +00:00 committed by Dawn LUCI CQ
parent 9be06c8d23
commit e5474a4efc
1 changed files with 57 additions and 16 deletions

View File

@ -134,7 +134,7 @@ func run() error {
var numRunners int var numRunners int
var flags dawnNodeFlags var flags dawnNodeFlags
flag.StringVar(&dawnNode, "dawn-node", "", "path to dawn.node module") flag.StringVar(&dawnNode, "dawn-node", "", "path to dawn.node module")
flag.StringVar(&cts, "cts", "", "root directory of WebGPU CTS") flag.StringVar(&cts, "cts", defaultCtsPath(), "root directory of WebGPU CTS")
flag.StringVar(&node, "node", defaultNodePath(), "path to node executable") flag.StringVar(&node, "node", defaultNodePath(), "path to node executable")
flag.StringVar(&npx, "npx", "", "path to npx executable") flag.StringVar(&npx, "npx", "", "path to npx executable")
flag.StringVar(&resultsPath, "output", "", "path to write test results file") flag.StringVar(&resultsPath, "output", "", "path to write test results file")
@ -1075,21 +1075,23 @@ func saveExpectations(path string, ex testcaseStatuses) error {
// command line flag. // command line flag.
func defaultNodePath() string { func defaultNodePath() string {
if dir := thisDir(); dir != "" { if dir := thisDir(); dir != "" {
node := filepath.Join(dir, "../../../../../../../third_party/node") if dawnRoot := getDawnRoot(); dawnRoot != "" {
if info, err := os.Stat(node); err == nil && info.IsDir() { node := filepath.Join(dawnRoot, "third_party/node")
path := "" if info, err := os.Stat(node); err == nil && info.IsDir() {
switch fmt.Sprintf("%v/%v", runtime.GOOS, runtime.GOARCH) { // See `go tool dist list` path := ""
case "darwin/amd64": switch fmt.Sprintf("%v/%v", runtime.GOOS, runtime.GOARCH) { // See `go tool dist list`
path = filepath.Join(node, "node-darwin-x64/bin/node") case "darwin/amd64":
case "darwin/arm64": path = filepath.Join(node, "node-darwin-x64/bin/node")
path = filepath.Join(node, "node-darwin-arm64/bin/node") case "darwin/arm64":
case "linux/amd64": path = filepath.Join(node, "node-darwin-arm64/bin/node")
path = filepath.Join(node, "node-linux-x64/bin/node") case "linux/amd64":
case "windows/amd64": path = filepath.Join(node, "node-linux-x64/bin/node")
path = filepath.Join(node, "node.exe") case "windows/amd64":
} path = filepath.Join(node, "node.exe")
if _, err := os.Stat(path); err == nil { }
return path if _, err := os.Stat(path); err == nil {
return path
}
} }
} }
} }
@ -1101,6 +1103,45 @@ func defaultNodePath() string {
return "" return ""
} }
// defaultCtsPath looks for the webgpu-cts directory in dawn's third_party
// directory. This is used as the default for the --cts command line flag.
func defaultCtsPath() string {
if dir := thisDir(); dir != "" {
if dawnRoot := getDawnRoot(); dawnRoot != "" {
cts := filepath.Join(dawnRoot, "third_party/webgpu-cts")
if info, err := os.Stat(cts); err == nil && info.IsDir() {
return cts
}
}
}
return ""
}
// getDawnRoot returns the path to the dawn project's root directory or empty
// string if not found.
func getDawnRoot() string {
return getPathOfFileInParentDirs(thisDir(), "DEPS")
}
// getPathOfFileInParentDirs looks for file with `name` in paths starting from
// `path`, and up into parent directories, returning the clean path in which the
// file is found, or empty string if not found.
func getPathOfFileInParentDirs(path string, name string) string {
sep := string(filepath.Separator)
path, _ = filepath.Abs(path)
numDirs := strings.Count(path, sep) + 1
for i := 0; i < numDirs; i++ {
test := filepath.Join(path, name)
if _, err := os.Stat(test); err == nil {
return filepath.Clean(path)
}
path = path + sep + ".."
}
return ""
}
// thisDir returns the path to the directory that holds the .go file of the // thisDir returns the path to the directory that holds the .go file of the
// caller function // caller function
func thisDir() string { func thisDir() string {