| 1 |
//go:build !no_antithesis_sdk |
| 2 |
|
| 3 |
package instrumentation |
| 4 |
|
| 5 |
import ( |
| 6 |
"github.com/antithesishq/antithesis-sdk-go/internal" |
| 7 |
) |
| 8 |
|
| 9 |
// A Module is one independently instrumented unit of coverage, registered with |
| 10 |
// its own symbol table and its own edge space. |
| 11 |
type Module struct { |
| 12 |
// offset is what init_coverage_module() returned: the value that must be |
| 13 |
// added to this module's edge ids before they are passed to notify_coverage(). |
| 14 |
offset uint64 |
| 15 |
|
| 16 |
// leases caches one coverage-lease word per edge, letting repeat hits be |
| 17 |
// counted locally without calling into the library; see notifyEdge. It is |
| 18 |
// nil when the loaded library predates leases. |
| 19 |
// |
| 20 |
// Each module holds its own leases because each has its own edge space, |
| 21 |
// numbered from 1. The revocation epoch they are validated against is |
| 22 |
// process-wide, so one revocation still voids every module's leases at once. |
| 23 |
leases []uint64 |
| 24 |
} |
| 25 |
|
| 26 |
// RegisterModule registers symbolTable as a new coverage module holding |
| 27 |
// edgeCount edges, and returns a handle for reporting them. |
| 28 |
func RegisterModule(symbolTable string, edgeCount int) *Module { |
| 29 |
// WARN Re: integer type conversion, see https://github.com/golang/go/issues/29878 |
| 30 |
return &Module{ |
| 31 |
offset: internal.InitCoverage(uint64(edgeCount), symbolTable), |
| 32 |
leases: newLeaseCache(edgeCount), |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// Notify reports that edge was reached. edge is relative to this module and |
| 37 |
// 0 <= edge <= edgeCount. Repeat hits are absorbed by this module's coverage |
| 38 |
// leases |
| 39 |
func (m *Module) Notify(edge int) { |
| 40 |
notifyEdge(edge, m.offset, m.leases) |
| 41 |
} |