From d3dad1ccfe1741a5a5f2c610d995b5c8cc603844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Fri, 14 Aug 2009 11:13:11 +0200 Subject: Move coverage tools to BuildTools dir. diff --git a/BuildTools/Coverage/FilterLCovData.py b/BuildTools/Coverage/FilterLCovData.py new file mode 100755 index 0000000..8d56a7f --- /dev/null +++ b/BuildTools/Coverage/FilterLCovData.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +# TODO: Add uncovered non-ignored files + +import sys, re, os.path + +assert(len(sys.argv) == 2) + +def isIgnored(file) : + return (find.find("/Swiften/") == -1 and find.find("/Slimber/") == -1 and find.find("/Swift/") == -1) or (find.find("/UnitTest/") != -1 or find.find("/QA/") != -1) + + +output = [] +inputFile = open(sys.argv[1]) +inIgnoredFile = False +for line in inputFile.readlines() : + if inIgnoredFile : + if line == "end_of_record\n" : + inIgnoredFile = False + else : + if line.startswith("SF:") and isIgnored(line) : + inIgnoredFile = True + else : + m = re.match("SF:(.*)", line) + if m : + line = "SF:" + os.path.realpath(m.group(1)) + "\n" + output.append(line) +inputFile.close() + +outputFile = open(sys.argv[1], 'w') +outputFile.write(''.join(output)) +outputFile.close() diff --git a/BuildTools/Coverage/GenerateCoverageResults.sh b/BuildTools/Coverage/GenerateCoverageResults.sh new file mode 100755 index 0000000..d3e6b12 --- /dev/null +++ b/BuildTools/Coverage/GenerateCoverageResults.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# This script assumes that it is run from the toplevel directory, that +# the 'configure' script has been called with '--enable-coverage' + +if [ ! -f config.status ]; then + echo "Please configure your build with --enable-coverage and rebuild." + exit -1 +fi +grep -q "\-\-enable-coverage" config.status +if [ "$?" != 0 ]; then + echo "Please configure your build with --enable-coverage and rebuild." + exit -1 +fi + +SOURCE_DIR=. +SCRIPT_DIR=Tools/Coverage +LCOVDIR=3rdParty/LCov + +RESULTS_DIR=Tools/Coverage/results +OUTPUT_DIR=$RESULTS_DIR/coverage-`git log --pretty=format:%ct-%h | head -n 1` + +make -C $SOURCE_DIR +if [ ! -f $OUTPUT_DIR ]; then + mkdir -p $OUTPUT_DIR +fi + +# Reset counters +$LCOVDIR/lcov --zerocounters --directory $SOURCE_DIR + +# All tests +make -C $SOURCE_DIR test +$LCOVDIR/lcov --capture --directory $SOURCE_DIR -b $SOURCE_DIR --output-file $OUTPUT_DIR/all.info --test-name all +cp $OUTPUT_DIR/all.info $OUTPUT_DIR/all.info.orig +$SCRIPT_DIR/FilterLCovData.py $OUTPUT_DIR/all.info + +# Generate HTML +$LCOVDIR/gendesc -o $OUTPUT_DIR/descriptions $SCRIPT_DIR/descriptions.txt +$LCOVDIR/genhtml --no-function-coverage --title "Swift Coverage" --output-directory $OUTPUT_DIR $OUTPUT_DIR/all.info + +# Generate summary +$SCRIPT_DIR/GenerateSummary.py $OUTPUT_DIR/all.info $OUTPUT_DIR/summary diff --git a/BuildTools/Coverage/GenerateOverview.py b/BuildTools/Coverage/GenerateOverview.py new file mode 100755 index 0000000..8928afd --- /dev/null +++ b/BuildTools/Coverage/GenerateOverview.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python + +import sys, os.path + +assert(len(sys.argv) == 4) + +resultsDir = sys.argv[1] +summaryFile = sys.argv[2] +overviewFile = sys.argv[3] + +results = [] +for dir in os.listdir(resultsDir) : + summary = os.path.join(resultsDir, dir, summaryFile) + if os.path.exists(summary) : + file = open(summary) + lines = file.readlines() + if len(lines) == 0 or len(lines[0].split("/")) != 2 : + continue + coveredCount = int(lines[0].split("/")[0]) + totalCount = int(lines[0].split("/")[1]) + results.append((dir,coveredCount,totalCount)) + +# Compute coverage chart URL +chartparams = ["chs=320x240", "cht=lc", "chtt=Coverage (Relative)", "chxt=y", "chxl=0:|50%|80%|100%|", "chxp=0,50,80,100"] +chartdata = [] +for (url,covered,total) in results : + chartdata.append(str(100*covered/total)) +chartparams.append("chd=t:" + ",".join(chartdata)) +coverageChartURL = "http://chart.apis.google.com/chart?" + '&'.join(chartparams) + +# Compute the maximum of lines over time +maximumNumberOfLines = 0 +for (url,covered,total) in results : + maximumNumberOfLines = max(maximumNumberOfLines,total) + +# Compute code chart URL +chartparams = ["chs=320x240", "cht=lc", "chtt=Coverage (Absolute)", "chxt=y", "chxl=0:|" + str(maximumNumberOfLines) + "|", "chxp=0,100", "chm=b,FF0000,0,1,0|b,80C65A,1,2,0", "chco=00000000,00000000,00000000"] +coveredLinesData = [] +totalLinesData = [] +nullLinesData = [] +for (url,covered,total) in results : + coveredLinesData.append(str(100*covered/maximumNumberOfLines)) + totalLinesData.append(str(100*total/maximumNumberOfLines)) + nullLinesData.append("0") +chartparams.append("chd=t:" + ",".join(totalLinesData) + "|" + ",".join(coveredLinesData) + "|" + ",".join(nullLinesData)) +codeChartURL = "http://chart.apis.google.com/chart?" + '&'.join(chartparams) + + +# Output page +output = open(os.path.join(resultsDir,overviewFile), 'w') +output.write("" % {'url' : coverageChartURL}) +output.write("" % {'url' : codeChartURL}) +output.write("") +output.close() + diff --git a/BuildTools/Coverage/GenerateSummary.py b/BuildTools/Coverage/GenerateSummary.py new file mode 100755 index 0000000..ec94a4f --- /dev/null +++ b/BuildTools/Coverage/GenerateSummary.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import sys, re + +assert(len(sys.argv) == 3) + +inputFile = open(sys.argv[1]) +currentFile = "" +coverage = {} +for line in inputFile.readlines() : + line = line.strip() + m = re.match("^SF:(.*)", line) + if m : + currentFile = m.group(1) + else : + m = re.match("^DA:(\d+),(\d+)", line) + if m : + currentFileCoverage = coverage.get(currentFile, {}) + line = int(m.group(1)) + count = int(m.group(2)) + currentFileCoverage[line] = currentFileCoverage.get(line, 0) + count + coverage[currentFile] = currentFileCoverage +inputFile.close() + +totalLines = 0 +coveredLines = 0 +for c in coverage.values() : + totalLines += len(c) + for l in c.values() : + if l > 0 : + coveredLines += 1 + +outputFile = open(sys.argv[2], 'w') +outputFile.write(str(coveredLines) + "/" + str(totalLines)) +outputFile.close() diff --git a/BuildTools/Coverage/descriptions.txt b/BuildTools/Coverage/descriptions.txt new file mode 100644 index 0000000..5b07e04 --- /dev/null +++ b/BuildTools/Coverage/descriptions.txt @@ -0,0 +1,2 @@ +all + All tests diff --git a/tools/coverage/FilterLCovData.py b/tools/coverage/FilterLCovData.py deleted file mode 100755 index 8d56a7f..0000000 --- a/tools/coverage/FilterLCovData.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -# TODO: Add uncovered non-ignored files - -import sys, re, os.path - -assert(len(sys.argv) == 2) - -def isIgnored(file) : - return (find.find("/Swiften/") == -1 and find.find("/Slimber/") == -1 and find.find("/Swift/") == -1) or (find.find("/UnitTest/") != -1 or find.find("/QA/") != -1) - - -output = [] -inputFile = open(sys.argv[1]) -inIgnoredFile = False -for line in inputFile.readlines() : - if inIgnoredFile : - if line == "end_of_record\n" : - inIgnoredFile = False - else : - if line.startswith("SF:") and isIgnored(line) : - inIgnoredFile = True - else : - m = re.match("SF:(.*)", line) - if m : - line = "SF:" + os.path.realpath(m.group(1)) + "\n" - output.append(line) -inputFile.close() - -outputFile = open(sys.argv[1], 'w') -outputFile.write(''.join(output)) -outputFile.close() diff --git a/tools/coverage/GenerateCoverageResults.sh b/tools/coverage/GenerateCoverageResults.sh deleted file mode 100755 index f006e4b..0000000 --- a/tools/coverage/GenerateCoverageResults.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -# This script assumes that it is run from the toplevel directory, that -# the 'configure' script has been called with '--enable-coverage' - -if [ ! -f config.status ]; then - echo "Please configure your build with --enable-coverage and rebuild." - exit -1 -fi -grep -q "\-\-enable-coverage" config.status -if [ "$?" != 0 ]; then - echo "Please configure your build with --enable-coverage and rebuild." - exit -1 -fi - -SOURCE_DIR=. -SCRIPT_DIR=tools/coverage -LCOVDIR=3rdParty/LCov - -RESULTS_DIR=tools/coverage/results -OUTPUT_DIR=$RESULTS_DIR/coverage-`git log --pretty=format:%ct-%h | head -n 1` - -make -C $SOURCE_DIR -if [ ! -f $OUTPUT_DIR ]; then - mkdir -p $OUTPUT_DIR -fi - -# Reset counters -$LCOVDIR/lcov --zerocounters --directory $SOURCE_DIR - -# All tests -make -C $SOURCE_DIR test -$LCOVDIR/lcov --capture --directory $SOURCE_DIR -b $SOURCE_DIR --output-file $OUTPUT_DIR/all.info --test-name all -cp $OUTPUT_DIR/all.info $OUTPUT_DIR/all.info.orig -$SCRIPT_DIR/FilterLCovData.py $OUTPUT_DIR/all.info - -# Generate HTML -$LCOVDIR/gendesc -o $OUTPUT_DIR/descriptions $SCRIPT_DIR/descriptions.txt -$LCOVDIR/genhtml --no-function-coverage --title "Swift Coverage" --output-directory $OUTPUT_DIR $OUTPUT_DIR/all.info - -# Generate summary -$SCRIPT_DIR/GenerateSummary.py $OUTPUT_DIR/all.info $OUTPUT_DIR/summary diff --git a/tools/coverage/GenerateOverview.py b/tools/coverage/GenerateOverview.py deleted file mode 100755 index 8928afd..0000000 --- a/tools/coverage/GenerateOverview.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python - -import sys, os.path - -assert(len(sys.argv) == 4) - -resultsDir = sys.argv[1] -summaryFile = sys.argv[2] -overviewFile = sys.argv[3] - -results = [] -for dir in os.listdir(resultsDir) : - summary = os.path.join(resultsDir, dir, summaryFile) - if os.path.exists(summary) : - file = open(summary) - lines = file.readlines() - if len(lines) == 0 or len(lines[0].split("/")) != 2 : - continue - coveredCount = int(lines[0].split("/")[0]) - totalCount = int(lines[0].split("/")[1]) - results.append((dir,coveredCount,totalCount)) - -# Compute coverage chart URL -chartparams = ["chs=320x240", "cht=lc", "chtt=Coverage (Relative)", "chxt=y", "chxl=0:|50%|80%|100%|", "chxp=0,50,80,100"] -chartdata = [] -for (url,covered,total) in results : - chartdata.append(str(100*covered/total)) -chartparams.append("chd=t:" + ",".join(chartdata)) -coverageChartURL = "http://chart.apis.google.com/chart?" + '&'.join(chartparams) - -# Compute the maximum of lines over time -maximumNumberOfLines = 0 -for (url,covered,total) in results : - maximumNumberOfLines = max(maximumNumberOfLines,total) - -# Compute code chart URL -chartparams = ["chs=320x240", "cht=lc", "chtt=Coverage (Absolute)", "chxt=y", "chxl=0:|" + str(maximumNumberOfLines) + "|", "chxp=0,100", "chm=b,FF0000,0,1,0|b,80C65A,1,2,0", "chco=00000000,00000000,00000000"] -coveredLinesData = [] -totalLinesData = [] -nullLinesData = [] -for (url,covered,total) in results : - coveredLinesData.append(str(100*covered/maximumNumberOfLines)) - totalLinesData.append(str(100*total/maximumNumberOfLines)) - nullLinesData.append("0") -chartparams.append("chd=t:" + ",".join(totalLinesData) + "|" + ",".join(coveredLinesData) + "|" + ",".join(nullLinesData)) -codeChartURL = "http://chart.apis.google.com/chart?" + '&'.join(chartparams) - - -# Output page -output = open(os.path.join(resultsDir,overviewFile), 'w') -output.write("" % {'url' : coverageChartURL}) -output.write("" % {'url' : codeChartURL}) -output.write("") -output.close() - diff --git a/tools/coverage/GenerateSummary.py b/tools/coverage/GenerateSummary.py deleted file mode 100755 index ec94a4f..0000000 --- a/tools/coverage/GenerateSummary.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python - -import sys, re - -assert(len(sys.argv) == 3) - -inputFile = open(sys.argv[1]) -currentFile = "" -coverage = {} -for line in inputFile.readlines() : - line = line.strip() - m = re.match("^SF:(.*)", line) - if m : - currentFile = m.group(1) - else : - m = re.match("^DA:(\d+),(\d+)", line) - if m : - currentFileCoverage = coverage.get(currentFile, {}) - line = int(m.group(1)) - count = int(m.group(2)) - currentFileCoverage[line] = currentFileCoverage.get(line, 0) + count - coverage[currentFile] = currentFileCoverage -inputFile.close() - -totalLines = 0 -coveredLines = 0 -for c in coverage.values() : - totalLines += len(c) - for l in c.values() : - if l > 0 : - coveredLines += 1 - -outputFile = open(sys.argv[2], 'w') -outputFile.write(str(coveredLines) + "/" + str(totalLines)) -outputFile.close() diff --git a/tools/coverage/descriptions.txt b/tools/coverage/descriptions.txt deleted file mode 100644 index 5b07e04..0000000 --- a/tools/coverage/descriptions.txt +++ /dev/null @@ -1,2 +0,0 @@ -all - All tests -- cgit v0.10.2-6-g49f6