vitess.io/vitess@v0.16.2/tools/all_test_for_coverage.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2019 The Vitess Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # The purpose of this script is to run testcase and get coverage report
    18  # These script runs all unit testcases including go endtoend testcase
    19  # Here we ignore any error from testcase as the purpose is to collect coverage.
    20  # So if there is a flaky test, it will get only chance to run, if it fails we ignore coverage from that.
    21  
    22  
    23  ### Execute unit testcase ###
    24  source build.env
    25  make tools
    26  make build
    27  echo "--------- executing unit testcases ---------"
    28  packages_with_all_tests=$(go list -f '{{if len .TestGoFiles}}{{.ImportPath}} {{join .TestGoFiles " "}}{{end}}{{if len .XTestGoFiles}}{{.ImportPath}} {{join .XTestGoFiles " "}}{{end}}' ./go/... | sort)
    29  all_except_endtoend_tests=$(echo "$packages_with_all_tests" | grep -v "endtoend" | cut -d" " -f1 )
    30  
    31  counter=0
    32  for pkg in $all_except_endtoend_tests
    33  do
    34     go test -coverpkg=vitess.io/vitess/go/... -coverprofile "/tmp/unit_$counter.out" -json > "/tmp/unit_$counter.json" $pkg -v -p=1 || :
    35     counter=$((counter+1))
    36  done
    37  
    38  ## Copy the test files to get instrumented binaries ###
    39  cp ./tools/coverage-go/vtctl_test.go ./go/cmd/vtctl/vtctl_test.go
    40  cp ./tools/coverage-go/vtctld_test.go ./go/cmd/vtctld/vtctld_test.go
    41  cp ./tools/coverage-go/mysqlctl_test.go ./go/cmd/mysqlctl/mysqlctl_test.go
    42  cp ./tools/coverage-go/vtctlclient_test.go ./go/cmd/vtctlclient/vtctlclient_test.go
    43  cp ./tools/coverage-go/vttablet_test.go ./go/cmd/vttablet/vttablet_test.go
    44  cp ./tools/coverage-go/vtgate_test.go ./go/cmd/vtgate/vtgate_test.go
    45  cp ./tools/coverage-go/vtworker_test.go ./go/cmd/vtworker/vtworker_test.go
    46  cp ./tools/coverage-go/vtworkerclient_test.go ./go/cmd/vtworkerclient/vtworkerclient_test.go
    47  
    48  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtctl -o ./bin/vtctl
    49  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtctld -o ./bin/vtctld
    50  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/mysqlctl -o ./bin/mysqlctl
    51  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtctlclient -o ./bin/vtctlclient
    52  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vttablet -o ./bin/vttablet
    53  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtgate -o ./bin/vtgate
    54  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtworker -o ./bin/vtworker
    55  go test -coverpkg=vitess.io/vitess/go/...  -c vitess.io/vitess/go/cmd/vtworkerclient -o ./bin/vtworkerclient
    56  
    57  ### Execute go/test/endtoend testcase ###
    58  echo "--------- executing endtoend testcases ---------"
    59  cluster_tests=$(echo "$packages_with_all_tests" | grep -E "go/test/endtoend" | cut -d" " -f1)
    60  
    61  
    62  # Run cluster test sequentially
    63  for i in $cluster_tests
    64  do
    65     echo "starting test for $i"
    66     go test  $i -v -p=1 -is-coverage=true || :
    67  done
    68