Skip to content

Commit

Permalink
Gcov for swss daemon (#1737)
Browse files Browse the repository at this point in the history
* [gcov] swss support gcov
* Introduce gcov-related automation script to test coverage rate for swss module
Signed-off-by: pettershao-ragilenetworks <[email protected]>
  • Loading branch information
pettershao-ragilenetworks authored Nov 5, 2021
1 parent 01c243a commit b20f0f4
Show file tree
Hide file tree
Showing 25 changed files with 1,203 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ parameters:
type: boolean
default: false

- name: archive_gcov
type: boolean
default: false

jobs:
- job:
displayName: ${{ parameters.arch }}
Expand Down Expand Up @@ -126,6 +130,9 @@ jobs:
set -x
tar czf pytest.tgz tests
cp -r pytest.tgz $(Build.ArtifactStagingDirectory)/
if [ '${{ parameters.archive_gcov }}' == True ]; then
export ENABLE_GCOV=y
fi
./autogen.sh
dpkg-buildpackage -us -uc -b -j$(nproc) && cp ../*.deb .
displayName: "Compile sonic swss"
Expand Down
4 changes: 4 additions & 0 deletions .azure-pipelines/docker-sonic-vs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ RUN dpkg -i /debs/syncd-vs_1.0.0_amd64.deb

RUN dpkg --purge swss
RUN dpkg -i /debs/swss_1.0.0_amd64.deb

RUN apt-get update

RUN apt-get -y install lcov
114 changes: 114 additions & 0 deletions .azure-pipelines/gcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
parameters:
- name: arch
type: string
values:
- amd64
default: amd64

- name: pool
type: string
values:
- sonicbld
- default
default: default

- name: timeout
type: number
default: 180

- name: sonic_slave
type: string

- name: sairedis_artifact_name
type: string

- name: swss_common_artifact_name
type: string

- name: swss_artifact_name
type: string

- name: artifact_name
type: string

- name: archive_gcov
type: boolean
default: false

jobs:
- job:
displayName: ${{ parameters.arch }}
timeoutInMinutes: ${{ parameters.timeout }}

pool:
${{ if ne(parameters.pool, 'default') }}:
name: ${{ parameters.pool }}
${{ if eq(parameters.pool, 'default') }}:
vmImage: 'ubuntu-20.04'

container:
image: sonicdev-microsoft.azurecr.io:443/${{ parameters.sonic_slave }}:latest


steps:
- script: |
sudo apt-get install -y lcov
displayName: "Install dependencies"
condition: eq('${{ parameters.archive_gcov }}', true)
- task: DownloadPipelineArtifact@2
inputs:
artifact: ${{ parameters.artifact_name }}
displayName: "Download gcov artifact"
condition: eq('${{ parameters.archive_gcov }}', true)
- script: |
set -x
ls -lh
sudo tar -zxvf sonic-gcov.tar.gz
sudo cp -rf sonic-gcov $(Build.ArtifactStagingDirectory)
sudo rm sonic-gcov.tar.gz
ls -lh
workingDirectory: $(Pipeline.Workspace)
displayName: "store sonic-gcov"
condition: eq('${{ parameters.archive_gcov }}', true)
- checkout: self
submodules: true
condition: eq('${{ parameters.archive_gcov }}', true)
- script: |
set -x
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
pushd ./s/
sudo tar -zcvf swss.tar.gz ./*
ls -lh ./*
cp ./gcovpreload/lcov_cobertura.py $(Build.ArtifactStagingDirectory)/
cp ./tests/gcov_support.sh $(Build.ArtifactStagingDirectory)/sonic-gcov
sudo cp -rf swss.tar.gz $(Build.ArtifactStagingDirectory)/sonic-gcov
popd
sudo cp -rf $(Build.ArtifactStagingDirectory)/sonic-gcov ./
pushd sonic-gcov
ls -lh ./*
sudo chmod +x ./gcov_support.sh
sudo ./gcov_support.sh generate
sudo ./gcov_support.sh merge_container_info $(Build.ArtifactStagingDirectory)
sudo cp -rf gcov_output $(Build.ArtifactStagingDirectory)
ls -lh $(Build.ArtifactStagingDirectory)
popd
workingDirectory: $(Pipeline.Workspace)
displayName: "generate gcov reports"
condition: eq('${{ parameters.archive_gcov }}', true)
- publish: $(Build.ArtifactStagingDirectory)/gcov_output
artifact: gcov_info
displayName: "Archive gcov info"
condition: eq('${{ parameters.archive_gcov }}', true)

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.ArtifactStagingDirectory)/gcov_output/AllMergeReport/coverage.xml'
reportDirectory: '$(Build.ArtifactStagingDirectory)/gcov_output/AllMergeReport/'
displayName: 'Publish c c++ test coverage'
condition: eq('${{ parameters.archive_gcov }}', true)

29 changes: 28 additions & 1 deletion .azure-pipelines/test-docker-sonic-vs-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ parameters:
- name: log_artifact_name
type: string

- name: gcov_artifact_name
type: string

- name: sonic_slave
type: string

- name: archive_gcov
type: boolean
default: false

jobs:
- job:
displayName: vstest
Expand Down Expand Up @@ -53,7 +63,12 @@ jobs:
sudo /sbin/ip link add Vrf1 type vrf table 1001 || { echo 'vrf command failed' ; exit 1; }
sudo /sbin/ip link del Vrf1 type vrf table 1001
pushd tests
sudo py.test -v --force-flaky --junitxml=tr.xml --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
if [ '${{ parameters.archive_gcov }}' == True ]; then
sudo py.test -v --force-flaky --junitxml=tr.xml --keeptb --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
else
sudo py.test -v --force-flaky --junitxml=tr.xml --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
fi
displayName: "Run vs tests"
- task: PublishTestResults@2
Expand All @@ -64,9 +79,21 @@ jobs:

- script: |
cp -r tests/log $(Build.ArtifactStagingDirectory)/
if [ '${{ parameters.archive_gcov }}' == True ]; then
sudo apt-get install -y lcov
./tests/gcov_support.sh set_environment $(Build.ArtifactStagingDirectory)
docker stop $(docker ps -q -a)
docker rm $(docker ps -q -a)
fi
displayName: "Collect logs"
condition: always()
- publish: $(Build.ArtifactStagingDirectory)/gcov_tmp
artifact: ${{ parameters.gcov_artifact_name }}
displayName: "Publish gcov output"
condition: eq('${{ parameters.archive_gcov }}', true)

- publish: $(Build.ArtifactStagingDirectory)/
artifact: ${{ parameters.log_artifact_name }}@$(System.JobAttempt)
displayName: "Publish logs"
Expand Down
7 changes: 6 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
SUBDIRS = fpmsyncd neighsyncd fdbsyncd portsyncd mclagsyncd natsyncd orchagent swssconfig cfgmgr tests gearsyncd
if GCOV_ENABLED
SUBDIRS = gcovpreload fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd
else
SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd
endif


if HAVE_LIBTEAM
SUBDIRS += teamsyncd tlm_teamd
Expand Down
20 changes: 20 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ stages:
sairedis_artifact_name: sonic-sairedis
artifact_name: sonic-swss
archive_pytests: true
archive_gcov: true

- stage: BuildArm
dependsOn: Build
Expand All @@ -38,6 +39,7 @@ stages:
swss_common_artifact_name: sonic-swss-common.armhf
sairedis_artifact_name: sonic-sairedis.armhf
artifact_name: sonic-swss.armhf
archive_gcov: false

- template: .azure-pipelines/build-template.yml
parameters:
Expand All @@ -50,6 +52,7 @@ stages:
buildimage_pipeline: 140
sairedis_artifact_name: sonic-sairedis.arm64
artifact_name: sonic-swss.arm64
archive_gcov: false

- stage: BuildDocker
dependsOn: Build
Expand All @@ -69,3 +72,20 @@ stages:
- template: .azure-pipelines/test-docker-sonic-vs-template.yml
parameters:
log_artifact_name: log
gcov_artifact_name: sonic-gcov
sonic_slave: sonic-slave-buster
archive_gcov: true

- stage: Gcov
dependsOn: Test
condition: always()
jobs:
- template: .azure-pipelines/gcov.yml
parameters:
arch: amd64
sonic_slave: sonic-slave-buster
swss_common_artifact_name: sonic-swss-common
sairedis_artifact_name: sonic-sairedis
swss_artifact_name: sonic-swss
artifact_name: sonic-gcov
archive_gcov: true
17 changes: 17 additions & 0 deletions cfgmgr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,20 @@ macsecmgrd_SOURCES = macsecmgrd.cpp macsecmgr.cpp $(top_srcdir)/orchagent/orch.c
macsecmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
macsecmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
macsecmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS)

if GCOV_ENABLED
vlanmgrd_LDADD += -lgcovpreload
teammgrd_LDADD += -lgcovpreload
portmgrd_LDADD += -lgcovpreload
intfmgrd_LDADD+= -lgcovpreload
buffermgrd_LDADD += -lgcovpreload
vrfmgrd_LDADD += -lgcovpreload
nbrmgrd_LDADD += -lgcovpreload
vxlanmgrd_LDADD += -lgcovpreload
sflowmgrd_LDADD += -lgcovpreload
natmgrd_LDADD += -lgcovpreload
coppmgrd_LDADD += -lgcovpreload
tunnelmgrd_LDADD += -lgcovpreload
macsecmgrd_LDADD += -lgcovpreload
endif

19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ CFLAGS_COMMON+=" -Wno-switch-default"
CFLAGS_COMMON+=" -Wno-long-long"
CFLAGS_COMMON+=" -Wno-redundant-decls"

# Code testing coverage with gcov
AC_MSG_CHECKING(whether to build with gcov testing)
AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], [Whether to enable gcov testing]),, enable_gcov=no)

if test "x$enable_gcov" = "xyes"; then
if test "$GCC" = "no"; then
AC_MSG_ERROR(not compiling with gcc, which is required for gcov testing)
fi

CFLAGS_COMMON+=" -fprofile-arcs -ftest-coverage"
AC_SUBST(CFLAGS_COMMON)

LDFLAGS+=" -fprofile-arcs -lgcov"
AC_SUBST(LDFLAGS)
fi

AM_CONDITIONAL(GCOV_ENABLED, test x$enable_gcov = xyes)
AC_MSG_RESULT($enable_gcov)

AC_SUBST(CFLAGS_COMMON)

AC_CONFIG_FILES([
Expand Down
10 changes: 10 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ include /usr/share/dpkg/default.mk
# dh_auto_configure -- \
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

ifeq ($(ENABLE_GCOV), y)
override_dh_auto_configure:
dh_auto_configure -- --enable-gcov
endif

override_dh_auto_install:
dh_auto_install --destdir=debian/swss
ifeq ($(ENABLE_GCOV), y)
mkdir -p debian/swss/tmp/gcov
sh ./tests/gcov_support.sh collect swss
endif

override_dh_strip:
dh_strip --dbg-package=swss-dbg

3 changes: 3 additions & 0 deletions fdbsyncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ fdbsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS)
fdbsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS)
fdbsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS)

if GCOV_ENABLED
fdbsyncd_LDADD += -lgcovpreload
endif
4 changes: 4 additions & 0 deletions fpmsyncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ fpmsyncd_SOURCES = fpmsyncd.cpp fpmlink.cpp routesync.cpp $(top_srcdir)/warmrest
fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
fpmsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon

if GCOV_ENABLED
fpmsyncd_LDADD += -lgcovpreload
endif
Loading

0 comments on commit b20f0f4

Please sign in to comment.