Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gcov-vs]support vs coverate rate #972

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c5d0390
support vs coverate rate
pettershao-ragilenetworks Nov 22, 2021
1eb71e0
Update gcov.yml
pettershao-ragilenetworks Nov 22, 2021
c74e71a
Update Makefile.am
pettershao-ragilenetworks Nov 22, 2021
64234e3
Update Makefile.am
pettershao-ragilenetworks Nov 22, 2021
e5a6cf8
add preloader Makefile
pettershao-ragilenetworks Nov 23, 2021
a278cf1
update script
pettershao-ragilenetworks Nov 23, 2021
a556021
update test yml
pettershao-ragilenetworks Nov 23, 2021
c3da170
update patch
pettershao-ragilenetworks Nov 23, 2021
d97e588
update patch
pettershao-ragilenetworks Nov 23, 2021
301e885
update path
pettershao-ragilenetworks Nov 23, 2021
91adb69
update path
pettershao-ragilenetworks Nov 23, 2021
348bf31
try to get unittest total info
pettershao-ragilenetworks Nov 24, 2021
37326be
fix unittest error
pettershao-ragilenetworks Nov 24, 2021
959ec32
fix make check error
pettershao-ragilenetworks Nov 24, 2021
c970c2a
fix make check error
pettershao-ragilenetworks Nov 24, 2021
43d0ced
fix test fail
pettershao-ragilenetworks Nov 24, 2021
a979f3b
try to fix can't find total.info
pettershao-ragilenetworks Nov 24, 2021
8630dad
archive unittest info
pettershao-ragilenetworks Nov 25, 2021
e4aa8fe
archive totol.info
pettershao-ragilenetworks Nov 25, 2021
56e6009
download unittest.info
pettershao-ragilenetworks Nov 25, 2021
cbff883
add sudo permission
pettershao-ragilenetworks Nov 25, 2021
55887ab
fix archive SAI faile
pettershao-ragilenetworks Nov 25, 2021
e76705c
fix archive SAI fail
pettershao-ragilenetworks Nov 25, 2021
5a3e0d7
fix archive info fail
pettershao-ragilenetworks Nov 26, 2021
50ed0ea
check total.info empty
pettershao-ragilenetworks Nov 26, 2021
a74abff
q
pettershao-ragilenetworks Nov 26, 2021
aeba308
adjust path for info files to merge
pettershao-ragilenetworks Nov 26, 2021
7effce8
revert back removing container
pettershao-ragilenetworks Nov 26, 2021
a616fe2
try to findout can't find info issue
pettershao-ragilenetworks Nov 26, 2021
ed69f67
remove container folders
pettershao-ragilenetworks Nov 26, 2021
e62d713
test all
pettershao-ragilenetworks Nov 26, 2021
e52a1e1
triggle rebuld
pettershao-ragilenetworks May 18, 2022
88b55d3
Update azure-pipelines.yml
pettershao-ragilenetworks Nov 7, 2022
fa30441
Update syncd.install
pettershao-ragilenetworks Nov 8, 2022
ebe72b1
Update build-template.yml
pettershao-ragilenetworks Nov 9, 2022
7dd927b
Update test-docker-sonic-vs-template.yml
pettershao-ragilenetworks Nov 9, 2022
09ff654
Update build-template.yml
pettershao-ragilenetworks Nov 9, 2022
355947e
Update Makefile.am
pettershao-ragilenetworks Nov 17, 2022
18495a1
Update azure-pipelines.yml
pettershao-ragilenetworks Nov 29, 2022
dee8177
Update gcovpreload.c
pettershao-ragilenetworks Dec 6, 2022
d8e93f4
Update test-docker-sonic-vs-template.yml
pettershao-ragilenetworks Dec 7, 2022
9156aa4
Update azure-pipelines.yml
pettershao-ragilenetworks Dec 7, 2022
9199a36
Update gcovpreload.c
pettershao-ragilenetworks Dec 7, 2022
fa7e30c
Merge branch 'master' into support_vs_coverage_rate
pettershao-ragilenetworks Feb 1, 2023
e56c5bf
Update gcovpreload.c
pettershao-ragilenetworks Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ parameters:
- name: syslog_artifact_name
type: string

- name: gcov_unittest_artifact_name
type: string

