1
2
3
4
5import time
6import isystem.connect as ic
7
8
9winidea_id = ''
10
11
12def init_target() -> ic.ConnectionMgr:
13 cmgr = ic.ConnectionMgr()
14 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
15
16 debug_ctrl = ic.CDebugFacade(cmgr)
17 session_ctrl = ic.CSessionCtrl(cmgr)
18
19 session_ctrl.begin_reset()
20
21 debug_ctrl.runUntilFunction("main")
22 debug_ctrl.waitUntilStopped()
23
24 return cmgr
25
26
27def run_test(cmgr: ic.ConnectionMgr):
28 test_controller = ic.CSystemTestController(cmgr)
29
30
31
32 stub_controller = test_controller.createStub('process_strings')
33
34
35 test_controller.createUserStub('get_random', 'stub_demo')
36
37 test_controller.init()
38
39 test_controller.run()
40
41 test_controller.waitUntilStopped()
42 testStatus = test_controller.getStatus()
43 if testStatus == ic.IConnectTest.stateStub:
44 print(f"Stub '{stub_controller.getStubName()}' hit.")
45 else:
46 raise Exception(f"Execution did not stop on stub. Status = {testStatus}")
47
48 test_controller.run()
49 time.sleep(2)
50 test_controller.stop()
51
52 g_process_counter = int(test_controller.evaluate('g_process_counter,d'), 0)
53 if g_process_counter == 0:
54 print('OK, function was stubbed!')
55 else:
56 print(f'ERROR: function was NOT stubbed! g_process_counter = {g_process_counter}')
57
58 test_controller.destroy()
59 print('OK')
60
61
62def main():
63 cmgr = init_target()
64 print('initialized')
65 run_test(cmgr)
66
67
68if __name__ == '__main__':
69 main()