Make the Individual tests linkable for meson
- In the current state, the tests can only be linkable
together into a single binary, as we are using the few
vaiables from external tests and using them during link
time to generate the executable.
- The idea of this commit is to make the unit test files
linkable individually, so that we have have a better way
of running unitests through meson, rather than bundling all
the tests into a gaigantic binary.
TestedBy:
The unit tests are passed in CI
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I67b953e5bc227d876139373aebeacbf5c20f56ef
diff --git a/test/Makefile.am b/test/Makefile.am
index 3d63748..26a6aa3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,6 +7,7 @@
test_SOURCES = \
test_util.cpp \
mock_syscall.cpp \
+ global_network_objects.cpp \
test_neighbor.cpp \
test_netlink.cpp \
test_network_manager.cpp \
diff --git a/test/global_network_objects.cpp b/test/global_network_objects.cpp
new file mode 100644
index 0000000..1aa71b7
--- /dev/null
+++ b/test/global_network_objects.cpp
@@ -0,0 +1,32 @@
+#include "mock_network_manager.hpp"
+#include "types.hpp"
+
+#include <sdeventplus/event.hpp>
+
+namespace phosphor
+{
+
+namespace network
+{
+
+std::unique_ptr<MockManager> manager = nullptr;
+std::unique_ptr<Timer> refreshObjectTimer = nullptr;
+std::unique_ptr<Timer> restartTimer = nullptr;
+
+/** @brief refresh the network objects. */
+void refreshObjects()
+{
+ if (manager)
+ {
+ manager->createChildObjects();
+ }
+}
+
+void initializeTimers()
+{
+ refreshObjectTimer = std::make_unique<Timer>(
+ sdeventplus::Event::get_default(), std::bind(refreshObjects));
+}
+
+} // namespace network
+} // namespace phosphor
diff --git a/test/mock_network_manager.hpp b/test/mock_network_manager.hpp
index b4a6894..1fc3f9b 100644
--- a/test/mock_network_manager.hpp
+++ b/test/mock_network_manager.hpp
@@ -12,6 +12,9 @@
namespace network
{
+void initializeTimers();
+void refreshObjects();
+
class MockManager : public phosphor::network::Manager
{
public:
diff --git a/test/test_network_manager.cpp b/test/test_network_manager.cpp
index df7db77..48da2f2 100644
--- a/test/test_network_manager.cpp
+++ b/test/test_network_manager.cpp
@@ -18,9 +18,6 @@
namespace network
{
-std::unique_ptr<Timer> refreshObjectTimer = nullptr;
-std::unique_ptr<Timer> restartTimer = nullptr;
-
namespace fs = std::filesystem;
class TestNetworkManager : public testing::Test
diff --git a/test/test_rtnetlink.cpp b/test/test_rtnetlink.cpp
index 6a8c02d..47ccecf 100644
--- a/test/test_rtnetlink.cpp
+++ b/test/test_rtnetlink.cpp
@@ -19,26 +19,11 @@
namespace network
{
sdbusplus::bus::bus bus(sdbusplus::bus::new_default());
-std::unique_ptr<MockManager> manager = nullptr;
+extern std::unique_ptr<MockManager> manager;
extern std::unique_ptr<Timer> refreshObjectTimer;
extern std::unique_ptr<Timer> restartTimer;
EventPtr eventPtr = nullptr;
-/** @brief refresh the network objects. */
-void refreshObjects()
-{
- if (manager)
- {
- manager->createChildObjects();
- }
-}
-
-void initializeTimers()
-{
- refreshObjectTimer = std::make_unique<Timer>(
- sdeventplus::Event::get_default(), std::bind(refreshObjects));
-}
-
class TestRtNetlink : public testing::Test
{