diff --git a/lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh b/lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh index 6c1e9ddc..a1cf9498 100644 --- a/lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh +++ b/lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh @@ -204,33 +204,44 @@ class LrauvTestFixture : public ::testing::Test } char buffer[512]; - while (!feof(pipe)) + while (fgets(buffer, 512, pipe) != nullptr) { - if (fgets(buffer, 512, pipe) != nullptr) + igndbg << "CMD OUTPUT: " << buffer << std::endl; + + // FIXME: LRAUV app hangs after quit, so force close it + // See https://github.com/osrf/lrauv/issues/83 + std::string bufferStr{buffer}; + + std::string error{"ERROR"}; + std::string critical{"CRITICAL"}; + if (bufferStr.find(error) != std::string::npos || + bufferStr.find(critical) != std::string::npos) + { + ignerr << buffer << "\n"; + } + + std::string quit{"Stop Mission called by Supervisor::terminate\n"}; + if (bufferStr.find(quit) != std::string::npos) { - igndbg << "CMD OUTPUT: " << buffer << std::endl; - - // FIXME: LRAUV app hangs after quit, so force close it - // See https://github.com/osrf/lrauv/issues/83 - std::string bufferStr{buffer}; - - std::string error{"ERROR"}; - std::string critical{"CRITICAL"}; - if (bufferStr.find(error) != std::string::npos || - bufferStr.find(critical) != std::string::npos) - { - ignerr << buffer << "\n"; - } - - std::string quit{"Stop Mission called by Supervisor::terminate\n"}; - if (bufferStr.find(quit) != std::string::npos) - { - ignmsg << "Quitting application" << std::endl; - break; - } + ignmsg << "Quitting application" << std::endl; + break; } } + KillLRAUV(); + + pclose(pipe); + + ignmsg << "Completed command [" << cmd << "]" << std::endl; + + _running = false; + } + + /// \brief Kill all LRAUV processes. + /// \return True if some process was killed. + public: static bool KillLRAUV() + { + bool killed{false}; for (auto process : {"sh.*bin/LRAUV", "bin/LRAUV"}) { auto pid = GetPID(process); @@ -243,13 +254,9 @@ class LrauvTestFixture : public ::testing::Test ignmsg << "Killing process [" << process << "] with pid [" << pid << "]" << std::endl; kill(pid, 9); + killed = true; } - - pclose(pipe); - - ignmsg << "Completed command [" << cmd << "]" << std::endl; - - _running = false; + return killed; } /// \brief How many times has OnPostUpdate been run diff --git a/lrauv_ignition_plugins/test/test_mission_depth_vbs.cc b/lrauv_ignition_plugins/test/test_mission_depth_vbs.cc index 11d09f7f..850f7477 100644 --- a/lrauv_ignition_plugins/test/test_mission_depth_vbs.cc +++ b/lrauv_ignition_plugins/test/test_mission_depth_vbs.cc @@ -53,25 +53,26 @@ TEST_F(LrauvTestFixture, DepthVBS) lrauvRunning); }); + // Run enough iterations (chosen empirically) to reach steady state, then kill + // the controller + int targetIterations{28000}; int maxSleep{100}; int sleep{0}; - for (; sleep < maxSleep && lrauvRunning; ++sleep) + for (; sleep < maxSleep && lrauvRunning && this->iterations < targetIterations; ++sleep) { igndbg << "Ran [" << this->iterations << "] iterations." << std::endl; std::this_thread::sleep_for(1s); } EXPECT_LT(sleep, maxSleep); - EXPECT_FALSE(lrauvRunning); + ASSERT_LT(targetIterations, this->tethysPoses.size()); + LrauvTestFixture::KillLRAUV(); lrauvThread.join(); ignmsg << "Logged [" << this->tethysPoses.size() << "] poses" << std::endl; - int maxIterations{28000}; - ASSERT_LT(maxIterations, this->tethysPoses.size()); - // Uncomment to get new expectations - // for (int i = 2000; i <= maxIterations; i += 2000) + // for (int i = 2000; i <= targetIterations; i += 2000) // { // auto pose = this->tethysPoses[i]; // std::cout << "this->CheckRange(" << i << ", {" diff --git a/lrauv_ignition_plugins/test/test_mission_pitch_and_depth_mass_vbs.cc b/lrauv_ignition_plugins/test/test_mission_pitch_and_depth_mass_vbs.cc index 267932b7..a5700a92 100644 --- a/lrauv_ignition_plugins/test/test_mission_pitch_and_depth_mass_vbs.cc +++ b/lrauv_ignition_plugins/test/test_mission_pitch_and_depth_mass_vbs.cc @@ -53,23 +53,24 @@ TEST_F(LrauvTestFixture, PitchDepthVBS) lrauvRunning); }); + // Run enough iterations (chosen empirically) to reach steady state, then kill + // the controller + int targetIterations{28000}; int maxSleep{100}; int sleep{0}; - for (; sleep < maxSleep && lrauvRunning; ++sleep) + for (; sleep < maxSleep && lrauvRunning && this->iterations < targetIterations; ++sleep) { igndbg << "Ran [" << this->iterations << "] iterations." << std::endl; std::this_thread::sleep_for(1s); } EXPECT_LT(sleep, maxSleep); - EXPECT_FALSE(lrauvRunning); + EXPECT_LT(targetIterations, this->tethysPoses.size()); + LrauvTestFixture::KillLRAUV(); lrauvThread.join(); ignmsg << "Logged [" << this->tethysPoses.size() << "] poses" << std::endl; - int maxIterations{28000}; - ASSERT_LT(maxIterations, this->tethysPoses.size()); - bool targetReached = false, firstSample = true; double prev_z = 0, totalDepthChange = 0; // Vehicle should sink to 10 meters and hold there diff --git a/lrauv_ignition_plugins/test/test_mission_pitch_mass.cc b/lrauv_ignition_plugins/test/test_mission_pitch_mass.cc index d9386981..7e8d6b3b 100644 --- a/lrauv_ignition_plugins/test/test_mission_pitch_mass.cc +++ b/lrauv_ignition_plugins/test/test_mission_pitch_mass.cc @@ -58,23 +58,24 @@ TEST_F(LrauvTestFixture, PitchMass) lrauvRunning); }); + // Run enough iterations (chosen empirically) to reach steady state, then kill + // the controller + int targetIterations{28000}; int maxSleep{100}; int sleep{0}; - for (; sleep < maxSleep && lrauvRunning; ++sleep) + for (; sleep < maxSleep && lrauvRunning && this->iterations < targetIterations; ++sleep) { igndbg << "Ran [" << this->iterations << "] iterations." << std::endl; std::this_thread::sleep_for(1s); } EXPECT_LT(sleep, maxSleep); - EXPECT_FALSE(lrauvRunning); + EXPECT_LT(targetIterations, this->tethysPoses.size()); + LrauvTestFixture::KillLRAUV(); lrauvThread.join(); ignmsg << "Logged [" << this->tethysPoses.size() << "] poses" << std::endl; - int maxIterations{28000}; - EXPECT_LT(maxIterations, this->tethysPoses.size()); - // Give it some iterations to reach steady state for (auto i = 2000u; i < this->tethysPoses.size(); i = i + 1000) { diff --git a/lrauv_ignition_plugins/test/test_mission_yoyo_circle.cc b/lrauv_ignition_plugins/test/test_mission_yoyo_circle.cc index ae3c1632..a18d937d 100644 --- a/lrauv_ignition_plugins/test/test_mission_yoyo_circle.cc +++ b/lrauv_ignition_plugins/test/test_mission_yoyo_circle.cc @@ -61,23 +61,24 @@ TEST_F(LrauvTestFixture, YoYoCircle) lrauvRunning); }); + // Run enough iterations (chosen empirically) to reach steady state, then kill + // the controller + int targetIterations{28000}; int maxSleep{100}; int sleep{0}; - for (; sleep < maxSleep && lrauvRunning; ++sleep) + for (; sleep < maxSleep && lrauvRunning && this->iterations < targetIterations; ++sleep) { igndbg << "Ran [" << this->iterations << "] iterations." << std::endl; std::this_thread::sleep_for(1s); } EXPECT_LT(sleep, maxSleep); - EXPECT_FALSE(lrauvRunning); + EXPECT_LT(targetIterations, this->tethysPoses.size()); + LrauvTestFixture::KillLRAUV(); lrauvThread.join(); ignmsg << "Logged [" << this->tethysPoses.size() << "] poses" << std::endl; - int minIterations{28000}; - ASSERT_LT(minIterations, this->tethysPoses.size()); - // Check bounds double dtSec = std::chrono::duration(this->dt).count(); ASSERT_LT(0.0, dtSec); diff --git a/lrauv_ignition_plugins/test/test_state_msg.cc b/lrauv_ignition_plugins/test/test_state_msg.cc index 1e968fb3..db9ba6c8 100644 --- a/lrauv_ignition_plugins/test/test_state_msg.cc +++ b/lrauv_ignition_plugins/test/test_state_msg.cc @@ -28,13 +28,20 @@ #include "lrauv_state.pb.h" ////////////////////////////////////////////////// -TEST_F(LrauvTestFixture, Command) +TEST_F(LrauvTestFixture, State) { // TODO(chapulina) Test other fields, see // https://github.com/osrf/lrauv/pull/81 // Initial state this->fixture->Server()->Run(true, 100, false); + int maxSleep{100}; + int sleep{0}; + for (; sleep < maxSleep && this->stateMsgs.size() < 100; ++sleep) + { + std::this_thread::sleep_for(100ms); + } + EXPECT_LT(sleep, maxSleep); EXPECT_EQ(100, this->stateMsgs.size()); auto latest = this->stateMsgs.back();