a | b/codesys-ide/scripts/runtest.py | ||
---|---|---|---|
1 | import sys, os |
||
2 | import helper |
||
3 | |||
4 | def runtest(): |
||
5 | devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.15.0') |
||
6 | proj = projects.primary |
||
7 | |||
8 | # delete existing testdev device |
||
9 | existing = proj.find('testdev') |
||
10 | if len(existing) > 0: |
||
11 | existing[0].remove() |
||
12 | |||
13 | # add device |
||
14 | proj.add('testdev', devId) |
||
15 | apps = proj.find('Application', True) |
||
16 | if len(apps) > 0: |
||
17 | app = apps[0] |
||
18 | tc = app.create_task_configuration() |
||
19 | |||
20 | # add task to call PRG_RUNTEST |
||
21 | task = tc.create_task('Task') |
||
22 | task.pous.add('PRG_RUNTEST') |
||
23 | |||
24 | # set device to simulation mode |
||
25 | devs = proj.find('testdev') |
||
26 | if len(devs) > 0: |
||
27 | devs[0].set_simulation_mode(True) |
||
28 | |||
29 | # login |
||
30 | onlineapp = online.create_online_application(app) |
||
31 | print(OnlineChangeOption) |
||
32 | onlineapp.login(OnlineChangeOption.Try, True) |
||
33 | |||
34 | # run program |
||
35 | onlineapp.start() |
||
36 | |||
37 | # wait until project finishes |
||
38 | for timeout in range(30): |
||
39 | system.delay(1000) |
||
40 | xready = onlineapp.read_value("PRG_RUNTEST.xReady") |
||
41 | if str(xready) == "TRUE": |
||
42 | break |
||
43 | # check for error |
||
44 | xerror = onlineapp.read_value("PRG_RUNTEST.xError") |
||
45 | |||
46 | if not (str(xready) == "TRUE" and str(xerror) == "FALSE"): |
||
47 | sys.exit("Test failed") |
||
48 | |||
49 | # display value in message view or command line |
||
50 | print("*** State Results of Test: xError: %s, xReady: %s\n" % (xerror, xready)) |
||
51 | try: |
||
52 | szMessage = onlineapp.read_value("PRG_RUNTEST.szMessage") |
||
53 | print("*** Test Results:\n") |
||
54 | print(szMessage) |
||
55 | print("*** end") |
||
56 | except: |
||
57 | print("*** No Test Results\n") |
||
58 | |||
59 | # log out |
||
60 | onlineapp.logout() |
||
61 | |||
62 | class SearchBuildDo(helper.SearchBuild): |
||
63 | # Test rules for: |
||
64 | # - *.library |
||
65 | def doit(self, filename): |
||
66 | artifacts = list() |
||
67 | |||
68 | if filename.endswith(".library"): |
||
69 | proj = projects.open(filename) |
||
70 | runtest() |
||
71 | proj.close() |
||
72 | |||
73 | return artifacts |
||
74 | |||
75 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
||
76 | |||
77 | sb = SearchBuildDo() |
||
78 | sb.search(".library", ".") |
||
79 | sb.save(".", ".drone-artifacts") |