-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This is cherry-pick from PR #5 Signed-off-by: kellyyeh [email protected] Why I did it Add unittest infrastructure How I did it Modified Makefile and added test directory How to verify it Run make
- Loading branch information
Showing
16 changed files
with
841 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
RM := rm -rf | ||
DHCP6RELAY_TARGET := dhcp6relay | ||
BUILD_DIR := build | ||
BUILD_TEST_DIR := build-test | ||
DHCP6RELAY_TARGET := $(BUILD_DIR)/dhcp6relay | ||
DHCP6RELAY_TEST_TARGET := $(BUILD_TEST_DIR)/dhcp6relay-test | ||
CP := cp | ||
MKDIR := mkdir | ||
MV := mv | ||
FIND := find | ||
GCOVR := gcovr | ||
override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system | ||
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 -fsanitize=address | ||
LDLIBS_TEST := --coverage -lgtest -pthread -lstdc++fs -fsanitize=address | ||
PWD := $(shell pwd) | ||
|
||
all: $(DHCP6RELAY_TARGET) | ||
all: $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET) | ||
|
||
-include src/subdir.mk | ||
-include test/subdir.mk | ||
|
||
# Use different build directories based on whether it's a regular build or a | ||
# test build. This is because in the test build, code coverage is enabled, | ||
# which means the object files that get built will be different | ||
OBJS = $(SRCS:%.cpp=$(BUILD_DIR)/%.o) | ||
TEST_OBJS = $(TEST_SRCS:%.cpp=$(BUILD_TEST_DIR)/%.o) | ||
|
||
ifneq ($(MAKECMDGOALS),clean) | ||
-include $(OBJS:%.o=%.d) | ||
-include $(TEST_OBJS:%.o=%.d) | ||
endif | ||
|
||
-include src/subdir.mk | ||
$(BUILD_DIR)/%.o: %.cpp | ||
@mkdir -p $(@D) | ||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< | ||
|
||
$(DHCP6RELAY_TARGET): $(OBJS) | ||
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | ||
|
||
install: | ||
$(MKDIR) -p $(DESTDIR)/usr/sbin | ||
$(MV) $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin | ||
$(BUILD_TEST_DIR)/%.o: %.cpp | ||
@mkdir -p $(@D) | ||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(CPPFLAGS_TEST) -c -o $@ $< | ||
|
||
deinstall: | ||
$(RM) $(DESTDIR)/usr/sbin/$(DHCP6RELAY_TARGET) | ||
$(RM) -rf $(DESTDIR)/usr/sbin | ||
$(DHCP6RELAY_TEST_TARGET): $(TEST_OBJS) | ||
$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_TEST) -o $@ | ||
|
||
clean: | ||
-$(RM) $(EXECUTABLES) $(OBJS:%.o=%.d) $(OBJS) $(DHCP6RELAY_TARGET) | ||
-@echo ' ' | ||
test: $(DHCP6RELAY_TEST_TARGET) | ||
sudo ASAN_OPTIONS=detect_leaks=0 ./$(DHCP6RELAY_TEST_TARGET) --gtest_output=xml:$(DHCP6RELAY_TEST_TARGET)-test-result.xml || true | ||
$(GCOVR) -r ./ --html --html-details -o $(DHCP6RELAY_TEST_TARGET)-code-coverage.html | ||
$(GCOVR) -r ./ --xml-pretty -o $(DHCP6RELAY_TEST_TARGET)-code-coverage.xml | ||
|
||
install: $(DHCP6RELAY_TARGET) | ||
install -D $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin/$(notdir $(DHCP6RELAY_TARGET)) | ||
|
||
.PHONY: all clean dependents | ||
uninstall: | ||
$(RM) $(DESTDIR)/usr/sbin/$(notdir $(DHCP6RELAY_TARGET)) | ||
|
||
clean: | ||
-$(RM) $(BUILD_DIR) $(BUILD_TEST_DIR) *.html *.xml | ||
$(FIND) . -name *.gcda -exec rm -f {} \; | ||
$(FIND) . -name *.gcno -exec rm -f {} \; | ||
$(FIND) . -name *.gcov -exec rm -f {} \; | ||
-@echo ' ' | ||
|
||
.PHONY: all clean test install uninstall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.