Skip to content

Commit

Permalink
Suggestions to #281 (#508)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Dec 23, 2020
1 parent e5a6992 commit e15b673
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 56 deletions.
2 changes: 1 addition & 1 deletion include/ignition/gazebo/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#define IGNITION_GAZEBO_GUI_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/gui"
#define IGNITION_GAZEBO_SYSTEM_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/systems"
#define IGNITION_GAZEBO_SERVER_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/"
#define IGNITION_GAZEBO_SERVER_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}"
#define IGN_GAZEBO_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
#define IGN_GAZEBO_GUI_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/gui"
#define IGN_GAZEBO_WORLD_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/worlds"
Expand Down
93 changes: 67 additions & 26 deletions src/ServerConfig_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace ignition;
using namespace gazebo;

//////////////////////////////////////////////////
TEST(parsePluginsFromString, valid)
TEST(ParsePluginsFromString, Valid)
{
std::string config = R"(
<server_config>
Expand Down Expand Up @@ -58,14 +58,30 @@ TEST(parsePluginsFromString, valid)
auto plugins = parsePluginsFromString(config);
ASSERT_EQ(3u, plugins.size());

EXPECT_EQ("default", plugins.begin()->EntityName());
EXPECT_EQ("world", plugins.begin()->EntityType());
EXPECT_EQ("TestWorldSystem", plugins.begin()->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugins.begin()->Name());
auto plugin = plugins.begin();

EXPECT_EQ("default", plugin->EntityName());
EXPECT_EQ("world", plugin->EntityType());
EXPECT_EQ("TestWorldSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugin->Name());

plugin = std::next(plugin, 1);

EXPECT_EQ("box", plugin->EntityName());
EXPECT_EQ("model", plugin->EntityType());
EXPECT_EQ("TestModelSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestModelSystem", plugin->Name());

plugin = std::next(plugin, 1);

EXPECT_EQ("default::box::link_1::camera", plugin->EntityName());
EXPECT_EQ("sensor", plugin->EntityType());
EXPECT_EQ("TestSensorSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestSensorSystem", plugin->Name());
}

//////////////////////////////////////////////////
TEST(parsePluginsFromString, invalid)
TEST(ParsePluginsFromString, Invalid)
{
std::string config = R"(
<server_config>
Expand All @@ -86,25 +102,41 @@ TEST(parsePluginsFromString, invalid)
}

//////////////////////////////////////////////////
TEST(parsePluginsFromFile, valid)
TEST(ParsePluginsFromFile, Valid)
{
auto config = common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/server_valid.config");
"test", "worlds", "server_valid.config");

auto plugins = parsePluginsFromFile(config);
ASSERT_EQ(3u, plugins.size());

EXPECT_EQ("default", plugins.begin()->EntityName());
EXPECT_EQ("world", plugins.begin()->EntityType());
EXPECT_EQ("TestWorldSystem", plugins.begin()->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugins.begin()->Name());
auto plugin = plugins.begin();

EXPECT_EQ("default", plugin->EntityName());
EXPECT_EQ("world", plugin->EntityType());
EXPECT_EQ("TestWorldSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugin->Name());

plugin = std::next(plugin, 1);

EXPECT_EQ("box", plugin->EntityName());
EXPECT_EQ("model", plugin->EntityType());
EXPECT_EQ("TestModelSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestModelSystem", plugin->Name());

plugin = std::next(plugin, 1);

EXPECT_EQ("default::box::link_1::camera", plugin->EntityName());
EXPECT_EQ("sensor", plugin->EntityType());
EXPECT_EQ("TestSensorSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestSensorSystem", plugin->Name());
}

//////////////////////////////////////////////////
TEST(parsePluginsFromFile, invalid)
TEST(ParsePluginsFromFile, Invalid)
{
auto config = common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/server_invalid.config");
"test", "worlds", "server_invalid.config");

// Valid file without valid content
auto plugins = parsePluginsFromFile(config);
Expand All @@ -116,35 +148,35 @@ TEST(parsePluginsFromFile, invalid)
}

//////////////////////////////////////////////////
TEST(parsePluginsFromFile, defaultConfig)
TEST(ParsePluginsFromFile, DefaultConfig)
{
// Note: This test validates that that the default
// configuration always parses.
// If more systems are added, then the number needs
// to be adjusted below.
auto config = common::joinPaths(PROJECT_SOURCE_PATH,
"/include/ignition/gazebo/server.config");
"include", "ignition", "gazebo", "server.config");

auto plugins = parsePluginsFromFile(config);
ASSERT_EQ(3u, plugins.size());
}

//////////////////////////////////////////////////
TEST(parsePluginsFromFile, playbackConfig)
TEST(ParsePluginsFromFile, PlaybackConfig)
{
// Note: This test validates that that the default
// configuration always parses.
// If more systems are added, then the number needs
// to be adjusted below.
auto config = common::joinPaths(PROJECT_SOURCE_PATH,
"/include/ignition/gazebo/playback_server.config");
"include", "ignition", "gazebo", "playback_server.config");

auto plugins = parsePluginsFromFile(config);
ASSERT_EQ(2u, plugins.size());
}

//////////////////////////////////////////////////
TEST(loadPluginInfo, fromEmptyEnv)
TEST(LoadPluginInfo, FromEmptyEnv)
{
// Set environment to something that doesn't exist
ASSERT_TRUE(common::setenv(gazebo::kServerConfigPathEnv, "foo"));
Expand All @@ -155,26 +187,35 @@ TEST(loadPluginInfo, fromEmptyEnv)
}

