tools: Add the 'cts merge' sub-command
Merges results files into one. Bug: dawn:1342 Change-Id: Ia241afc982c88c840a102abba211053611f77f5b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88441 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
09eafe71b5
commit
1ed858c20a
|
@ -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/merge"
|
||||
_ "dawn.googlesource.com/dawn/tools/src/cmd/cts/results"
|
||||
_ "dawn.googlesource.com/dawn/tools/src/cmd/cts/time"
|
||||
)
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
// 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 merge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/cmd/cts/common"
|
||||
"dawn.googlesource.com/dawn/tools/src/cts/result"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Register(&cmd{})
|
||||
}
|
||||
|
||||
type cmd struct {
|
||||
flags struct {
|
||||
output string
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd) Name() string { return "merge" }
|
||||
|
||||
func (cmd) Desc() string { return "merges results files into one" }
|
||||
|
||||
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")
|
||||
return []string{"first-results.txt", "second-results.txt ..."}, nil
|
||||
}
|
||||
|
||||
func (c *cmd) Run(ctx context.Context, cfg common.Config) error {
|
||||
// Load each of the results files and merge together
|
||||
var results result.List
|
||||
for _, path := range flag.Args() {
|
||||
// Load results
|
||||
r, err := result.Load(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("while reading '%v': %w", path, err)
|
||||
}
|
||||
// Combine and merge
|
||||
if len(results) > 0 {
|
||||
results = result.Merge(results, r)
|
||||
} else {
|
||||
results = r
|
||||
}
|
||||
}
|
||||
|
||||
// Open output file
|
||||
output := os.Stdout
|
||||
if c.flags.output != "-" {
|
||||
var err error
|
||||
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()
|
||||
}
|
||||
|
||||
// Write out
|
||||
return result.Write(output, results)
|
||||
}
|
Loading…
Reference in New Issue