diff --git a/test/control_manager/CMakeLists.txt b/test/control_manager/CMakeLists.txt index 80faabe..a5f8119 100644 --- a/test/control_manager/CMakeLists.txt +++ b/test/control_manager/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory(goto_service) +add_subdirectory(goto_relative_service) + add_subdirectory(eland_control_error) add_subdirectory(eland_innovation) @@ -29,3 +31,9 @@ add_subdirectory(set_heading_relative_service) add_subdirectory(goto_altitude_service) add_subdirectory(hover_service) + +add_subdirectory(reference_service) + +add_subdirectory(reference_service_local_origin) + +add_subdirectory(reference_topic) diff --git a/test/control_manager/goto_relative_service/CMakeLists.txt b/test/control_manager/goto_relative_service/CMakeLists.txt new file mode 100644 index 0000000..bf8f985 --- /dev/null +++ b/test/control_manager/goto_relative_service/CMakeLists.txt @@ -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) diff --git a/test/control_manager/goto_relative_service/goto_relative_service.test b/test/control_manager/goto_relative_service/goto_relative_service.test new file mode 100644 index 0000000..604b743 --- /dev/null +++ b/test/control_manager/goto_relative_service/goto_relative_service.test @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/control_manager/goto_relative_service/test.cpp b/test/control_manager/goto_relative_service/test.cpp new file mode 100644 index 0000000..dfd66be --- /dev/null +++ b/test/control_manager/goto_relative_service/test.cpp @@ -0,0 +1,74 @@ +#include + +#include + +class Tester : public mrs_uav_testing::TestGeneric { + +public: + bool test(); +}; + +bool Tester::test() { + + std::shared_ptr uh; + + { + auto [uhopt, message] = getUAVHandler(_uav_name_); + + if (!uhopt) { + ROS_ERROR("[%s]: Failed obtain handler for '%s': '%s'", ros::this_node::getName().c_str(), _uav_name_.c_str(), message.c_str()); + return false; + } + + uh = uhopt.value(); + } + + { + auto [success, message] = uh->activateMidAir(); + + if (!success) { + ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + { + auto [success, message] = uh->gotoRel(5, 10, 2.0, 1.2); + + if (!success) { + ROS_ERROR("[%s]: goto relative failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + this->sleep(5.0); + + if (uh->isFlyingNormally()) { + return true; + } else { + ROS_ERROR("[%s]: not flying normally", ros::this_node::getName().c_str()); + return false; + } +} + +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(); +} diff --git a/test/control_manager/goto_service/test.cpp b/test/control_manager/goto_service/test.cpp index f3c6d7b..2eec814 100644 --- a/test/control_manager/goto_service/test.cpp +++ b/test/control_manager/goto_service/test.cpp @@ -51,7 +51,6 @@ bool Tester::test() { } } - TEST(TESTSuite, test) { Tester tester; diff --git a/test/control_manager/reference_service/CMakeLists.txt b/test/control_manager/reference_service/CMakeLists.txt new file mode 100644 index 0000000..bf8f985 --- /dev/null +++ b/test/control_manager/reference_service/CMakeLists.txt @@ -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) diff --git a/test/control_manager/reference_service/reference_service.test b/test/control_manager/reference_service/reference_service.test new file mode 100644 index 0000000..604b743 --- /dev/null +++ b/test/control_manager/reference_service/reference_service.test @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/control_manager/reference_service/test.cpp b/test/control_manager/reference_service/test.cpp new file mode 100644 index 0000000..90e9e53 --- /dev/null +++ b/test/control_manager/reference_service/test.cpp @@ -0,0 +1,74 @@ +#include + +#include + +class Tester : public mrs_uav_testing::TestGeneric { + +public: + bool test(); +}; + +bool Tester::test() { + + std::shared_ptr uh; + + { + auto [uhopt, message] = getUAVHandler(_uav_name_); + + if (!uhopt) { + ROS_ERROR("[%s]: Failed obtain handler for '%s': '%s'", ros::this_node::getName().c_str(), _uav_name_.c_str(), message.c_str()); + return false; + } + + uh = uhopt.value(); + } + + { + auto [success, message] = uh->activateMidAir(); + + if (!success) { + ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + { + auto [success, message] = uh->gotoReference(0, 0, 2.0, 0, ""); + + if (!success) { + ROS_ERROR("[%s]: goto reference failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + this->sleep(5.0); + + if (uh->isFlyingNormally()) { + return true; + } else { + ROS_ERROR("[%s]: not flying normally", ros::this_node::getName().c_str()); + return false; + } +} + +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(); +} diff --git a/test/control_manager/reference_service_local_origin/CMakeLists.txt b/test/control_manager/reference_service_local_origin/CMakeLists.txt new file mode 100644 index 0000000..bf8f985 --- /dev/null +++ b/test/control_manager/reference_service_local_origin/CMakeLists.txt @@ -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) diff --git a/test/control_manager/reference_service_local_origin/reference_service_local_origin.test b/test/control_manager/reference_service_local_origin/reference_service_local_origin.test new file mode 100644 index 0000000..604b743 --- /dev/null +++ b/test/control_manager/reference_service_local_origin/reference_service_local_origin.test @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/control_manager/reference_service_local_origin/test.cpp b/test/control_manager/reference_service_local_origin/test.cpp new file mode 100644 index 0000000..73ce9d3 --- /dev/null +++ b/test/control_manager/reference_service_local_origin/test.cpp @@ -0,0 +1,74 @@ +#include + +#include + +class Tester : public mrs_uav_testing::TestGeneric { + +public: + bool test(); +}; + +bool Tester::test() { + + std::shared_ptr uh; + + { + auto [uhopt, message] = getUAVHandler(_uav_name_); + + if (!uhopt) { + ROS_ERROR("[%s]: Failed obtain handler for '%s': '%s'", ros::this_node::getName().c_str(), _uav_name_.c_str(), message.c_str()); + return false; + } + + uh = uhopt.value(); + } + + { + auto [success, message] = uh->activateMidAir(); + + if (!success) { + ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + { + auto [success, message] = uh->gotoReference(3.2, -1.3, 1.2, -2.3, _uav_name_ + "/local_origin"); + + if (!success) { + ROS_ERROR("[%s]: goto reference failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + this->sleep(5.0); + + if (uh->isFlyingNormally()) { + return true; + } else { + ROS_ERROR("[%s]: not flying normally", ros::this_node::getName().c_str()); + return false; + } +} + +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(); +} diff --git a/test/control_manager/reference_topic/CMakeLists.txt b/test/control_manager/reference_topic/CMakeLists.txt new file mode 100644 index 0000000..bf8f985 --- /dev/null +++ b/test/control_manager/reference_topic/CMakeLists.txt @@ -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) diff --git a/test/control_manager/reference_topic/reference_topic.test b/test/control_manager/reference_topic/reference_topic.test new file mode 100644 index 0000000..604b743 --- /dev/null +++ b/test/control_manager/reference_topic/reference_topic.test @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/control_manager/reference_topic/test.cpp b/test/control_manager/reference_topic/test.cpp new file mode 100644 index 0000000..04f88f9 --- /dev/null +++ b/test/control_manager/reference_topic/test.cpp @@ -0,0 +1,74 @@ +#include + +#include + +class Tester : public mrs_uav_testing::TestGeneric { + +public: + bool test(); +}; + +bool Tester::test() { + + std::shared_ptr uh; + + { + auto [uhopt, message] = getUAVHandler(_uav_name_); + + if (!uhopt) { + ROS_ERROR("[%s]: Failed obtain handler for '%s': '%s'", ros::this_node::getName().c_str(), _uav_name_.c_str(), message.c_str()); + return false; + } + + uh = uhopt.value(); + } + + { + auto [success, message] = uh->activateMidAir(); + + if (!success) { + ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + { + auto [success, message] = uh->gotoReferenceTopic(0, 0, 2.0, 0, ""); + + if (!success) { + ROS_ERROR("[%s]: goto reference failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + this->sleep(5.0); + + if (uh->isFlyingNormally()) { + return true; + } else { + ROS_ERROR("[%s]: not flying normally", ros::this_node::getName().c_str()); + return false; + } +} + +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(); +} diff --git a/test/run_tests.sh b/test/run_tests.sh index 6f0fb27..e9646fb 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -5,4 +5,4 @@ set -e trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR -catkin test --this -i -p 1 -s +catkin test --this -i -s