Skip to content

Commit 235601b

Browse files
saiarcot895kellyyeh
authored andcommitted
Start up redis server, and initialize Sonic DB for tests
Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent a345c12 commit 235601b

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.azure-pipelines/build.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
libnl-3-dev \
4141
libnl-route-3-dev \
4242
libnl-genl-3-dev \
43-
libnl-nf-3-dev
43+
libnl-nf-3-dev \
44+
redis-server
4445
4546
displayName: "Install dependencies"
4647
- checkout: self

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboos
1212
override CPPFLAGS += -Wall -std=c++17 -fPIE -I/usr/include/swss
1313
override CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)"
1414
CPPFLAGS_TEST := --coverage -fprofile-arcs -ftest-coverage -fprofile-generate
15-
LDLIBS_TEST := --coverage -lgtest_main -lgtest -pthread -lstdc++fs
15+
LDLIBS_TEST := --coverage -lgtest -pthread -lstdc++fs
1616
PWD := $(shell pwd)
1717

1818
all: $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET)

test/MockRelay.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,3 @@ TEST(relay, dhcp6relay_stop) {
687687
event_new(base, filter, EV_READ|EV_PERSIST, callback, &config);
688688
dhcp6relay_stop();
689689
}
690-
691-
int main_test(int argc, char *argv[]) {
692-
::testing::InitGoogleTest(&argc, argv);
693-
return RUN_ALL_TESTS();
694-
}

test/main.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "gtest/gtest.h"
2+
#include <swss/dbconnector.h>
3+
#include <string>
4+
5+
std::string database_config = "./test/database_config.json";
6+
7+
class DhcpRelayEnvironment : public ::testing::Environment {
8+
public:
9+
// Override this to define how to set up the environment.
10+
void SetUp() override {
11+
// by default , init should be false
12+
EXPECT_FALSE(swss::SonicDBConfig::isInit());
13+
14+
// load local config file, init should be true
15+
swss::SonicDBConfig::initialize(database_config);
16+
EXPECT_TRUE(swss::SonicDBConfig::isInit());
17+
}
18+
};
19+
20+
int main(int argc, char* argv[])
21+
{
22+
testing::InitGoogleTest(&argc, argv);
23+
// Registers a global test environment, and verifies that the
24+
// registration function returns its argument.
25+
DhcpRelayEnvironment* env = new DhcpRelayEnvironment;
26+
testing::AddGlobalTestEnvironment(env);
27+
return RUN_ALL_TESTS();
28+
}

test/subdir.mk

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
TEST_SRCS += \
22
test/mock_send.cpp \
3+
test/main.cpp \
34
src/relay.cpp \
45
src/configInterface.cpp \
56
test/MockRelay.cpp

0 commit comments

Comments
 (0)