blob: cdd74862f68e522b25586cb7742293ea50e8f6b8 [file] [log] [blame]
Ben Claytonaad2e9c2022-09-17 19:30:29 +00001// Copyright 2022 The Dawn Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package validate
16
17import (
18 "context"
19 "flag"
20 "fmt"
21 "os"
22
23 "dawn.googlesource.com/dawn/tools/src/cmd/cts/common"
24 "dawn.googlesource.com/dawn/tools/src/cts/expectations"
25)
26
27func init() {
28 common.Register(&cmd{})
29}
30
31type cmd struct {
32 flags struct {
33 expectations string // expectations file path
Austin Eng0dae5ce2023-08-17 22:07:36 +000034 slow string // slow test expectations file path
Ben Claytonaad2e9c2022-09-17 19:30:29 +000035 }
36}
37
38func (cmd) Name() string {
39 return "validate"
40}
41
42func (cmd) Desc() string {
43 return "validates a WebGPU expectations.txt file"
44}
45
46func (c *cmd) RegisterFlags(ctx context.Context, cfg common.Config) ([]string, error) {
47 defaultExpectations := common.DefaultExpectationsPath()
Austin Eng74dcafc2023-05-19 15:35:38 +000048 slowExpectations := common.DefaultSlowExpectationsPath()
49 flag.StringVar(&c.flags.expectations, "expectations", defaultExpectations, "path to CTS expectations file to validate")
50 flag.StringVar(&c.flags.slow, "slow", slowExpectations, "path to CTS slow expectations file to validate")
Ben Claytonaad2e9c2022-09-17 19:30:29 +000051 return nil, nil
52}
53
54func (c *cmd) Run(ctx context.Context, cfg common.Config) error {
Austin Eng74dcafc2023-05-19 15:35:38 +000055 // Load expectations.txt
56 content, err := expectations.Load(c.flags.expectations)
Ben Claytonaad2e9c2022-09-17 19:30:29 +000057 if err != nil {
58 return err
59 }
Austin Eng74dcafc2023-05-19 15:35:38 +000060 diags := content.Validate()
Ben Claytonaad2e9c2022-09-17 19:30:29 +000061
62 // Print any diagnostics
63 diags.Print(os.Stdout, c.flags.expectations)
64 if numErrs := diags.NumErrors(); numErrs > 0 {
65 return fmt.Errorf("%v errors found", numErrs)
66 }
67
Austin Eng74dcafc2023-05-19 15:35:38 +000068 // Load slow_tests.txt
69 content, err = expectations.Load(c.flags.slow)
70 if err != nil {
71 return err
72 }
73
74 diags = content.ValidateSlowTests()
75 // Print any diagnostics
76 diags.Print(os.Stdout, c.flags.expectations)
77 if numErrs := diags.NumErrors(); numErrs > 0 {
78 return fmt.Errorf("%v errors found", numErrs)
79 }
80
Ben Claytonaad2e9c2022-09-17 19:30:29 +000081 fmt.Println("no issues found")
82 return nil
83}