func addInput(inp RpcInput) { corpusMu.Lock() defer corpusMu.Unlock() coverMu.Lock() defer coverMu.Unlock() if noCover { panic("should not be called when coverage is disabled") } p, err := prog.Deserialize(inp.Prog) if err != nil { panic(err) } if inp.CallIndex < 0 || inp.CallIndex >= len(p.Calls) { panic("bad call index") } call := p.Calls[inp.CallIndex].Meta sig := hash(inp.Prog) if _, ok := corpusHashes[sig]; ok { return } cov := cover.Canonicalize(inp.Cover) diff := cover.Difference(cov, maxCover[call.CallID]) diff = cover.Difference(diff, flakes) if len(diff) == 0 { return } corpus = append(corpus, p) corpusCover[call.CallID] = cover.Union(corpusCover[call.CallID], cov) maxCover[call.CallID] = cover.Union(maxCover[call.CallID], cov) corpusHashes[hash(inp.Prog)] = struct{}{} }
func addInput(inp RpcInput) { p, err := prog.Deserialize(inp.Prog) if err != nil { panic(err) } if inp.CallIndex < 0 || inp.CallIndex >= len(p.Calls) { panic("bad call index") } call := p.Calls[inp.CallIndex].Meta sig := hash(inp.Prog) if _, ok := corpusHashes[sig]; ok { return } cov := cover.Canonicalize(inp.Cover) diff := cover.Difference(cov, maxCover[call.CallID]) diff = cover.Difference(diff, flakes) if len(diff) == 0 { return } inp1 := Input{p, inp.CallIndex, cov} corpus = append(corpus, inp1) corpusCover[call.CallID] = cover.Union(corpusCover[call.CallID], cov) maxCover[call.CallID] = cover.Union(maxCover[call.CallID], cov) corpusHashes[hash(inp.Prog)] = struct{}{} }
func (mgr *Manager) uniqueCover(perCall bool) cover.Cover { totalCover := make(map[uint32]int) callCover := make(map[string]map[uint32]bool) for _, inp := range mgr.corpus { if perCall && callCover[inp.Call] == nil { callCover[inp.Call] = make(map[uint32]bool) } for _, pc := range inp.Cover { if perCall { if callCover[inp.Call][pc] { continue } callCover[inp.Call][pc] = true } totalCover[pc]++ } } var cov cover.Cover for pc, count := range totalCover { if count == 1 { cov = append(cov, pc) } } cover.Canonicalize(cov) return cov }