--- a/codesys-ide/scripts/runtest.py +++ b/codesys-ide/scripts/runtest.py @@ -1,8 +1,16 @@ +# CODESYS with UI import sys, os import helper +# redirect output, as in UI mode no output is printed on the console +sys.stdout = open('.codesys.output.txt', 'w') + def runtest(): - devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.15.0') +# devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.15.0') + devId = None + devices = device_repository.get_all_devices("CODESYS Control Win V3") + for device in devices: + devId = device.device_id proj = projects.primary # delete existing testdev device @@ -28,14 +36,17 @@ # login onlineapp = online.create_online_application(app) - print(OnlineChangeOption) - onlineapp.login(OnlineChangeOption.Try, True) + try: + onlineapp.login(OnlineChangeOption.Try, True) + except: + print("Error: compile error") + return False # run program onlineapp.start() # wait until project finishes - for timeout in range(30): + for timeout in range(10): system.delay(1000) xready = onlineapp.read_value("PRG_RUNTEST.xReady") if str(xready) == "TRUE": @@ -43,21 +54,27 @@ # check for error xerror = onlineapp.read_value("PRG_RUNTEST.xError") - if not (str(xready) == "TRUE" and str(xerror) == "FALSE"): - sys.exit("Test failed") + # display value in message view or command line + print("Info: State Results of Test: xError: %s, xReady: %s" % (xerror, xready)) - # display value in message view or command line - print("*** State Results of Test: xError: %s, xReady: %s\n" % (xerror, xready)) + + try: szMessage = onlineapp.read_value("PRG_RUNTEST.szMessage") - print("*** Test Results:\n") + print("*** Test Messages:") print(szMessage) print("*** end") except: - print("*** No Test Results\n") + pass - # log out - onlineapp.logout() + if not str(xerror) == "FALSE": + print("Error: Test failed") + onlineapp.logout() + return False + else: + print("Info: Test passed") + onlineapp.logout() + return True class SearchBuildDo(helper.SearchBuild): # Test rules for: @@ -66,8 +83,10 @@ artifacts = list() if filename.endswith(".library"): + print("\n\n*** Test: %s" % filename) proj = projects.open(filename) - runtest() + if not runtest(): + self.error = True proj.close() return artifacts @@ -77,3 +96,7 @@ sb = SearchBuildDo() sb.search(".library", ".") sb.save(".", ".drone-artifacts") + +if sb.error: + system.exit(1) +system.exit()