github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/cmerge/merge.go (about) 1 // Copyright 2022 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 package cmerge 6 7 import ( 8 "github.com/shogo82148/std/internal/coverage" 9 ) 10 11 type ModeMergePolicy uint8 12 13 const ( 14 ModeMergeStrict ModeMergePolicy = iota 15 ModeMergeRelaxed 16 ) 17 18 // Merger provides state and methods to help manage the process of 19 // merging together coverage counter data for a given function, for 20 // tools that need to implicitly merge counter as they read multiple 21 // coverage counter data files. 22 type Merger struct { 23 cmode coverage.CounterMode 24 cgran coverage.CounterGranularity 25 policy ModeMergePolicy 26 overflow bool 27 } 28 29 func (cm *Merger) SetModeMergePolicy(policy ModeMergePolicy) 30 31 // MergeCounters takes the counter values in 'src' and merges them 32 // into 'dst' according to the correct counter mode. 33 func (m *Merger) MergeCounters(dst, src []uint32) (error, bool) 34 35 // Saturating add does a saturating addition of 'dst' and 'src', 36 // returning added value or math.MaxUint32 if there is an overflow. 37 // Overflows are recorded in case the client needs to track them. 38 func (m *Merger) SaturatingAdd(dst, src uint32) uint32 39 40 // Saturating add does a saturating addition of 'dst' and 'src', 41 // returning added value or math.MaxUint32 plus an overflow flag. 42 func SaturatingAdd(dst, src uint32) (uint32, bool) 43 44 // SetModeAndGranularity records the counter mode and granularity for 45 // the current merge. In the specific case of merging across coverage 46 // data files from different binaries, where we're combining data from 47 // more than one meta-data file, we need to check for and resolve 48 // mode/granularity clashes. 49 func (cm *Merger) SetModeAndGranularity(mdf string, cmode coverage.CounterMode, cgran coverage.CounterGranularity) error 50 51 func (cm *Merger) ResetModeAndGranularity() 52 53 func (cm *Merger) Mode() coverage.CounterMode 54 55 func (cm *Merger) Granularity() coverage.CounterGranularity