gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/secfuzz/secfuzz_nocoverageguidance.go (about)

     1  // Copyright 2023 The gVisor Authors.
     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  //go:build !fuzz
    16  // +build !fuzz
    17  
    18  package secfuzz
    19  
    20  import (
    21  	"gvisor.dev/gvisor/pkg/bpf"
    22  )
    23  
    24  // Go does coverage-based fuzzing, so it discovers inputs that are
    25  // "interesting" if they manage to cover new code.
    26  // Go does not understand "BPF coverage", and there is no easy way to
    27  // tell it that a certain BPF input has covered new lines of code.
    28  // For this reason, this package has an auto-generated
    29  // "secfuzz_covermeup.go" file which translates BPF code coverage into
    30  // Go code coverage. However, it is huge and takes a long time to compile.
    31  // For this reason, the file you're reading now acts as a stand-in for
    32  // it which does not give the Go fuzzer any coverage-guidance.
    33  // This is useful for fast builds and fuzz tests that don't need
    34  // coverage-based guidance.
    35  
    36  // countExecutedLinesProgram1 converts coverage data of the first BPF
    37  // program to Go coverage data.
    38  func countExecutedLinesProgram1(execution bpf.ExecutionMetrics, fuzzee *Fuzzee) {
    39  	for i, covered := range execution.Coverage {
    40  		if covered {
    41  			fuzzee.coverage[i].Store(true)
    42  		}
    43  	}
    44  }
    45  
    46  // countExecutedLinesProgram2 converts coverage data of the second BPF
    47  // program to Go coverage data.
    48  func countExecutedLinesProgram2(execution bpf.ExecutionMetrics, fuzzee *Fuzzee) {
    49  	for i, covered := range execution.Coverage {
    50  		if covered {
    51  			fuzzee.coverage[i].Store(true)
    52  		}
    53  	}
    54  }