winIDEA SDK
test_coverage_all_code.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import os
6import time
7import isystem.connect as ic
8
9
10winidea_id = ''
11
12
13def test_cvrg_all_code():
14 cmgr = ic.ConnectionMgr()
15 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
16
17 debugCtrl = ic.CDebugFacade(cmgr)
18 debugCtrl.reset()
19
20 # Create coverage document.
21 coverage = ic.CCoverageController2(cmgr, 'sdk_example.trd', 'w')
22
23 # Wait until winIDEA has loaded the document, if it already existed.
24 if not coverage.waitUntilLoaded(5000):
25 print('isBusy = ', coverage.isBusy())
26 print("Warning - timeout ocurred when loading coverage document - some data may not be loaded!")
27
28 # Create and select a new coverage trigger. First make sure, that it does
29 # not already exist.
30 coverage.removeTrigger('coverageTrigger')
31 triggerIdx = coverage.createTrigger('coverageTrigger')
32 coverage.select(triggerIdx)
33
34 # Set scope to all downloaded code.
35 coverage.setScope(triggerIdx, ic.CCoverageController2.EScopeAllDownloadedCode)
36
37 # Start recording and run the target
38 coverage.start()
39 debugCtrl.run()
40 print('Target is running, coverage is recording data...')
41 time.sleep(3)
42 debugCtrl.stop()
43 coverage.stopSampling()
44
45 print('Target stopped, loading coverage data...')
46 while not coverage.waitUntilLoaded(3000):
47 print("winIDEA is analyzing coverage recording, please wait ...!")
48 print(' isBusy = ', coverage.isBusy())
49
50 # Coverage is recorded, let's export it to XML file.
51 exportCfg = ic.CCoverageExportConfig()
52 exportFmt = ic.CCoverageXMLExportFormat()
53 exportCfg.setFileName('coverageSample-1.xml') \
54 .setFormatter(exportFmt) \
55 .setExportModules(True) \
56 .setExportModuleLines(True) \
57 .setExportSources(True) \
58 .setExportFunctions(True) \
59 .setExportFunctionLines(True) \
60 .setExportFunctionAsm(True) \
61 .setExportAsm(True) \
62 .setExportRanges(True)
63
64 coverage.exportData(exportCfg)
65 coverage.closeAll()
66
67
68if __name__ == "__main__":
69 test_cvrg_all_code()