winIDEA SDK
Loading...
Searching...
No Matches
target_call_with_trace.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import sys
import isystem.connect as ic
winidea_id = ''
def callTarget(connectionMgr, functionName, params, traceCtrl):
"""
This function executes function on the target, and also
starts trace. Use it instead of CExecutionController.call(),
when you have to record trace.
Parameters:
connectionMgr - isntance of ConnectionMgr()
functionName - name of the function to execute
params - values of function parameters, can be empty list: []
traceCtrl - analyzer document, which will record trace
"""
retValName = "isystem___test_ret_val"
paramPrefix = "isystem___test_param_"
# make sure there is no half executed call from the past
ic.CTestCaseController.clearAllTests(cmgr)
testCtrl = ic.CTestCaseController(connectionMgr, functionName, retValName)
try:
# create parameters
for idx in range(0, len(params)):
parameterName = paramPrefix + str(idx)
testCtrl.createParameter(idx, parameterName)
testCtrl.init()
traceCtrl.start()
# set parameters
idx = 0
for param in params:
parameterName = paramPrefix + str(idx)
testCtrl.modify(parameterName, param)
idx += 1
testCtrl.run()
testCtrl.waitUntilStopped(0, 50) # INFINITE, 50 ms polling interval
if testCtrl.getStatus() != ic.IConnectTest.stateEnded:
raise Exception("Function call didn't finish normally!" +
testCtrl.testState2str(testCtrl.getStatus()))
testCtrl.destroy()
return
except Exception:
testCtrl.destroy()
raise
def main():
# Main program
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debugCtrl = ic.CDebugFacade(cmgr)
# Skip target initialization if there is any parameter in command line.
# This way we can save time when the target is already initialized.
if len(sys.argv) == 1:
debugCtrl.download()
debugCtrl.runUntilFunction("main")
debugCtrl.waitUntilStopped()
print(ic.getModuleVersion())
# create trace document
traceCtrl = ic.CTraceController(cmgr, 'tracedoc_hw.trd', 'w')
# call the function and record trace
callTarget(cmgr, 'test_debug', [], traceCtrl)
if __name__ == "__main__":
main()