Skip to content

Commit a31e497

Browse files
committed
Add unittest infrastructure
1 parent 6f94c2e commit a31e497

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Makefile

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
RM := rm -rf
22
DHCP6RELAY_TARGET := dhcp6relay
3+
DHCP6RELAY_TEST_TARGET := dhcp6relay-test
34
CP := cp
45
MKDIR := mkdir
56
MV := mv
7+
FIND := find
8+
GCOVR := gcovr
9+
GCOV_FLAGS := -fprofile-use -fprofile-arcs -ftest-coverage -fprofile-generate
610
override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system
11+
override LDLIBS_TEST += -lgtest_main -lgtest -pthread -lstdc++fs
712
override CPPFLAGS += -Wall -std=c++17 -fPIE -I/usr/include/swss
813
override CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)"
914
PWD := $(shell pwd)
1015

11-
all: $(DHCP6RELAY_TARGET)
16+
test-targets: CPP_FLAGS = -O0 -Wall -fmessage-length=0 -fPIC $(GCOV_FLAGS)
17+
18+
all: $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET)
1219

1320
ifneq ($(MAKECMDGOALS),clean)
1421
-include $(OBJS:%.o=%.d)
1522
endif
1623

1724
-include src/subdir.mk
25+
-include test/subdir.mk
1826

1927
$(DHCP6RELAY_TARGET): $(OBJS)
2028
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
2129

30+
$(DHCP6RELAY_TEST_TARGET): $(OBJS_DHCP6RELAY_TEST)
31+
$(CC) -lgcov --coverage -o "$(DHCP6RELAY_TEST_TARGET)" $(CPP_FLAGS) $(OBJS_DHCP6RELAY_TEST) $(LDLIBS) $(LDLIBS_TEST)
32+
./$(DHCP6RELAY_TEST_TARGET)
33+
$(GCOVR) -r ./ --html --html-details -o $(DHCP6RELAY_TEST_TARGET)-result.html
34+
$(GCOVR) -r ./ --xml-pretty -o $(DHCP6RELAY_TEST_TARGET)-result.xml
35+
36+
2237
install:
2338
$(MKDIR) -p $(DESTDIR)/usr/sbin
2439
$(MV) $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin
@@ -28,7 +43,10 @@ deinstall:
2843
$(RM) -rf $(DESTDIR)/usr/sbin
2944

3045
clean:
31-
-$(RM) $(EXECUTABLES) $(OBJS:%.o=%.d) $(OBJS) $(DHCP6RELAY_TARGET)
46+
-$(RM) $(EXECUTABLES) $(OBJS:%.o=%.d) $(OBJS) $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET) $(OBJS_DHCP6RELAY_TEST) *.html *.xml
47+
$(FIND) . -name *.gcda -exec rm -f {} \;
48+
$(FIND) . -name *.gcno -exec rm -f {} \;
49+
$(FIND) . -name *.gcov -exec rm -f {} \;
3250
-@echo ' '
3351

3452
.PHONY: all clean dependents

test/subdir.mk

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OBJS += \
2+
$(PWD)/src/relay.o \
3+
$(PWD)/src/configInterface.o \
4+
$(PWD)/src/main.o

0 commit comments

Comments
 (0)