2018-08-04 17:48:47 -03:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
import serial, time
|
|
|
|
import subprocess
|
|
|
|
from subprocess import call, Popen
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
import re
|
2020-02-25 04:58:02 -04:00
|
|
|
import unittest
|
|
|
|
import os
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2019-06-15 12:09:21 -03:00
|
|
|
def do_test(port, baudrate, test_name):
|
2018-08-04 17:48:47 -03:00
|
|
|
databits = serial.EIGHTBITS
|
|
|
|
stopbits = serial.STOPBITS_ONE
|
|
|
|
parity = serial.PARITY_NONE
|
2019-06-15 13:03:37 -03:00
|
|
|
ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=10)
|
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
ser.write('\n')
|
2019-06-15 12:09:21 -03:00
|
|
|
|
2019-06-15 13:03:37 -03:00
|
|
|
success = False
|
|
|
|
|
|
|
|
timeout = 10 # 10 seconds
|
|
|
|
timeout_start = time.time()
|
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
while True:
|
2018-08-04 17:48:47 -03:00
|
|
|
serial_line = ser.readline()
|
2019-06-15 12:09:21 -03:00
|
|
|
print(serial_line.replace('\n',''))
|
2018-08-04 17:48:47 -03:00
|
|
|
|
|
|
|
if "nsh>" in serial_line:
|
2020-09-28 17:41:28 -03:00
|
|
|
break
|
|
|
|
elif "NuttShell (NSH)" in serial_line:
|
|
|
|
break
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2019-06-15 13:03:37 -03:00
|
|
|
if time.time() > timeout_start + timeout:
|
|
|
|
print("Error, timeout")
|
|
|
|
break
|
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
ser.write('\n')
|
|
|
|
time.sleep(0.01)
|
2019-06-15 13:03:37 -03:00
|
|
|
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
# run test cmd
|
|
|
|
cmd = 'tests ' + test_name
|
|
|
|
ser.write(cmd + '\n')
|
|
|
|
|
|
|
|
timeout = 180 # 3 minutes
|
2019-06-15 13:03:37 -03:00
|
|
|
timeout_start = time.time()
|
2020-09-28 17:41:28 -03:00
|
|
|
timeout_newline = timeout_start
|
2019-06-15 13:03:37 -03:00
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
while True:
|
2018-08-04 17:48:47 -03:00
|
|
|
serial_line = ser.readline()
|
2019-06-15 12:09:21 -03:00
|
|
|
print(serial_line.replace('\n',''))
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2020-09-28 17:41:28 -03:00
|
|
|
if cmd in serial_line:
|
|
|
|
continue
|
|
|
|
elif test_name + " PASSED" in serial_line:
|
2019-06-15 12:09:21 -03:00
|
|
|
success = True
|
2020-09-28 17:41:28 -03:00
|
|
|
break
|
2019-06-15 12:09:21 -03:00
|
|
|
elif test_name + " FAILED" in serial_line:
|
|
|
|
success = False
|
2020-09-28 17:41:28 -03:00
|
|
|
break
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2019-06-15 13:03:37 -03:00
|
|
|
if time.time() > timeout_start + timeout:
|
|
|
|
print("Error, timeout")
|
|
|
|
print(test_name + " FAILED")
|
|
|
|
success = False
|
|
|
|
break
|
|
|
|
|
|
|
|
# newline every 30 seconds if still running
|
|
|
|
if time.time() - timeout_newline > 30:
|
|
|
|
ser.write('\n')
|
|
|
|
timeout_newline = time.time()
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2019-06-15 12:09:21 -03:00
|
|
|
ser.close()
|
|
|
|
|
|
|
|
return success
|
2018-08-04 17:48:47 -03:00
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
class TestHardwareMethods(unittest.TestCase):
|
2020-02-25 04:58:02 -04:00
|
|
|
TEST_DEVICE = 0
|
|
|
|
TEST_BAUDRATE = 0
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
def test_atomic_bitset(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "atomic_bitset"))
|
|
|
|
|
2020-02-25 04:58:02 -04:00
|
|
|
def test_bezier(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bezier"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
def test_bitset(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bitset"))
|
|
|
|
|
2020-02-25 04:58:02 -04:00
|
|
|
def test_bson(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bson"))
|
|
|
|
|
2020-02-27 19:12:49 -04:00
|
|
|
def test_commander(self):
|
2020-02-25 04:58:02 -04:00
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "commander"))
|
|
|
|
|
|
|
|
def test_controllib(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "controllib"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
# def test_dataman(self):
|
|
|
|
# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "dataman"))
|
2020-02-25 04:58:02 -04:00
|
|
|
|
|
|
|
def floattest_float(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "float"))
|
|
|
|
|
|
|
|
def test_hrt(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "hrt"))
|
|
|
|
|
|
|
|
def test_IntrusiveQueue(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "IntrusiveQueue"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
def test_IntrusiveSortedList(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "IntrusiveSortedList"))
|
|
|
|
|
2020-02-25 04:58:02 -04:00
|
|
|
def test_List(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "List"))
|
|
|
|
|
|
|
|
def test_mathlib(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mathlib"))
|
|
|
|
|
|
|
|
def test_matrix(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "matrix"))
|
|
|
|
|
2020-07-09 15:12:25 -03:00
|
|
|
def test_microbench_atomic(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_atomic"))
|
|
|
|
|
2020-02-25 04:58:02 -04:00
|
|
|
def test_microbench_hrt(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_hrt"))
|
|
|
|
|
|
|
|
def test_microbench_math(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_math"))
|
|
|
|
|
|
|
|
def test_microbench_matrix(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_matrix"))
|
|
|
|
|
|
|
|
def test_microbench_uorb(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_uorb"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
# def test_mixer(self):
|
|
|
|
# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mixer"))
|
2020-02-25 04:58:02 -04:00
|
|
|
|
|
|
|
def test_param(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "param"))
|
|
|
|
|
|
|
|
def test_parameters(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "parameters"))
|
|
|
|
|
|
|
|
def test_perf(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "perf"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
# def test_rc(self):
|
|
|
|
# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "rc"))
|
|
|
|
|
|
|
|
def test_search_min(self):
|
2020-02-25 04:58:02 -04:00
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "search_min"))
|
|
|
|
|
|
|
|
def test_sleep(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "sleep"))
|
|
|
|
|
|
|
|
def test_smoothz(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "smoothz"))
|
|
|
|
|
|
|
|
def test_time(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "time"))
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
def test_uorb(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "uorb"))
|
2020-02-25 04:58:02 -04:00
|
|
|
|
|
|
|
def test_versioning(self):
|
|
|
|
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "versioning"))
|
|
|
|
|
2018-08-04 17:48:47 -03:00
|
|
|
def main():
|
|
|
|
parser = ArgumentParser(description=__doc__)
|
|
|
|
parser.add_argument('--device', "-d", nargs='?', default = None, help='')
|
|
|
|
parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-11-10 17:41:13 -04:00
|
|
|
TestHardwareMethods.TEST_DEVICE = args.device
|
|
|
|
TestHardwareMethods.TEST_BAUDRATE = args.baudrate
|
2019-06-15 12:09:21 -03:00
|
|
|
|
2020-02-25 04:58:02 -04:00
|
|
|
unittest.main(__name__, argv=['main'])
|
2018-08-04 17:48:47 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-06-15 12:09:21 -03:00
|
|
|
main()
|