Class Coverage

java.lang.Object
edu.berkeley.cs.jqf.fuzz.util.Coverage
All Implemented Interfaces:
ICoverage<Counter>, TraceEventVisitor

public class Coverage extends Object implements TraceEventVisitor, ICoverage<Counter>
Utility class to collect branch and function coverage
Author:
Rohan Padhye
  • Constructor Details

    • Coverage

      public Coverage()
      Creates a new coverage map.
  • Method Details

    • copy

      public Coverage copy()
      Creates a copy of an this coverage map.
      Specified by:
      copy in interface ICoverage<Counter>
    • size

      public int size()
      Returns the size of the coverage map.
      Specified by:
      size in interface ICoverage<Counter>
      Returns:
      the size of the coverage map
    • handleEvent

      public void handleEvent(TraceEvent e)
      Updates coverage information based on emitted event.

      This method updates its internal counters for branch and call events.

      Parameters:
      e - the event to be processed
    • visitBranchEvent

      public void visitBranchEvent(BranchEvent b)
      Specified by:
      visitBranchEvent in interface TraceEventVisitor
    • visitCallEvent

      public void visitCallEvent(CallEvent e)
      Specified by:
      visitCallEvent in interface TraceEventVisitor
    • getNonZeroCount

      public int getNonZeroCount()
      Returns the number of edges covered.
      Specified by:
      getNonZeroCount in interface ICoverage<Counter>
      Returns:
      the number of edges with non-zero counts
    • getCovered

      public org.eclipse.collections.api.list.primitive.IntList getCovered()
      Returns a collection of branches that are covered.
      Specified by:
      getCovered in interface ICoverage<Counter>
      Returns:
      a collection of keys that are covered
    • computeNewCoverage

      public org.eclipse.collections.api.list.primitive.IntList computeNewCoverage(ICoverage baseline)
      Returns a set of edges in this coverage that don't exist in baseline
      Specified by:
      computeNewCoverage in interface ICoverage<Counter>
      Parameters:
      baseline - the baseline coverage
      Returns:
      the set of edges that do not exist in baseline
    • clear

      public void clear()
      Clears the coverage map.
      Specified by:
      clear in interface ICoverage<Counter>
    • updateBits

      public boolean updateBits(ICoverage that)
      Updates this coverage with bits from the parameter.
      Specified by:
      updateBits in interface ICoverage<Counter>
      Parameters:
      that - the run coverage whose bits to OR
      Returns:
      true iff that is not a subset of this, causing this to change.
    • hashCode

      public int hashCode()
      Returns a hash code of the edge counts in the coverage map.
      Overrides:
      hashCode in class Object
    • nonZeroHashCode

      public int nonZeroHashCode()
      Returns a hash code of the list of edges that have been covered at least once.
      Specified by:
      nonZeroHashCode in interface ICoverage<Counter>
      Returns:
      a hash of non-zero entries
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representing the counter
    • getCounter

      public Counter getCounter()
      Specified by:
      getCounter in interface ICoverage<Counter>