github.com/cockroachdb/pebble@v1.1.2/scripts/code-coverage.sh (about)

     1  #!/bin/bash
     2  
     3  # This script runs unit tests and the metamorphic tests with coverage
     4  # instrumentation and generates three lcov files:
     5  #  - ./artifacts/profile-tests.lcov
     6  #  - ./artifacts/profile-meta.lcov
     7  #  - ./artifacts/profile-tests-and-meta.lcov
     8  
     9  set -euxo pipefail
    10  
    11  mkdir -p artifacts
    12  
    13  tmpdir=$(mktemp -d)
    14  trap 'rm -rf "$tmpdir"' EXIT
    15  
    16  test_failed=0
    17  # The coverpkg argument ensures that coverage is not restricted to the tested
    18  # package; so this will get us overall coverage for all tests.
    19  go test -tags invariants ./... -coverprofile=artifacts/profile-tests.gocov -coverpkg=./... || test_failed=1
    20  
    21  # The metamorphic test executes itself for each run; we don't get coverage for
    22  # the inner run. To fix this, we use metarunner as the "inner" binary and we
    23  # instrument it with coverage (see https://go.dev/testing/coverage/#building).
    24  go build -tags invariants -o "${tmpdir}/metarunner" -cover ./internal/metamorphic/metarunner
    25  mkdir -p "${tmpdir}/metacover"
    26  
    27  GOCOVERDIR="${tmpdir}/metacover" go test ./internal/metamorphic \
    28    -count 50 --inner-binary="${tmpdir}/metarunner" || test_failed=1
    29  
    30  go tool covdata textfmt -i "${tmpdir}/metacover" -o artifacts/profile-meta.gocov
    31  
    32  # TODO(radu): make the crossversion metamorphic test work.
    33  
    34  go run github.com/cockroachdb/code-cov-utils/convert@v1.1.0 -out artifacts/profile-tests.lcov \
    35    -trim-prefix github.com/cockroachdb/pebble/ \
    36    artifacts/profile-tests.gocov
    37  
    38  go run github.com/cockroachdb/code-cov-utils/convert@v1.1.0 -out artifacts/profile-meta.lcov \
    39    -trim-prefix github.com/cockroachdb/pebble/ \
    40    artifacts/profile-meta.gocov
    41  
    42  go run github.com/cockroachdb/code-cov-utils/convert@v1.1.0 -out artifacts/profile-tests-and-meta.lcov \
    43    -trim-prefix github.com/cockroachdb/pebble/ \
    44    artifacts/profile-tests.gocov artifacts/profile-meta.gocov
    45  
    46  if [ $test_failed -eq 1 ]; then
    47    # TODO(radu): somehow plumb the error and publish it.
    48    echo "WARNING: some tests have failed; coverage might be incomplete."
    49  fi