-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
find_package(rostest REQUIRED) | ||
|
||
add_subdirectory(test_example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | ||
trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR | ||
|
||
ORIGINAL_PATH=`pwd` | ||
|
||
while [ ! -e ".catkin_tools" ]; do | ||
cd .. | ||
if [[ `pwd` == "/" ]]; then | ||
# we reached the root and didn't find the build/COLCON_IGNORE file - that's a fail! | ||
echo "$0: could not find the root of the current workspace". | ||
return 1 | ||
fi | ||
done | ||
|
||
cd build | ||
|
||
OLD_FILES=$(find . -name "*.gcda") | ||
|
||
for FILE in $OLD_FILES; do | ||
echo "$0: removing old coverage file '$FILE'" | ||
rm $FILE | ||
done | ||
|
||
cd $ORIGINAL_PATH | ||
|
||
# build the package | ||
catkin build --this # it has to be fully built normally before building with --catkin-make-args tests | ||
catkin build --this --no-deps --catkin-make-args tests | ||
|
||
catkin test --this -i -p 1 -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | ||
trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR | ||
|
||
# build the package | ||
catkin build --this # it has to be fully built normally before building with --catkin-make-args tests | ||
catkin build --this --no-deps --catkin-make-args tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
get_filename_component(TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) | ||
|
||
catkin_add_executable_with_gtest(test_${TEST_NAME} | ||
test.cpp | ||
) | ||
|
||
target_link_libraries(test_${TEST_NAME} | ||
${catkin_LIBRARIES} | ||
) | ||
|
||
add_dependencies(test_${TEST_NAME} | ||
${${PROJECT_NAME}_EXPORTED_TARGETS} | ||
${catkin_EXPORTED_TARGETS} | ||
) | ||
|
||
add_rostest(${TEST_NAME}.test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <mrs_uav_testing/test_generic.h> | ||
|
||
class Tester : public mrs_uav_testing::TestGeneric { | ||
|
||
public: | ||
Tester(); | ||
|
||
bool test(); | ||
}; | ||
|
||
Tester::Tester() : mrs_uav_testing::TestGeneric() { | ||
|
||
// create your own subscribers, publishers, etc here. | ||
// | ||
// check the mrs_uav_testing::TestGeneric for existing stuff | ||
// this->nh_ is available | ||
} | ||
|
||
bool Tester::test() { | ||
|
||
{ | ||
auto [success, message] = spawnGazeboUav(); | ||
|
||
if (!success) { | ||
ROS_ERROR("[%s]: gazebo UAV spawning failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); | ||
return false; | ||
} | ||
} | ||
|
||
// wait for the MRS system | ||
while (true) { | ||
|
||
ROS_INFO_THROTTLE(1.0, "[%s]: waiting for the MRS system", ros::this_node::getName().c_str()); | ||
|
||
if (!ros::ok()) { | ||
ROS_ERROR("[%s]: killed from outside", ros::this_node::getName().c_str()); | ||
return false; | ||
} | ||
|
||
if (this->mrsSystemReady()) { | ||
break; | ||
} | ||
} | ||
|
||
{ | ||
auto [success, message] = this->takeoff(); | ||
|
||
if (!success) { | ||
ROS_ERROR("[%s]: takeoff failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); | ||
return false; | ||
} | ||
} | ||
|
||
this->sleep(5.0); | ||
|
||
if (this->isFlyingNormally()) { | ||
return true; | ||
} else { | ||
ROS_ERROR("[%s]: not flying normally", ros::this_node::getName().c_str()); | ||
return false; | ||
} | ||
} | ||
|
||
// -------------------------------------------------------------- | ||
// | DO NOT MODIFY BELOW | | ||
// -------------------------------------------------------------- | ||
|
||
TEST(TESTSuite, test) { | ||
|
||
Tester tester; | ||
|
||
bool result = tester.test(); | ||
|
||
if (result) { | ||
GTEST_SUCCEED(); | ||
} else { | ||
GTEST_FAIL(); | ||
} | ||
} | ||
|
||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { | ||
|
||
ros::init(argc, argv, "test"); | ||
|
||
testing::InitGoogleTest(&argc, argv); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<launch> | ||
|
||
<arg name="this_path" default="$(dirname)" /> | ||
|
||
<arg name="UAV_NAME" default="uav1" /> | ||
<arg name="UAV_TYPE" default="x500" /> | ||
|
||
<!-- automatically deduce the test name --> | ||
<arg name="test_name" default="$(eval arg('this_path').split('/')[-1])" /> | ||
|
||
<!-- automatically deduce the package name --> | ||
<arg name="import_eval" default="eval('_' + '_import_' + '_')"/> | ||
<arg name="package_eval" default="eval(arg('import_eval') + '(\'rospkg\')').get_package_name(arg('this_path'))" /> | ||
<arg name="package" default="$(eval eval(arg('package_eval')))" /> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/gazebo_simulator.launch" /> | ||
|
||
<include file="$(find mrs_uav_px4_api)/launch/api.launch"> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
<arg name="RUN_TYPE" default="simulation" /> | ||
</include> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/mrs_uav_system.launch"> | ||
<arg name="automatic_start" default="true" /> | ||
<arg name="platform_config" default="$(find mrs_uav_gazebo_simulation)/config/mrs_uav_system/$(arg UAV_TYPE).yaml" /> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
</include> | ||
|
||
<test pkg="$(arg package)" type="test_$(arg test_name)" test-name="$(arg test_name)" time-limit="120.0"> | ||
<param name="test_name" value="$(arg test_name)" /> | ||
<param name="uav_name" value="$(arg UAV_NAME)" /> | ||
<param name="gazebo_spawner_params" value="1 --$(arg UAV_TYPE) --enable-rangefinder" /> | ||
</test> | ||
|
||
</launch> |