| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build (darwin || linux || windows || freebsd) && (amd64 || arm64) |
| 6 |
|
| 7 |
package fuzz |
| 8 |
|
| 9 |
import ( |
| 10 |
"internal/unsafeheader" |
| 11 |
"unsafe" |
| 12 |
) |
| 13 |
|
| 14 |
// coverage returns a []byte containing unique 8-bit counters for each edge of |
| 15 |
// the instrumented source code. This coverage data will only be generated if |
| 16 |
// `-d=libfuzzer` is set at build time. This can be used to understand the code |
| 17 |
// coverage of a test execution. |
| 18 |
func coverage() []byte { |
| 19 |
addr := unsafe.Pointer(&_counters) |
| 20 |
size := uintptr(unsafe.Pointer(&_ecounters)) - uintptr(addr) |
| 21 |
|
| 22 |
var res []byte |
| 23 |
*(*unsafeheader.Slice)(unsafe.Pointer(&res)) = unsafeheader.Slice{ |
| 24 |
Data: addr, |
| 25 |
Len: int(size), |
| 26 |
Cap: int(size), |
| 27 |
} |
| 28 |
return res |
| 29 |
} |