Skip to content
Snippets Groups Projects
Commit 8863edf7 authored by bbartels's avatar bbartels
Browse files

quad: Add UART tests to CI

parent 47bf22d8
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ test: all
$(MAKE) -C src/computation_graph test
$(MAKE) -C src/quad_app test
ruby scripts/tests/test_safety_checks.rb
ruby scripts/tests/test_unix_uart.rb
clean:
rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR)
......
#!/usr/bin/env python
import sys
import time
import os
import threading
path = os.path.dirname(__file__) + '/../../bin/virt-quad-fifos/'
def create_msg():
msg = bytes()
msg += b'\xBE'
msg += b'\x01'
msg += b'\x00'
msg += b'\x00'
msg += b'\x00'
msg += b'\x00'
msg += b'\x00'
print msg
checksum = 0
for b in msg:
checksum ^= b
msg += checksum.to_bytes(1, 'little')
return msg
def listen():
with open(path + 'uart-tx', 'r') as fifo:
while True:
c = fifo.read()
if c:
print c
def do_test():
# Start a listener
t = threading.Thread(target=listen)
t.daemon = True
t.start()
fifo = open(path + 'uart-rx', 'w')
fifo.write(b'\xBE\x01\x00\x00\x00\x00\x00\xBF')
fifo.write(b'\xBE\x01\x00\x00\x00\x00\x00\xBF')
fifo.write(b'\xBE\x01\x00\x00\x00\x00\x00\xBF')
if __name__ == '__main__':
for i in range(1):
print("Test ", i)
do_test()
time.sleep(1)
#!/usr/bin/env ruby
# UART test
#
# This test is pretty simple, just a UART smoke test, using
# the debug callback on the quad
GEAR_ON = 170800
GEAR_OFF = 118300
GEAR = "virt-quad-fifos/pwm-input-gear"
UART_RX = "virt-quad-fifos/uart-rx"
UART_TX = "virt-quad-fifos/uart-tx"
require 'test/unit/assertions'
require 'thread'
include Test::Unit::Assertions
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
# Start virtual quad
quad = Process.spawn("./virt-quad")
sleep 1
#################
# Begin Tests
#################
begin
# Flip gear on
File.write(GEAR, GEAR_ON)
sleep 0.015
for j in 1..10
# Send a debug command
File.write(UART_RX, [0xBE, 1, 0, 0, 0, 0, 0, 0xBF].pack("CCCCCCCC"))
fifo = File.open(UART_TX)
msg = []
for i in 1..7
sleep 0.010
msg.push(fifo.read(1))
end
length = msg[5..7].join().unpack("S")[0]
msg = []
for i in 1..length
sleep 0.010
msg.push(fifo.read(1))
end
fifo.close
puts msg.join()
assert_equal(msg.join().force_encoding("UTF-8"), "Packets received: #{j}")
end
puts "Basic UART test passed."
ensure
Process.kill(9, quad)
end
......@@ -4,13 +4,11 @@
#include <sys/types.h>
#include <fcntl.h>
static char *fifo_name_rx;
static char *fifo_full_name_rx;
static char *fifo_full_name_tx;
static int fifo_rx;
int unix_uart_reset(struct UARTDriver *self) {
fifo_name_rx = "uart-rx";
fifo_full_name_rx = VIRT_QUAD_FIFOS_DIR "/uart-rx";
fifo_full_name_tx = VIRT_QUAD_FIFOS_DIR "/uart-tx";
......@@ -30,6 +28,7 @@ int unix_uart_reset(struct UARTDriver *self) {
int unix_uart_write(struct UARTDriver *self, unsigned char c) {
int fifo = open(fifo_full_name_tx, O_WRONLY | O_NONBLOCK);
if (fifo >= 0) {
printf("%s: %x\n", "uart-tx", c);
write(fifo, &c, 1);
}
close(fifo);
......@@ -38,5 +37,8 @@ int unix_uart_write(struct UARTDriver *self, unsigned char c) {
int unix_uart_read(struct UARTDriver *self, unsigned char *c) {
int err = read(fifo_rx, c, 1);
if (err > 0) {
printf("%s: %x\n", "uart-rx", *c);
}
return err <= 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment