diff --git a/.azure-pipelines/build-template.yml b/.azure-pipelines/build-template.yml index 6cd6a7a699..40f85237d6 100644 --- a/.azure-pipelines/build-template.yml +++ b/.azure-pipelines/build-template.yml @@ -23,6 +23,12 @@ parameters: - name: sonic_slave type: string +- name: buildimage_artifact_name + type: string + +- name: buildimage_pipeline + type: number + - name: sairedis_artifact_name type: string @@ -36,6 +42,10 @@ parameters: type: boolean default: false +- name: archive_gcov + type: boolean + default: false + jobs: - job: displayName: ${{ parameters.arch }} @@ -51,26 +61,28 @@ jobs: image: sonicdev-microsoft.azurecr.io:443/${{ parameters.sonic_slave }}:latest steps: + - checkout: self + clean: true + submodules: true + - script: | + sourceBranch=$(Build.SourceBranchName) + if [[ "$(Build.Reason)" == "PullRequest" ]];then + sourceBranch=$(System.PullRequest.TargetBranch) + fi + echo "Download artifact branch: $sourceBranch" + echo "##vso[task.setvariable variable=sourceBranch]$sourceBranch" + displayName: "Get correct artifact downloading branch" - script: | sudo apt-get install -y libhiredis0.14 libhiredis-dev sudo apt-get install -y libzmq5 libzmq3-dev sudo apt-get install -qq -y \ libhiredis-dev \ - libnl-3-dev \ - libnl-genl-3-dev \ - libnl-route-3-dev \ - libnl-nf-3-dev \ swig3.0 sudo apt-get install -y libdbus-1-3 sudo apt-get install -y libteam-dev \ libteam5 \ libteamdctl0 displayName: "Install dependencies" - - script: | - ls -al $(Pipeline.Workspace) - rm -rf $(Pipeline.Workspace)/*.deb - ls -al $(Pipeline.Workspace) - displayName: "Clean workspace" - task: DownloadPipelineArtifact@2 inputs: source: specific @@ -78,7 +90,12 @@ jobs: pipeline: 9 artifact: ${{ parameters.swss_common_artifact_name }} runVersion: 'latestFromBranch' - runBranch: 'refs/heads/master' + runBranch: 'refs/heads/$(sourceBranch)' + path: '$(Build.SourcesDirectory)/${{ parameters.swss_common_artifact_name }}' + allowFailedBuilds: true + patterns: | + **/libswsscommon_1.0.0_${{ parameters.arch }}.deb + **/libswsscommon-dev_1.0.0_${{ parameters.arch }}.deb displayName: "Download sonic swss common deb packages" - task: DownloadPipelineArtifact@2 inputs: @@ -87,26 +104,50 @@ jobs: pipeline: 12 artifact: ${{ parameters.sairedis_artifact_name }} runVersion: 'latestFromBranch' - runBranch: 'refs/heads/master' + runBranch: 'refs/heads/$(sourceBranch)' + path: '$(Build.SourcesDirectory)/${{ parameters.sairedis_artifact_name }}' + allowFailedBuilds: true + patterns: | + **/libsaivs_*.deb + **/libsaivs-dev_*.deb + **/libsairedis_*.deb + **/libsairedis-dev_*.deb + **/libsaimetadata_*.deb + **/libsaimetadata-dev_*.deb + **/syncd-vs_*.deb displayName: "Download sonic sairedis deb packages" + - task: DownloadPipelineArtifact@2 + inputs: + source: specific + project: build + pipeline: ${{ parameters.buildimage_pipeline }} + runVersion: 'latestFromBranch' + runBranch: 'refs/heads/$(sourceBranch)' + path: '$(Build.SourcesDirectory)/${{ parameters.buildimage_artifact_name }}' + allowFailedBuilds: true + patterns: | + **/target/debs/**/libnl-3-200_*.deb + **/target/debs/**/libnl-3-dev_*.deb + **/target/debs/**/libnl-genl-3-200_*.deb + **/target/debs/**/libnl-genl-3-dev_*.deb + **/target/debs/**/libnl-route-3-200_*.deb + **/target/debs/**/libnl-route-3-dev_*.deb + **/target/debs/**/libnl-nf-3-200_*.deb + **/target/debs/**/libnl-nf-3-dev_*.deb + displayName: "Download sonic buildimage deb packages" - script: | - sudo dpkg -i libswsscommon_1.0.0_${{ parameters.arch }}.deb - sudo dpkg -i libswsscommon-dev_1.0.0_${{ parameters.arch }}.deb - sudo dpkg -i libsaivs_*.deb - sudo dpkg -i libsaivs-dev_*.deb - sudo dpkg -i libsairedis_*.deb - sudo dpkg -i libsairedis-dev_*.deb - sudo dpkg -i libsaimetadata_*.deb - sudo dpkg -i libsaimetadata-dev_*.deb - sudo dpkg -i syncd-vs_*.deb - workingDirectory: $(Pipeline.Workspace) - displayName: "Install sonic swss common and sairedis" - - checkout: self - submodules: true + set -ex + sudo dpkg -i $(find ${{ parameters.buildimage_artifact_name }} -name "*.deb") + sudo dpkg -i $(find ${{ parameters.swss_common_artifact_name }} -name "*.deb") + sudo dpkg -i $(find ${{ parameters.sairedis_artifact_name }} -name "*.deb") + displayName: "Install libnl3, sonic swss common and sairedis" - script: | - set -x + set -ex 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" diff --git a/.azure-pipelines/docker-sonic-vs/Dockerfile b/.azure-pipelines/docker-sonic-vs/Dockerfile index d425a6ffea..f288c8fdaa 100644 --- a/.azure-pipelines/docker-sonic-vs/Dockerfile +++ b/.azure-pipelines/docker-sonic-vs/Dockerfile @@ -4,6 +4,15 @@ ARG docker_container_name ADD ["debs", "/debs"] +RUN dpkg --purge python-swsscommon +RUN dpkg --purge python3-swsscommon +RUN dpkg --purge swss +RUN dpkg --purge libsairedis +RUN dpkg --purge libswsscommon +RUN dpkg --purge libsaimetadata +RUN dpkg --purge libsaivs +RUN dpkg --purge syncd-vs + RUN dpkg -i /debs/libswsscommon_1.0.0_amd64.deb RUN dpkg -i /debs/python-swsscommon_1.0.0_amd64.deb RUN dpkg -i /debs/python3-swsscommon_1.0.0_amd64.deb @@ -15,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 diff --git a/.azure-pipelines/gcov.yml b/.azure-pipelines/gcov.yml new file mode 100644 index 0000000000..0940f82cce --- /dev/null +++ b/.azure-pipelines/gcov.yml @@ -0,0 +1,129 @@ +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' + + variables: + DIFF_COVER_CHECK_THRESHOLD: 0 + DIFF_COVER_ENABLE: 'true' + DIFF_COVER_WORKING_DIRECTORY: $(System.DefaultWorkingDirectory)/gcov/ + + container: + image: sonicdev-microsoft.azurecr.io:443/${{ parameters.sonic_slave }}:latest + + + steps: + - 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" + - 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) + mkdir -p $(System.DefaultWorkingDirectory)/gcov + sudo cp -rf $(Build.ArtifactStagingDirectory)/gcov_output/AllMergeReport/* $(System.DefaultWorkingDirectory)/gcov/ + 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) + diff --git a/.azure-pipelines/test-docker-sonic-vs-template.yml b/.azure-pipelines/test-docker-sonic-vs-template.yml index d5db0e1c8f..237778af4a 100644 --- a/.azure-pipelines/test-docker-sonic-vs-template.yml +++ b/.azure-pipelines/test-docker-sonic-vs-template.yml @@ -1,11 +1,21 @@ parameters: - name: timeout type: number - default: 180 + default: 240 - 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 @@ -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 @@ -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" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a8cfe15cb2..6db3c6bda5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,21 @@ trigger: branches: include: - - "*" + - master + - 20???? +pr: + branches: + include: + - master + - 20???? +schedules: +- cron: "0 0 * * 0" + displayName: Weekly Sunday build + branches: + include: + - master + - 20???? + always: true stages: - stage: Build @@ -16,14 +30,16 @@ stages: parameters: arch: amd64 sonic_slave: sonic-slave-buster + buildimage_artifact_name: sonic-buildimage.vs + buildimage_pipeline: 142 swss_common_artifact_name: sonic-swss-common sairedis_artifact_name: sonic-sairedis artifact_name: sonic-swss archive_pytests: true + archive_gcov: true - stage: BuildArm - dependsOn: Build - condition: succeeded('Build') + dependsOn: [] jobs: - template: .azure-pipelines/build-template.yml parameters: @@ -31,9 +47,12 @@ stages: timeout: 240 pool: sonicbld-armhf sonic_slave: sonic-slave-buster-armhf + buildimage_artifact_name: sonic-buildimage.marvell-armhf + buildimage_pipeline: 141 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: @@ -42,8 +61,11 @@ stages: pool: sonicbld-arm64 sonic_slave: sonic-slave-buster-arm64 swss_common_artifact_name: sonic-swss-common.arm64 + buildimage_artifact_name: sonic-buildimage.centec-arm64 + buildimage_pipeline: 140 sairedis_artifact_name: sonic-sairedis.arm64 artifact_name: sonic-swss.arm64 + archive_gcov: false - stage: BuildDocker dependsOn: Build @@ -63,3 +85,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