diff --git a/tools/src/cmd/cts/common/cmds.go b/tools/src/cmd/cts/common/cmds.go new file mode 100644 index 0000000000..00a655ae24 --- /dev/null +++ b/tools/src/cmd/cts/common/cmds.go @@ -0,0 +1,31 @@ +// Copyright 2022 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "dawn.googlesource.com/dawn/tools/src/subcmd" +) + +// The registered commands +var commands []Command + +// Command is the type of a single cts command +type Command = subcmd.Command[Config] + +// Register registers the command for use by the 'cts' tool +func Register(c Command) { commands = append(commands, c) } + +// Commands returns all the commands registered +func Commands() []Command { return commands } diff --git a/tools/src/cmd/cts/common/paths.go b/tools/src/cmd/cts/common/paths.go new file mode 100644 index 0000000000..fda05ed20d --- /dev/null +++ b/tools/src/cmd/cts/common/paths.go @@ -0,0 +1,38 @@ +// Copyright 2022 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "os" + "path/filepath" + + "dawn.googlesource.com/dawn/tools/src/utils" +) + +const ( + // RelativeExpectationsPath is the dawn-root relative path to the + // expectations.txt file. + RelativeExpectationsPath = "webgpu-cts/expectations.txt" +) + +// DefaultExpectationsPath returns the default path to the expectations.txt +// file. Returns an empty string if the file cannot be found. +func DefaultExpectationsPath() string { + path := filepath.Join(utils.DawnRoot(), RelativeExpectationsPath) + if _, err := os.Stat(path); err != nil { + return "" + } + return path +} diff --git a/tools/src/cmd/cts/format/format.go b/tools/src/cmd/cts/format/format.go new file mode 100644 index 0000000000..823e1bea1c --- /dev/null +++ b/tools/src/cmd/cts/format/format.go @@ -0,0 +1,55 @@ +// Copyright 2022 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package format + +import ( + "context" + "flag" + + "dawn.googlesource.com/dawn/tools/src/cmd/cts/common" + "dawn.googlesource.com/dawn/tools/src/cts/expectations" +) + +func init() { + common.Register(&cmd{}) +} + +type cmd struct { + flags struct { + expectations string // expectations file path + } +} + +func (cmd) Name() string { + return "format" +} + +func (cmd) Desc() string { + return "formats a WebGPUExpectation file" +} + +func (c *cmd) RegisterFlags(ctx context.Context, cfg common.Config) ([]string, error) { + defaultExpectations := common.DefaultExpectationsPath() + flag.StringVar(&c.flags.expectations, "expectations", defaultExpectations, "path to CTS expectations file to update") + return nil, nil +} + +func (c *cmd) Run(ctx context.Context, cfg common.Config) error { + ex, err := expectations.Load(c.flags.expectations) + if err != nil { + return err + } + return ex.Save(c.flags.expectations) +} diff --git a/tools/src/cmd/cts/main.go b/tools/src/cmd/cts/main.go new file mode 100644 index 0000000000..542ae40f34 --- /dev/null +++ b/tools/src/cmd/cts/main.go @@ -0,0 +1,49 @@ +// Copyright 2022 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// cts is a collection of sub-commands for operating on the WebGPU CTS. +// +// To view available commands run: '/tools/run cts --help' +package main + +import ( + "context" + "fmt" + "os" + "path/filepath" + + "dawn.googlesource.com/dawn/tools/src/cmd/cts/common" + "dawn.googlesource.com/dawn/tools/src/subcmd" + "dawn.googlesource.com/dawn/tools/src/utils" + + // Register sub-commands + _ "dawn.googlesource.com/dawn/tools/src/cmd/cts/format" +) + +func main() { + ctx := context.Background() + + cfg, err := common.LoadConfig(filepath.Join(utils.ThisDir(), "config.json")) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + if err := subcmd.Run(ctx, *cfg, common.Commands()...); err != nil { + if err != subcmd.ErrInvalidCLA { + fmt.Fprintln(os.Stderr, err) + } + os.Exit(1) + } +}