import os
import isystem.connect as ic
from coverage_data import test_get_coverage_meta_info as cvrg
winidea_id = ''
def test_getStatistic():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
ideCtrl = ic.CIDEController(connMgr)
xmlFilePath = os.path.join(ideCtrl.getPath(ic.CIDEController.WORKSPACE_DIR), "cvrgExport.xml")
cvrg._exportCoverageToXML(connMgr, 'sdk_example.trd', "cvrgExport.xml")
covData = ic.CCoverageData2.createInstance(xmlFilePath, True)
print(f"Get execution statistics for module 'main' (by name):")
stat = covData.getStatistic(ic.CCoverageStatistic2.EModule, "main.cpp")
print("\tNumber of called functions:", stat.getExecutionCount(), "(function 'main')")
print("\tExecuted lines:", stat.getLinesExecuted(), "out of:", stat.getLinesAll())
print(f"Get statistics explicitly defined by symbol data:")
stat = covData.getStatistic("sdk_example_stm32.elf", 'build/debug', "utils.cpp", "fibonacci")
print("\tFunction calls count:", stat.getCallCount())
print("\tExecuted code (in bytes):", stat.getBytesExecuted(), "out of:", stat.getBytesAll())
covData.closeParser()
if __name__ == "__main__":
test_getStatistic()