From 77fa0cff3cd2a038bb6cd1417b417f919f13173c Mon Sep 17 00:00:00 2001 From: QxBytes Date: Mon, 31 Mar 2025 12:51:13 -0700 Subject: [PATCH 1/7] generate code coverage --- .pipelines/templates/run-unit-tests.yaml | 15 ++++++++++++++- Makefile | 5 ++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index 3d8f18e7a3..3c1c263afd 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -13,7 +13,12 @@ stages: steps: - script: | make tools - # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout + sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov + sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml + + # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), + # stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. + # Read all output from fd 4 (output from tee) and write to top stdout { { { { sudo -E env "PATH=$PATH" make test-all; echo $? >&3; @@ -21,9 +26,17 @@ stages: } 3>&1; } | { read xs; exit $xs; } } 4>&1 + + gocov convert coverage-all.out > total_ut_coverage.json + gocov-xml < total_ut_coverage.json > total_ut_coverage.xml retryCountOnTaskFailure: 3 name: "Test" displayName: "Run Tests" + - task: PublishCodeCoverageResults@2 + displayName: "Publish Code Coverage Report" + condition: always() + inputs: + summaryFileLocation: total_ut_coverage.xml - stage: test_windows displayName: Test ACN Windows diff --git a/Makefile b/Makefile index 4911f52476..0dc26049b4 100644 --- a/Makefile +++ b/Makefile @@ -758,9 +758,8 @@ RESTART_CASE ?= false CNI_TYPE ?= cilium test-all: ## run all unit tests. - @$(eval COVER_FILTER=`go list $(COVER_PKG)/... | tr '\n' ','`) - @echo Test coverpkg: $(COVER_FILTER) - go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -coverpkg=$(COVER_FILTER) -race -covermode atomic -coverprofile=coverage.out $(COVER_PKG)/... + -go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=coverage-all.out $(COVER_PKG)/... + go tool cover -func=coverage-all.out test-integration: ## run all integration tests. AZURE_IPAM_VERSION=$(AZURE_IPAM_VERSION) \ From 80e3d7c0f33c4da260435b5cbce8f9a050adc6e3 Mon Sep 17 00:00:00 2001 From: QxBytes Date: Mon, 31 Mar 2025 15:36:31 -0700 Subject: [PATCH 2/7] ut regression check --- .pipelines/templates/run-unit-tests.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index 3c1c263afd..e05f14c479 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -37,6 +37,17 @@ stages: condition: always() inputs: summaryFileLocation: total_ut_coverage.xml + - task: BuildQualityChecks@8 + displayName: "Check Code Coverage Regression" + condition: always() + inputs: + checkCoverage: true + coverageFailOption: "build" + coverageType: "lines" + fallbackOnPRTargetBranch: false + baseBranchRef: "master" + allowCoverageVariance: true + coverageVariance: 0.25 - stage: test_windows displayName: Test ACN Windows From 58a44f1f4fd21c37b5f4b116f2d1fdd218da02de Mon Sep 17 00:00:00 2001 From: QxBytes Date: Tue, 1 Apr 2025 15:18:06 -0700 Subject: [PATCH 3/7] move coverage report generation to separate step --- .pipelines/templates/run-unit-tests.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index e05f14c479..25993b13f0 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -12,6 +12,7 @@ stages: name: "$(BUILD_POOL_NAME_DEFAULT)" steps: - script: | + set -e make tools sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml @@ -26,12 +27,15 @@ stages: } 3>&1; } | { read xs; exit $xs; } } 4>&1 - - gocov convert coverage-all.out > total_ut_coverage.json - gocov-xml < total_ut_coverage.json > total_ut_coverage.xml retryCountOnTaskFailure: 3 name: "Test" displayName: "Run Tests" + - bash: | + gocov convert coverage-all.out > total_ut_coverage.json + gocov-xml < total_ut_coverage.json > total_ut_coverage.xml + name: "Coverage" + displayName: "Generate Coverage Report" + condition: always() - task: PublishCodeCoverageResults@2 displayName: "Publish Code Coverage Report" condition: always() From 3f6beddc76522047d6ebabce6b7fb4bba8eb45ff Mon Sep 17 00:00:00 2001 From: QxBytes Date: Wed, 2 Apr 2025 12:03:00 -0700 Subject: [PATCH 4/7] move link where it's needed --- .pipelines/templates/run-unit-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index 25993b13f0..3a1353fb7a 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -14,8 +14,6 @@ stages: - script: | set -e make tools - sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov - sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), # stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. @@ -31,6 +29,8 @@ stages: name: "Test" displayName: "Run Tests" - bash: | + sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov + sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml gocov convert coverage-all.out > total_ut_coverage.json gocov-xml < total_ut_coverage.json > total_ut_coverage.xml name: "Coverage" From 8e342e34f0174c4000e885f529d39bb66e671c18 Mon Sep 17 00:00:00 2001 From: QxBytes Date: Wed, 2 Apr 2025 12:48:29 -0700 Subject: [PATCH 5/7] add windows ut coverage --- .pipelines/templates/run-unit-tests.yaml | 82 ++++++++++++++++++------ 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index 3a1353fb7a..2b183659c7 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -25,13 +25,73 @@ stages: } 3>&1; } | { read xs; exit $xs; } } 4>&1 + + mv coverage-all.out linux-coverage.out retryCountOnTaskFailure: 3 name: "Test" displayName: "Run Tests" + - task: PublishPipelineArtifact@1 + inputs: + targetPath: 'linux-coverage.out' + artifactName: 'linux-coverage' + + - stage: test_windows + displayName: Test ACN Windows + dependsOn: + - setup + jobs: + - job: test + displayName: Run Tests + variables: + STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ] + pool: + name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)" + steps: + # Only run one go test per script + - script: | + cd azure-container-networking/ + go test -timeout 30m -covermode atomic -coverprofile=windows-coverage.out ./npm/... ./cni/... ./platform/... + go tool cover -func=windows-coverage.out + retryCountOnTaskFailure: 3 + name: "TestWindows" + displayName: "Run Windows Tests" + - task: PublishPipelineArtifact@1 + inputs: + targetPath: 'windows-coverage.out' + artifactName: 'windows-coverage' + + - stage: code_coverage + displayName: Code Coverage Check + dependsOn: + - test + - test_windows + jobs: + - job: coverage + displayName: Check Coverage + pool: + name: "$(BUILD_POOL_NAME_DEFAULT)" + steps: + - task: DownloadPipelineArtifact@2 + inputs: + artifact: 'linux-coverage' + path: './' + - task: DownloadPipelineArtifact@2 + inputs: + artifact: 'windows-coverage' + path: './' - bash: | + make tools sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml - gocov convert coverage-all.out > total_ut_coverage.json + + sed -i "1d" linux-coverage.out + sed -i "1d" windows-coverage.out + + echo "mode: atomic" > total_ut_coverage.out + cat linux-coverage.out >> total_ut_coverage.out + cat windows-coverage.out >> total_ut_coverage.out + + gocov convert total_ut_coverage.out > total_ut_coverage.json gocov-xml < total_ut_coverage.json > total_ut_coverage.xml name: "Coverage" displayName: "Generate Coverage Report" @@ -52,23 +112,3 @@ stages: baseBranchRef: "master" allowCoverageVariance: true coverageVariance: 0.25 - - - stage: test_windows - displayName: Test ACN Windows - dependsOn: - - setup - jobs: - - job: test - displayName: Run Tests - variables: - STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ] - pool: - name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)" - steps: - # Only run one go test per script - - script: | - cd azure-container-networking/ - go test -timeout 30m ./npm/... ./cni/... ./platform/... - retryCountOnTaskFailure: 3 - name: "TestWindows" - displayName: "Run Windows Tests" From 353126a96d7f508a8ca28fc291da0e4ee8502d76 Mon Sep 17 00:00:00 2001 From: QxBytes Date: Wed, 2 Apr 2025 17:00:23 -0700 Subject: [PATCH 6/7] publish multiple coverage reports since unable to merge diff oses --- .pipelines/templates/run-unit-tests.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.pipelines/templates/run-unit-tests.yaml b/.pipelines/templates/run-unit-tests.yaml index 2b183659c7..2993fdbf40 100644 --- a/.pipelines/templates/run-unit-tests.yaml +++ b/.pipelines/templates/run-unit-tests.yaml @@ -84,15 +84,16 @@ stages: sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml - sed -i "1d" linux-coverage.out - sed -i "1d" windows-coverage.out + GOOS=linux gocov convert linux-coverage.out > linux-coverage.json + GOOS=linux gocov-xml < linux-coverage.json > linux-coverage.xml - echo "mode: atomic" > total_ut_coverage.out - cat linux-coverage.out >> total_ut_coverage.out - cat windows-coverage.out >> total_ut_coverage.out - - gocov convert total_ut_coverage.out > total_ut_coverage.json - gocov-xml < total_ut_coverage.json > total_ut_coverage.xml + GOOS=windows gocov convert windows-coverage.out > windows-coverage.json + GOOS=windows gocov-xml < windows-coverage.json > windows-coverage.xml + + mkdir coverage + + mv linux-coverage.xml coverage/ + mv windows-coverage.xml coverage/ name: "Coverage" displayName: "Generate Coverage Report" condition: always() @@ -100,7 +101,7 @@ stages: displayName: "Publish Code Coverage Report" condition: always() inputs: - summaryFileLocation: total_ut_coverage.xml + summaryFileLocation: coverage/* - task: BuildQualityChecks@8 displayName: "Check Code Coverage Regression" condition: always() From b880184386c304c84acde318898e7e5b5f4c8977 Mon Sep 17 00:00:00 2001 From: QxBytes Date: Thu, 3 Apr 2025 09:58:09 -0700 Subject: [PATCH 7/7] remove debug always succeed --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0dc26049b4..06eb314308 100644 --- a/Makefile +++ b/Makefile @@ -758,7 +758,7 @@ RESTART_CASE ?= false CNI_TYPE ?= cilium test-all: ## run all unit tests. - -go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=coverage-all.out $(COVER_PKG)/... + go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=coverage-all.out $(COVER_PKG)/... go tool cover -func=coverage-all.out test-integration: ## run all integration tests.