6This script reads data recorded by winIDEA coverage and prints it to stdout.
7It demonstrates usage of class CCoverageData2 and related classes.
10from __future__
import print_function
13import isystem.connect
as ic
16def printFuncAsmNodes(stat, indent):
17 numAsmLines = stat.getNumAsmLines()
18 for idx
in range(numAsmLines):
19 asmLine = stat.getAsmLine(idx)
21 print(indent,
' lineType:', asmLine.getLineType())
22 print(indent,
' coverageMarker:', asmLine.getCoverageMarker())
23 print(indent,
' address:', asmLine.getAddress())
24 print(indent,
' lineText:', asmLine.getLineText())
25 print(indent,
' lineNumber:', asmLine.getLineNumber())
26 print(indent,
' moduleName:', asmLine.getModuleName())
29def printStatisticForArea(stat, isPrintSourceLinesInModule=False, indent=2):
32 print(
'ERROR: no statistic to print!')
36 print(sp,
'Statistic:')
37 print(sp,
' areaType: ', ic.CCoverageStatistic2.areaType2Str(stat.getAreaType()))
38 print(sp,
' areaName: ', stat.getAreaName())
40 if stat.getParent()
is not None:
41 print(sp,
' parentName: ', stat.getParent().getAreaName())
43 print(sp,
' linesInArea: ', stat.getLinesAll())
44 print(sp,
' lines executed/not exec.: ', stat.getLinesExecuted(),
' / ',
45 stat.getLinesAll() - stat.getLinesExecuted())
46 print(sp,
' bytesInArea: ', stat.getBytesAll())
47 print(sp,
' bytes executed/not exec.: ', stat.getBytesExecuted(),
' / ',
48 stat.getBytesAll() - stat.getBytesExecuted())
49 print(sp,
' conditionsInArea: ', stat.getConditionsAll())
50 print(sp,
' conditions true: ', stat.getConditionsTrue())
51 print(sp,
' conditions false: ', stat.getConditionsFalse())
52 print(sp,
' conditions both: ', stat.getConditionsBoth())
53 print(sp,
' execution count: ', stat.getExecutionCount())
54 printFuncAsmNodes(stat, sp +
' ')
56 print(sp,
' number of children: ', stat.getNumChildren())
58 if (stat.getAreaType() == ic.CCoverageStatistic2.EFolder
or
59 stat.getAreaType() == ic.CCoverageStatistic2.EModule):
61 print(sp,
' abs. path: ', stat.getTextOrAbsPath())
62 print(sp,
' rel. path: ', stat.getRelPath())
64 if stat.getAreaType() == ic.CCoverageStatistic2.ESrcLine:
65 print(sp,
' source line number: ', stat.getLineNumber())
66 print(sp,
' source text: ', stat.getTextOrAbsPath())
68 if (stat.getAreaType() == ic.CCoverageStatistic2.EModule
and
69 isPrintSourceLinesInModule):
71 numSrcLines = stat.getNumSourceLines()
72 print(sp,
' No. of source lines: ', numSrcLines,
':')
73 for i
in range(numSrcLines):
74 srcLineInfo = stat.getSourceLineInfo(i)
75 print(sp,
' - source text: ', srcLineInfo.getSourceLineText())
76 print(sp,
' source line number: ', srcLineInfo.getSourceLineNumber())
77 print(sp,
' coverage marker: ', srcLineInfo.getCoverageMarker())
79 numAsmOpCodes = srcLineInfo.getNumAsmOpCodes()
80 print(sp,
' Assembler Op Codes: ', numAsmOpCodes,
':')
81 for j
in range(numAsmOpCodes):
82 asmOpCodeInfo = srcLineInfo.getAsmOpCodeInfo(j)
83 print(sp,
' - source text: ', asmOpCodeInfo.getSourceLineText())
84 print(sp,
' coverage marker: ', asmOpCodeInfo.getCoverageMarker())
85 print(sp,
' address: ', asmOpCodeInfo.getAddress())
88def printCoverageInfo2(info):
89 print(
' Coverage meta information:')
90 print(
' tester name: ', info.getName())
91 print(
' id: ', info.getId())
92 print(
' date: ', info.getDate())
93 print(
' time: ', info.getTime())
94 print(
' software: ', info.getSoftware())
95 print(
' hardware: ', info.getHardware())
96 print(
' description: ', info.getDescription())
97 print(
' comment: ', info.getComment())
100def iterateStatistic(coverageData, areaType):
102 This method demonstrates iteration on tree of statistic nodes.
104 it = coverageData.getIterator(areaType)
106 printStatisticForArea(it.next())
109def iterateStatisticChildren(statistic):
111 This method demonstrates walking tree of statistic nodes. It can be used
112 only when complete file has been parsed into memory.
115 printStatisticForArea(statistic)
117 numChildren = statistic.getNumChildren()
118 for idx
in range(numChildren):
119 printStatisticForArea(statistic.getChild(idx))
122def iterateStatisticRecursively(statistic, indent=2):
124 This method demonstrates walking tree of statistic nodes. It can be used
125 only when complete file has been parsed into memory.
128 printStatisticForArea(statistic, indent = indent)
130 numChildren = statistic.getNumChildren()
131 for idx
in range(numChildren):
132 childStat = statistic.getChild(idx)
134 iterateStatisticRecursively(childStat, indent + 2)
137def printCoverageInfo():
138 print(
'In-memory coverage data parser')
139 print(
'==============================\n')
140 coverageData = ic.CCoverageData2.createInstance(
'../../targetProjects/coverageSample-1.xml',
143 warnings = coverageData.getParserWarnings()
145 print(
'WARNING(S): ', warnings)
147 print(
'OK, 0 warnings')
149 coverageData.closeParser()
151 printCoverageInfo2(coverageData.getCoverageMetaInfo())
153 print(
'\n\n ---\nCoverage statistic for complete recording: ')
154 rootStatistic = coverageData.getRoot()
155 printStatisticForArea(rootStatistic)
157 funcName =
'test_fibonacci'
158 print(
'\n\n ---\nCoverage statistic for ' + funcName)
159 func1Stat = coverageData.getStatistic(ic.CCoverageStatistic2.EFunction,
161 printStatisticForArea(func1Stat)
163 print(
"\n\n ---\nCoverage statistic for '" + funcName +
164 "' and it's immediate children.")
167 iterateStatisticRecursively(func1Stat)
169 print(
"\n\n ---\nCoverage statistic for all folders.")
170 iterateStatistic(coverageData, ic.CCoverageStatistic2.EFolder)
172 print(
"\n\n ---\nList of all modules in coverage file.")
173 iter = coverageData.getIterator(ic.CCoverageStatistic2.EModule)
174 while iter.hasNext():
177 print(stat.getAreaName())
180def printCoverageInfoWithIterarors():
181 print(
'\n\nFile parser')
182 print(
'===========\n')
184 coverageData = ic.CCoverageData2.createInstance(
'../../targetProjects/coverageSample-1.xml',
187 printCoverageInfo2(coverageData.getCoverageMetaInfo())
189 moduleName =
'main.cpp'
190 print(
"\n\n ---\nCoverage statistic for '" + moduleName +
"' including source lines:")
191 mainStat = coverageData.getStatistic(ic.CCoverageStatistic2.EModule,
193 warnings = coverageData.getParserWarnings()
195 print(
'WARNING(S): ', warnings)
197 printStatisticForArea(mainStat,
True)
199 coverageData.closeParser()
202 coverageData = ic.CCoverageData2.createInstance(
'../../targetProjects/coverageSample-1.xml',
205 print(
'\n\n ---\nCoverage statistic for all functions (percentage of object code executed):')
206 iter = coverageData.getIterator(ic.CCoverageStatistic2.EFunction)
207 while iter.hasNext():
210 print(
' ', stat.getAreaName() +
': ' +
211 str(stat.getBytesExecuted() * 100 / stat.getBytesAll()) +
'%')
215printCoverageInfoWithIterarors()