coverage

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveCoverageTracerResults

func RemoveCoverageTracerResults(messageResults *types.MessageResults)

RemoveCoverageTracerResults removes CoverageMaps stored by a CoverageTracer from message results.

func WriteHTMLReport added in v0.1.7

func WriteHTMLReport(sourceAnalysis *SourceAnalysis, reportDir string) (string, error)

WriteHTMLReport takes a previously performed source analysis and generates an HTML coverage report from it.

func WriteLCOVReport added in v0.1.7

func WriteLCOVReport(sourceAnalysis *SourceAnalysis, reportDir string) (string, error)

WriteLCOVReport takes a previously performed source analysis and generates an LCOV report from it.

Types

type ContractCoverageMap added in v0.1.1

type ContractCoverageMap struct {
	// contains filtered or unexported fields
}

ContractCoverageMap represents a data structure used to identify instruction execution coverage of a contract.

func (*ContractCoverageMap) Equal added in v0.1.1

Equal checks whether the provided ContractCoverageMap contains the same data as the current one. Returns a boolean indicating whether the two maps match.

type CoverageMapBytecodeData added in v0.1.1

type CoverageMapBytecodeData struct {
	// contains filtered or unexported fields
}

CoverageMapBytecodeData represents a data structure used to identify instruction execution coverage of some init or runtime bytecode.

func (*CoverageMapBytecodeData) Equal added in v0.1.1

Equal checks whether the provided CoverageMapBytecodeData contains the same data as the current one. Returns a boolean indicating whether the two maps match.

func (*CoverageMapBytecodeData) HitCount added in v0.1.7

func (cm *CoverageMapBytecodeData) HitCount(pc int) uint

HitCount returns the number of times that the provided program counter (PC) has been hit. If zero is returned, then the PC has not been hit, the map is empty, or the PC is out-of-bounds

func (*CoverageMapBytecodeData) Reset added in v0.1.1

func (cm *CoverageMapBytecodeData) Reset()

Reset resets the bytecode coverage map data to be empty.

type CoverageMaps

type CoverageMaps struct {
	// contains filtered or unexported fields
}

CoverageMaps represents a data structure used to identify instruction execution coverage of various smart contracts across a transaction or multiple transactions.

func GetCoverageTracerResults

func GetCoverageTracerResults(messageResults *types.MessageResults) *CoverageMaps

GetCoverageTracerResults obtains CoverageMaps stored by a CoverageTracer from message results. This is nil if no CoverageMaps were recorded by a tracer (e.g. CoverageTracer was not attached during this message execution).

func NewCoverageMaps

func NewCoverageMaps() *CoverageMaps

NewCoverageMaps initializes a new CoverageMaps object.

func (*CoverageMaps) Equal added in v0.1.1

func (cm *CoverageMaps) Equal(b *CoverageMaps) bool

Equal checks whether two coverage maps are the same. Equality is determined if the keys and values are all the same.

func (*CoverageMaps) GetContractCoverageMap added in v0.1.1

func (cm *CoverageMaps) GetContractCoverageMap(bytecode []byte, init bool) (*ContractCoverageMap, error)

GetContractCoverageMap obtains a total coverage map representing coverage for the provided bytecode. If the provided bytecode could not find coverage maps, nil is returned. Returns the total coverage map, or an error if one occurs.

func (*CoverageMaps) Reset

func (cm *CoverageMaps) Reset()

Reset clears the coverage state for the CoverageMaps.

func (*CoverageMaps) RevertAll added in v0.1.1

func (cm *CoverageMaps) RevertAll() (bool, error)

RevertAll sets all coverage in the coverage map as reverted coverage. Reverted coverage is updated with successful coverage, the successful coverage is cleared. Returns a boolean indicating whether reverted coverage increased, and an error if one occurred.

func (*CoverageMaps) UniquePCs added in v0.1.7

func (cm *CoverageMaps) UniquePCs() uint64

UniquePCs is a function that returns the total number of unique program counters (PCs)

func (*CoverageMaps) Update

func (cm *CoverageMaps) Update(coverageMaps *CoverageMaps) (bool, bool, error)

Update updates the current coverage maps with the provided ones. Returns two booleans indicating whether successful or reverted coverage changed, or an error if one occurred.

func (*CoverageMaps) UpdateAt added in v0.1.7

func (cm *CoverageMaps) UpdateAt(codeAddress common.Address, codeLookupHash common.Hash, codeSize int, pc uint64) (bool, error)

UpdateAt updates the hit count of a given program counter location within code coverage data.

type CoverageTracer

type CoverageTracer struct {
	// contains filtered or unexported fields
}

CoverageTracer implements tracers.Tracer to collect information such as coverage maps for fuzzing campaigns from EVM execution traces.

func NewCoverageTracer

func NewCoverageTracer() *CoverageTracer

NewCoverageTracer returns a new CoverageTracer.

func (*CoverageTracer) CaptureTxEndSetAdditionalResults

func (t *CoverageTracer) CaptureTxEndSetAdditionalResults(results *types.MessageResults)

