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

Remove duplicated functionality from test_config #457

Merged
merged 3 commits into from
Nov 2, 2023
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
16 changes: 9 additions & 7 deletions log/test/integration/playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <gz/transport/log/Playback.hh>
#include <gz/transport/log/Recorder.hh>
#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "ChirpParams.hh"
Expand Down Expand Up @@ -800,17 +802,17 @@ int main(int argc, char **argv)
partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", partition);

setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH);

setenv(gz::transport::log::SchemaLocationEnvVar.c_str(),
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv(gz::transport::log::SchemaLocationEnvVar,
GZ_TRANSPORT_LOG_SQL_PATH);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
16 changes: 9 additions & 7 deletions log/test/integration/recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <gz/transport/log/Log.hh>
#include <gz/transport/log/Recorder.hh>
#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "ChirpParams.hh"
Expand Down Expand Up @@ -538,17 +540,17 @@ int main(int argc, char **argv)
partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", partition);

setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH);

setenv(gz::transport::log::SchemaLocationEnvVar.c_str(),
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv(gz::transport::log::SchemaLocationEnvVar,
GZ_TRANSPORT_LOG_SQL_PATH);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
4 changes: 3 additions & 1 deletion log/test/integration/topicChirp_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>

#include "ChirpParams.hh"

//////////////////////////////////////////////////
Expand Down Expand Up @@ -90,7 +92,7 @@ int main(int argc, char **argv)
return -2;
}

setenv("GZ_PARTITION", argv[1], 1);
gz::utils::setenv("GZ_PARTITION", argv[1]);

const int chirps = atoi(argv[2]);

Expand Down
9 changes: 6 additions & 3 deletions src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/
#include <gz/msgs/stringmsg.pb.h>

#include "gtest/gtest.h"
#include "gz/transport/CIface.h"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

static int count;
Expand Down Expand Up @@ -180,10 +183,10 @@ int main(int argc, char **argv)
std::string partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", partition);

// Enable verbose mode.
// setenv("GZ_VERBOSE", "1", 1);
// gz::utils::setenv("GZ_VERBOSE", "1");

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
34 changes: 9 additions & 25 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,11 @@
#include "gz/transport/Publisher.hh"
#include "gz/transport/TransportTypes.hh"
#include "gz/transport/Uuid.hh"
#include "test_config.hh"

// Temporarily introduce a "DISABLED_ON_LINUX" macro.
// It currently does not exist upstream.
// This can be removed when it is in upstream gz-utils
// or the discovery WrongGzIp test passes on linux
#include <gz/utils/detail/ExtraTestMacros.hh>
#if defined __linux__
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
DETAIL_GZ_UTILS_ADD_DISABLED_PREFIX(TestName)
#else
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
TestName
#endif // defined __linux__
#include "gz/utils/Environment.hh"
#include "gz/utils/ExtraTestMacros.hh"

#include "test_config.hh"

using namespace gz;
using namespace transport;
Expand Down Expand Up @@ -540,31 +531,24 @@ TEST(DiscoveryTest, TestActivity)
discovery1.TestActivity(proc2Uuid, false);
}

/// Logic to disable the following test via Linux
#if defined __linux__
#define TEST_NAME DISABLED_WrongIgnIp
#else
#define TEST_NAME WrongIgnIp
#endif // defined __linux__

//////////////////////////////////////////////////
/// \brief Check that a wrong GZ_IP value makes HostAddr() to return 127.0.0.1
TEST(DiscoveryTest, TEST_NAME)
TEST(DiscoveryTest, GZ_UTILS_TEST_DISABLED_ON_LINUX(WrongGzIp))
{
// Save the current value of GZ_IP environment variable.
std::string gzIp;
env("GZ_IP", gzIp);
gz::utils::env("GZ_IP", gzIp);

// Incorrect value for GZ_IP
setenv("GZ_IP", "127.0.0.0", 1);
ASSERT_TRUE(gz::utils::setenv("GZ_IP", "127.0.0.0"));

transport::Discovery<MessagePublisher> discovery1(pUuid1, g_ip, g_msgPort);
EXPECT_EQ(discovery1.HostAddr(), "127.0.0.1");

// Unset GZ_IP.
unsetenv("GZ_IP");
ASSERT_TRUE(gz::utils::unsetenv("GZ_IP"));

// Restore GZ_IP.
if (!gzIp.empty())
setenv("GZ_IP", gzIp.c_str(), 1);
gz::utils::setenv("GZ_IP", gzIp);
}
5 changes: 4 additions & 1 deletion src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "gz/transport/Helpers.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

Expand All @@ -33,7 +36,7 @@ TEST(HelpersTest, env)
EXPECT_FALSE(transport::env(name, value));

// Create a random environment variable and give it its name as value.
setenv(name.c_str(), name.c_str(), 1);
ASSERT_TRUE(gz::utils::setenv(name, name));

