From cdf0edbe50d11e74704248772d13bbdc3495b60a Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Tue, 4 Jun 2024 16:33:14 -0400 Subject: [PATCH 1/3] add test: SubjuGator can spawn in Gazebo --- .../subjugator_gazebo/CMakeLists.txt | 11 +++++++- .../simulation/subjugator_gazebo/package.xml | 1 + .../subjugator_gazebo/test/spawn_test.cpp | 24 +++++++++++++++++ .../test/subjugator_gazebo.test | 7 +++++ .../mil_tools/include/mil_tools/test.hpp | 26 +++++++++++++++++++ .../mil_tools/src/mil_tools/mil_tools.cpp | 1 + 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp create mode 100644 SubjuGator/simulation/subjugator_gazebo/test/subjugator_gazebo.test create mode 100644 mil_common/utils/mil_tools/include/mil_tools/test.hpp diff --git a/SubjuGator/simulation/subjugator_gazebo/CMakeLists.txt b/SubjuGator/simulation/subjugator_gazebo/CMakeLists.txt index 935d9f892..26cd29dae 100644 --- a/SubjuGator/simulation/subjugator_gazebo/CMakeLists.txt +++ b/SubjuGator/simulation/subjugator_gazebo/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(catkin rospy gazebo_ros roscpp + mil_tools message_generation xacro) catkin_python_setup() @@ -107,7 +108,7 @@ target_link_libraries( catkin_package( INCLUDE_DIRS include LIBRARIES subjugator_buoyancy subjugator_thrusters subjugator_state_set subjugator_liftdrag - CATKIN_DEPENDS gazebo_ros roscpp rospy std_msgs message_runtime + CATKIN_DEPENDS gazebo_ros roscpp rospy std_msgs message_runtime mil_tools DEPENDS ) @@ -119,3 +120,11 @@ xacro_add_files( INSTALL DESTINATION urdf TARGET xacro_urdf ) + +if(CATKIN_ENABLE_TESTING) + find_package(rostest REQUIRED) + add_rostest_gtest(subjugator_gazebo_spawn_test + test/subjugator_gazebo.test + test/spawn_test.cpp) + target_link_libraries(subjugator_gazebo_spawn_test ${catkin_LIBRARIES}) +endif() diff --git a/SubjuGator/simulation/subjugator_gazebo/package.xml b/SubjuGator/simulation/subjugator_gazebo/package.xml index 783516591..8f3ac6154 100644 --- a/SubjuGator/simulation/subjugator_gazebo/package.xml +++ b/SubjuGator/simulation/subjugator_gazebo/package.xml @@ -15,6 +15,7 @@ std_msgs subjugator_msgs xacro + mil_tools message_runtime message_runtime MIT diff --git a/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp b/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp new file mode 100755 index 000000000..f9f1b1ead --- /dev/null +++ b/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp @@ -0,0 +1,24 @@ +/** + * Author: Cameron Brown + * Date: June 1, 2024 + */ +#include +#include + +#include + +using namespace mil_tools; + +// Ensure that at least sub8 or sub9 shows up when launching gazebo +TEST(SpawnTest, spawnTest) +{ + ros::NodeHandle nh; + EXPECT_TRUE(mil_tools::gazeboModelExists(nh, "sub8") || mil_tools::gazeboModelExists(nh, "sub8_no_cams") || mil_tools::gazeboModelExists(nh, "sub9")); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + ros::init(argc, argv, "subjugator_gazebo_spawn_test"); + return RUN_ALL_TESTS(); +} diff --git a/SubjuGator/simulation/subjugator_gazebo/test/subjugator_gazebo.test b/SubjuGator/simulation/subjugator_gazebo/test/subjugator_gazebo.test new file mode 100644 index 000000000..7cb9804d1 --- /dev/null +++ b/SubjuGator/simulation/subjugator_gazebo/test/subjugator_gazebo.test @@ -0,0 +1,7 @@ + + + + + + + diff --git a/mil_common/utils/mil_tools/include/mil_tools/test.hpp b/mil_common/utils/mil_tools/include/mil_tools/test.hpp new file mode 100644 index 000000000..2aa1daa55 --- /dev/null +++ b/mil_common/utils/mil_tools/include/mil_tools/test.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace mil_tools +{ +bool gazeboModelExists(ros::NodeHandle &nh, const std::string &_name, const ros::WallDuration _timeout = ros::WallDuration(5, 0)) +{ + ros::WallTime timeout = ros::WallTime::now() + _timeout; + while (ros::WallTime::now() < timeout) + { + gazebo_msgs::ModelStatesConstPtr modelStates = + ros::topic::waitForMessage(std::string("/gazebo/model_states"), nh, ros::Duration(0.3)); + + if (!modelStates) + continue; + for (auto model : modelStates->name) + { + if (model == _name) + return true; + } + } + return false; +} +} // namespace mil_tools diff --git a/mil_common/utils/mil_tools/src/mil_tools/mil_tools.cpp b/mil_common/utils/mil_tools/src/mil_tools/mil_tools.cpp index 015ba8b6e..12015e30a 100644 --- a/mil_common/utils/mil_tools/src/mil_tools/mil_tools.cpp +++ b/mil_common/utils/mil_tools/src/mil_tools/mil_tools.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace mil_tools { From d98c6c43ee1aa71e735435736e6b0a71443735ee Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Tue, 4 Jun 2024 16:37:46 -0400 Subject: [PATCH 2/3] Testing new checkout action --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 34d943fe2..e43d72d15 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: mkdir -p $GITHUB_WORKSPACE/catkin_ws/src sudo apt reinstall python3-pip - name: Check out code from GitHub - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v4 with: submodules: recursive path: catkin_ws/src/mil @@ -106,7 +106,7 @@ jobs: if: github.ref == 'refs/heads/master' steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Make folders run: | From c10b082df198c9df888222daea24c3fef48e68d6 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Tue, 4 Jun 2024 16:57:28 -0400 Subject: [PATCH 3/3] pre-commit changes --- .../simulation/subjugator_gazebo/package.xml | 2 +- .../subjugator_gazebo/test/spawn_test.cpp | 3 +- .../mil_tools/include/mil_tools/test.hpp | 9 ++-- scripts/setup.bash | 44 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) mode change 100755 => 100644 SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp diff --git a/SubjuGator/simulation/subjugator_gazebo/package.xml b/SubjuGator/simulation/subjugator_gazebo/package.xml index 8f3ac6154..204ec539d 100644 --- a/SubjuGator/simulation/subjugator_gazebo/package.xml +++ b/SubjuGator/simulation/subjugator_gazebo/package.xml @@ -10,12 +10,12 @@ geometry_msgs message_generation mil_gazebo + mil_tools roscpp rospy std_msgs subjugator_msgs xacro - mil_tools message_runtime message_runtime MIT diff --git a/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp b/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp old mode 100755 new mode 100644 index f9f1b1ead..79e962a10 --- a/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp +++ b/SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp @@ -13,7 +13,8 @@ using namespace mil_tools; TEST(SpawnTest, spawnTest) { ros::NodeHandle nh; - EXPECT_TRUE(mil_tools::gazeboModelExists(nh, "sub8") || mil_tools::gazeboModelExists(nh, "sub8_no_cams") || mil_tools::gazeboModelExists(nh, "sub9")); + EXPECT_TRUE(mil_tools::gazeboModelExists(nh, "sub8") || mil_tools::gazeboModelExists(nh, "sub8_no_cams") || + mil_tools::gazeboModelExists(nh, "sub9")); } int main(int argc, char **argv) diff --git a/mil_common/utils/mil_tools/include/mil_tools/test.hpp b/mil_common/utils/mil_tools/include/mil_tools/test.hpp index 2aa1daa55..c2bd685a5 100644 --- a/mil_common/utils/mil_tools/include/mil_tools/test.hpp +++ b/mil_common/utils/mil_tools/include/mil_tools/test.hpp @@ -1,17 +1,18 @@ #pragma once -#include #include +#include namespace mil_tools { -bool gazeboModelExists(ros::NodeHandle &nh, const std::string &_name, const ros::WallDuration _timeout = ros::WallDuration(5, 0)) +bool gazeboModelExists(ros::NodeHandle &nh, const std::string &_name, + const ros::WallDuration _timeout = ros::WallDuration(5, 0)) { ros::WallTime timeout = ros::WallTime::now() + _timeout; while (ros::WallTime::now() < timeout) { - gazebo_msgs::ModelStatesConstPtr modelStates = - ros::topic::waitForMessage(std::string("/gazebo/model_states"), nh, ros::Duration(0.3)); + gazebo_msgs::ModelStatesConstPtr modelStates = ros::topic::waitForMessage( + std::string("/gazebo/model_states"), nh, ros::Duration(0.3)); if (!modelStates) continue; diff --git a/scripts/setup.bash b/scripts/setup.bash index 929ed99bb..898809842 100755 --- a/scripts/setup.bash +++ b/scripts/setup.bash @@ -109,28 +109,28 @@ RED='\033[0;31m' # cm --> catkin_make --only-pkg-with-deps # cm --test --> catkin_make --only-pkg-with-deps run_tests cm() { - if [ $# -eq 0 ]; then - catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCATKIN_WHITELIST_PACKAGES="" -C "$MIL_WS" - mv "$MIL_WS/build/compile_commands.json" "$MIL_WS" - else - if [[ "$1" == "--test" ]]; then - catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 run_tests -C "$MIL_WS" - mv "$MIL_WS/build/compile_commands.json" "$MIL_WS" - elif [[ "$2" == "--test" ]]; then - # Build specific package then run tests - cd "$MIL_WS" || return - catkin_make --only-pkg-with-deps "$1" - catkin_make run_tests --only-pkg-with-deps "$1" -C "$MIL_WS" - cd - > /dev/null || exit - echo -e "${RED}!! Warning: Future calls to catkin_make will just build the '$1' package. To revert this, ensure you run 'cm' or 'cd $MIL_WS && catkin_make -DCATKIN_WHITELIST_PACKAGES=\"\"' when you want to recompile the entire repository.\e[0m" - else - # Build specific package - cd "$MIL_WS" || return - catkin_make --only-pkg-with-deps "$1" - cd - > /dev/null || exit - echo -e "${RED}!! Warning: Future calls to catkin_make will just build the '$1' package. To revert this, ensure you run 'cm' or 'cd $MIL_WS && catkin_make -DCATKIN_WHITELIST_PACKAGES=\"\"' when you want to recompile the entire repository.\e[0m" - fi - fi + if [ $# -eq 0 ]; then + catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCATKIN_WHITELIST_PACKAGES="" -C "$MIL_WS" + mv "$MIL_WS/build/compile_commands.json" "$MIL_WS" + else + if [[ $1 == "--test" ]]; then + catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1 run_tests -C "$MIL_WS" + mv "$MIL_WS/build/compile_commands.json" "$MIL_WS" + elif [[ $2 == "--test" ]]; then + # Build specific package then run tests + cd "$MIL_WS" || return + catkin_make --only-pkg-with-deps "$1" + catkin_make run_tests --only-pkg-with-deps "$1" -C "$MIL_WS" + cd - >/dev/null || exit + echo -e "${RED}!! Warning: Future calls to catkin_make will just build the '$1' package. To revert this, ensure you run 'cm' or 'cd $MIL_WS && catkin_make -DCATKIN_WHITELIST_PACKAGES=\"\"' when you want to recompile the entire repository.\e[0m" + else + # Build specific package + cd "$MIL_WS" || return + catkin_make --only-pkg-with-deps "$1" + cd - >/dev/null || exit + echo -e "${RED}!! Warning: Future calls to catkin_make will just build the '$1' package. To revert this, ensure you run 'cm' or 'cd $MIL_WS && catkin_make -DCATKIN_WHITELIST_PACKAGES=\"\"' when you want to recompile the entire repository.\e[0m" + fi + fi } alias xbox=startxbox