diff --git a/.azure-pipelines/build.yml b/.azure-pipelines/build.yml index 49f7f15..02d87e8 100644 --- a/.azure-pipelines/build.yml +++ b/.azure-pipelines/build.yml @@ -40,7 +40,8 @@ jobs: libnl-3-dev \ libnl-route-3-dev \ libnl-genl-3-dev \ - libnl-nf-3-dev + libnl-nf-3-dev \ + redis-server displayName: "Install dependencies" - checkout: self diff --git a/Makefile b/Makefile index 776fd6d..b685e81 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboos override CPPFLAGS += -Wall -std=c++17 -fPIE -I/usr/include/swss override CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" CPPFLAGS_TEST := --coverage -fprofile-arcs -ftest-coverage -fprofile-generate -LDLIBS_TEST := --coverage -lgtest_main -lgtest -pthread -lstdc++fs +LDLIBS_TEST := --coverage -lgtest -pthread -lstdc++fs PWD := $(shell pwd) all: $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET) diff --git a/test/MockRelay.cpp b/test/MockRelay.cpp index 583b782..58dd222 100644 --- a/test/MockRelay.cpp +++ b/test/MockRelay.cpp @@ -687,8 +687,3 @@ TEST(relay, dhcp6relay_stop) { event_new(base, filter, EV_READ|EV_PERSIST, callback, &config); dhcp6relay_stop(); } - -int main_test(int argc, char *argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..dfca267 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,28 @@ +#include "gtest/gtest.h" +#include +#include + +std::string database_config = "./test/database_config.json"; + +class DhcpRelayEnvironment : public ::testing::Environment { +public: + // Override this to define how to set up the environment. + void SetUp() override { + // by default , init should be false + EXPECT_FALSE(swss::SonicDBConfig::isInit()); + + // load local config file, init should be true + swss::SonicDBConfig::initialize(database_config); + EXPECT_TRUE(swss::SonicDBConfig::isInit()); + } +}; + +int main(int argc, char* argv[]) +{ + testing::InitGoogleTest(&argc, argv); + // Registers a global test environment, and verifies that the + // registration function returns its argument. + DhcpRelayEnvironment* env = new DhcpRelayEnvironment; + testing::AddGlobalTestEnvironment(env); + return RUN_ALL_TESTS(); +} diff --git a/test/subdir.mk b/test/subdir.mk index 8a73a2d..2523d4b 100644 --- a/test/subdir.mk +++ b/test/subdir.mk @@ -1,5 +1,6 @@ TEST_SRCS += \ test/mock_send.cpp \ +test/main.cpp \ src/relay.cpp \ src/configInterface.cpp \ test/MockRelay.cpp