| Ben Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package validate |
| 16 | |
| 17 | import ( |
| 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 | |
| 27 | func init() { |
| 28 | common.Register(&cmd{}) |
| 29 | } |
| 30 | |
| 31 | type cmd struct { |
| 32 | flags struct { |
| 33 | expectations string // expectations file path |
| Austin Eng | 0dae5ce | 2023-08-17 22:07:36 +0000 | [diff] [blame] | 34 | slow string // slow test expectations file path |
| Ben Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | func (cmd) Name() string { |
| 39 | return "validate" |
| 40 | } |
| 41 | |
| 42 | func (cmd) Desc() string { |
| 43 | return "validates a WebGPU expectations.txt file" |
| 44 | } |
| 45 | |
| 46 | func (c *cmd) RegisterFlags(ctx context.Context, cfg common.Config) ([]string, error) { |
| 47 | defaultExpectations := common.DefaultExpectationsPath() |
| Austin Eng | 74dcafc | 2023-05-19 15:35:38 +0000 | [diff] [blame] | 48 | 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 Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 51 | return nil, nil |
| 52 | } |
| 53 | |
| 54 | func (c *cmd) Run(ctx context.Context, cfg common.Config) error { |
| Austin Eng | 74dcafc | 2023-05-19 15:35:38 +0000 | [diff] [blame] | 55 | // Load expectations.txt |
| 56 | content, err := expectations.Load(c.flags.expectations) |
| Ben Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| Austin Eng | 74dcafc | 2023-05-19 15:35:38 +0000 | [diff] [blame] | 60 | diags := content.Validate() |
| Ben Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 61 | |
| 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 Eng | 74dcafc | 2023-05-19 15:35:38 +0000 | [diff] [blame] | 68 | // 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 Clayton | aad2e9c | 2022-09-17 19:30:29 +0000 | [diff] [blame] | 81 | fmt.Println("no issues found") |
| 82 | return nil |
| 83 | } |