winIDEA SDK
test_case_controller_example.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6
7
8winidea_id = ''
9
10
11def init_target() -> ic.ConnectionMgr:
12 cmgr = ic.ConnectionMgr()
13 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
14
15 debugCtrl = ic.CDebugFacade(cmgr)
16 debugCtrl.reset()
17
18 debugCtrl.runUntilFunction('main')
19 debugCtrl.waitUntilStopped()
20 return cmgr
21
22
23def run_test(cmgr: ic.ConnectionMgr):
24 # Specify the function to be called and the parameters
25 testCaseCtrl = ic.CTestCaseController(cmgr, 'sum', 'retVal')
26 testCaseCtrl.createParameter(0, 'param1')
27 testCaseCtrl.createParameter(1, 'param2')
28 testCaseCtrl.createParameter(2, 'param3')
29 # Add the new variable to be used just for this test case
30 testCaseCtrl.createVariable('newVariable', 'int[10]')
31
32 # Initialize the test case
33 testCaseCtrl.init()
34
35 # Initialize the array and reset the first element after that
36 testCaseCtrl.modifyAsString('newVariable', "{0, 1, 2, -6, 4, 5, 6, 7, 8, 9}")
37 testCaseCtrl.modify('newVariable[0]', '10')
38
39 # Use two static values and our variable as call parameters
40 # This will return 5 + 10 + (-6) == 9
41 testCaseCtrl.modify('param1', '5')
42 testCaseCtrl.modify('param2', 'newVariable[0]')
43 testCaseCtrl.modify('param3', 'newVariable[3]')
44
45 print('Running test...')
46 testCaseCtrl.run()
47 testCaseCtrl.waitUntilStopped()
48 print('Finished.')
49
50 state = testCaseCtrl.getStatus()
51 if state == ic.IConnectTest.stateEnded:
52 print('Test finished normally.')
53 else:
54 print('Test ended in unexpected state: ', state)
55
56 # Gets function return value. Format specifier 'd' is used to always get
57 # decimal value, regardless of winIDEA settings.
58 rv = testCaseCtrl.evaluate('retVal,d')
59 print('return value: ', rv)
60 if rv != '9':
61 print('Test failed! retVal =', rv)
62
63 testCaseCtrl.destroy()
64
65
66def main():
67 cmgr = init_target()
68 print('initialized')
69 run_test(cmgr)
70
71
72if __name__ == '__main__':
73 main()