Skip to content

Commit 6e06a4d

Browse files
saiarcot895kellyyeh
authored andcommitted
Test infra changes/improvements
Fix up the variables used for building a test binary, use a separate build directory (one for regular builds and one for test builds), minor changes to the install/uninstall targets. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent a31e497 commit 6e06a4d

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

.azure-pipelines/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ jobs:
7474
- ${{ if and(eq(parameters.arch, 'amd64'), parameters.codeCoverage) }}:
7575
- task: PublishCodeCoverageResults@1
7676
inputs:
77-
summaryFileLocation: dhcprelay-test-result.xml
77+
summaryFileLocation: dhcp6relay-test-result.xml
7878
pathToSources: $(Build.SourcesDirectory)
7979
codeCoverageTool: 'Cobertura'

Makefile

+33-21
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,66 @@
11
RM := rm -rf
2-
DHCP6RELAY_TARGET := dhcp6relay
3-
DHCP6RELAY_TEST_TARGET := dhcp6relay-test
2+
BUILD_DIR := build
3+
BUILD_TEST_DIR := build-test
4+
DHCP6RELAY_TARGET := $(BUILD_DIR)/dhcp6relay
5+
DHCP6RELAY_TEST_TARGET := $(BUILD_TEST_DIR)/dhcp6relay-test
46
CP := cp
57
MKDIR := mkdir
68
MV := mv
79
FIND := find
810
GCOVR := gcovr
9-
GCOV_FLAGS := -fprofile-use -fprofile-arcs -ftest-coverage -fprofile-generate
1011
override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system
11-
override LDLIBS_TEST += -lgtest_main -lgtest -pthread -lstdc++fs
1212
override CPPFLAGS += -Wall -std=c++17 -fPIE -I/usr/include/swss
1313
override CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)"
14+
CPPFLAGS_TEST := --coverage -fprofile-arcs -ftest-coverage -fprofile-generate
15+
LDLIBS_TEST := --coverage -lgtest_main -lgtest -pthread -lstdc++fs
1416
PWD := $(shell pwd)
1517

16-
test-targets: CPP_FLAGS = -O0 -Wall -fmessage-length=0 -fPIC $(GCOV_FLAGS)
17-
1818
all: $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET)
1919

20+
-include src/subdir.mk
21+
-include test/subdir.mk
22+
23+
# Use different build directories based on whether it's a regular build or a
24+
# test build. This is because in the test build, code coverage is enabled,
25+
# which means the object files that get built will be different
26+
OBJS = $(SRCS:%.cpp=$(BUILD_DIR)/%.o)
27+
TEST_OBJS = $(SRCS:%.cpp=$(BUILD_TEST_DIR)/%.o)
28+
2029
ifneq ($(MAKECMDGOALS),clean)
2130
-include $(OBJS:%.o=%.d)
31+
-include $(TEST_OBJS:%.o=%.d)
2232
endif
2333

24-
-include src/subdir.mk
25-
-include test/subdir.mk
34+
$(BUILD_DIR)/%.o: %.cpp
35+
@mkdir -p $(@D)
36+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
2637

2738
$(DHCP6RELAY_TARGET): $(OBJS)
2839
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
2940

30-
$(DHCP6RELAY_TEST_TARGET): $(OBJS_DHCP6RELAY_TEST)
31-
$(CC) -lgcov --coverage -o "$(DHCP6RELAY_TEST_TARGET)" $(CPP_FLAGS) $(OBJS_DHCP6RELAY_TEST) $(LDLIBS) $(LDLIBS_TEST)
41+
$(BUILD_TEST_DIR)/%.o: %.cpp
42+
@mkdir -p $(@D)
43+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(CPPFLAGS_TEST) -c -o $@ $<
44+
45+
$(DHCP6RELAY_TEST_TARGET): $(TEST_OBJS)
46+
$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_TEST) -o $@
47+
48+
test: $(DHCP6RELAY_TEST_TARGET)
3249
./$(DHCP6RELAY_TEST_TARGET)
3350
$(GCOVR) -r ./ --html --html-details -o $(DHCP6RELAY_TEST_TARGET)-result.html
3451
$(GCOVR) -r ./ --xml-pretty -o $(DHCP6RELAY_TEST_TARGET)-result.xml
3552

53+
install: $(DHCP6RELAY_TARGET)
54+
install -D $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin/$(notdir $(DHCP6RELAY_TARGET))
3655

37-
install:
38-
$(MKDIR) -p $(DESTDIR)/usr/sbin
39-
$(MV) $(DHCP6RELAY_TARGET) $(DESTDIR)/usr/sbin
40-
41-
deinstall:
42-
$(RM) $(DESTDIR)/usr/sbin/$(DHCP6RELAY_TARGET)
43-
$(RM) -rf $(DESTDIR)/usr/sbin
56+
uninstall:
57+
$(RM) $(DESTDIR)/usr/sbin/$(notdir $(DHCP6RELAY_TARGET))
4458

4559
clean:
46-
-$(RM) $(EXECUTABLES) $(OBJS:%.o=%.d) $(OBJS) $(DHCP6RELAY_TARGET) $(DHCP6RELAY_TEST_TARGET) $(OBJS_DHCP6RELAY_TEST) *.html *.xml
60+
-$(RM) $(BUILD_DIR) $(BUILD_TEST_DIR) *.html *.xml
4761
$(FIND) . -name *.gcda -exec rm -f {} \;
4862
$(FIND) . -name *.gcno -exec rm -f {} \;
4963
$(FIND) . -name *.gcov -exec rm -f {} \;
5064
-@echo ' '
5165

52-
.PHONY: all clean dependents
53-
54-
66+
.PHONY: all clean test install uninstall

azure-pipelines.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
arch: amd64
1515
pool:
1616
vmImage: 'ubuntu-20.04'
17-
codeCoverage: false
17+
codeCoverage: true
1818
containerImage: sonicdev-microsoft.azurecr.io:443/sonic-slave-bullseye:latest
1919
- template: .azure-pipelines/build.yml
2020
parameters:

src/subdir.mk

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

test/subdir.mk

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

0 commit comments

Comments
 (0)