dawn-cmake/tools/src/cts/expectations/validate_test.go
Ben Clayton aad2e9c0b5 tools/cts: Add cts validate, improvements & fixes
• Add `cts validate` command used to check for expectation collisions.
  Can be used as a presubmit check.
  This is more tightly checked than the previous logic, as this works on just
  the expectations, instead of results.

• Fix an issue where the test result reduction could introduce collisions with
  'Skip' expectations.
  To fix this, the update process first adds 'consumed' results for the skipped
  tests, preventing test tree reduction for that part of the tree.

• Fix a bug in the generation of 'New failures' and 'New flakes' which produced
  more expectations than was necessary.
  The issue here was that the tree roots could contain overlaps, and roots could
  be processed before sub-trees, resulting in inefficient expectations.

• Fix collisions in the expectations file, and update with results from
  the most recent roll.

Change-Id: I7b64553408998fb4416458ce564fc49c8f6d4d07
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101860
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2022-09-17 19:30:29 +00:00

131 lines
3.6 KiB
Go

// 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 expectations_test
import (
"testing"
"dawn.googlesource.com/dawn/tools/src/cts/expectations"
"github.com/google/go-cmp/cmp"
)
func TestValidate(t *testing.T) {
header := `# BEGIN TAG HEADER
# OS
# tags: [ os-a os-b os-c ]
# GPU
# tags: [ gpu-a gpu-b gpu-c ]
# END TAG HEADER
`
type Test struct {
name string
expectations string
diagnostics expectations.Diagnostics
}
for _, test := range []Test{
{ //////////////////////////////////////////////////////////////////////
name: "empty",
expectations: ``,
},
{ //////////////////////////////////////////////////////////////////////
name: "simple",
expectations: `
crbug.com/a/123 a:b,c:d,* [ Failure ]
`,
},
{ //////////////////////////////////////////////////////////////////////
name: "no-tag collision",
expectations: `
crbug.com/a/123 a:b,c:d,* [ Failure ]
crbug.com/a/123 a:x,x:d,* [ Failure ]
crbug.com/a/123 a:b,c:d,* [ Failure ]
`,
diagnostics: expectations.Diagnostics{
{
Line: 8,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 10",
},
{
Line: 10,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 8",
},
},
},
{ //////////////////////////////////////////////////////////////////////
name: "tag collision",
expectations: `
crbug.com/a/123 [ os-a ] a:b,c:d,* [ Failure ]
crbug.com/a/123 a:x,x:d,* [ Failure ]
crbug.com/a/123 [ os-a ] a:b,c:d,* [ Failure ]
`,
diagnostics: expectations.Diagnostics{
{
Line: 8,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 10",
},
{
Line: 10,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 8",
},
},
},
{ //////////////////////////////////////////////////////////////////////
name: "nested no-tag collision",
expectations: `
crbug.com/a/123 a:b,c:d,e:* [ Failure ]
crbug.com/a/123 a:x,x:d,* [ Failure ]
crbug.com/a/123 a:b,c:d,* [ Failure ]
`,
diagnostics: expectations.Diagnostics{
{
Line: 10,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 8",
},
},
},
{ //////////////////////////////////////////////////////////////////////
name: "tag collision",
expectations: `
crbug.com/a/123 [ os-a ] a:b,c:d,e:* [ Failure ]
crbug.com/a/123 a:x,x:d,* [ Failure ]
crbug.com/a/123 [ os-a ] a:b,c:d,* [ Failure ]
`,
diagnostics: expectations.Diagnostics{
{
Line: 10,
Severity: expectations.Error,
Message: "expectation collides with expectation on line 8",
},
},
},
} {
ex, err := expectations.Parse(header + test.expectations)
if err != nil {
t.Fatalf("'%v': expectations.Parse():\n%v", test.name, err)
}
diagnostics := ex.Validate()
if diff := cmp.Diff(diagnostics, test.diagnostics); diff != "" {
t.Errorf("'%v': expectations.Update() error:\n%v", test.name, diff)
}
}
}