// Check that we find the environment variable and the value is correct.
EXPECT_TRUE(transport::env(name, value));
Expand Down
7 changes: 5 additions & 2 deletions src/NodeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include "gz/transport/NetUtils.hh"
#include "gz/transport/NodeOptions.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

Expand All @@ -30,7 +33,7 @@ TEST(NodeOptionsTest, ignPartition)
{
// Set GZ_PARTITION
std::string aPartition = "customPartition";
setenv("GZ_PARTITION", aPartition.c_str(), 1);
ASSERT_TRUE(gz::utils::setenv("GZ_PARTITION", aPartition));

transport::NodeOptions opts;
EXPECT_EQ(opts.Partition(), aPartition);
Expand All @@ -53,7 +56,7 @@ TEST(NodeOptionsTest, ignPartition)
TEST(NodeOptionsTest, accessors)
{
// Check the default values.
unsetenv("GZ_PARTITION");
gz::utils::unsetenv("GZ_PARTITION");
transport::NodeOptions opts;
EXPECT_TRUE(opts.NameSpace().empty());
auto defaultPartition = transport::hostname() + ":" + transport::username();
Expand Down
9 changes: 6 additions & 3 deletions src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
#include <string>
#include <thread>

#include "gtest/gtest.h"
#include "gz/transport/AdvertiseOptions.hh"
#include "gz/transport/MessageInfo.hh"
#include "gz/transport/Node.hh"
#include "gz/transport/NodeOptions.hh"
#include "gz/transport/TopicStatistics.hh"
#include "gz/transport/TopicUtils.hh"
#include "gz/transport/TransportTypes.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -2324,10 +2327,10 @@ int main(int argc, char **argv)
g_FQNPartition = std::string("/") + partition;

// Set the partition name for this process.
setenv("GZ_PARTITION", partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", partition);

// Enable verbose mode.
setenv("GZ_VERBOSE", "1", 1);
gz::utils::setenv("GZ_VERBOSE", "1");

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <fstream>
#include <iostream>
#include <string>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "gtest/gtest.h"
Expand Down Expand Up @@ -536,7 +538,7 @@ int main(int argc, char **argv)
g_partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", g_partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", g_partition);

// Make sure that we load the library recently built and not the one installed
// in your system.
Expand All @@ -545,7 +547,7 @@ int main(int argc, char **argv)
transport::env("LD_LIBRARY_PATH", value);
// Add the directory where Gazebo Transport has been built.
value = std::string(GZ_TEST_LIBRARY_PATH) + ":" + value;
setenv("LD_LIBRARY_PATH", value.c_str(), 1);
gz::utils::setenv("LD_LIBRARY_PATH", value);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/gz_src_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
#pragma warning(pop)
#endif

#include "gtest/gtest.h"
#include "gz.hh"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;

Expand Down Expand Up @@ -296,7 +299,7 @@ int main(int argc, char **argv)
g_partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", g_partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", g_partition);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
9 changes: 6 additions & 3 deletions test/integration/authPubSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
#include "gz/transport/TransportTypes.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand All @@ -40,8 +43,8 @@ static std::string g_topic = "/foo"; // NOLINT(*)
TEST(authPubSub, InvalidAuth)
{
// Setup the username and password for this test
setenv("GZ_TRANSPORT_USERNAME", "admin", 1);
setenv("GZ_TRANSPORT_PASSWORD", "test", 1);
ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_USERNAME", "admin"));
ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_PASSWORD", "test"));

transport::Node node;
auto pub = node.Advertise<msgs::Int32>(g_topic);
Expand Down Expand Up @@ -86,7 +89,7 @@ int main(int argc, char **argv)
partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("GZ_PARTITION", partition.c_str(), 1);
gz::utils::setenv("GZ_PARTITION", partition);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
9 changes: 6 additions & 3 deletions test/integration/authPubSubSubscriberInvalid_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

Expand Down Expand Up @@ -81,13 +84,13 @@ int main(int argc, char **argv)
}

// Set the partition name for this test.
setenv("GZ_PARTITION", argv[1], 1);
gz::utils::setenv("GZ_PARTITION", argv[1]);

// Set the username for this test.
setenv("GZ_TRANSPORT_USERNAME", argv[2], 1);
gz::utils::setenv("GZ_TRANSPORT_USERNAME", argv[2]);

// Set the password for this test.
setenv("GZ_TRANSPORT_PASSWORD", argv[3], 1);
gz::utils::setenv("GZ_TRANSPORT_PASSWORD", argv[3]);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
5 changes: 4 additions & 1 deletion test/integration/fastPub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -58,7 +61,7 @@ int main(int argc, char **argv)
}

// Set the partition name for this test.
setenv("GZ_PARTITION", argv[1], 1);
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
5 changes: 4 additions & 1 deletion test/integration/pub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -59,7 +62,7 @@ int main(int argc, char **argv)
}

// Set the partition name for this test.
setenv("GZ_PARTITION", argv[1], 1);
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
Loading