tools: Add the 'cts results' sub-command

Pulls the CTS results from a patchset

Bug: dawn:1342
Change-Id: I879605b71517004d3a8e81a1b4481bbc0105a22c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88440
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2022-04-29 19:09:17 +00:00
parent 40bed821f8
commit 09eafe71b5
2 changed files with 80 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import (
// Register sub-commands
_ "dawn.googlesource.com/dawn/tools/src/cmd/cts/format"
_ "dawn.googlesource.com/dawn/tools/src/cmd/cts/results"
_ "dawn.googlesource.com/dawn/tools/src/cmd/cts/time"
)

View File

@ -0,0 +1,79 @@
// 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 results
import (
"context"
"flag"
"fmt"
"os"
"dawn.googlesource.com/dawn/tools/src/cmd/cts/common"
"dawn.googlesource.com/dawn/tools/src/cts/result"
"go.chromium.org/luci/auth/client/authcli"
)
func init() {
common.Register(&cmd{})
}
type cmd struct {
flags struct {
output string
source common.ResultSource
auth authcli.Flags
}
}
func (cmd) Name() string {
return "results"
}
func (cmd) Desc() string {
return "obtains the CTS results from a patchset"
}
func (c *cmd) RegisterFlags(ctx context.Context, cfg common.Config) ([]string, error) {
flag.StringVar(&c.flags.output, "o", "results.txt", "output file. '-' writes to stdout")
c.flags.source.RegisterFlags(cfg)
c.flags.auth.Register(flag.CommandLine, common.DefaultAuthOptions())
return nil, nil
}
func (c *cmd) Run(ctx context.Context, cfg common.Config) error {
// Validate command line arguments
auth, err := c.flags.auth.Options()
if err != nil {
return fmt.Errorf("failed to obtain authentication options: %w", err)
}
// Obtain the results
results, err := c.flags.source.GetResults(ctx, cfg, auth)
if err != nil {
return err
}
// Open output file
output := os.Stdout
if c.flags.output != "-" {
output, err = os.Create(c.flags.output)
if err != nil {
return fmt.Errorf("failed to open output file '%v': %w", c.flags.output, err)
}
defer output.Close()
}
return result.Write(output, results)
}