diff --git a/quad/Makefile b/quad/Makefile index b3d2929b7d5a0865ca98d033eddbb562381169c0..0a92c686ac1fd60dc693dbc0a8f0c86f0768331a 100644 --- a/quad/Makefile +++ b/quad/Makefile @@ -40,7 +40,7 @@ test: all $(MAKE) -C src/quad_app test ruby scripts/tests/test_safety_checks.rb ruby scripts/tests/test_memory_integrity.rb - # ruby scripts/tests/test_unix_uart.rb + ruby scripts/tests/test_communication.rb clean: rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR) diff --git a/quad/scripts/tests/test_communication.rb b/quad/scripts/tests/test_communication.rb new file mode 100644 index 0000000000000000000000000000000000000000..230eb7f793f89e98233754786f2f054ae70de6a9 --- /dev/null +++ b/quad/scripts/tests/test_communication.rb @@ -0,0 +1,72 @@ +#!/usr/bin/env ruby + +# UART test +# +# This test is pretty simple, just a UART smoke test, using +# the debug callback on the quad + +script_dir = File.expand_path(File.dirname(__FILE__)) +require script_dir + "/testing_library" + +bin_dir = script_dir + "/../../bin/" +Dir.chdir(bin_dir) + +Timeout::timeout(30) { + + puts("Setting up...") + + sleep 1 + + # Start virtual quad + quad_pid = Process.spawn("./virt-quad -q", + { :rlimit_as => 536870912, # 512 MiB total RAM + :rlimit_stack => 1048576}) # 1 MiB stack + + delay_spin_cursor(1) + + # Set RC switches + set_gear GEAR_OFF + set_flap FLAP_OFF + + # Set initial quad orientation (flat on the ground, facing forward) + `./virt-quad set i2c_imu_x 0` + `./virt-quad set i2c_imu_y 0` + `./virt-quad set i2c_imu_z -1` + `./virt-quad set rc_roll 0.498` + `./virt-quad set rc_pitch 0.497` + `./virt-quad set rc_yaw 0.498` + + + ################# + # Begin Tests + ################# + + begin + + puts "------------------------------------------" + puts "-- Beginning basic communication test..." + puts "------------------------------------------" + + for j in 1..10 + + # Send a debug command + Thread.new { + sleep 0.1 + send_packet [0xBE, 1, 0, 0, 0, 0, 0, 0xBF] + } + + msg = recv_packet + puts msg + assert_equal(msg.force_encoding("UTF-8"), "Packets received: #{j}") + end + + puts "Basic communication test passed." + puts "------------------------------------------" + + ensure + + Process.kill(9, quad_pid) + Process.wait(quad_pid) + + end +} diff --git a/quad/scripts/tests/test_memory_integrity.rb b/quad/scripts/tests/test_memory_integrity.rb index f422b49e81043f469d93b5f3f5eb87d0f62252ef..fe145365c667100635f6d632ff3bd0655aeaafe0 100644 --- a/quad/scripts/tests/test_memory_integrity.rb +++ b/quad/scripts/tests/test_memory_integrity.rb @@ -26,7 +26,9 @@ set_flap FLAP_ON ################## begin - puts("Starting flight...") + puts "------------------------------------------" + puts "-- Beginning memory integrity test..." + puts "------------------------------------------" # Set initial quad orientation (flat on ground, facing forward) `./virt-quad set i2c_imu_x 0` @@ -94,12 +96,14 @@ ensure everything = file.readlines last_line = everything.last errors = last_line.scanf("%s ERROR SUMMARY: %d errors %s") + puts everything if errors[1] > 0 - puts everything puts "Memory Integrity Check Failed." + puts "------------------------------------------" Kernel.exit(1) end puts "Memory Integrity Check Passed." + puts "------------------------------------------" end diff --git a/quad/scripts/tests/test_safety_checks.rb b/quad/scripts/tests/test_safety_checks.rb index f7cd8ddb0e4ba010ce4e5b0feb717678a6c3e35f..b39685af90c811713baf95e90de83d7d18a08a7f 100644 --- a/quad/scripts/tests/test_safety_checks.rb +++ b/quad/scripts/tests/test_safety_checks.rb @@ -40,7 +40,9 @@ Timeout::timeout(60) { ################# begin - puts("Beginning tests...") + puts "------------------------------------------" + puts "-- Beginning safety checks test..." + puts "------------------------------------------" puts("Check that motors are off at startup") check_motors_are_off "Motors weren't off at startup! How dangerous!" @@ -141,6 +143,7 @@ Timeout::timeout(60) { set_throttle THROTTLE_MIN puts "All safety checks passed." + puts "------------------------------------------" ensure diff --git a/quad/scripts/tests/test_unix_uart.rb b/quad/scripts/tests/test_unix_uart.rb deleted file mode 100644 index 1c9b6a82e4fb3c84ded4038e666378c8b4a5016f..0000000000000000000000000000000000000000 --- a/quad/scripts/tests/test_unix_uart.rb +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env ruby - -# UART test -# -# This test is pretty simple, just a UART smoke test, using -# the debug callback on the quad - -script_dir = File.expand_path(File.dirname(__FILE__)) -require script_dir + "/testing_library" - -bin_dir = script_dir + "/../../bin/" -Dir.chdir(bin_dir) - - -Timeout::timeout(30) { - - puts("Setting up...") - - sleep 1 - - # Start virtual quad - quad_pid = Process.spawn("./virt-quad -q", - { :rlimit_as => 536870912, # 512 MiB total RAM - :rlimit_stack => 1048576}) # 1 MiB stack - - delay_spin_cursor(5) - - ################# - # Begin Tests - ################# - - begin - - puts("Beginning tests...") - - # 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) - - # Receive the header - msg = [] - for i in 1..7 - sleep 0.010 - msg.push(fifo.read(1)) - end - - # Receive the remaining data, according to the header specified length - 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_pid) - Process.wait(quad_pid) - - end -} diff --git a/quad/scripts/tests/testing_library.rb b/quad/scripts/tests/testing_library.rb index e8afdc7a01574016cc861c265624c422b2fbd9ef..b3ac12bfaa454e825b47c2c0975d0ee6f846fe13 100644 --- a/quad/scripts/tests/testing_library.rb +++ b/quad/scripts/tests/testing_library.rb @@ -13,20 +13,6 @@ FLAP_ON = 0.9 FLAP_OFF = 0.1 GRAVITY = 4096 -MOTOR1 = "virt-quad-fifos/motor1" -MOTOR2 = "virt-quad-fifos/motor2" -MOTOR3 = "virt-quad-fifos/motor3" -MOTOR4 = "virt-quad-fifos/motor4" - -GEAR = "virt-quad-fifos/rc-gear" -THROTTLE = "virt-quad-fifos/rc-throttle" - -LED = "virt-quad-fifos/mio7-led" - -I2C_MPU_ACCEL_X = "virt-quad-fifos/i2c-mpu-accel-x" -I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y" -I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z" - UART_RX = "virt-quad-fifos/uart-rx" UART_TX = "virt-quad-fifos/uart-tx" @@ -92,3 +78,30 @@ def delay_spin_cursor(delay) print "\b" end end + +def send_packet(bytes) + File.write(UART_RX, bytes.pack("C" * bytes.length)) +end + +def recv_packet + fifo = File.open(UART_TX) + + # Receive the header + msg = [] + for i in 1..7 + sleep 0.010 + c = fifo.read(1) + msg.push(c) + end + + # Receive the remaining data, according to the header specified length + 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 + + msg.join() +end