diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 83edd04f..8553a260 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,6 +51,7 @@ jobs: libboost-regex1.71-dev \ googletest \ libgtest-dev \ + libgmock-dev \ libgcc-8-dev \ libhiredis0.14 \ libhiredis-dev \ diff --git a/objects.mk b/objects.mk index 35d0011a..27baa2cd 100644 --- a/objects.mk +++ b/objects.mk @@ -13,5 +13,5 @@ LIBS := \ -lnl-route-3 LIBS_TEST := \ - -lgtest_main \ - -lgtest + -lgtest \ + -lgmock diff --git a/test/FakeMuxPort.cpp b/test/FakeMuxPort.cpp index deedaebd..179c69a0 100644 --- a/test/FakeMuxPort.cpp +++ b/test/FakeMuxPort.cpp @@ -52,11 +52,6 @@ FakeMuxPort::FakeMuxPort( std::make_shared (mActiveStandbyStateMachinePtr->getLinkProberStateMachinePtr().get()) ) { - std::string prog_name = "linkmgrd-test"; - std::string log_filename = "/tmp/" + prog_name + ".log"; - bool extraLogFile = true; - common::MuxLogger::getInstance()->initialize(prog_name, log_filename, boost::log::trivial::debug, extraLogFile); - common::MuxLogger::getInstance()->setLevel(boost::log::trivial::trace); mMuxPortConfig.setMode(common::MuxPortConfig::Mode::Auto); getActiveStandbyStateMachinePtr()->setInitializeProberFnPtr( boost::bind(&FakeLinkProber::initialize, mFakeLinkProber.get()) diff --git a/test/LinkMgrdTestMain.cpp b/test/LinkMgrdTestMain.cpp new file mode 100644 index 00000000..57d3ab53 --- /dev/null +++ b/test/LinkMgrdTestMain.cpp @@ -0,0 +1,20 @@ +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "common/MuxLogger.h" + +void initLogger() +{ + std::string prog_name = "linkmgrd-test"; + std::string log_filename = "/tmp/" + prog_name + ".log"; + bool extraLogFile = true; + common::MuxLogger::getInstance()->initialize(prog_name, log_filename, boost::log::trivial::debug, extraLogFile); + common::MuxLogger::getInstance()->setLevel(boost::log::trivial::trace); +} + +int main(int argc, char** argv) +{ + initLogger(); + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/subdir.mk b/test/subdir.mk index a5782d2d..5451c70b 100644 --- a/test/subdir.mk +++ b/test/subdir.mk @@ -5,7 +5,8 @@ CPP_SRCS += \ ./test/FakeMuxPort.cpp \ ./test/LinkManagerStateMachineTest.cpp \ ./test/LinkProberTest.cpp \ - ./test/MuxManagerTest.cpp + ./test/MuxManagerTest.cpp \ + ./test/LinkMgrdTestMain.cpp OBJS_LINKMGRD_TEST += \ ./test/FakeDbInterface.o \ @@ -13,7 +14,8 @@ OBJS_LINKMGRD_TEST += \ ./test/FakeMuxPort.o \ ./test/LinkManagerStateMachineTest.o \ ./test/LinkProberTest.o \ - ./test/MuxManagerTest.o + ./test/MuxManagerTest.o \ + ./test/LinkMgrdTestMain.o CPP_DEPS += \ ./test/FakeDbInterface.d \ @@ -21,7 +23,8 @@ CPP_DEPS += \ ./test/FakeMuxPort.d \ ./test/LinkManagerStateMachineTest.d \ ./test/LinkProberTest.d \ - ./test/MuxManagerTest.d + ./test/MuxManagerTest.d \ + ./test/LinkMgrdTestMain.d # Each subdirectory must supply rules for building sources it contributes test/%.o: test/%.cpp