5import isystem.connect
as ic
6import isystem.itest
as it
12MODULE_NAME =
"utils.cpp"
16 def __init__(self, no_of_sub_tasks):
17 self.no_of_sub_tasks = no_of_sub_tasks
23 def subTask(self, taskDesc):
26 def worked(self, count):
27 self.test_count += count
28 print(
'#' * self.test_count +
'-' * (self.no_of_sub_tasks - self.test_count))
31def init_target() -> ic.ConnectionMgr:
32 cmgr = ic.ConnectionMgr()
34 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
36 debug_ctrl = ic.CDebugFacade(cmgr)
40 debug_ctrl.runUntilFunction(
'main')
41 debug_ctrl.waitUntilStopped()
46def run_test(connection_mgr: ic.ConnectionMgr) -> ic.CCoverageController2:
47 test_case = it.PTestCase(connection_mgr)
51 print(
"Target initialized, configuring coverage...")
55 coverage_ctrl = ic.CCoverageController2(connection_mgr,
"moduleCoverage.trd",
'w')
57 trigger_idx = coverage_ctrl.getActiveTriggerIndex()
59 coverage_ctrl.setScope(trigger_idx, ic.CCoverageController2.EScopeCustom)
60 coverage_ctrl.setProvideAssemblerInfo(trigger_idx,
True)
63 coverage_ctrl.addArea(trigger_idx, ic.CCoverageController2.EAreaModule, MODULE_NAME)
67 print(
"Coverage configured and started!")
70 testSpec = ic.CTestSpecification.parseTestSpec(
76 document: moduleCoverage.trd
81 - func: [fibonacci, [0], rv]
83 expressions: [rv == 0]
85 - func: [fibonacci, [2], rv]
90 monitor = Monitor(testSpec.getNoOfTests(True))
91 test_case.runDerivedTests(testSpec,
None, monitor)
96def print_coverage(coverage_ctrl: ic.CCoverageController2):
98 coverage_data = ic.CCoverageData2.createInstance(coverage_ctrl,
103 warnings = coverage_data.getParserWarnings()
105 print(
'WARNING(S): ', warnings)
107 coverage_data.closeParser()
109 stat = coverage_data.getStatistic(ic.CCoverageStatistic2.EModule, MODULE_NAME)
111 bytes_all = stat.getBytesAll()
112 bytes_executed = stat.getBytesExecuted()
113 conditions_all = stat.getConditionsAll()
114 conditions_executed = stat.getConditionsExecuted()
115 conditions_taken = stat.getConditionsTrue()
116 conditions_not_taken = stat.getConditionsFalse()
117 conditions_both = stat.getConditionsBoth()
119 print(
'code coverage:', 100. * bytes_executed / bytes_all,
'%')
120 print(
'conditions executed', 100. * conditions_executed / conditions_all,
'%')
121 print(
'conditions taken', 100. * conditions_taken / conditions_all,
'%')
122 print(
'conditions not taken', 100. * conditions_not_taken / conditions_all,
'%')
123 print(
'conditions both', 100. * conditions_both / conditions_all,
'%')
126if __name__ ==
'__main__':
128 cvrg_ctrl = run_test(cmgr)
129 print_coverage(cvrg_ctrl)