//////////////////////////////////////////////////
TEST(loadPluginInfo, fromValidEnv)
TEST(LoadPluginInfo, FromValidEnv)
{
auto validPath = common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/server_valid2.config");
"test", "worlds", "server_valid2.config");

ASSERT_TRUE(common::setenv(gazebo::kServerConfigPathEnv, validPath));

auto plugins = loadPluginInfo();
ASSERT_EQ(2u, plugins.size());

EXPECT_EQ("*", plugins.begin()->EntityName());
EXPECT_EQ("world", plugins.begin()->EntityType());
EXPECT_EQ("TestWorldSystem", plugins.begin()->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugins.begin()->Name());
auto plugin = plugins.begin();

EXPECT_EQ("*", plugin->EntityName());
EXPECT_EQ("world", plugin->EntityType());
EXPECT_EQ("TestWorldSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestWorldSystem", plugin->Name());

plugin = std::next(plugin, 1);

EXPECT_EQ("box", plugin->EntityName());
EXPECT_EQ("model", plugin->EntityType());
EXPECT_EQ("TestModelSystem", plugin->Filename());
EXPECT_EQ("ignition::gazebo::TestModelSystem", plugin->Name());

EXPECT_TRUE(common::unsetenv(gazebo::kServerConfigPathEnv));
}

//////////////////////////////////////////////////
TEST(ServerConfig, generateRecordPlugin)
TEST(ServerConfig, GenerateRecordPlugin)
{
ServerConfig config;
config.SetUseLogRecord(true);
Expand Down
54 changes: 54 additions & 0 deletions src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,60 @@ void ServerPrivate::AddRecordPlugin(const ServerConfig &_config)
pluginElem = pluginElem->GetNextElement();
}
}

// A record plugin is not already specified in SDF. Add one.
sdf::ElementPtr recordElem = worldElem->AddElement("plugin");
sdf::ParamPtr recordName = recordElem->GetAttribute("name");
recordName->SetFromString(LoggingPlugin::RecordPluginName());
sdf::ParamPtr recordFileName = recordElem->GetAttribute("filename");
recordFileName->SetFromString(LoggingPlugin::LoggingPluginFileName());

// Add custom record path
if (!_config.LogRecordPath().empty())
{
sdf::ElementPtr pathElem = std::make_shared<sdf::Element>();
pathElem->SetName("path");
recordElem->AddElementDescription(pathElem);
pathElem = recordElem->GetElement("path");
pathElem->AddValue("string", "", false, "");
pathElem->Set<std::string>(_config.LogRecordPath());
}

// Set whether to record resources
sdf::ElementPtr resourceElem = std::make_shared<sdf::Element>();
resourceElem->SetName("record_resources");
recordElem->AddElementDescription(resourceElem);
resourceElem = recordElem->GetElement("record_resources");
resourceElem->AddValue("bool", "false", false, "");
resourceElem->Set<bool>(_config.LogRecordResources() ? true : false);

// Set whether to compress
sdf::ElementPtr compressElem = std::make_shared<sdf::Element>();
compressElem->SetName("compress");
recordElem->AddElementDescription(compressElem);
compressElem = recordElem->GetElement("compress");
compressElem->AddValue("bool", "false", false, "");
compressElem->Set<bool>(_config.LogRecordCompressPath().empty() ? false :
true);

// Set compress path
sdf::ElementPtr cPathElem = std::make_shared<sdf::Element>();
cPathElem->SetName("compress_path");
recordElem->AddElementDescription(cPathElem);
cPathElem = recordElem->GetElement("compress_path");
cPathElem->AddValue("string", "", false, "");
cPathElem->Set<std::string>(_config.LogRecordCompressPath());

// If record topics specified, add in SDF
for (const std::string &topic : _config.LogRecordTopics())
{
sdf::ElementPtr topicElem = std::make_shared<sdf::Element>();
topicElem->SetName("record_topic");
recordElem->AddElementDescription(topicElem);
topicElem = recordElem->AddElement("record_topic");
topicElem->AddValue("string", "false", false, "");
topicElem->Set<std::string>(topic);
}
}

//////////////////////////////////////////////////
Expand Down
10 changes: 2 additions & 8 deletions src/Server_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ class ServerFixture : public ::testing::TestWithParam<int>
/////////////////////////////////////////////////
TEST_P(ServerFixture, DefaultServerConfig)
{
// Always override to the default config, in case
// a user has customized their installed config
auto validPath = common::joinPaths(PROJECT_SOURCE_PATH,
"/include/ignition/gazebo/server.config");
ASSERT_TRUE(common::setenv(gazebo::kServerConfigPathEnv, validPath));

ignition::gazebo::ServerConfig serverConfig;
EXPECT_TRUE(serverConfig.SdfFile().empty());
EXPECT_TRUE(serverConfig.SdfString().empty());
Expand Down Expand Up @@ -227,8 +221,8 @@ TEST_P(ServerFixture, ServerConfigSensorPlugin)
{
// Start server
ServerConfig serverConfig;
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/air_pressure.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"test", "worlds", "air_pressure.sdf"));

sdf::ElementPtr sdf(new sdf::Element);
sdf->SetName("plugin");
Expand Down
Loading

0 comments on commit e15b673

Please sign in to comment.