From 2c9f96252332d9d3159e451918bd21b02d0011fe Mon Sep 17 00:00:00 2001 From: Bernard Davison Date: Wed, 21 Mar 2012 13:56:33 +1100 Subject: [PATCH] Changing the testing to not run hardware tests by default. Started to create some sim testing for the Microjet. Removed the test_all_examples target. --- Makefile | 5 +- .../LisaL/{01_upload.t => 01_With_b2_v1.2.t} | 15 ++- tests/LisaL/02_With_aspirin_v1.5_and_overo.t | 94 +++++++++++++++++++ tests/Makefile | 16 +++- tests/sim/01_Microjet.t | 84 +++++++++++++++++ 5 files changed, 199 insertions(+), 15 deletions(-) rename tests/LisaL/{01_upload.t => 01_With_b2_v1.2.t} (87%) create mode 100644 tests/LisaL/02_With_aspirin_v1.5_and_overo.t create mode 100644 tests/sim/01_Microjet.t diff --git a/Makefile b/Makefile index 65e483cf43..95a1d950a2 100644 --- a/Makefile +++ b/Makefile @@ -274,8 +274,5 @@ sw/simulator/launchsitl: chmod a+x $@ test: all replace_current_conf_xml - cd tests; $(MAKE) $(@) - -test_all_example_airframes: replace_current_conf_xml - cd tests; $(MAKE) $(@) TARGET_BOARD=examples + cd tests; $(MAKE) test diff --git a/tests/LisaL/01_upload.t b/tests/LisaL/01_With_b2_v1.2.t similarity index 87% rename from tests/LisaL/01_upload.t rename to tests/LisaL/01_With_b2_v1.2.t index 56c139579e..23f83fdbcf 100644 --- a/tests/LisaL/01_upload.t +++ b/tests/LisaL/01_With_b2_v1.2.t @@ -12,7 +12,7 @@ $|++; # Make the airframe my $make_compile_options = "AIRCRAFT=LisaLv11_Booz2v12_RC clean_ac ap.compile"; my $compile_output = run_program( - "Attempting to build and upload the firmware.", + "Attempting to build the firmware.", $ENV{'PAPARAZZI_SRC'}, "make $make_compile_options", 0,1); @@ -31,25 +31,24 @@ unlike($upload_output, '/\bError\b/i', "The upload output does not contain the w # Start the server process my $server_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/server"; -my $server_options = ""; -my $server = Proc::Background->new($server_command, $server_options); +my @server_options = qw(-n) +my $server = Proc::Background->new($server_command, @server_options); sleep 2; # The service should die in this time if there's an error -ok($server->alive(), "The server started successfully"); +ok($server->alive(), "The server process started successfully"); # Start the link process my $link_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/link"; my @link_options = qw(-d /dev/tty.usbserial-000013FD -s 57600 -transport xbee -xbee_addr 123); -#my @link_options = qw(-d /dev/tty.usbserial-000013FD -s 57600); sleep 2; # The service should die in this time if there's an error my $link = Proc::Background->new($link_command, @link_options); -ok($link->alive(), "The link started successfully"); +ok($link->alive(), "The link process started successfully"); # Open the Ivy bus and read from it... # TODO: learn how to read and write to the Ivy bus # Shutdown the server and link processes -ok($server->die(), "The server shutdown successfully."); -ok($link->die(), "The link shutdown successfully."); +ok($server->die(), "The server process shutdown successfully."); +ok($link->die(), "The link process shutdown successfully."); ################################################################################ # functions used by this test script. diff --git a/tests/LisaL/02_With_aspirin_v1.5_and_overo.t b/tests/LisaL/02_With_aspirin_v1.5_and_overo.t new file mode 100644 index 0000000000..32024c37e1 --- /dev/null +++ b/tests/LisaL/02_With_aspirin_v1.5_and_overo.t @@ -0,0 +1,94 @@ +#!/usr/bin/perl -w + +use Test::More tests => 7; +use lib "$ENV{'PAPARAZZI_SRC'}/tests/lib"; +use Program; +use Proc::Background; +use Ivy; + +$|++; + +#################### +# Make the airframe +my $make_compile_options = "AIRCRAFT=LisaLv11_Booz2v12_RC clean_ac ap.compile"; +my $compile_output = run_program( + "Attempting to build the firmware.", + $ENV{'PAPARAZZI_SRC'}, + "make $make_compile_options", + 0,1); +unlike($compile_output, '/Aircraft \'LisaLv11_Booz2v12_RC\' not found in/', "The compile output does not contain the message \"Aircraft \'LisaLv11_Booz2v12_RC\' not found in\""); +unlike($compile_output, '/\bError\b/i', "The compile output does not contain the word \"Error\""); + +#################### +# Upload the airframe +my $make_upload_options = "AIRCRAFT=LisaLv11_Booz2v12_RC BOARD_SERIAL=LISA-L-000154 ap.upload"; +my $upload_output = run_program( + "Attempting to build and upload the firmware.", + $ENV{'PAPARAZZI_SRC'}, + "make $make_upload_options", + 0,1); +unlike($upload_output, '/\bError\b/i', "The upload output does not contain the word \"Error\""); + +# Start the server process +my $server_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/server"; +my @server_options = qw(-n) +my $server = Proc::Background->new($server_command, @server_options); +sleep 2; # The service should die in this time if there's an error +ok($server->alive(), "The server process started successfully"); + +# Start the link process +my $link_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/link"; +my @link_options = qw(-d /dev/tty.usbserial-000013FD -s 57600 -transport xbee -xbee_addr 123); +sleep 2; # The service should die in this time if there's an error +my $link = Proc::Background->new($link_command, @link_options); +ok($link->alive(), "The link process started successfully"); + +# Open the Ivy bus and read from it... +# TODO: learn how to read and write to the Ivy bus + +# Shutdown the server and link processes +ok($server->die(), "The server process shutdown successfully."); +ok($link->die(), "The link process shutdown successfully."); + +################################################################################ +# functions used by this test script. +sub run_program +{ + my $message = shift; + my $dir = shift; + my $command = shift; + my $verbose = shift; + my $dont_fail_on_error = shift; + + warn "$message\n" if $verbose; + if (defined $dir) + { + $command = "cd $dir;" . $command; + } + my $prog = new Program("bash"); + my $fh = $prog->open("-c \"$command\""); + warn "Running command: \"". $prog->last_command() ."\"\n" if $verbose; + $fh->autoflush(1); + my @output; + while (<$fh>) + { + warn $_ if $verbose; + chomp $_; + push @output, $_; + } + $fh->close; + my $exit_status = $?/256; + unless ($exit_status == 0) + { + if ($dont_fail_on_error) + { + warn "Error: The command \"". $prog->last_command() ."\" failed to complete successfully. Exit status: $exit_status\n" if $verbose; + } + else + { + die "Error: The command \"". $prog->last_command() ."\" failed to complete successfully. Exit status: $exit_status\n"; + } + } + return wantarray ? @output : join "\n", @output; +} + diff --git a/tests/Makefile b/tests/Makefile index f6eb2bd4b5..e5f6198eb5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,10 +1,20 @@ Q = @ PERL = /usr/bin/perl TEST_VERBOSE = 0 -ifeq ($(TARGET_BOARD),) - TARGET_BOARD = * +NON_TEST_DIRS = lib|results +HARDWARE_REGEX = Lisa|Tiny|Umarim +HARDWARE_TEST_DIRS = $(shell find -L * -d 0 -type d | grep -Ev "$(NON_TEST_DIRS)" | grep -E "$(HARDWARE_REGEX)") +NON_HARDWARE_TEST_DIRS = $(shell find -L * -d 0 -type d | grep -Ev "$(NON_TEST_DIRS)" | grep -Ev "$(HARDWARE_REGEX)") +ifneq ($(TARGET_BOARD),) + TEST_DIRECTORIES = $(TARGET_BOARD) +else +ifeq ($(TEST_HARDWARE),) + TEST_DIRECTORIES = $(NON_HARDWARE_TEST_DIRS) +else + TEST_DIRECTORIES = $(NON_HARDWARE_TEST_DIRS) $(HARDWARE_TEST_DIRS) endif -TEST_FILES := $(shell ls $(TARGET_BOARD)/*.t) +endif +TEST_FILES := $(shell ls $(TEST_DIRECTORIES:%=%/*.t)) ifneq ($(JUNIT),) PERLENV=PERL_TEST_HARNESS_DUMP_TAP=$(PAPARAZZI_SRC)/tests/results diff --git a/tests/sim/01_Microjet.t b/tests/sim/01_Microjet.t new file mode 100644 index 0000000000..6dfae3ec49 --- /dev/null +++ b/tests/sim/01_Microjet.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w + +use Test::More tests => 6; +use lib "$ENV{'PAPARAZZI_SRC'}/tests/lib"; +use Program; +use Proc::Background; +use Ivy; + +$|++; + +#################### +# Make the airframe +my $make_compile_options = "AIRCRAFT=Microjet clean_ac sim.compile"; +my $compile_output = run_program( + "Attempting to build the sim firmware.", + $ENV{'PAPARAZZI_SRC'}, + "make $make_compile_options", + 0,1); +unlike($compile_output, '/Aircraft \'Microjet\' not found in/', "The compile output does not contain the message \"Aircraft \'Microjet\' not found in\""); +unlike($compile_output, '/\bError\b/i', "The compile output does not contain the word \"Error\""); + +# Start the server process +my $server_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/server"; +my @server_options = qw(-n); +my $server = Proc::Background->new($server_command, @server_options); +sleep 2; # The service should die in this time if there's an error +ok($server->alive(), "The server process started successfully"); + +# Start the sim process +my $link_command = "$ENV{'PAPARAZZI_HOME'}/sw/simulator/launchsitl"; +my @link_options = qw(-a -boot -norc); +sleep 2; # The service should die in this time if there's an error +my $link = Proc::Background->new($link_command, @link_options); +ok($link->alive(), "The launchsitl process started successfully"); + +# Open the Ivy bus and read from it... +# TODO: learn how to read and write to the Ivy bus + +# Shutdown the server and link processes +ok($server->die(), "The server process shutdown successfully."); +ok($link->die(), "The launchsitl process shutdown successfully."); + +################################################################################ +# functions used by this test script. +sub run_program +{ + my $message = shift; + my $dir = shift; + my $command = shift; + my $verbose = shift; + my $dont_fail_on_error = shift; + + warn "$message\n" if $verbose; + if (defined $dir) + { + $command = "cd $dir;" . $command; + } + my $prog = new Program("bash"); + my $fh = $prog->open("-c \"$command\""); + warn "Running command: \"". $prog->last_command() ."\"\n" if $verbose; + $fh->autoflush(1); + my @output; + while (<$fh>) + { + warn $_ if $verbose; + chomp $_; + push @output, $_; + } + $fh->close; + my $exit_status = $?/256; + unless ($exit_status == 0) + { + if ($dont_fail_on_error) + { + warn "Error: The command \"". $prog->last_command() ."\" failed to complete successfully. Exit status: $exit_status\n" if $verbose; + } + else + { + die "Error: The command \"". $prog->last_command() ."\" failed to complete successfully. Exit status: $exit_status\n"; + } + } + return wantarray ? @output : join "\n", @output; +} +