1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

cmd/stress: add "-ignore regexp" flag

This adds a flag for specifying a regular expression for failures that
should be ignored. This is useful for filtering out known issues and
provides a logical mirror to the existing -failure flag.

Change-Id: Ibbacdd2125aa23fe819896e5a17664b703c4ee35
Reviewed-on: https://go-review.googlesource.com/12676
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
This commit is contained in:
Austin Clements 2015-07-25 00:13:09 -04:00
parent 4d49207e6b
commit 69f53eb622

View File

@ -29,6 +29,7 @@ var (
flagTimeout = flag.Duration("timeout", 10*time.Minute, "timeout each process after `duration`")
flagKill = flag.Bool("kill", true, "kill timed out processes if true, otherwise just print pid (to attach with gdb)")
flagFailure = flag.String("failure", "", "fail only if output matches `regexp`")
flagIgnore = flag.String("ignore", "", "ignore failure if output matches `regexp`")
)
func main() {
@ -37,7 +38,7 @@ func main() {
flag.Usage()
os.Exit(1)
}
var failureRe *regexp.Regexp
var failureRe, ignoreRe *regexp.Regexp
if *flagFailure != "" {
var err error
if failureRe, err = regexp.Compile(*flagFailure); err != nil {
@ -45,6 +46,13 @@ func main() {
os.Exit(1)
}
}
if *flagIgnore != "" {
var err error
if ignoreRe, err = regexp.Compile(*flagIgnore); err != nil {
fmt.Println("bad ignore regexp:", err)
os.Exit(1)
}
}
res := make(chan []byte)
for i := 0; i < *flagP; i++ {
go func() {
@ -73,7 +81,7 @@ func main() {
}
out, err := cmd.CombinedOutput()
close(done)
if err != nil && (failureRe == nil || failureRe.Match(out)) {
if err != nil && (failureRe == nil || failureRe.Match(out)) && (ignoreRe == nil || !ignoreRe.Match(out)) {
out = append(out, fmt.Sprintf("\n\nERROR: %v\n", err)...)
} else {
out = []byte{}