| 1 |
#!/usr/bin/perl |
| 2 |
#========================================================================== |
| 3 |
# testcoverage |
| 4 |
# |
| 5 |
# A script for launching the common use cases of gcovmerge. |
| 6 |
# |
| 7 |
# Usage: |
| 8 |
# |
| 9 |
# testcoverage [--with-package=PKG] \ |
| 10 |
# [--trilinos-dir=PATH] \ |
| 11 |
# [--build-dir=PATH] \ |
| 12 |
# [--run-tests] \ |
| 13 |
# [--with-comm=[serial|mpi]] \ |
| 14 |
# [--print-cmd] \ |
| 15 |
# [--with-report] \ |
| 16 |
# [--with-report=PREFIX] \ |
| 17 |
# [--help] |
| 18 |
# |
| 19 |
# This script should always be called from the build directory, which is |
| 20 |
# assumed to be a direct subdirectory of the Trilinos root directory. |
| 21 |
# For example: |
| 22 |
# cd ~/Trilinos |
| 23 |
# cd BUILD_LINUX_MPI |
| 24 |
# ../testcoverage --with-packages=anasazi --run-tests |
| 25 |
# |
| 26 |
# If no --with-packages options are specified, then it performs coverage |
| 27 |
# testing for for all of Trilinos, with a reporting breakdown by directory. |
| 28 |
# |
| 29 |
# Arguments: |
| 30 |
# |
| 31 |
# --with-package=PKG |
| 32 |
# When specified, do not perform testing of all of Trilinos. |
| 33 |
# Instead, test the specified packages and report coverage |
| 34 |
# on a file-by-file basis. |
| 35 |
# |
| 36 |
# --trilinos-dir=PATH |
| 37 |
# Absolute path to the Trilinos root directory. Required argument. |
| 38 |
# e.g., --trilinos-dir=/home/anyone/Trilinos-6.0 |
| 39 |
# |
| 40 |
# --build-dir=PATH |
| 41 |
# Path to the build dir, relative to the Trilinos root. |
| 42 |
# Required argument. |
| 43 |
# e.g., --build-dir=LINUX_CODE_COV |
| 44 |
# |
| 45 |
# --run-tests |
| 46 |
# Run the test harness for the configured packages. |
| 47 |
# |
| 48 |
# --with-comm=[serial|mpi] |
| 49 |
# Run test harness in serial or mpi (for use with --run-tests). |
| 50 |
# If unspecified, default is "serial" |
| 51 |
# |
| 52 |
# --print-cmd |
| 53 |
# Print the commands before they issued. These will include the |
| 54 |
# calls to the test harness and the calls to gcovmerge. |
| 55 |
# |
| 56 |
# --with-report |
| 57 |
# --with-report=PREFIX |
| 58 |
# Tells gcovmerge to generate line-by-line coverage reports for |
| 59 |
# the source files. If --with-package flag is used, then |
| 60 |
# seperate HTML files are made, one for each package, where the |
| 61 |
# HTML file name is PREFIX followed by the package name. For example, |
| 62 |
# --with-report=mycov would generate filenames like "mycov_anasazi.html" |
| 63 |
# and "mycov_teuchos.html". |
| 64 |
# If PREFIX is not specified, the prefix "coverage_" is used. |
| 65 |
# When the --with-package flag is not specified, the --with-report option |
| 66 |
# is passed directly to gcovmerge. |
| 67 |
# |
| 68 |
# Additional options are passed to gcovmerge. See documentation there. |
| 69 |
# |
| 70 |
# Written by Chris Baker ([email protected]) 2005-08-01 |
| 71 |
# |
| 72 |
#========================================================================== |
| 73 |
|
| 74 |
# base options |
| 75 |
use Cwd; |
| 76 |
chomp($base = cwd); |
| 77 |
@file_types = ("cpp", "c++", "c", "hpp", "h++", "h"); |
| 78 |
%source_files = (); |
| 79 |
@pkg_list = (); |
| 80 |
|
| 81 |
# parse command-line options |
| 82 |
my $buildDir; |
| 83 |
my $trilinosDir; |
| 84 |
$source_directory = "../packages"; |
| 85 |
$runtests = 0; |
| 86 |
$extra_args = (); |
| 87 |
$print_cmd = 0; |
| 88 |
$comm = "serial"; |
| 89 |
$category = "FRAMEWORK"; |
| 90 |
$gen_report = 0; |
| 91 |
foreach (@ARGV){ |
| 92 |
if(/--with-package=(.*)/){ |
| 93 |
push @pkg_list, $1; |
| 94 |
} |
| 95 |
elsif(/--run-tests=(.*)/){ |
| 96 |
$runtests = 1; |
| 97 |
$category = $1; |
| 98 |
} |
| 99 |
elsif(/--run-tests/){ |
| 100 |
$runtests = 1; |
| 101 |
} |
| 102 |
elsif(/--trilinos-dir=(.*)/){ |
| 103 |
$trilinosDir = $1; |
| 104 |
} |
| 105 |
elsif(/--build-dir=(.*)/){ |
| 106 |
$buildDir = $1; |
| 107 |
} |
| 108 |
elsif(/--print-cmd/){ |
| 109 |
$print_cmd = 1; |
| 110 |
} |
| 111 |
elsif(/--with-comm=(.*)/){ |
| 112 |
$comm = $1; |
| 113 |
} |
| 114 |
elsif(/--with-report=(.*)/){ |
| 115 |
$gen_report = 1; |
| 116 |
$report_prefix = $1; |
| 117 |
} |
| 118 |
elsif(/--with-report/){ |
| 119 |
$gen_report = 1; |
| 120 |
} |
| 121 |
elsif(/--help/){ |
| 122 |
print "testcoverage - A Trilinos Code Coverage Utility\n"; |
| 123 |
print "\n"; |
| 124 |
print "Usage: \n"; |
| 125 |
print "\n"; |
| 126 |
print " testcoverage [--with-package=PKG] \\\n"; |
| 127 |
print " [--trilinos-dir=PATH] \\\n"; |
| 128 |
print " [--build-dir=PATH] \\\n"; |
| 129 |
print " [--run-tests] \\\n"; |
| 130 |
print " [--with-comm=[serial|mpi]] \\\n"; |
| 131 |
print " [--print-cmd] \\\n"; |
| 132 |
print " [--help]\n"; |
| 133 |
print "\n"; |
| 134 |
print "Arguments:\n"; |
| 135 |
print "\n"; |
| 136 |
print " --with-package=PKG\n"; |
| 137 |
print " When specified, do not perform testing of all of Trilinos.\n"; |
| 138 |
print " Instead, test the specified packages and report coverage\n"; |
| 139 |
print " on a file-by-file basis.\n"; |
| 140 |
print "\n"; |
| 141 |
print " --trilinos-dir=PATH\n"; |
| 142 |
print " Absolute path to the Trilinos root directory. Required argument.\n"; |
| 143 |
print " e.g., --trilinos-dir=/home/anyone/Trilinos-6.0\n"; |
| 144 |
print "\n"; |
| 145 |
print " --build-dir=PATH\n"; |
| 146 |
print " Path to the build dir, relative to the Trilinos root. \n"; |
| 147 |
print " Required argument.\n"; |
| 148 |
print " e.g., --build-dir=LINUX_CODE_COV\n"; |
| 149 |
print "\n"; |
| 150 |
print " --run-tests \n"; |
| 151 |
print " --run-tests=CATEGORY \n"; |
| 152 |
print " Run the test harness for the configured packages. This runs tests of category CATEGORY, with a default of FRAMEWORK.\n"; |
| 153 |
print "\n"; |
| 154 |
print " --with-comm=[serial|mpi]\n"; |
| 155 |
print " Run test harness in serial or mpi (for use with --run-tests).\n"; |
| 156 |
print " If unspecified, default is \"serial\"\n"; |
| 157 |
print "\n"; |
| 158 |
print " --print-cmd\n"; |
| 159 |
print " Print the commands before they issued. These will include the\n"; |
| 160 |
print " calls to the test harness and the calls to gcovmerge.\n"; |
| 161 |
print "\n"; |
| 162 |
print " --with-report\n"; |
| 163 |
print " --with-report=PREFIX\n"; |
| 164 |
print " Tells gcovmerge to generate line-by-line coverage reports for \n"; |
| 165 |
print " the source files. If --with-package flag is used, then\n"; |
| 166 |
print " seperate HTML files are made, one for each package, where the\n"; |
| 167 |
print " HTML file name is PREFIX followed by the package name. For example,\n"; |
| 168 |
print " --with-report=mycov would generate filenames like \"mycov_anasazi.html\"\n"; |
| 169 |
print " and \"mycov_teuchos.html\".\n"; |
| 170 |
print " If PREFIX is not specified, the prefix \"coverage_\" is used.\n"; |
| 171 |
print " When the --with-package flag is not specified, the --with-report option\n"; |
| 172 |
print " is passed directly to gcovmerge.\n"; |
| 173 |
print " --help\n"; |
| 174 |
print " Print this help output and exit.\n"; |
| 175 |
print "\n"; |
| 176 |
print " Additional options are passed to gcovmerge. See documentation there.\n"; |
| 177 |
print "\n"; |
| 178 |
print " See README.testcoverage for more help.\n"; |
| 179 |
print "\n"; |
| 180 |
|
| 181 |
exit; |
| 182 |
} |
| 183 |
else{ |
| 184 |
$extra_args .= $_." "; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
if ($extra_args ne ""){ |
| 189 |
print "\nArgs to gcovmerge: $extra_args\n"; |
| 190 |
} |
| 191 |
|
| 192 |
# check for existance of trilinos-dir argument and actual directory |
| 193 |
if (!$trilinosDir) { |
| 194 |
die "trilinos-dir value required\n"; |
| 195 |
} else { |
| 196 |
if (!stat($trilinosDir)) { |
| 197 |
die "cannot stat trilinos-dir: $trilinosDir\n"; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
# check for existance of build-dir argument and actual directory |
| 202 |
if (!$buildDir) { |
| 203 |
die "build-dir value required\n"; |
| 204 |
} else { |
| 205 |
if (!stat($buildDir)) { |
| 206 |
die "cannot stat build-dir: $buildDir\n"; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
# run tests, if required |
| 211 |
if ($runtests==1){ |
| 212 |
print "\nRunning tests...\n"; |
| 213 |
$cmd = "$trilinosDir/commonTools/test/utilities/runtests"; |
| 214 |
$cmd .= " --trilinos-dir=$trilinosDir --comm=$comm --build-dir=$buildDir --category=$category"; |
| 215 |
if ($print_cmd) { |
| 216 |
print "Command: $cmd\n"; |
| 217 |
} |
| 218 |
print "------------------------------------------------------------------------------\n"; |
| 219 |
system($cmd); |
| 220 |
} |
| 221 |
|
| 222 |
# call gcovmerge |
| 223 |
$numpkg = @pkg_list; |
| 224 |
if ($numpkg == 0){ |
| 225 |
# call gcovmerge for the whole of trilinos |
| 226 |
$cmd = "$trilinosDir/commonTools/test/coverage/gcovmerge"; |
| 227 |
if ($extra_args ne "") { |
| 228 |
$cmd .= " ".$extra_args; |
| 229 |
} |
| 230 |
$cmd .= " --exclude=test/ --exclude=/example/ --exclude=doc/ --exclude=util/ --exclude=ModalAnalysisSolvers/"; |
| 231 |
$cmd .= " --without-files --with-directories-recursive"; |
| 232 |
$cmd .= " --source-dir=$trilinosDir/packages"; |
| 233 |
if ($gen_report){ |
| 234 |
if (!defined($report_prefix)){ |
| 235 |
$cmd .= " --with-report"; |
| 236 |
} |
| 237 |
else { |
| 238 |
$cmd .= " --with-report=$report_prefix"; |
| 239 |
} |
| 240 |
} |
| 241 |
$cmd .= " $buildDir"; |
| 242 |
print "\nGenerating coverage information...\n"; |
| 243 |
if ($print_cmd) { |
| 244 |
print "Command: $cmd\n"; |
| 245 |
} |
| 246 |
print "------------------------------------------------------------------------------\n"; |
| 247 |
system $cmd; |
| 248 |
} |
| 249 |
else { |
| 250 |
# call gcovmerge for the specified packages |
| 251 |
foreach (@pkg_list){ |
| 252 |
$cmd = "$trilinosDir/commonTools/test/coverage/gcovmerge"; |
| 253 |
if ($extra_args ne "") { |
| 254 |
$cmd .= " ".$extra_args; |
| 255 |
} |
| 256 |
$cmd .= " --exclude=test/ --exclude=/example/ --exclude=doc/ --exclude=util/ --exclude=ModalAnalysisSolvers/"; |
| 257 |
$cmd .= " --source-dir=$trilinosDir/packages/$_"; |
| 258 |
if ($gen_report){ |
| 259 |
if (!defined($report_prefix)){ |
| 260 |
$cmd .= " --with-report=coverage_$_.html"; |
| 261 |
} |
| 262 |
else { |
| 263 |
$cmd .= " --with-report=$report_prefix\_$_.html"; |
| 264 |
} |
| 265 |
} |
| 266 |
$cmd .= " $buildDir"; |
| 267 |
print "\nGenerating coverage information for package $_...\n"; |
| 268 |
if ($print_cmd) { |
| 269 |
print "Command: $cmd\n"; |
| 270 |
} |
| 271 |
print "------------------------------------------------------------------------------\n"; |
| 272 |
system $cmd; |
| 273 |
} |
| 274 |
} |
| 275 |
print "\n"; |