- name: run_unit_test
type: boolean
default: false
Expand Down Expand Up @@ -154,9 +157,11 @@ jobs:
set -ex
rm ../*.deb || true
./autogen.sh
extraflags='--enable-code-coverage'
extraflags='--enable-code-coverage --enable-gcov'
if [ '${{ parameters.asan }}' == True ]; then
extraflags='--enable-asan'
else
export ENABLE_GCOV=y
fi
DEB_BUILD_OPTIONS=nocheck fakeroot debian/rules DEB_CONFIGURE_EXTRA_FLAGS=$extraflags CFLAGS="" CXXFLAGS="" binary-syncd-vs
mv ../*.deb .
Expand All @@ -181,27 +186,18 @@ jobs:
# Add SYS_TIME capability for settimeofday ok in syncd test
sudo setcap "cap_sys_time=eip" syncd/.libs/tests
make check
gcovr --version
find SAI/meta -name "*.gc*" | xargs rm -vf
gcovr -r ./ -e ".*/SAI/.*" -e ".+/json.hpp" -e "swss/.+" -e ".*/.libs/.*" -e ".*/debian/.*" --exclude-unreachable-branches --exclude-throw-branches -x --xml-pretty -o coverage.xml
sudo apt-get install -y lcov
sudo mkdir -p $(Build.ArtifactStagingDirectory)/gcov_unittest_tmp
./gcov_support.sh get_info $(Build.ArtifactStagingDirectory)/gcov_unittest_tmp
displayName: "Run sonic sairedis unit tests"
- publish: $(System.DefaultWorkingDirectory)/
artifact: ${{ parameters.artifact_name }}
displayName: "Archive sonic sairedis debian packages"
- ${{ if eq(parameters.archive_gcov, true) }}:
- script: |
set -ex
# Install .NET CORE
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-add-repository https://packages.microsoft.com/debian/10/prod
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
displayName: "Install .NET CORE"
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
displayName: 'Publish test coverage'
- publish: $(Build.ArtifactStagingDirectory)/gcov_unittest_tmp
artifact: ${{ parameters.gcov_unittest_artifact_name }}
displayName: "Publish gcov unittest output"
condition: eq('${{ parameters.archive_gcov }}', true)
- script: |
pwd
sudo chmod a+r /var/log/syslog*
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 @@ -19,3 +19,7 @@ RUN dpkg -i /debs/syncd-vs_1.0.0_amd64.deb
RUN if [ "$need_dbg" = "y" ] ; then dpkg -i /debs/syncd-vs-dbg_1.0.0_amd64.deb ; fi

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

RUN apt-get update

RUN apt-get -y install lcov
127 changes: 127 additions & 0 deletions .azure-pipelines/gcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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: gcov_unittest_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.sairedis_artifact_name }}
displayName: "Download sonic sairedis deb packages"
- task: DownloadPipelineArtifact@2
inputs:
artifact: ${{ parameters.artifact_name }}
displayName: "Download gcov artifact"
condition: eq('${{ parameters.archive_gcov }}', true)
- task: DownloadPipelineArtifact@2
inputs:
artifact: ${{ parameters.gcov_unittest_artifact_name }}
displayName: "Download gcov unittest artifact"
condition: eq('${{ parameters.archive_gcov }}', true)
- script: |
set -x
ls -lh
sudo tar -zxvf sonic-gcov.tar.gz
sudo cp unittest_total.info sonic-gcov/
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 syncd.tar.gz ./*
ls -lh ./*
sudo cp ./lcov_cobertura.py $(Build.ArtifactStagingDirectory)/
sudo cp ./gcov_support.sh $(Build.ArtifactStagingDirectory)/sonic-gcov
sudo cp -rf syncd.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 find gcov_output -name "SAI" | xargs sudo rm -rf
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)
31 changes: 30 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

- name: docker_sonic_vs_name
type: string
default: docker-sonic-vs
Expand Down Expand Up @@ -84,13 +94,21 @@ jobs:
test_set+=("${test}")
if [ ${#test_set[@]} -ge 20 ]; then
test_name=$(echo "${test_set[0]}" | cut -d "." -f 1)
if [ '${{ parameters.archive_gcov }}' == True ]; then
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" $params --keeptb --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
else
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" $params --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
fi
test_set=()
fi
done
if [ ${#test_set[@]} -gt 0 ]; then
test_name=$(echo "${test_set[0]}" | cut -d "." -f 1)
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" $params --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
if [ '${{ parameters.archive_gcov }}' == True ]; then
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" --keeptb $params --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
else
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" $params --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
fi
fi
rm -rf $(Build.ArtifactStagingDirectory)/download
displayName: "Run vs tests"
Expand All @@ -104,12 +122,23 @@ jobs:

- script: |
cp -r sonic-swss/tests/log $(Build.ArtifactStagingDirectory)/
if [ '${{ parameters.archive_gcov }}' == True ]; then
sudo apt-get install -y lcov
./sonic-sairedis/gcov_support.sh set_environment $(Build.ArtifactStagingDirectory)
docker stop $(docker ps -q -a)
docker rm $(docker ps -q -a)
fi
if [ '${{ parameters.asan }}' == True ]; then
cp -vr sonic-swss/tests/log/*/log/asan $(Build.ArtifactStagingDirectory)/
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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = meta lib vslib pyext
SUBDIRS = gcovpreload meta lib vslib pyext

