mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-05 05:01:36 +08:00
Jenkins: HIL improve run_tests.py and run_nsh_cmd.py helper
- switch to python3 - run_nsh_cmd.py return error if command fails - decrease timeout in checking for output - Jenkins hardware tests tolerate certain command failures that aren't available on all boards (flash constrained, etc)
This commit is contained in:
+42
-40
@@ -1,72 +1,74 @@
|
||||
#! /usr/bin/python
|
||||
#! /usr/bin/env python3
|
||||
|
||||
import serial, time
|
||||
import subprocess
|
||||
from subprocess import call, Popen
|
||||
from argparse import ArgumentParser
|
||||
import re
|
||||
import sys
|
||||
|
||||
def do_nsh_cmd(port, baudrate, cmd):
|
||||
databits = serial.EIGHTBITS
|
||||
stopbits = serial.STOPBITS_ONE
|
||||
parity = serial.PARITY_NONE
|
||||
ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=10)
|
||||
|
||||
ser.write('\n')
|
||||
|
||||
finished = 0
|
||||
success = False
|
||||
|
||||
timeout = 10 # 10 seconds
|
||||
timeout_start = time.time()
|
||||
|
||||
while True:
|
||||
serial_line = ser.readline()
|
||||
print(serial_line.replace('\n',''))
|
||||
|
||||
if "nsh>" in serial_line:
|
||||
break
|
||||
elif "NuttShell (NSH)" in serial_line:
|
||||
break
|
||||
|
||||
if time.time() > timeout_start + timeout:
|
||||
print("Error, timeout")
|
||||
break
|
||||
|
||||
ser.write('\n')
|
||||
time.sleep(0.01)
|
||||
|
||||
ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=0.1)
|
||||
|
||||
# run command
|
||||
ser.write(cmd + '\n')
|
||||
|
||||
timeout = 30 # 30 seconds
|
||||
timeout_start = time.time()
|
||||
timeout_newline = timeout_start
|
||||
timeout = 10 # 10 seconds
|
||||
|
||||
success_cmd = "cmd succeeded!"
|
||||
|
||||
while True:
|
||||
serial_line = ser.readline()
|
||||
print(serial_line.replace('\n',''))
|
||||
serial_cmd = '{0}; echo "{1}"\n'.format(cmd, success_cmd)
|
||||
ser.write(serial_cmd.encode("utf-8"))
|
||||
ser.flush()
|
||||
|
||||
serial_line = ser.readline().decode("utf-8", errors='ignore')
|
||||
|
||||
if cmd in serial_line:
|
||||
continue
|
||||
elif "nsh>" in serial_line:
|
||||
break
|
||||
elif "NuttShell (NSH)" in serial_line:
|
||||
break
|
||||
else:
|
||||
print(serial_line.replace('\n', ''))
|
||||
|
||||
if time.time() > timeout_start + timeout:
|
||||
print("Error, timeout")
|
||||
sys.exit(-1)
|
||||
break
|
||||
|
||||
ser.write('\n')
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
timeout_start = time.time()
|
||||
timeout = 30 # 30 seconds
|
||||
|
||||
while True:
|
||||
serial_line = ser.readline().decode("utf-8", errors='ignore')
|
||||
|
||||
if success_cmd in serial_line:
|
||||
break
|
||||
else:
|
||||
if len(serial_line) > 0:
|
||||
print(serial_line.replace('\n', ''))
|
||||
|
||||
if "nsh>" in serial_line:
|
||||
sys.exit(-1) # error, command didn't complete successfully
|
||||
elif "NuttShell (NSH)" in serial_line:
|
||||
sys.exit(-1) # error, command didn't complete successfully
|
||||
|
||||
if len(serial_line) <= 0:
|
||||
ser.write("\n".encode("utf-8"))
|
||||
ser.flush()
|
||||
|
||||
if time.time() > timeout_start + timeout:
|
||||
print("Error, timeout")
|
||||
sys.exit(-1)
|
||||
|
||||
ser.close()
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--device', "-d", nargs='?', default = None, help='')
|
||||
parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True)
|
||||
parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600)
|
||||
parser.add_argument("--cmd", "-c", dest="cmd", help="Command to run")
|
||||
args = parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user