Line data Source code
1 : // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : // metarunner is a utility which runs metamorphic.RunOnce or Compare. It is 6 : // equivalent to executing `internal/metamorphic.TestMeta` with `--run-dir` or 7 : // `--compare`. It is used for code coverage instrumentation. 8 : package main 9 : 10 : import ( 11 : "flag" 12 : "fmt" 13 : "os" 14 : "path/filepath" 15 : "strings" 16 : 17 : "github.com/cockroachdb/pebble/internal/metamorphic/metaflags" 18 : "github.com/cockroachdb/pebble/metamorphic" 19 : ) 20 : 21 : var runOnceFlags = metaflags.InitRunOnceFlags() 22 : var _ = flag.String("test.run", "", `ignored; used for compatibility with TestMeta`) 23 : 24 1 : func main() { 25 1 : flag.Parse() 26 1 : onceOpts := runOnceFlags.MakeRunOnceOptions() 27 1 : t := &mockT{} 28 1 : switch { 29 0 : case runOnceFlags.Compare != "": 30 0 : runDirs := strings.Split(runOnceFlags.Compare, ",") 31 0 : metamorphic.Compare(t, runOnceFlags.Dir, runOnceFlags.Seed, runDirs, onceOpts...) 32 : 33 1 : case runOnceFlags.RunDir != "": 34 1 : // The --run-dir flag is specified either in the child process (see 35 1 : // runOptions() below) or the user specified it manually in order to re-run 36 1 : // a test. 37 1 : metamorphic.RunOnce(t, runOnceFlags.RunDir, runOnceFlags.Seed, filepath.Join(runOnceFlags.RunDir, "history"), onceOpts...) 38 : 39 0 : default: 40 0 : t.Errorf("--compare or --run-dir must be used") 41 : } 42 : 43 1 : if t.Failed() { 44 0 : // Make sure we return an error code. 45 0 : t.FailNow() 46 0 : } 47 : } 48 : 49 : type mockT struct { 50 : failed bool 51 : } 52 : 53 : var _ metamorphic.TestingT = (*mockT)(nil) 54 : 55 0 : func (t *mockT) Errorf(format string, args ...interface{}) { 56 0 : t.failed = true 57 0 : fmt.Fprintf(os.Stderr, format+"\n", args...) 58 0 : } 59 : 60 0 : func (t *mockT) FailNow() { 61 0 : os.Exit(2) 62 0 : } 63 : 64 1 : func (t *mockT) Failed() bool { 65 1 : return t.failed 66 1 : }