Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission tests: kill LRAUV application after enough iterations #122

Merged
merged 4 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lrauv_ignition_plugins/test/test_mission_depth_vbs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ", {"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lrauv_ignition_plugins/test/test_mission_pitch_mass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 6 additions & 5 deletions lrauv_ignition_plugins/test/test_mission_yoyo_circle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(this->dt).count();
ASSERT_LT(0.0, dtSec);
Expand Down
9 changes: 8 additions & 1 deletion lrauv_ignition_plugins/test/test_state_msg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down