if SYNCD
SUBDIRS += syncd saiplayer saidump saidiscovery saisdkdump saiasiccmp tests unittest
Expand Down
25 changes: 23 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ stages:
swss_common_artifact_name: sonic-swss-common
artifact_name: sonic-sairedis
syslog_artifact_name: sonic-sairedis.syslog
gcov_unittest_artifact_name: gcov_unitest.info
run_unit_test: true
archive_gcov: true
debian_version: ${{ parameters.debian_version }}
Expand Down Expand Up @@ -88,6 +89,7 @@ stages:
swss_common_artifact_name: sonic-swss-common.armhf
artifact_name: sonic-sairedis.armhf
syslog_artifact_name: sonic-sairedis.syslog.armhf
gcov_unittest_artifact_name: gcov_unitest.info
debian_version: ${{ parameters.debian_version }}

- template: .azure-pipelines/build-template.yml
Expand All @@ -99,11 +101,12 @@ stages:
swss_common_artifact_name: sonic-swss-common.arm64
artifact_name: sonic-sairedis.arm64
syslog_artifact_name: sonic-sairedis.syslog.arm64
gcov_unittest_artifact_name: gcov_unitest.info
debian_version: ${{ parameters.debian_version }}

- stage: BuildSwss
dependsOn: Build
condition: succeeded('Build')
condition: always()
jobs:
- template: .azure-pipelines/build-swss-template.yml
parameters:
Expand All @@ -116,7 +119,7 @@ stages:

- stage: BuildDocker
dependsOn: BuildSwss
condition: succeeded('BuildSwss')
condition: always()
jobs:
- template: .azure-pipelines/build-docker-sonic-vs-template.yml
parameters:
Expand Down Expand Up @@ -146,6 +149,24 @@ 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
gcov_unittest_artifact_name: gcov_unitest.info
swss_artifact_name: sonic-swss
artifact_name: sonic-gcov
archive_gcov: true

- stage: TestAsan
dependsOn: BuildDockerAsan
Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ CXXFLAGS_COMMON+=" -Wno-switch-default"
CXXFLAGS_COMMON+=" -Wconversion"
CXXFLAGS_COMMON+=" -Wno-psabi"

# 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

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

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

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

SAVED_FLAGS="$CXXFLAGS"
CXXFLAGS="-Wcast-align=strict"
AC_MSG_CHECKING([whether CXX supports -Wcast-align=strict])
Expand Down Expand Up @@ -210,6 +229,7 @@ CXXFLAGS="$SAVED_FLAGS"
AC_CHECK_FUNCS(sai_bulk_object_clear_stats sai_bulk_object_get_stats)

AC_OUTPUT(Makefile
gcovpreload/Makefile
meta/Makefile
lib/Makefile
vslib/Makefile
Expand Down
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ override_dh_auto_configure:
dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS) $(shell cat /tmp/syncd-build) ${SWSS_COMMON_CONFIG} $(configure_opts)

override_dh_install:
sh ./gcov_support.sh collect syncd-vs
dh_install
# Note: escape $ with an extra $ symbol
if egrep -q '(^| )--enable-rpcserver=yes( |$$)' /tmp/syncd-build && [ -f debian/syncd-rpc/usr/bin/syncd_init_common.sh ] ; then
Expand Down
2 changes: 2 additions & 0 deletions debian/syncd.install
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
usr/lib/*/libgcovpreload*.so.* usr/lib
usr/bin/saidump
usr/bin/saiplayer
usr/bin/saisdkdump
usr/bin/saidiscovery
usr/bin/saiasiccmp
usr/bin/syncd*
syncd/scripts/* usr/bin
gcov tmp
Loading