Skip to content
Snippets Groups Projects
Commit 6cf99d18 authored by bbartels's avatar bbartels
Browse files

quad: add test script for logging

parent fb59a95d
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,28 @@ Timeout::timeout(30) {
send_packet [0xBE, 1, 0, 0, 0, 0, 0, 0xBF]
}
msg = recv_packet
fifo = File.open(UART_TX)
# Receive the header
msg = []
for i in 1..7
sleep 0.0001
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.0001
c = fifo.read(1)
msg.push(c)
end
fifo.close
msg = msg.join()
puts msg
assert_equal(msg.force_encoding("UTF-8"), "Packets received: #{j}")
end
......
#!/usr/bin/env ruby
# Logging test
#
# Let the quad fly for a bit, and then ensure we can
# get its logs
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...")
# Start virtual quad
quad_pid = Process.spawn("./virt-quad -q",
{ :rlimit_as => 536870912, # 512 MiB total RAM
:rlimit_stack => 1048576}) # 1 MiB stack
sleep 0.5
# 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 logging test..."
puts "------------------------------------------"
# Set initial quad orientation (flat on 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`
puts("Turning on GEAR...")
set_gear GEAR_ON
set_flap FLAP_ON
sleep 0.015
puts("Increasing Thrust to half maximum...")
for i in (THROTTLE_MIN..THROTTLE_MID).step(0.01)
set_throttle(i)
sleep 0.005
end
puts("Hovering for 3 seconds")
sleep 3
puts("Switching to autonomous and hovering for 3 seconds")
set_flap FLAP_OFF
sleep 3
puts("Switch back to manual, relaxing thrust to zero")
set_flap FLAP_ON
i = THROTTLE_MID
while i > THROTTLE_MIN
i -= 0.01
set_throttle(i)
sleep 0.005
end
# Get logs
Thread.new {
sleep 0.5
puts("Swiching off GEAR...")
set_gear GEAR_OFF
}
logs = []
begin
while true
logs.push(recv_packet)
end
rescue Timeout::Error
puts "No logs left"
end
if logs.length == 2
log_data = logs[1].split("\n")
for data in log_data
puts data
end
p log_data.length
end
puts "------------------------------------------"
ensure
Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}
......@@ -52,11 +52,11 @@ begin
sleep 3
puts("Switching to autonomous and hovering for 3 seconds")
set_flap FLAP_ON
set_flap FLAP_OFF
sleep 3
puts("Switch back to manual, relaxing thrust to zero")
set_flap FLAP_OFF
set_flap FLAP_ON
i = THROTTLE_MID
while i > THROTTLE_MIN
i -= 0.01
......@@ -67,11 +67,14 @@ begin
puts("Swiching off GEAR...")
set_gear GEAR_OFF
sleep 3
set_throttle THROTTLE_MIN
puts("Flight ended successfully.");
ensure
Process.kill(2, quad)
sleep 1 # wait for valgrind to write to file
# Process the valgrind file
......
......@@ -72,22 +72,25 @@ def send_packet(bytes)
end
def recv_packet
fifo = File.open(UART_TX)
fifo = nil
Timeout::timeout(5) {
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))
c = fifo.read(1)
msg.push(c)
end
fifo.close
......
......@@ -30,8 +30,8 @@ int unix_uart_write(struct UARTDriver *self, unsigned char c) {
if (fifo >= 0) {
printf("%s: %x\n", "uart-tx", c);
write(fifo, &c, 1);
close(fifo);
}
close(fifo);
return 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