diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b72f4adba7..e5d9af9aab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,6 +89,13 @@ jobs: tar -xzf /tmp/reports.tar.gz -C /tmp/reports sudo chown -R $(id -u):$(id -g) /tmp/reports tree -nh /tmp/reports + - + name: Send to Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./bundles + env_vars: RUNNER_OS + flags: unit - name: Upload reports if: always() @@ -222,6 +229,7 @@ jobs: make -o build test-integration env: TEST_SKIP_INTEGRATION_CLI: 1 + TESTCOVERAGE: 1 - name: Prepare reports if: always() @@ -235,6 +243,13 @@ jobs: tar -xzf /tmp/reports.tar.gz -C $reportsPath sudo chown -R $(id -u):$(id -g) $reportsPath tree -nh $reportsPath + - + name: Send to Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./bundles/test-integration + env_vars: RUNNER_OS + flags: integration,${{ matrix.mode }} - name: Test daemon logs if: always() @@ -312,6 +327,7 @@ jobs: make -o build test-integration env: TEST_SKIP_INTEGRATION: 1 + TESTCOVERAGE: 1 TESTFLAGS: "-test.run (${{ matrix.test }})/" - name: Prepare reports @@ -324,6 +340,13 @@ jobs: tar -xzf /tmp/reports.tar.gz -C $reportsPath sudo chown -R $(id -u):$(id -g) $reportsPath tree -nh $reportsPath + - + name: Send to Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./bundles/test-integration + env_vars: RUNNER_OS + flags: integration-cli - name: Test daemon logs if: always() diff --git a/Jenkinsfile b/Jenkinsfile index fd3408472e..4da30e1cfd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -234,7 +234,7 @@ pipeline { sh ''' bundleName=unit echo "Creating ${bundleName}-bundles.tar.gz" - tar -czvf ${bundleName}-bundles.tar.gz bundles/junit-report*.xml bundles/go-test-report*.json bundles/profile*.out + tar -czvf ${bundleName}-bundles.tar.gz bundles/junit-report*.xml bundles/go-test-report*.json bundles/coverage*.out ''' archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true diff --git a/Makefile b/Makefile index d5a9be0da0..93868c487d 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,7 @@ DOCKER_ENVS := \ -e TEST_INTEGRATION_DIR \ -e TEST_SKIP_INTEGRATION \ -e TEST_SKIP_INTEGRATION_CLI \ + -e TESTCOVERAGE \ -e TESTDEBUG \ -e TESTDIRS \ -e TESTFLAGS \ diff --git a/hack/make/.integration-test-helpers b/hack/make/.integration-test-helpers index 87614fea03..bbfc4edb86 100644 --- a/hack/make/.integration-test-helpers +++ b/hack/make/.integration-test-helpers @@ -16,6 +16,7 @@ source "${MAKEDIR}/.go-autogen" : "${TEST_REPEAT:=1}" : "${TESTFLAGS:=}" : "${TESTDEBUG:=}" +: "${TESTCOVERAGE:=}" : "${GOCACHE:=$(go env GOCACHE)}" setup_integration_test_filter() { @@ -80,7 +81,13 @@ run_test_integration_suites() { # Finally, we use periods as separator (instead of slashes) to be more # in line with Java package names (which is what junit.xml was designed for) pkgname="$(go env GOARCH).${pkgname//\//.}" - echo "Running $PWD (${pkgname}) flags=${flags}" + + pkgtestflags=$flags + if [ -n "${TESTCOVERAGE}" ]; then + pkgtestflags="$pkgtestflags -test.coverprofile=${ABS_DEST}/${pkgname//./-}-coverage.out" + fi + + echo "Running $PWD (${pkgname}) flags=${pkgtestflags}" [ -n "$TESTDEBUG" ] && set -x # shellcheck disable=SC2086 test_env gotestsum \ @@ -88,7 +95,7 @@ run_test_integration_suites() { --jsonfile="${ABS_DEST}/${pkgname//./-}-go-test-report.json" \ --junitfile="${ABS_DEST}/${pkgname//./-}-junit-report.xml" \ --raw-command \ - -- go tool test2json -p "${pkgname}" -t ./test.main ${flags} + -- go tool test2json -p "${pkgname}" -t ./test.main ${pkgtestflags} ); then exit 1; fi done } @@ -112,8 +119,12 @@ build_test_suite_binaries() { build_test_suite_binary() { local dir="$1" local out="$2" + local testflags echo Building test suite binary "$dir/$out" - go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "$dir" + if [ -n "${TESTCOVERAGE}" ]; then + testflags="-cover -covermode=atomic" + fi + go test ${testflags} -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "$dir" } cleanup_test_suite_binaries() { diff --git a/hack/test/unit b/hack/test/unit index 89666c9218..fefe065e38 100755 --- a/hack/test/unit +++ b/hack/test/unit @@ -32,7 +32,7 @@ if [ -n "${base_pkg_list}" ]; then gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \ "${BUILDFLAGS[@]}" \ -cover \ - -coverprofile=bundles/profile.out \ + -coverprofile=bundles/coverage.out \ -covermode=atomic \ ${TESTFLAGS} \ ${base_pkg_list} @@ -44,7 +44,7 @@ if [ -n "${libnetwork_pkg_list}" ]; then gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml -- \ "${BUILDFLAGS[@]}" \ -cover \ - -coverprofile=bundles/profile-libnetwork.out \ + -coverprofile=bundles/coverage-libnetwork.out \ -covermode=atomic \ -p=1 \ ${TESTFLAGS} \