github.com/opencontainers/umoci@v0.4.8-0.20240508124516-656e4836fb0d/hack/collate.awk (about)

     1  #!/usr/bin/awk -f
     2  # Copyright (C) 2016-2020 SUSE LLC
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #   http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # collate.awk allows you to collate a bunch of Go coverprofiles for a given
    17  # binary (generated with -test.coverprofile), so that the statistics actually
    18  # make sense. The input to this function is just the concatenated versions of
    19  # the coverage reports, and the output is the combined coverage report.
    20  #
    21  # NOTE: This will _only_ work on coverage binaries compiles with
    22  # -covermode=count. The other modes aren't supported.
    23  
    24  {
    25  	# Every coverage file in the set will start with a "mode:" header. Just make
    26  	# sure they're all set to "count".
    27  	if ($1 == "mode:") {
    28  		if ($0 != "mode: count") {
    29  			print "Invalid coverage mode", $2 > "/dev/stderr"
    30  			exit 1
    31  		}
    32  		next
    33  	}
    34  
    35  	# The format of all other lines is as follows.
    36  	#   <file>:<startline>.<startcol>,<endline>.<endcol> <numstmt> <count>
    37  	# We only care about the first field and the count.
    38  	statements[$1] = $2
    39  	counts[$1] += $3
    40  }
    41  
    42  END {
    43  	print "mode: count"
    44  	for (block in statements) {
    45  		print block, statements[block], counts[block]
    46  	}
    47  }