"""
This script reads data recorded by winIDEA coverage and prints it to stdout.
It demonstrates usage of class CCoverageData2 and related classes.
"""
from __future__ import print_function
import sys
import isystem.connect as ic
def printFuncAsmNodes(stat, indent):
numAsmLines = stat.getNumAsmLines()
for idx in range(numAsmLines):
asmLine = stat.getAsmLine(idx)
print(indent, 'Asm:')
print(indent, ' lineType:', asmLine.getLineType())
print(indent, ' coverageMarker:', asmLine.getCoverageMarker())
print(indent, ' address:', asmLine.getAddress())
print(indent, ' lineText:', asmLine.getLineText())
print(indent, ' lineNumber:', asmLine.getLineNumber())
print(indent, ' moduleName:', asmLine.getModuleName())
def printStatisticForArea(stat, isPrintSourceLinesInModule=False, indent=2):
if stat is None:
print('ERROR: no statistic to print!')
return
sp = ' ' * indent
print(sp, 'Statistic:')
print(sp, ' areaType: ', ic.CCoverageStatistic2.areaType2Str(stat.getAreaType()))
print(sp, ' areaName: ', stat.getAreaName())
if stat.getParent() is not None:
print(sp, ' parentName: ', stat.getParent().getAreaName())
print(sp, ' linesInArea: ', stat.getLinesAll())
print(sp, ' lines executed/not exec.: ', stat.getLinesExecuted(), ' / ',
stat.getLinesAll() - stat.getLinesExecuted())
print(sp, ' bytesInArea: ', stat.getBytesAll())
print(sp, ' bytes executed/not exec.: ', stat.getBytesExecuted(), ' / ',
stat.getBytesAll() - stat.getBytesExecuted())
print(sp, ' conditionsInArea: ', stat.getConditionsAll())
print(sp, ' conditions true: ', stat.getConditionsTrue())
print(sp, ' conditions false: ', stat.getConditionsFalse())
print(sp, ' conditions both: ', stat.getConditionsBoth())
print(sp, ' execution count: ', stat.getExecutionCount())
printFuncAsmNodes(stat, sp + ' ')
print(sp, ' number of children: ', stat.getNumChildren())
if (stat.getAreaType() == ic.CCoverageStatistic2.EFolder or
stat.getAreaType() == ic.CCoverageStatistic2.EModule):
print(sp, ' abs. path: ', stat.getTextOrAbsPath())
print(sp, ' rel. path: ', stat.getRelPath())
if stat.getAreaType() == ic.CCoverageStatistic2.ESrcLine:
print(sp, ' source line number: ', stat.getLineNumber())
print(sp, ' source text: ', stat.getTextOrAbsPath())
if (stat.getAreaType() == ic.CCoverageStatistic2.EModule and
isPrintSourceLinesInModule):
numSrcLines = stat.getNumSourceLines()
print(sp, ' No. of source lines: ', numSrcLines, ':')
for i in range(numSrcLines):
srcLineInfo = stat.getSourceLineInfo(i)
print(sp, ' - source text: ', srcLineInfo.getSourceLineText())
print(sp, ' source line number: ', srcLineInfo.getSourceLineNumber())
print(sp, ' coverage marker: ', srcLineInfo.getCoverageMarker())
numAsmOpCodes = srcLineInfo.getNumAsmOpCodes()
print(sp, ' Assembler Op Codes: ', numAsmOpCodes, ':')
for j in range(numAsmOpCodes):
asmOpCodeInfo = srcLineInfo.getAsmOpCodeInfo(j)
print(sp, ' - source text: ', asmOpCodeInfo.getSourceLineText())
print(sp, ' coverage marker: ', asmOpCodeInfo.getCoverageMarker())
print(sp, ' address: ', asmOpCodeInfo.getAddress())
def printCoverageInfo2(info):
print(' Coverage meta information:')
print(' tester name: ', info.getName())
print(' id: ', info.getId())
print(' date: ', info.getDate())
print(' time: ', info.getTime())
print(' software: ', info.getSoftware())
print(' hardware: ', info.getHardware())
print(' description: ', info.getDescription())
print(' comment: ', info.getComment())
def iterateStatistic(coverageData, areaType):
"""
This method demonstrates iteration on tree of statistic nodes.
"""
it = coverageData.getIterator(areaType)
while it.hasNext():
printStatisticForArea(it.next())
def iterateStatisticChildren(statistic):
"""
This method demonstrates walking tree of statistic nodes. It can be used
only when complete file has been parsed into memory.
"""
printStatisticForArea(statistic)
numChildren = statistic.getNumChildren()
for idx in range(numChildren):
printStatisticForArea(statistic.getChild(idx))
def iterateStatisticRecursively(statistic, indent=2):
"""
This method demonstrates walking tree of statistic nodes. It can be used
only when complete file has been parsed into memory.
"""
printStatisticForArea(statistic, indent = indent)
numChildren = statistic.getNumChildren()
for idx in range(numChildren):
childStat = statistic.getChild(idx)
iterateStatisticRecursively(childStat, indent + 2)
def printCoverageInfo():
print('In-memory coverage data parser')
print('==============================\n')
coverageData = ic.CCoverageData2.createInstance('../../targetProjects/coverageSample-1.xml',
True)
warnings = coverageData.getParserWarnings()
if warnings:
print('WARNING(S): ', warnings)
else:
print('OK, 0 warnings')
coverageData.closeParser()
printCoverageInfo2(coverageData.getCoverageMetaInfo())
print('\n\n ---\nCoverage statistic for complete recording: ')
rootStatistic = coverageData.getRoot()
printStatisticForArea(rootStatistic)
funcName = 'test_fibonacci'
print('\n\n ---\nCoverage statistic for ' + funcName)
func1Stat = coverageData.getStatistic(ic.CCoverageStatistic2.EFunction,
funcName)
printStatisticForArea(func1Stat)
print("\n\n ---\nCoverage statistic for '" + funcName +
"' and it's immediate children.")
iterateStatisticRecursively(func1Stat)
print("\n\n ---\nCoverage statistic for all folders.")
iterateStatistic(coverageData, ic.CCoverageStatistic2.EFolder)
print("\n\n ---\nList of all modules in coverage file.")
iter = coverageData.getIterator(ic.CCoverageStatistic2.EModule)
while iter.hasNext():
stat = iter.next()
print(stat.getAreaName())
def printCoverageInfoWithIterarors():
print('\n\nFile parser')
print('===========\n')
coverageData = ic.CCoverageData2.createInstance('../../targetProjects/coverageSample-1.xml',
False)
printCoverageInfo2(coverageData.getCoverageMetaInfo())
moduleName = 'main.cpp'
print("\n\n ---\nCoverage statistic for '" + moduleName + "' including source lines:")
mainStat = coverageData.getStatistic(ic.CCoverageStatistic2.EModule,
moduleName)
warnings = coverageData.getParserWarnings()
if warnings:
print('WARNING(S): ', warnings)
printStatisticForArea(mainStat, True)
coverageData.closeParser()
coverageData = ic.CCoverageData2.createInstance('../../targetProjects/coverageSample-1.xml',
False)
print('\n\n ---\nCoverage statistic for all functions (percentage of object code executed):')
iter = coverageData.getIterator(ic.CCoverageStatistic2.EFunction)
while iter.hasNext():
stat = iter.next()
print(' ', stat.getAreaName() + ': ' +
str(stat.getBytesExecuted() * 100 / stat.getBytesAll()) + '%')
if __name__ == '__main__':
printCoverageInfo()
printCoverageInfoWithIterarors()