CaptureTxEndSetAdditionalResults can be used to set additional results captured from execution tracing. If this tracer is used during transaction execution (block creation), the results can later be queried from the block. This method will only be called on the added tracer if it implements the extended TestChainTracer interface.

func (*CoverageTracer) NativeTracer added in v0.1.4

func (t *CoverageTracer) NativeTracer() *chain.TestChainTracer

NativeTracer returns the underlying TestChainTracer.

func (*CoverageTracer) OnEnter added in v0.1.4

func (t *CoverageTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)

OnEnter initializes the tracing operation for the top of a call frame, as defined by tracers.Tracer.

func (*CoverageTracer) OnExit added in v0.1.4

func (t *CoverageTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool)

OnExit is called after a call to finalize tracing completes for the top of a call frame, as defined by tracers.Tracer.

func (*CoverageTracer) OnOpcode added in v0.1.4

func (t *CoverageTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error)

OnOpcode records data from an EVM state update, as defined by tracers.Tracer.

func (*CoverageTracer) OnTxStart added in v0.1.4

func (t *CoverageTracer) OnTxStart(vm *tracing.VMContext, tx *coretypes.Transaction, from common.Address)

OnTxStart is called upon the start of transaction execution, as defined by tracers.Tracer.

type SourceAnalysis added in v0.1.1

type SourceAnalysis struct {
	// Files describes the analysis results for a given source file path.
	Files map[string]*SourceFileAnalysis
}

SourceAnalysis describes source code coverage across a list of compilations, after analyzing associated CoverageMaps.

func AnalyzeSourceCoverage added in v0.1.1

func AnalyzeSourceCoverage(compilations []types.Compilation, coverageMaps *CoverageMaps) (*SourceAnalysis, error)

AnalyzeSourceCoverage takes a list of compilations and a set of coverage maps, and performs source analysis to determine source coverage information. Returns a SourceAnalysis object, or an error if one occurs.

func (*SourceAnalysis) ActiveLineCount added in v0.1.1

func (s *SourceAnalysis) ActiveLineCount() int

ActiveLineCount returns the count of lines that are marked executable/active across all source files.

func (*SourceAnalysis) CoveredLineCount added in v0.1.1

func (s *SourceAnalysis) CoveredLineCount() int

CoveredLineCount returns the count of lines that were covered across all source files.

func (*SourceAnalysis) GenerateLCOVReport added in v0.1.7

func (s *SourceAnalysis) GenerateLCOVReport() string

GenerateLCOVReport generates an LCOV report from the source analysis. The spec of the format is here https://github.com/linux-test-project/lcov/blob/07a1127c2b4390abf4a516e9763fb28a956a9ce4/man/geninfo.1#L989

func (*SourceAnalysis) LineCount added in v0.1.1

func (s *SourceAnalysis) LineCount() int

LineCount returns the count of lines across all source files.

func (*SourceAnalysis) SortedFiles added in v0.1.1

func (s *SourceAnalysis) SortedFiles() []*SourceFileAnalysis

SortedFiles returns a list of Files within the SourceAnalysis, sorted by source file path in alphabetical order.

type SourceFileAnalysis added in v0.1.1

type SourceFileAnalysis struct {
	// Path describes the file path of the source file. This is kept here for access during report generation.
	Path string

	// CumulativeOffsetByLine describes the cumulative byte offset for each line in the source file.
	// For example, for a file with 5 lines, the list might look like: [0, 45, 98, 132, 189], where each number is the byte offset of the line's starting position
	// This allows us to quickly determine which line a given byte offset falls within using a binary search.
	CumulativeOffsetByLine []int

	// Lines describes information about a given source line and its coverage.
	Lines []*SourceLineAnalysis

	// Functions is a list of functions defined in the source file
	Functions []*types.FunctionDefinition
}

SourceFileAnalysis describes coverage information for a given source file.

func (*SourceFileAnalysis) ActiveLineCount added in v0.1.1

func (s *SourceFileAnalysis) ActiveLineCount() int

ActiveLineCount returns the count of lines that are marked executable/active within the source file.

func (*SourceFileAnalysis) CoveredLineCount added in v0.1.1

func (s *SourceFileAnalysis) CoveredLineCount() int

CoveredLineCount returns the count of lines that were covered within the source file.

type SourceLineAnalysis added in v0.1.1

type SourceLineAnalysis struct {
	// IsActive indicates the given source line was executable.
	IsActive bool

	// Start describes the starting byte offset of the line in its parent source file.
	Start int

	// End describes the ending byte offset of the line in its parent source file.
	End int

	// Contents describe the bytes associated with the given source line.
	Contents []byte

	// IsCovered indicates whether the source line has been executed without reverting.
	IsCovered bool

	// SuccessHitCount describes how many times this line was executed successfully
	SuccessHitCount uint

	// RevertHitCount describes how many times this line reverted during execution
	RevertHitCount uint

	// IsCoveredReverted indicates whether the source line has been executed before reverting.
	IsCoveredReverted bool
}

SourceLineAnalysis describes coverage information for a specific source file line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL