winIDEA SDK
target_call_with_trace.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import sys
6import isystem.connect as ic
7
8
9winidea_id = ''
10
11
12def callTarget(connectionMgr, functionName, params, traceCtrl):
13 """
14 This function executes function on the target, and also
15 starts trace. Use it instead of CExecutionController.call(),
16 when you have to record trace.
17
18 Parameters:
19 connectionMgr - isntance of ConnectionMgr()
20 functionName - name of the function to execute
21 params - values of function parameters, can be empty list: []
22 traceCtrl - analyzer document, which will record trace
23 """
24 retValName = "isystem___test_ret_val"
25 paramPrefix = "isystem___test_param_"
26
27 # make sure there is no half executed call from the past
28 ic.CTestCaseController.clearAllTests(cmgr)
29
30 testCtrl = ic.CTestCaseController(connectionMgr, functionName, retValName)
31
32 try:
33 # create parameters
34 for idx in range(0, len(params)):
35 parameterName = paramPrefix + str(idx)
36 testCtrl.createParameter(idx, parameterName)
37
38 testCtrl.init()
39
40 traceCtrl.start()
41
42 # set parameters
43 idx = 0
44 for param in params:
45 parameterName = paramPrefix + str(idx)
46 testCtrl.modify(parameterName, param)
47 idx += 1
48
49 testCtrl.run()
50
51 testCtrl.waitUntilStopped(0, 50) # INFINITE, 50 ms polling interval
52
53 if testCtrl.getStatus() != ic.IConnectTest.stateEnded:
54 raise Exception("Function call didn't finish normally!" +
55 testCtrl.testState2str(testCtrl.getStatus()))
56
57 testCtrl.destroy()
58 return
59
60 except Exception:
61 testCtrl.destroy()
62 raise
63
64
65# Main program
66cmgr = ic.ConnectionMgr()
67cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
68
69debugCtrl = ic.CDebugFacade(cmgr)
70
71# Skip target initialization if there is any parameter in command line.
72# This way we can save time when the target is already initialized.
73if len(sys.argv) == 1:
74 debugCtrl.download()
75 debugCtrl.runUntilFunction("main")
76 debugCtrl.waitUntilStopped()
77
78print(ic.getModuleVersion())
79
80# create trace document
81traceCtrl = ic.CTraceController(cmgr, 'tracedoc_hw.trd', 'w')
82# call the function and record trace
83callTarget(cmgr, 'test_debug', [], traceCtrl)