github.com/pingcap/failpoint@v0.0.0-20240412033321-fd0796e60f86/marker.go (about)

     1  // Copyright 2019 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package failpoint
    16  
    17  import "context"
    18  
    19  // Inject marks a fail point routine, which will be rewrite to a `if` statement
    20  // and be triggered by fail point name specified `fpname`
    21  // Note: The fail point closure  parameter type can only be `failpoint.Value`
    22  // e.g:
    23  // failpoint.Inject("fail-point-name", func() (...){}
    24  // failpoint.Inject("fail-point-name", func(val failpoint.Value) (...){}
    25  // failpoint.Inject("fail-point-name", func(_ failpoint.Value) (...){}
    26  func Inject(fpname string, fpbody interface{}) {}
    27  
    28  // InjectContext marks a fail point routine, which will be rewrite to a `if` statement
    29  // and be triggered by fail point name specified `fpname`
    30  // Note: The fail point closure  parameter type can only be `failpoint.Value`
    31  // e.g:
    32  // failpoint.InjectContext(ctx, "fail-point-name", func() (...){}
    33  // failpoint.InjectContext(ctx, "fail-point-name", func(val failpoint.Value) (...){}
    34  // failpoint.InjectContext(ctx, "fail-point-name", func(_ failpoint.Value) (...){}
    35  func InjectContext(ctx context.Context, fpname string, fpbody interface{}) {}
    36  
    37  // Break will generate a break statement in a loop, e.g:
    38  // case1:
    39  //
    40  //	for i := 0; i < max; i++ {
    41  //	    failpoint.Inject("break-if-index-equal-2", func() {
    42  //	        if i == 2 {
    43  //	            failpoint.Break()
    44  //	        }
    45  //	    }
    46  //	}
    47  //
    48  // failpoint.Break() => break
    49  //
    50  // case2:
    51  //
    52  //	outer:
    53  //	for i := 0; i < max; i++ {
    54  //	    for j := 0; j < max / 2; j++ {
    55  //	        failpoint.Inject("break-if-index-i-equal-j", func() {
    56  //	            if i == j {
    57  //	                failpoint.Break("outer")
    58  //	            }
    59  //	        }
    60  //	    }
    61  //	}
    62  //
    63  // failpoint.Break("outer") => break outer
    64  func Break(label ...string) {}
    65  
    66  // Goto will generate a goto statement the same as `failpoint.Break()`
    67  func Goto(label string) {}
    68  
    69  // Continue will generate a continue statement the same as `failpoint.Break()`
    70  func Continue(label ...string) {}
    71  
    72  // Fallthrough will translate to a `fallthrough` statement
    73  func Fallthrough() {}
    74  
    75  // Return will translate to a `return` statement
    76  func Return(result ...interface{}) {}
    77  
    78  // Label will generate a label statement, e.g.
    79  // case1:
    80  //
    81  //	failpoint.Label("outer")
    82  //	for i := 0; i < max; i++ {
    83  //	    for j := 0; j < max / 2; j++ {
    84  //	        failpoint.Inject("break-if-index-i-equal-j", func() {
    85  //	            if i == j {
    86  //	                failpoint.Break("outer")
    87  //	            }
    88  //	        }
    89  //	    }
    90  //	}
    91  //
    92  // failpoint.Label("outer") => outer:
    93  // failpoint.Break("outer") => break outer
    94  func Label(label string) {}