winIDEA SDK
Loading...
Searching...
No Matches
stubs_and_user_stubs_in_sys_tests.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 time
import isystem.connect as ic
winidea_id = ''
def init_target() -> ic.ConnectionMgr:
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debug_ctrl = ic.CDebugFacade(cmgr)
session_ctrl = ic.CSessionCtrl(cmgr)
session_ctrl.begin_reset()
debug_ctrl.runUntilFunction("main")
debug_ctrl.waitUntilStopped()
return cmgr
def run_test(cmgr: ic.ConnectionMgr):
test_controller = ic.CSystemTestController(cmgr)
# create normal stub - when it is hit, execution on target is stopped and
# Python script can modify variables, then continue with execution
stub_controller = test_controller.createStub('process_strings')
# create user stub - replace function which modifies global parameter with
# some other function. Execution on target does not stop, when the stub is hit.
test_controller.createUserStub('get_random', 'stub_demo')
test_controller.init()
test_controller.run()
test_controller.waitUntilStopped()
testStatus = test_controller.getStatus()
if testStatus == ic.IConnectTest.stateStub:
print(f"Stub '{stub_controller.getStubName()}' hit.")
else:
raise Exception(f"Execution did not stop on stub. Status = {testStatus}")
test_controller.run()
time.sleep(2)
test_controller.stop()
g_process_counter = int(test_controller.evaluate('g_process_counter,d'), 0)
if g_process_counter == 0:
print('OK, function was stubbed!')
else:
print(f'ERROR: function was NOT stubbed! g_process_counter = {g_process_counter}')
test_controller.destroy()
print('OK')
def main():
cmgr = init_target()
print('initialized')
run_test(cmgr)
if __name__ == '__main__':
main()