Skip to content

Commit

Permalink
Start up redis server, and initialize Sonic DB for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Saikrishna Arcot <[email protected]>
  • Loading branch information
saiarcot895 committed Jul 31, 2022
1 parent 008b45d commit 0902ada
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .azure-pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions test/MockRelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
28 changes: 28 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "gtest/gtest.h"
#include <swss/dbconnector.h>
#include <string>

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();
}
1 change: 1 addition & 0 deletions test/subdir.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TEST_SRCS += \
test/mock_send.cpp \
test/main.cpp \
src/relay.cpp \
src/configInterface.cpp \
test/MockRelay.cpp

0 comments on commit 0902ada

Please sign in to comment.