mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Integrate Bro script coverage profiling with the btest suite.
This commit is contained in:
parent
1181444f37
commit
9aefeec4ce
7 changed files with 75 additions and 14 deletions
46
testing/scripts/coverage-calc
Executable file
46
testing/scripts/coverage-calc
Executable file
|
@ -0,0 +1,46 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
# This script aggregates many files containing Bro script coverage information
|
||||
# into a single file and reports the overall coverage information. Usage:
|
||||
#
|
||||
# coverage-calc <quoted glob of filenames> <output file> <ignored script dir>
|
||||
#
|
||||
# The last argument is used to ignore Bro scripts that are part of the test
|
||||
# suite itself as those should not count towards the coverage calculation.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
|
||||
stats = {}
|
||||
inputglob = sys.argv[1]
|
||||
outputfile = sys.argv[2]
|
||||
ignoredir = os.path.abspath(sys.argv[3])
|
||||
|
||||
for filename in glob.glob(inputglob):
|
||||
with open(filename, 'r') as f:
|
||||
for line in f.read().splitlines():
|
||||
parts = line.split("\t")
|
||||
exec_count = int(parts[0])
|
||||
location = os.path.normpath(parts[1])
|
||||
# ignore scripts that don't appear to be part of Bro distribution
|
||||
if location.startswith(ignoredir) or not location.startswith("/"):
|
||||
continue
|
||||
desc = parts[2]
|
||||
key = location + desc
|
||||
if key in stats:
|
||||
stats[key][0] += exec_count
|
||||
else:
|
||||
stats[key] = [exec_count, location, desc]
|
||||
|
||||
with open(outputfile, 'w') as f:
|
||||
for k in sorted(stats, key=lambda i: stats[i][1]):
|
||||
f.write("%s\t%s\t%s\n" % (stats[k][0], stats[k][1], stats[k][2]))
|
||||
|
||||
num_covered = 0
|
||||
for k in stats:
|
||||
if stats[k][0] > 0:
|
||||
num_covered += 1
|
||||
|
||||
if len(stats) > 0:
|
||||
print "%s/%s (%.1f%%) Bro script statements covered." % (num_covered, len(stats), float(num_covered)/len(stats)*100)
|
Loading…
Add table
Add a link
Reference in a new issue