Skip to content
Snippets Groups Projects
Commit 82b0bb14 authored by bbartels's avatar bbartels
Browse files

quad: run make deep-clean on ci test

- Add some prints to scripts to help with debugging
- Add timeout if spawn fails
- Add more time to allow changes to take effect
- Fix input design
parent c123eeb9
No related branches found
No related tags found
No related merge requests found
...@@ -4,4 +4,4 @@ set -e ...@@ -4,4 +4,4 @@ set -e
export PATH=/usr/local/bin:$PATH export PATH=/usr/local/bin:$PATH
# Quad # Quad
(cd quad && make test) (cd quad && make deep-clean && make && make test)
...@@ -38,8 +38,8 @@ test: all ...@@ -38,8 +38,8 @@ test: all
$(MAKE) -C src/queue test $(MAKE) -C src/queue test
$(MAKE) -C src/computation_graph test $(MAKE) -C src/computation_graph test
$(MAKE) -C src/quad_app test $(MAKE) -C src/quad_app test
#ruby scripts/tests/test_safety_checks.rb ruby scripts/tests/test_safety_checks.rb
#ruby scripts/tests/test_unix_uart.rb ruby scripts/tests/test_unix_uart.rb
clean: clean:
rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR) rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR)
......
...@@ -32,6 +32,7 @@ I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y" ...@@ -32,6 +32,7 @@ I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y"
I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z" I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z"
require 'test/unit/assertions' require 'test/unit/assertions'
require 'timeout'
require 'thread' require 'thread'
include Test::Unit::Assertions include Test::Unit::Assertions
...@@ -73,97 +74,106 @@ def get_motor_averages ...@@ -73,97 +74,106 @@ def get_motor_averages
average average
end end
def check_led(on) def check_led(is_on)
led = read_fifo_num(LED) led = read_fifo_num(LED)
assert_equal(led, on) assert_equal(led, is_on)
end end
script_dir = File.expand_path(File.dirname(__FILE__)) Timeout::timeout(30) {
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
# Start virtual quad puts("Setting up...")
quad = Process.spawn("./virt-quad")
sleep 1 script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
################# sleep 1
# Begin Tests
################# # Start virtual quad
quad_pid = Process.spawn("./virt-quad")
sleep 5
#################
# Begin Tests
#################
begin begin
puts("beginning tests")
# Set gravity
File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
puts("Check that motors are off at startup") puts("Beginning tests...")
check_motors_are_off
puts("Check that LED is off at startup") # Set gravity
check_led(0) File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
puts("Check that increasing the throttle does nothing to motors") puts("Check that motors are off at startup")
# (because gear is still off)
for i in (THROTTLE_MIN..THROTTLE_MAX).step(1000)
File.write(THROTTLE, i)
check_motors_are_off check_motors_are_off
sleep 0.005
end
puts("Check that flipping gear to 1 while throttle is high does nothing") puts("Check that LED is off at startup")
# (motors should still be off, LED should still be off) check_led(0)
File.write(GEAR, GEAR_ON)
sleep 0.015 puts("Check that increasing the throttle does nothing to motors")
check_motors_are_off # (because gear is still off)
i = THROTTLE_MAX for i in (THROTTLE_MIN..THROTTLE_MAX).step(1000)
while i > THROTTLE_MID File.write(THROTTLE, i)
i -= 1000 check_motors_are_off
File.write(THROTTLE, i) sleep 0.005
end
puts("Check that flipping gear to 1 while throttle is high does nothing")
# (motors should still be off, LED should still be off)
File.write(GEAR, GEAR_ON)
sleep 0.015
check_motors_are_off
i = THROTTLE_MAX
while i > THROTTLE_MID
i -= 1000
File.write(THROTTLE, i)
check_motors_are_off
check_led 0
sleep 0.005
end
# (swtich GEAR back to off and bring throttle off)
File.write(GEAR, GEAR_OFF)
File.write(THROTTLE, THROTTLE_MIN)
puts("Check that the LED turns on when gear is flipped on")
# (motors should still be off because our throttle is low)
File.write(GEAR, GEAR_ON)
sleep 0.1
check_led 1
check_motors_are_off
puts("Check that motors turn on")
File.write(THROTTLE, THROTTLE_MID)
averages = get_motor_averages
average = (averages[0] + averages[1] + averages[2] + averages[3])/4
puts averages, "(#{average})"
assert average.between?(THROTTLE_EIGHTH, MOTOR_MAX)
# Check that gear switch kills the motors
# (and that light goes off)
File.write(GEAR, GEAR_OFF)
sleep 0.1
check_motors_are_off check_motors_are_off
check_led 0 check_led 0
sleep 0.005
end
# (swtich GEAR back to off and bring throttle off) # (Bring the RC throttle back down)
File.write(GEAR, GEAR_OFF) File.write(THROTTLE, THROTTLE_MIN)
File.write(THROTTLE, THROTTLE_MIN)
puts("Check that the LED turns on when gear is flipped on")
# (motors should still be off because our throttle is low)
File.write(GEAR, GEAR_ON)
sleep 0.020
check_led 1
check_motors_are_off
puts("Check that motors turn on")
File.write(THROTTLE, THROTTLE_MID)
averages = get_motor_averages
average = (averages[0] + averages[1] + averages[2] + averages[3])/4
puts averages, "(#{average})"
assert average.between?(THROTTLE_EIGHTH, MOTOR_MAX)
# Check that gear switch kills the motors
# (and that light goes off)
File.write(GEAR, GEAR_OFF)
sleep 0.040
check_motors_are_off
check_led 0
# (Bring the RC throttle back down)
File.write(THROTTLE, THROTTLE_MIN)
# Check that we can resume flight
File.write(GEAR, GEAR_ON)
sleep 0.040
check_led 1
sleep 1 # Check that we can resume flight
puts "All safety checks passed." File.write(GEAR, GEAR_ON)
sleep 0.1
check_led 1
ensure sleep 1
puts "All safety checks passed."
Process.kill(9, quad) ensure
end Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}
...@@ -15,54 +15,64 @@ UART_TX = "virt-quad-fifos/uart-tx" ...@@ -15,54 +15,64 @@ UART_TX = "virt-quad-fifos/uart-tx"
require 'test/unit/assertions' require 'test/unit/assertions'
require 'thread' require 'thread'
require 'timeout'
include Test::Unit::Assertions include Test::Unit::Assertions
script_dir = File.expand_path(File.dirname(__FILE__)) Timeout::timeout(30) {
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
# Start virtual quad puts("Setting up...")
quad = Process.spawn("./virt-quad")
sleep 1 script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
################# sleep 1
# Begin Tests
#################
begin # Start virtual quad
quad_pid = Process.spawn("./virt-quad")
# Flip gear on sleep 5
File.write(GEAR, GEAR_ON)
sleep 0.015
for j in 1..10 #################
# Send a debug command # Begin Tests
File.write(UART_RX, [0xBE, 1, 0, 0, 0, 0, 0, 0xBF].pack("CCCCCCCC")) #################
fifo = File.open(UART_TX) begin
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() puts("Beginning tests...")
assert_equal(msg.join().force_encoding("UTF-8"), "Packets received: #{j}")
end # Flip gear on
File.write(GEAR, GEAR_ON)
sleep 0.015
puts "Basic UART test passed." for j in 1..10
# Send a debug command
File.write(UART_RX, [0xBE, 1, 0, 0, 0, 0, 0, 0xBF].pack("CCCCCCCC"))
ensure 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
Process.kill(9, quad) puts msg.join()
assert_equal(msg.join().force_encoding("UTF-8"), "Packets received: #{j}")
end
puts "Basic UART test passed."
end ensure
Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}
...@@ -20,14 +20,8 @@ static short last_dev; ...@@ -20,14 +20,8 @@ static short last_dev;
static short last_reg; static short last_reg;
static short last_val; static short last_val;
static int zero = 0; static int nums[] = {0, 1, 2, 3, 4, 5};
static int one = 1; static pthread_t workers[6];
static int two = 2;
static int three = 3;
static int four = 4;
static int five = 5;
static pthread_t worker;
int unix_i2c_reset(struct I2CDriver *self) { int unix_i2c_reset(struct I2CDriver *self) {
input_names[0] = "i2c-mpu-accel-x"; input_names[0] = "i2c-mpu-accel-x";
...@@ -40,12 +34,10 @@ int unix_i2c_reset(struct I2CDriver *self) { ...@@ -40,12 +34,10 @@ int unix_i2c_reset(struct I2CDriver *self) {
mkdir(VIRT_QUAD_FIFOS_DIR, 0777); mkdir(VIRT_QUAD_FIFOS_DIR, 0777);
// Start up worker thread whose job is to update the caches // Start up worker thread whose job is to update the caches
pthread_create(&worker, 0, update_i2c_input_cache, &zero); int i;
pthread_create(&worker, 0, update_i2c_input_cache, &one); for (i = 0; i < 6; i += 1) {
pthread_create(&worker, 0, update_i2c_input_cache, &two); pthread_create(&workers[i], 0, update_i2c_input_cache, &nums[i]);
pthread_create(&worker, 0, update_i2c_input_cache, &three); }
pthread_create(&worker, 0, update_i2c_input_cache, &four);
pthread_create(&worker, 0, update_i2c_input_cache, &five);
cache[0].s = 0; cache[0].s = 0;
cache[1].s = 0; cache[1].s = 0;
......
...@@ -10,7 +10,8 @@ void * update_input_cache(); ...@@ -10,7 +10,8 @@ void * update_input_cache();
static char *input_names[6]; static char *input_names[6];
static int fifos[6]; static int fifos[6];
static unsigned long cache[6]; static unsigned long cache[6];
pthread_t worker; static pthread_t workers[6];
static int nums[] = {0, 1, 2, 3, 4, 5};
int unix_pwm_input_reset(struct PWMInputDriver *self) { int unix_pwm_input_reset(struct PWMInputDriver *self) {
input_names[0] = "pwm-input-throttle"; input_names[0] = "pwm-input-throttle";
...@@ -25,7 +26,8 @@ int unix_pwm_input_reset(struct PWMInputDriver *self) { ...@@ -25,7 +26,8 @@ int unix_pwm_input_reset(struct PWMInputDriver *self) {
// Start up worker thread whose job is to update the caches // Start up worker thread whose job is to update the caches
int i; int i;
for (i = 0; i < 6; i += 1) { for (i = 0; i < 6; i += 1) {
pthread_create(&worker, 0, update_input_cache, &i); pthread_create(&workers[i], 0, update_input_cache, &nums[i]);
usleep(1000);
} }
cache[0] = THROTTLE_MIN; cache[0] = THROTTLE_MIN;
......
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