diff --git a/.github/workflows/suite.yml b/.github/workflows/suite.yml index 7bc0fb3..1c79dfc 100644 --- a/.github/workflows/suite.yml +++ b/.github/workflows/suite.yml @@ -15,7 +15,7 @@ jobs: - name: setup go uses: actions/setup-go@v2 with: - go-version: 1.13 + go-version: 1.22 - name: validation run: make build test - name: codecov diff --git a/Makefile b/Makefile index 197268d..5b656ef 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.gitBranch=$(sh LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.goVersion=$(shell go version)" FAILPOINT_CTL_BIN := bin/failpoint-ctl +FAILPOINT_TOOLEXEC_BIN := bin/failpoint-toolexec path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))) export PATH := $(path_to_add):$(PATH):$(shell pwd)/tools/bin @@ -31,12 +32,17 @@ default: build checksuccess build: $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -o $(FAILPOINT_CTL_BIN) failpoint-ctl/main.go + $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -o $(FAILPOINT_TOOLEXEC_BIN) failpoint-toolexec/main.go checksuccess: @if [ -f $(FAILPOINT_CTL_BIN) ]; \ then \ echo "failpoint-ctl build successfully :-) !" ; \ fi + @if [ -f $(FAILPOINT_TOOLEXEC_BIN) ]; \ + then \ + echo "failpoint-toolexec build successfully :-) !" ; \ + fi test: gotest check-static diff --git a/README.md b/README.md index 2d382e9..b6ed271 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ An implementation of [failpoints][failpoint] for Golang. Fail points are used to [failpoint]: http://www.freebsd.org/cgi/man.cgi?query=fail -## Quick Start +## Quick Start (use `failpoint-ctl`) 1. Build `failpoint-ctl` from source @@ -51,6 +51,47 @@ An implementation of [failpoints][failpoint] for Golang. Fail points are used to GO_FAILPOINTS="main/testPanic=return(true)" go run your-program.go binding__failpoint_binding__.go ``` +## Quick Start (use `failpoint-toolexec`) + +1. Build `failpoint-toolexec` from source + + ``` bash + git clone https://github.com/pingcap/failpoint.git + cd failpoint + make + ls bin/failpoint-toolexec + ``` + +2. Inject failpoints to your program, eg: + + ``` go + package main + + import "github.com/pingcap/failpoint" + + func main() { + failpoint.Inject("testPanic", func() { + panic("failpoint triggerd") + }) + } + ``` + +3. Use a separate build cache to avoid mixing caches without `failpoint-toolexec`, and build + + `GOCACHE=/tmp/failpoint-cache go build -toolexec path/to/failpoint-toolexec` + +4. Enable failpoints with `GO_FAILPOINTS` environment variable + + ``` bash + GO_FAILPOINTS="main/testPanic=return(true)" ./your-program + ``` + +5. You can also use `go run` or `go test`, like: + + ```bash + GOCACHE=/tmp/failpoint-cache GO_FAILPOINTS="main/testPanic=return(true)" go run -toolexec path/to/failpoint-toolexec your-program.go + ``` + ## Design principles - Define failpoint in valid Golang code, not comments or anything else diff --git a/code/expr_rewriter.go b/code/expr_rewriter.go index 18d0950..6f592fd 100644 --- a/code/expr_rewriter.go +++ b/code/expr_rewriter.go @@ -66,7 +66,7 @@ func (r *Rewriter) rewriteInject(call *ast.CallExpr) (bool, ast.Stmt, error) { } fpnameExtendCall := &ast.CallExpr{ - Fun: ast.NewIdent(extendPkgName), + Fun: ast.NewIdent(ExtendPkgName), Args: []ast.Expr{fpname}, } @@ -163,7 +163,7 @@ func (r *Rewriter) rewriteInjectContext(call *ast.CallExpr) (bool, ast.Stmt, err } fpnameExtendCall := &ast.CallExpr{ - Fun: ast.NewIdent(extendPkgName), + Fun: ast.NewIdent(ExtendPkgName), Args: []ast.Expr{fpname}, } diff --git a/code/restorer.go b/code/restorer.go index e67afdc..7d1f478 100644 --- a/code/restorer.go +++ b/code/restorer.go @@ -32,6 +32,7 @@ const ( // Restorer represents a manager to restore currentFile tree which has been modified by // `failpoint-ctl enable`, e.g: +/* // ├── foo // │ ├── foo.go // │   └── foo.go__failpoint_stash__ @@ -48,6 +49,7 @@ const ( // │   └── bar.go <- bar.go__failpoint_stash__ // └── foobar //    └── foobar.go <- foobar.go__failpoint_stash__ +*/ type Restorer struct { path string } @@ -154,6 +156,6 @@ func init() { func %s(name string) string { return __failpointBindingCache.pkgpath + "/" + name } -`, pak, extendPkgName) +`, pak, ExtendPkgName) return ioutil.WriteFile(bindingFile, []byte(bindingContent), 0644) } diff --git a/code/rewriter.go b/code/rewriter.go index ed62917..f0bd812 100644 --- a/code/rewriter.go +++ b/code/rewriter.go @@ -32,7 +32,7 @@ const ( packageName = "failpoint" evalFunction = "Eval" evalCtxFunction = "EvalContext" - extendPkgName = "_curpkg_" + ExtendPkgName = "_curpkg_" // It is an indicator to indicate the label is converted from `failpoint.Label("...")` // We use an illegal suffix to avoid conflict with the user's code // So `failpoint.Label("label1")` will be converted to `label1-tmp-marker:` in expression @@ -44,12 +44,13 @@ const ( // corresponding statements in Golang. It will traverse the specified path and filter // out files which do not have failpoint injection sites, and rewrite the remain files. type Rewriter struct { - rewriteDir string - currentPath string - currentFile *ast.File - currsetFset *token.FileSet - failpointName string - rewritten bool + rewriteDir string + currentPath string + currentFile *ast.File + currsetFset *token.FileSet + failpointName string + allowNotChecked bool + rewritten bool output io.Writer } @@ -66,6 +67,21 @@ func (r *Rewriter) SetOutput(out io.Writer) { r.output = out } +// SetAllowNotChecked sets whether the rewriter allows the file which does not import failpoint package. +func (r *Rewriter) SetAllowNotChecked(b bool) { + r.allowNotChecked = b +} + +// GetRewritten returns whether the rewriter has rewritten the file in a RewriteFile call. +func (r *Rewriter) GetRewritten() bool { + return r.rewritten +} + +// GetCurrentFile returns the current file which is being rewritten +func (r *Rewriter) GetCurrentFile() *ast.File { + return r.currentFile +} + func (r *Rewriter) pos(pos token.Pos) string { p := r.currsetFset.Position(pos) return fmt.Sprintf("%s:%d", p.Filename, p.Line) @@ -603,6 +619,9 @@ func (r *Rewriter) RewriteFile(path string) (err error) { } } if failpointImport == nil { + if r.allowNotChecked { + return nil + } panic("import path should be check before rewrite") } if failpointImport.Name != nil { diff --git a/failpoint-toolexec/main.go b/failpoint-toolexec/main.go new file mode 100644 index 0000000..5b2e80b --- /dev/null +++ b/failpoint-toolexec/main.go @@ -0,0 +1,190 @@ +// Copyright 2024 PingCAP, Inc. +// +// 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 main + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + + "github.com/pingcap/errors" + "github.com/pingcap/failpoint/code" + "golang.org/x/mod/modfile" +) + +var logger = log.New(os.Stderr, "[failpoint-toolexec]", log.LstdFlags) + +func main() { + if len(os.Args) < 2 { + return + } + goCmd, buildArgs := os.Args[1], os.Args[2:] + goCmdBase := filepath.Base(goCmd) + if runtime.GOOS == "windows" { + goCmdBase = strings.TrimSuffix(goCmd, ".exe") + } + + if strings.ToLower(goCmdBase) == "compile" { + if err := injectFailpoint(&buildArgs); err != nil { + logger.Println("failed to inject failpoint", err) + } + } + + cmd := exec.Command(goCmd, buildArgs...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + if err := cmd.Run(); err != nil { + logger.Println("failed to run command", err) + } +} + +func injectFailpoint(argsP *[]string) error { + callersModule, err := findCallersModule() + if err != nil { + return err + } + + // ref https://pkg.go.dev/cmd/compile#hdr-Command_Line + var module string + args := *argsP + for i, arg := range args { + if arg == "-p" { + if i+1 < len(args) { + module = args[i+1] + } + break + } + } + if !strings.HasPrefix(module, callersModule) && module != "main" { + return nil + } + + fileIndices := make([]int, 0, len(args)) + for i, arg := range args { + // find the golang source files of the caller's package + if strings.HasSuffix(arg, ".go") && !inSDKOrMod(arg) { + fileIndices = append(fileIndices, i) + } + } + + needExtraFile := false + writer := &code.Rewriter{} + writer.SetAllowNotChecked(true) + for _, idx := range fileIndices { + needExtraFile = needExtraFile || injectFailpointForFile(writer, &args[idx], module) + } + if needExtraFile { + newFile := filepath.Join(tmpFolder, module, "failpoint_toolexec_extra.go") + if err := writeExtraFile(newFile, writer.GetCurrentFile().Name.Name, module); err != nil { + return err + } + *argsP = append(args, newFile) + } + return nil +} + +// ref https://github.com/golang/go/blob/bdd27c4debfb51fe42df0c0532c1c747777b7a32/src/cmd/go/internal/modload/init.go#L1511 +func findCallersModule() (string, error) { + cwd, err := os.Getwd() + if err != nil { + return "", err + } + dir := filepath.Clean(cwd) + + // Look for enclosing go.mod. + for { + goModPath := filepath.Join(dir, "go.mod") + if fi, err := os.Stat(goModPath); err == nil && !fi.IsDir() { + data, err := os.ReadFile(goModPath) + if err != nil { + return "", err + } + f, err := modfile.ParseLax(goModPath, data, nil) + if err != nil { + return "", err + } + return f.Module.Mod.Path, err + } + d := filepath.Dir(dir) + if d == dir { + break + } + dir = d + } + return "", errors.New("go.mod file not found") +} + +var goModCache = os.Getenv("GOMODCACHE") +var goRoot = runtime.GOROOT() + +func inSDKOrMod(path string) bool { + absPath, err := filepath.Abs(path) + if err != nil { + logger.Println("failed to get absolute path", err) + return false + } + + if goModCache != "" && strings.HasPrefix(absPath, goModCache) { + return true + } + if strings.HasPrefix(absPath, goRoot) { + return true + } + return false +} + +var tmpFolder = filepath.Join(os.TempDir(), "failpoint-toolexec") + +func injectFailpointForFile(w *code.Rewriter, file *string, module string) bool { + newFile := filepath.Join(tmpFolder, module, filepath.Base(*file)) + newFileDir := filepath.Dir(newFile) + if err := os.MkdirAll(newFileDir, 0700); err != nil { + logger.Println("failed to create temp folder", err) + return false + } + f, err := os.OpenFile(newFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + if err != nil { + logger.Println("failed to open temp file", err) + return false + } + defer f.Close() + w.SetOutput(f) + + if err := w.RewriteFile(*file); err != nil { + logger.Println("failed to rewrite file", err) + return false + } + if !w.GetRewritten() { + return false + } + *file = newFile + return true +} + +func writeExtraFile(filePath, packageName, module string) error { + bindingContent := fmt.Sprintf(` +package %s + +func %s(name string) string { + return "%s/" + name +} +`, packageName, code.ExtendPkgName, module) + return os.WriteFile(filePath, []byte(bindingContent), 0644) +} diff --git a/go.mod b/go.mod index e3efaa4..0b4a5e0 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/sergi/go-diff v1.1.0 github.com/stretchr/testify v1.7.0 go.uber.org/goleak v1.1.10 + golang.org/x/mod v0.17.0 ) go 1.13 diff --git a/go.sum b/go.sum index 63b4841..b011b34 100644 --- a/go.sum +++ b/go.sum @@ -18,19 +18,59 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 h1:Yq9t9jnGoR+dBuitxdo9l6Q7xh/zOyNnYUtDKaQ3x0E= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/marker.go b/marker.go index dc6921d..640a7cb 100644 --- a/marker.go +++ b/marker.go @@ -36,26 +36,30 @@ func InjectContext(ctx context.Context, fpname string, fpbody interface{}) {} // Break will generate a break statement in a loop, e.g: // case1: -// for i := 0; i < max; i++ { -// failpoint.Inject("break-if-index-equal-2", func() { -// if i == 2 { -// failpoint.Break() -// } -// } -// } +// +// for i := 0; i < max; i++ { +// failpoint.Inject("break-if-index-equal-2", func() { +// if i == 2 { +// failpoint.Break() +// } +// } +// } +// // failpoint.Break() => break // // case2: -// outer: -// for i := 0; i < max; i++ { -// for j := 0; j < max / 2; j++ { -// failpoint.Inject("break-if-index-i-equal-j", func() { -// if i == j { -// failpoint.Break("outer") -// } -// } -// } -// } +// +// outer: +// for i := 0; i < max; i++ { +// for j := 0; j < max / 2; j++ { +// failpoint.Inject("break-if-index-i-equal-j", func() { +// if i == j { +// failpoint.Break("outer") +// } +// } +// } +// } +// // failpoint.Break("outer") => break outer func Break(label ...string) {} @@ -73,16 +77,18 @@ func Return(result ...interface{}) {} // Label will generate a label statement, e.g. // case1: -// failpoint.Label("outer") -// for i := 0; i < max; i++ { -// for j := 0; j < max / 2; j++ { -// failpoint.Inject("break-if-index-i-equal-j", func() { -// if i == j { -// failpoint.Break("outer") -// } -// } -// } -// } +// +// failpoint.Label("outer") +// for i := 0; i < max; i++ { +// for j := 0; j < max / 2; j++ { +// failpoint.Inject("break-if-index-i-equal-j", func() { +// if i == j { +// failpoint.Break("outer") +// } +// } +// } +// } +// // failpoint.Label("outer") => outer: // failpoint.Break("outer") => break outer func Label(label string) {}