|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sofya.base.Handler sofya.ed.structural.TraceHandler
public class TraceHandler
The trace handler provides routines to manipulate Sofya coverage trace (.tr) files and to create coverage trace objects.
CoverageTrace
,
TraceViewer
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface sofya.base.SConstants |
---|
SConstants.BlockLabel, SConstants.BlockObjectType, SConstants.BlockSubType, SConstants.BlockType, SConstants.BranchObjectType, SConstants.BranchType, SConstants.EDObjectType, SConstants.TraceObjectType |
Field Summary |
---|
Fields inherited from class sofya.base.Handler |
---|
HANDLER_EXTENSIONS, LINE_SEP |
Fields inherited from interface sofya.base.SConstants |
---|
DEFAULT_PORT, INST_COMPATIBLE, INST_OLD_UNSUPPORTED, INST_OPT_NORMAL, INST_OPT_SEQUENCE, SIG_CHKALIVE, SIG_ECHO |
Constructor Summary | |
---|---|
TraceHandler()
Creates a trace handler with no traces yet registered and the structural entity type set to basic blocks. |
|
TraceHandler(int typeFlags)
Creates a trace handler with the specified trace types active and the structural enetity type set to basic blocks. |
|
TraceHandler(int typeFlags,
SConstants.TraceObjectType objectType)
Creates a trace handler with the specified trace types and structural entity type. |
Method Summary | |
---|---|
void |
clear()
Removes all of the method traces. |
void |
commitCoverageResults(int streamId)
Notification that an event stream has completed. |
java.util.List |
configure(java.util.List params)
Configures this component from command line parameters. |
boolean |
containsTrace(java.lang.String methodName)
Reports whether the handler contains a trace for the given method. |
BlockCoverageListener |
getBlockCoverageListener(java.lang.String classAndSignature)
Gets the basic block listener for a particular method. |
BranchCoverageListener |
getBranchCoverageListener(java.lang.String classAndSignature)
Gets the branch listener for a particular method. |
java.lang.String[] |
getMethodList()
Gets the list of methods names for which traces are currently registered with the handler. |
SConstants.TraceObjectType |
getObjectType()
Gets the type code for the trace entities recorded in the traces being managed by the handler. |
CoverageTrace |
getTrace(java.lang.String methodName)
Gets the trace associated with a given method. |
java.lang.String |
getTraceFileName()
Gets the name of the trace file that will be written. |
int |
getTypeFlags()
Gets the bit mask indicating what types of objects are marked by the traces being managed by the handler. |
java.lang.String |
getTypesString()
Gets a string listing the types of objects marked by the traces being managed by the handler. |
void |
initialize()
Initializes the coverage listener manager. |
void |
initializeBlockListener(java.lang.String classAndSignature,
int blockCount)
Notification to initialize a basic block listener for a method. |
void |
initializeBranchListener(java.lang.String classAndSignature,
int branchCount)
Notification to initialize a branch listener for a method. |
boolean |
isAppending()
Reports whether the trace handler will merge any new coverage information into any existing trace file of the same name. |
boolean |
isReady()
Reports whether this component is ready for the event dispatcher to begin dispatching events. |
static void |
main(java.lang.String[] argv)
Provides a function to merge two trace files, if given the argument ' -merge ' with appropriate values. |
void |
mergeTraceFile(java.lang.String fileName)
Merges another trace file with the currently loaded trace file. |
void |
newEventStream(int streamId)
Notification that a new event stream is starting. |
void |
readTraceFile(java.lang.String fileName)
Reads a trace file, making the information available for request from the handler. |
void |
readTraceFile(java.lang.String fileName,
boolean safe)
Reads a trace file, making the information available for request from the handler. |
void |
register(EventDispatcherConfiguration edConfig)
Registers this component with the event dispatcher. |
void |
release()
Notifies this component that its current lifecycle has expired and that it should commit any stored state and release resources. |
void |
reset()
Notifies this component to clear its configuration and reset any internal state. |
void |
setAppending(boolean enable)
Sets whether the trace handler will merge any new coverage information into any existing trace file of the same name. |
void |
setObjectType(SConstants.TraceObjectType type)
Sets the type code for the trace entities recorded in the traces being managed by the handler. |
void |
setTrace(java.lang.String methodName,
CoverageTrace trace)
Sets the trace associated with a given method. |
void |
setTraceFileName(java.lang.String value)
Sets the name of the trace file to be written. |
void |
setTypeFlags(int typeFlags)
Sets the bit mask indicating what types of objects are marked by the traces being managed by the handler. |
protected static java.util.BitSet |
toBinary(java.lang.String hexString)
|
protected static java.lang.String |
toHex(java.util.BitSet bv,
int size)
|
void |
writeTraceFile(java.lang.String fileName,
boolean append)
Writes a trace file to the Sofya database using the trace information currently registered with the handler. |
Methods inherited from class sofya.base.Handler |
---|
copyFile, createCacheFile, disableParseNumbers, ensureTagExists, formatSignature, isIntAvailable, isStringAvailable, newCache, openCacheFile, openInputFile, openInputFile, openOutputFile, openOutputFile, parseClass, prepareTokenizer, readInt, readIntIgnoreEOL, readJarClasses, readNextLine, readProgFile, readString, readStringIgnoreEOL, readToEOL, readToNextDataLine |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TraceHandler()
Note: You must call
setTypeFlags(int)
before attempting
to save a trace file or an IllegalArgumentException will be thrown.
public TraceHandler(int typeFlags)
typeFlags
- Bit mask representing the types of blocks that are
marked in the traces managed by the handler. Can be any bitwise
combination of the following (See SConstants
):
SConstants.BlockType.MASK_BASIC
SConstants.BlockType.MASK_ENTRY
SConstants.BlockType.MASK_EXIT
SConstants.BlockType.MASK_CALL
java.lang.IllegalArgumentException
- If the bit vector doesn't have a bit
set which corresponds to a valid block type.public TraceHandler(int typeFlags, SConstants.TraceObjectType objectType)
typeFlags
- Bit mask representing the types of objects that are
marked in the traces managed by the handler. The meaning of the bits
in the vector is determined by objectType
.objectType
- Code specifying the type of trace entities recorded
by the traces managed by the handler.Method Detail |
---|
public boolean isAppending()
true
if the trace handler will merge current
coverage information with the information contained in any existing
trace file with the same name.public void setAppending(boolean enable)
enable
- true
to instruct the trace handler to
merge current coverage information with the information contained
in any existing trace file with the same name.public java.lang.String getTraceFileName()
public void setTraceFileName(java.lang.String value)
value
- The name of the trace file to be written.public void register(EventDispatcherConfiguration edConfig)
ActiveComponent
Registers this component with the event dispatcher.
This method is called each time an event dispatcher prepares to
initiate a new event stream, caused by a call to
ProgramEventDispatcher.startDispatcher()
.
register
in interface ActiveComponent
edConfig
- The current configuration of system global resources
and settings that the component may (and should) use as appropriate.public java.util.List configure(java.util.List params)
ActiveComponent
Configures this component from command line parameters.
This method provides a component the opportunity to define and process command line parameters required to configure itself. Components participate in a processing chain, initiated in Sofya-provided event dispatchers by calling this method on the processing strategy. The processing strategies provided by Sofya in turn invoke this method on any listeners implementing this interface.
configure
in interface ActiveComponent
params
- A list of command line tokens that have not yet
been processed by any previous components.
public void reset()
ActiveComponent
Notifies this component to clear its configuration and reset any internal state.
Calls to this method are chained similary to the ActiveComponent.configure(java.util.List)
method. This method is invoked by the event dispatcher prior to
reconfiguration. Normally it should be used to clear any configuration
state to avoid using stale values.
reset
in interface ActiveComponent
public boolean isReady()
ActiveComponent
Reports whether this component is ready for the event dispatcher to begin dispatching events.
Calls to this method are chained similarly to the ActiveComponent.configure(java.util.List)
method. The event dispatcher will fail with an error if a client
invokes ProgramEventDispatcher.startDispatcher()
when any
attached component returns false
from this method.
isReady
in interface ActiveComponent
true
if this component is ready for the event
dispatcher to begin dispatching events, false
otherwise.public void release()
ActiveComponent
Notifies this component that its current lifecycle has expired and that it should commit any stored state and release resources.
Calls to this method are chained similary to the ActiveComponent.configure(java.util.List)
method. This method is invoked directly by a client of the event
dispatcher. Normally, it should be used to release any resources that
were required to persist over multiple runs of the event dispatcher.
release
in interface ActiveComponent
public void initialize()
CoverageListenerManager
Initializes the coverage listener manager. Listener managers that need to perform configuration or setup of state that will persist across multiple event streams should implement this method.
This method is called automatically by a
JUnitEventDispatcher
prior to beginning
execution of test cases. It is the responsibility of the applications
using other event dispatchers to call this method at the appropriate
time.
initialize
in interface CoverageListenerManager
public void newEventStream(int streamId)
CoverageListenerManager
Notification that a new event stream is starting.
newEventStream
in interface CoverageListenerManager
streamId
- Identifier associated with the event stream, such as
a test case number.public void commitCoverageResults(int streamId)
CoverageListenerManager
Notification that an event stream has completed.
commitCoverageResults
in interface CoverageListenerManager
streamId
- Identifier associated with the finished event stream,
such as a test case number.public void initializeBlockListener(java.lang.String classAndSignature, int blockCount)
CoverageListenerManager
Notification to initialize a basic block listener for a method.
initializeBlockListener
in interface CoverageListenerManager
classAndSignature
- Concatenation of the fully qualified class
name, method name, and JNI signature of the method for which a basic
block listener is to be initialized.blockCount
- The number of basic blocks in the method.public void initializeBranchListener(java.lang.String classAndSignature, int branchCount)
CoverageListenerManager
Notification to initialize a branch listener for a method.
initializeBranchListener
in interface CoverageListenerManager
classAndSignature
- Concatenation of the fully qualified class
name, method name, and JNI signature of the method for which a branch
listener is to be initialized.branchCount
- The number of basic blocks in the method.public BlockCoverageListener getBlockCoverageListener(java.lang.String classAndSignature)
CoverageListenerManager
Gets the basic block listener for a particular method.
getBlockCoverageListener
in interface CoverageListenerManager
classAndSignature
- Concatenation of the fully qualified class
name, method name, and JNI signature of the method for which a basic
block listener is to be retrieved.public BranchCoverageListener getBranchCoverageListener(java.lang.String classAndSignature)
CoverageListenerManager
Gets the branch listener for a particular method.
getBranchCoverageListener
in interface CoverageListenerManager
classAndSignature
- Concatenation of the fully qualified class
name, method name, and JNI signature of the method for which a branch
listener is to be retrieved.public void writeTraceFile(java.lang.String fileName, boolean append) throws java.io.IOException
fileName
- Name of the trace file to be written, without extension.append
- If true
, data will be appended to the end
of the specified trace file, otherwise the existing contents of the
trace file will be overwritten.
java.io.IOException
- If an error occurs while writing to the trace file.public void readTraceFile(java.lang.String fileName) throws java.io.FileNotFoundException, EmptyFileException, BadFileFormatException, java.io.IOException
getTrace(java.lang.String)
method
can be used to retrieve information loaded by this method.
This method assumes that the trace file must contain information
about the same type of trace objects (basic blocks or branch edges)
that the handler is currently set to operate on (as with
setObjectType(sofya.base.SConstants.TraceObjectType)
).
fileName
- Name of the trace file to be read.
java.io.FileNotFoundException
- If the specified file doesn't exist.
EmptyFileException
- If the specified file contains no data.
BadFileFormatException
- If the specified file is not a .tr
file or is otherwise malformed or corrupted.
java.io.IOException
- If there is an error reading from the .tr file.public void readTraceFile(java.lang.String fileName, boolean safe) throws java.io.FileNotFoundException, EmptyFileException, BadFileFormatException, java.io.IOException
getTrace(java.lang.String)
method
can be used to retrieve information loaded by this method.
fileName
- Name of the trace file to be read.safe
- Specifies whether the contents of the trace file
should correspond to the same type of trace entities that the handler
is currently set to operate on. If true
, a
BadFileFormatException
is thrown if there is a mismatch.
If false
, the trace entity type for the handler will be
changed to object type found in the trace file and the type flags
will be set accordingly.
java.io.FileNotFoundException
- If the specified file doesn't exist.
EmptyFileException
- If the specified file contains no data.
BadFileFormatException
- If the specified file is not a .tr
file or is otherwise malformed or corrupted.
java.io.IOException
- If there is an error reading from the .tr file.public java.lang.String[] getMethodList()
public CoverageTrace getTrace(java.lang.String methodName) throws MethodNotFoundException
methodName
- Name of the method for which the trace is to
be retrieved.
CoverageTrace
associated with
the specified method.
MethodNotFoundException
- If the handler has no trace associated
with a method of the specified name.public void setTrace(java.lang.String methodName, CoverageTrace trace)
If a test history already exists for the specified method, it is overwritten. Otherwise the method and test history are added to the set of methods registered with the handler.
methodName
- Name of the method for which a trace is
being specified.trace
- The test history to be associated with the method.public boolean containsTrace(java.lang.String methodName)
methodName
- Name of the method which the handler should
check for a trace.
true
if a trace is registered for the given
method, false
otherwise.public SConstants.TraceObjectType getObjectType()
public void setObjectType(SConstants.TraceObjectType type)
type
- Code specifying the type of trace entities recorded in the
traces.public void setTypeFlags(int typeFlags)
typeFlags
- Bit mask representing the types of objects marked
by this trace.
java.lang.IllegalArgumentException
- If the bit mask doesn't have a bit
set which corresponds to a valid object type for the current trace
entity type.public int getTypeFlags()
public java.lang.String getTypesString()
public void clear()
public void mergeTraceFile(java.lang.String fileName) throws java.io.FileNotFoundException, EmptyFileException, BadFileFormatException, java.io.IOException
fileName
- Name of the trace file to be merged with the currently
loaded file.
java.io.FileNotFoundException
- If the trace file to be merged with cannot
be found.
EmptyFileException
- If the trace file to be merged with is empty.
BadFileFormatException
- If the trace file to be merged with is
not a .tr file or is otherwise malformed or corrupted.
java.io.IOException
- If any other error I/O occurs while trying to read
the trace file to be merged with.protected static java.lang.String toHex(java.util.BitSet bv, int size)
protected static java.util.BitSet toBinary(java.lang.String hexString)
public static void main(java.lang.String[] argv)
-merge
' with appropriate values.
Simply runs a couple of basic tests if no arguments are supplied.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |