Skip to content

Commit

Permalink
Merge branch 'ign-gazebo4' into gonzodepedro/world_exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Koenig committed Jan 29, 2021
2 parents e44a66e + 59ea1c6 commit 7ea379d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 60 deletions.
3 changes: 3 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ in SDF by setting the `<visual><material><double_sided>` SDF element.
std::string(const gazebo::Entity &,
const sdf::Sensor &, const std::string &)>)`

* Log playback using `<path>` SDF parameter is removed. Use --playback command
line argument instead.

## Ignition Gazebo 2.x to 3.x

* Use ign-rendering3, ign-sensors3 and ign-gui3.
Expand Down
4 changes: 2 additions & 2 deletions src/ServerConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ ServerConfig::LogPlaybackPlugin() const
if (!this->LogPlaybackPath().empty())
{
sdf::ElementPtr pathElem = std::make_shared<sdf::Element>();
pathElem->SetName("path");
pathElem->SetName("playback_path");
playbackElem->AddElementDescription(pathElem);
pathElem = playbackElem->GetElement("path");
pathElem = playbackElem->GetElement("playback_path");
pathElem->AddValue("string", "", false, "");
pathElem->Set<std::string>(this->LogPlaybackPath());
}
Expand Down
2 changes: 1 addition & 1 deletion src/systems/log/LogPlayback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void LogPlayback::Configure(const Entity &,
EntityComponentManager &_ecm, EventManager &_eventMgr)
{
// Get directory paths from SDF
this->dataPtr->logPath = _sdf->Get<std::string>("path");
this->dataPtr->logPath = _sdf->Get<std::string>("playback_path");

this->dataPtr->eventManager = &_eventMgr;

Expand Down
85 changes: 30 additions & 55 deletions test/integration/log_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class LogSystemTest : public ::testing::Test
common::removeAll(this->logsDir);
}
common::createDirectories(this->logsDir);
common::createDirectories(this->logPlaybackDir);
}

// Append extension to the end of a path, removing the separator at
Expand Down Expand Up @@ -266,10 +265,6 @@ class LogSystemTest : public ::testing::Test
/// \brief Path to recorded log file
public: std::string logDir = common::joinPaths(logsDir,
"test_logs_record");

/// \brief Path to log file for playback
public: std::string logPlaybackDir =
common::joinPaths(this->logsDir, "test_logs_playback");
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -341,16 +336,16 @@ TEST_F(LogSystemTest, LogDefaults)
EXPECT_EQ(setenv(IGN_HOMEDIR, homeFake.c_str(), 1), 0);

// Test case 1:
// No path specified, on both command line and SDF. This does not go through
// No path specified on command line. This does not go through
// ign.cc, so ignLogDirectory() is not initialized (empty string). Recording
// should not take place.
{
// Change log path in SDF to empty
// Load SDF
sdf::Root recordSdfRoot;
this->ChangeLogPath(recordSdfRoot, recordSdfPath, "LogRecord",
" ");
EXPECT_EQ(recordSdfRoot.Load(recordSdfPath).size(), 0lu);
EXPECT_GT(recordSdfRoot.WorldCount(), 0lu);

// Pass changed SDF to server
// Pass SDF to server
ServerConfig recordServerConfig;
recordServerConfig.SetSdfString(recordSdfRoot.Element()->ToString(""));

Expand Down Expand Up @@ -743,25 +738,17 @@ TEST_F(LogSystemTest, RecordAndPlayback)
auto logFile = common::joinPaths(this->logDir, "state.tlog");
EXPECT_TRUE(common::exists(logFile));

// move the log file to the playback directory
auto logPlaybackFile = common::joinPaths(this->logPlaybackDir, "state.tlog");
// Path to log file for playback
std::string logPlaybackDir =
common::joinPaths(this->logsDir, "test_logs_playback");
common::createDirectories(logPlaybackDir);

// Move the log file to the playback directory
auto logPlaybackFile = common::joinPaths(logPlaybackDir, "state.tlog");
common::moveFile(logFile, logPlaybackFile);
EXPECT_TRUE(common::exists(logPlaybackFile));

// World file to load
const auto playSdfPath = common::joinPaths(std::string(PROJECT_SOURCE_PATH),
"test", "worlds", "log_playback.sdf");

// Change log path in world SDF to build directory
sdf::Root playSdfRoot;
this->ChangeLogPath(playSdfRoot, playSdfPath, "LogPlayback",
this->logPlaybackDir);
ASSERT_EQ(1u, playSdfRoot.WorldCount());

const auto sdfWorld = playSdfRoot.WorldByIndex(0);
EXPECT_EQ("default", sdfWorld->Name());

// Load log file recorded above
// Load log file recorded above for validation
transport::log::Log log;
log.Open(logPlaybackFile);

Expand Down Expand Up @@ -794,10 +781,6 @@ TEST_F(LogSystemTest, RecordAndPlayback)
EXPECT_EQ(32, stateMsg.entities_size());
EXPECT_EQ(batch.end(), ++recordedIter);

// Pass changed SDF to server
ServerConfig playServerConfig;
playServerConfig.SetSdfString(playSdfRoot.Element()->ToString(""));

// Keep track of total number of pose comparisons
int nTotal{0};

Expand All @@ -818,6 +801,10 @@ TEST_F(LogSystemTest, RecordAndPlayback)
EXPECT_EQ(0, recordedMsg.header().stamp().sec());
EXPECT_EQ(1000000, recordedMsg.header().stamp().nsec());

// Playback config
ServerConfig playServerConfig;
playServerConfig.SetLogPlaybackPath(logPlaybackDir);

// Start server
Server playServer(playServerConfig);

Expand Down Expand Up @@ -1026,7 +1013,7 @@ TEST_F(LogSystemTest, LogOverwrite)
// Create temp directory to store log
this->CreateLogsDir();
#ifndef __APPLE__
EXPECT_EQ(1, entryCount(this->logsDir));
EXPECT_EQ(0, entryCount(this->logsDir));
EXPECT_EQ(0, entryCount(this->logDir));
#endif

Expand Down Expand Up @@ -1062,7 +1049,7 @@ TEST_F(LogSystemTest, LogOverwrite)

#ifndef __APPLE__
// Log files were created
EXPECT_EQ(2, entryCount(this->logsDir));
EXPECT_EQ(1, entryCount(this->logsDir));
EXPECT_EQ(2, entryCount(this->logDir));
std::filesystem::path tlogStdPath = tlogPath;
auto tlogPrevTime = std::filesystem::last_write_time(tlogStdPath);
Expand All @@ -1088,7 +1075,7 @@ TEST_F(LogSystemTest, LogOverwrite)

#ifndef __APPLE__
// No new files were created
EXPECT_EQ(2, entryCount(this->logsDir));
EXPECT_EQ(1, entryCount(this->logsDir));
EXPECT_EQ(2, entryCount(this->logDir));

// Test timestamp is newer
Expand Down Expand Up @@ -1116,7 +1103,7 @@ TEST_F(LogSystemTest, LogOverwrite)
EXPECT_TRUE(common::exists(clogPath));

// No new files were created
EXPECT_EQ(2, entryCount(this->logsDir));
EXPECT_EQ(1, entryCount(this->logsDir));
EXPECT_EQ(2, entryCount(this->logDir));

// Test timestamp is newer
Expand Down Expand Up @@ -1158,7 +1145,7 @@ TEST_F(LogSystemTest, LogOverwrite)
"server_console.log")));

// New files were created
EXPECT_EQ(3, entryCount(this->logsDir));
EXPECT_EQ(2, entryCount(this->logsDir));
EXPECT_EQ(2, entryCount(this->logDir));
EXPECT_EQ(2, entryCount(this->logDir + "(1)"));

Expand All @@ -1175,16 +1162,8 @@ TEST_F(LogSystemTest, LogControlLevels)
auto logPath = common::joinPaths(PROJECT_SOURCE_PATH, "test", "media",
"levels_log");

const auto playSdfPath = common::joinPaths(std::string(PROJECT_SOURCE_PATH),
"test", "worlds", "log_playback.sdf");

// Change log path in world SDF to build directory
sdf::Root playSdfRoot;
this->ChangeLogPath(playSdfRoot, playSdfPath, "LogPlayback",
logPath);

ServerConfig config;
config.SetSdfString(playSdfRoot.Element()->ToString(""));
config.SetLogPlaybackPath(logPath);

Server server(config);

Expand Down Expand Up @@ -1390,29 +1369,25 @@ TEST_F(LogSystemTest, LogCompress)
// Test compressed file exists
EXPECT_TRUE(common::exists(customCmpPath));

// Path to log file for playback
std::string logPlaybackDir =
common::joinPaths(this->logsDir, "test_logs_playback");
common::createDirectories(logPlaybackDir);

// Move recorded file to playback directory
// Prefix the zip by the name of the original recorded folder. Playback will
// extract and assume subdirectory to take on the name of the zip file
// without extension.
auto newCmpPath = common::joinPaths(this->logPlaybackDir,
auto newCmpPath = common::joinPaths(logPlaybackDir,
common::basename(defaultCmpPath));
common::moveFile(customCmpPath, newCmpPath);
EXPECT_TRUE(common::exists(newCmpPath));

// Play back compressed file
{
// World with playback plugin
const auto playSdfPath = common::joinPaths(std::string(PROJECT_SOURCE_PATH),
"test", "worlds", "log_playback.sdf");

// Change log path in world SDF to build directory
sdf::Root playSdfRoot;
this->ChangeLogPath(playSdfRoot, playSdfPath, "LogPlayback",
newCmpPath);

// Pass changed SDF to server
ServerConfig playServerConfig;
playServerConfig.SetSdfString(playSdfRoot.Element()->ToString(""));
playServerConfig.SetLogPlaybackPath(newCmpPath);

// Run server
Server playServer(playServerConfig);
Expand Down
2 changes: 0 additions & 2 deletions test/worlds/log_playback.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<plugin
filename='ignition-gazebo-log-system'
name='ignition::gazebo::systems::LogPlayback'>
<!-- Will be automatically changed in integration test. -->
<path>/tmp/log</path>
</plugin>
</world>
</sdf>
Expand Down
5 changes: 5 additions & 0 deletions tutorials/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ directory specified to record:

`ign gazebo -r -v 4 --playback <path>`

### From plugin in SDF

Playing back via the SDF tag `<path>` has been removed.
Please use the command line argument.

## Known issues

* When using command-line playback there is currently a small caveat.
Expand Down

0 comments on commit 7ea379d

Please sign in to comment.