diff --git a/Migration.md b/Migration.md index ab87e91c01..30fded54d3 100644 --- a/Migration.md +++ b/Migration.md @@ -24,6 +24,9 @@ in SDF by setting the `` SDF element. std::string(const gazebo::Entity &, const sdf::Sensor &, const std::string &)>)` +* Log playback using `` 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. diff --git a/src/ServerConfig.cc b/src/ServerConfig.cc index beee1e2ba4..b7dd413cb6 100644 --- a/src/ServerConfig.cc +++ b/src/ServerConfig.cc @@ -572,9 +572,9 @@ ServerConfig::LogPlaybackPlugin() const if (!this->LogPlaybackPath().empty()) { sdf::ElementPtr pathElem = std::make_shared(); - 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(this->LogPlaybackPath()); } diff --git a/src/systems/log/LogPlayback.cc b/src/systems/log/LogPlayback.cc index c061bbe997..e7b557e44d 100644 --- a/src/systems/log/LogPlayback.cc +++ b/src/systems/log/LogPlayback.cc @@ -183,7 +183,7 @@ void LogPlayback::Configure(const Entity &, EntityComponentManager &_ecm, EventManager &_eventMgr) { // Get directory paths from SDF - this->dataPtr->logPath = _sdf->Get("path"); + this->dataPtr->logPath = _sdf->Get("playback_path"); this->dataPtr->eventManager = &_eventMgr; diff --git a/test/integration/log_system.cc b/test/integration/log_system.cc index 06dc2b62e7..205ff31a16 100644 --- a/test/integration/log_system.cc +++ b/test/integration/log_system.cc @@ -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 @@ -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"); }; ///////////////////////////////////////////////// @@ -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("")); @@ -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); @@ -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}; @@ -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); @@ -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 @@ -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); @@ -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 @@ -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 @@ -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)")); @@ -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); @@ -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); diff --git a/test/worlds/log_playback.sdf b/test/worlds/log_playback.sdf index 4ad6985c1a..b46b04d357 100644 --- a/test/worlds/log_playback.sdf +++ b/test/worlds/log_playback.sdf @@ -7,8 +7,6 @@ - - /tmp/log diff --git a/tutorials/log.md b/tutorials/log.md index 4a69e41eef..09423fa8a7 100644 --- a/tutorials/log.md +++ b/tutorials/log.md @@ -96,6 +96,11 @@ directory specified to record: `ign gazebo -r -v 4 --playback ` +### From plugin in SDF + +Playing back via the SDF tag `` has been removed. +Please use the command line argument. + ## Known issues * When using command-line playback there is currently a small caveat.