1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
# =========================================================================
#
# Program: Insight Segmentation & Registration Toolkit
# Module: $RCSfile: Purify.tcl,v $
# Language: Tcl
# Date: $Date: 2004/01/28 13:05:02 $
# Version: $Revision: 1.38 $
#
# Copyright (c) 2001 Insight Consortium
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * The name of the Insight Consortium, nor the names of any consortium members,
# nor of any contributors, may be used to endorse or promote products derived
# from this software without specific prior written permission.
# * Modified source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
proc CheckFile { Filename } {
return [expr [file exists $Filename] && [file executable $Filename]]
}
proc ReportError { Status Result } {
global errorInfo
if { $Status } {
puts $Result
puts $errorInfo
}
}
proc RemoveFile { file } \
{
file delete -force -- $file
}
proc ProcessPurify { Test PLog } { return [ProcessLog $Test $PLog] }
proc ProcessLog { Test PLog } \
{
global Purify
if { ![file exists $PLog] } \
{
set Purify([lindex $Test 0],Status) failed
return
}
set f [open $PLog r]
set Purify([lindex $Test 0],PurifyLog) ""
foreach Message $Purify(Messages) \
{
set Purify([lindex $Test 0],$Message) 0
}
while { ![eof $f] } \
{
set line [gets $f]
append Purify([lindex $Test 0],PurifyLog) [XMLSafeString "$line\n"]
foreach Message $Purify(Messages) \
{
set match "$Message:"
if { [regexp $match $line] } \
{
incr Purify([lindex $Test 0],$Message)
incr Purify($Message,Count)
}
}
}
}
proc Purify { Model BuildStampDir {MemoryChecker Purify} } {
global Dart tcl_platform Purify errorInfo TestList
set HTMLDir [file join Testing HTML]
set TempDir [file join Testing Temporary]
set TempFile [file join $Dart(BuildDirectory) $TempDir PurifyLog.txt]
set UtilitiesDirectory [file join $Dart(DartRoot) Source Client]
set SiteDir [file join $HTMLDir TestingResults Sites $Dart(Site)]
set BuildNameDir [file join $SiteDir $Dart(BuildName)]
set BuildStamp [file tail $BuildStampDir]
set XMLDir [file join $BuildStampDir XML]
set Out [open [file join $XMLDir DynamicAnalysis.xml] w]
puts $Out $Dart(XMLHeader)
puts $Out "<Site BuildName=\"$Dart(BuildName)\" BuildStamp=\"$BuildStamp\" Name=\"$Dart(Site)\">"
puts $Out "<DynamicAnalysis Checker=\"Purify\">"
puts $Out "\t<StartDateTime>[AbbreviateTimeZone [clock format [clock seconds]]]</StartDateTime>"
# Find the list of canidate tests
puts "\tFinding Tests to run Purify on"
set TestList ""
set OldDir [pwd]
cd $Dart(BuildDirectory)
set TestList [FindTests .]
cd $OldDir
puts "\tFound [llength $TestList] tests for Purify"
# Delete any old purify files
puts "\tRemoving old purify logs"
set Status [catch { FileMap [glob -nocomplain *] [list *.plog] RemoveFile } Result]
ReportError $Status $Result
# Write the list
puts $Out "\t<TestList>"
foreach Test $TestList \
{
puts $Out "\t\t<Test>[XMLSafeString [lindex $Test 1]/[lindex $Test 0]]</Test>"
}
puts $Out "\t</TestList>"
puts $Out "\t<DefectList>"
set Purify(Messages) [list MLK PLK MPK ABR ABW ABWL IPR NPR ODS COR EXU FMM FUM FMR FMW FFM MAF UMC UMR]
foreach Message $Purify(Messages) \
{
puts $Out "\t\t<Defect Type=\"[XMLSafeString $Message]\"/>"
set Purify($Message,Count) 0
}
puts $Out "\t</DefectList>"
# if we are using msdev, then determine the configuration to test
set alternateDirectories ""
if { [regexp "^(.*msdev.*).*" $Dart(MakeCommand)] } {
# extract the configuration
set makeConfiguration [lindex [lindex $Dart(MakeCommand) 3] 2]
# if makeConfiguration is "ALL", then use "Debug" as the test
# configuration, otherwise use the specified configuration
if { $makeConfiguration == "ALL" } {
set alternateDirectories "Debug"
} else {
set alternateDirectories $makeConfiguration
}
puts "\tWill search for executables in configuration subdirectory $alternateDirectories"
}
# For each test, cd to the directory, and run it.
puts "\tRunning Purify Tests"
set ReportPassed 0
set ReportFailed 0
set ReportNotRun 0
foreach Test $TestList \
{
# Each $Test = {TestIdentifier PathFromBuildDirToTest Executable [args]}
cd $Dart(BuildDirectory)
cd [lindex $Test 1]
set Filename [lindex $Test 2]
# first check to see if Executable exists
set candidates ""
# extract prepath form exe name
set fname [file tail $Filename]
set pdir [file dirname $Filename]
foreach path [list "." "" $alternateDirectories] {
lappend candidates [file join $pdir $path $fname]
lappend candidates [file join $pdir $path $fname.exe]
}
set NewFilename ""
foreach candidate $candidates {
if { [CheckFile $candidate] } {
set NewFilename $candidate
break
}
}
set Purify([lindex $Test 0],Status) notrun
set Result ""
set PLog ""
if { $NewFilename != "" } \
{
puts "\tRunning $NewFilename [lrange $Test 3 end]"
set PLog "[lindex $Test 0].plog"
if { $tcl_platform(platform) != "windows" } {
set OldDir [pwd]
cd [file dirname $NewFilename]
switch $MemoryChecker {
Purify {
# running purify on unix
set PurifyOptions $Dart(PurifyOptions)
append PurifyOptions "-suppression-file-names=[file join $Dart(SourceDirectory) $UtilitiesDirectory .purify] "
append PurifyOptions "-log-file=$PLog "
# Save current directory
set PurifyFilename [file tail $NewFilename]
set Status [catch { eval exec [list $Dart(PurifyCommand)] $PurifyOptions [list $PurifyFilename] [lrange $Test 3 end] 2> $TempFile } Result]
ReportError $Status $Result
set Status [catch { eval exec [list $PurifyFilename.pure] [lrange $Test 3 end] 2> $TempFile } Result]
ReportError $Status $Result
set Purify([lindex $Test 0],Status) passed
ProcessPurify $Test $PLog
# delete the purified executable to save disk space
file delete $PurifyFilename.pure
file delete $PurifyFilename.plog
}
}
cd $OldDir
} else {
# running purify on windows
set PurifyOptions "/SAVETEXTDATA=$PLog "
set Status [catch { eval exec [list $Dart(PurifyCommand)] $PurifyOptions [list $NewFilename] [lrange $Test 3 end]} Result]
ReportError $Status $Result
set Purify([lindex $Test 0],Status) passed
ProcessPurify $Test $PLog
# delete the purified executable to save disk space
# but windows purify stashes these in a cache...
}
}
puts $Out "\t<Test Status=\"$Purify([lindex $Test 0],Status)\">"
puts $Out "\t\t<Name>[XMLSafeString [lindex $Test 0]]</Name>"
puts $Out "\t\t<Path>[XMLSafeString [lindex $Test 1]]</Path>"
puts $Out "\t\t<FullName>[XMLSafeString [file join [lindex $Test 1] [lindex $Test 0]]]</FullName>"
puts $Out "\t\t<FullCommandLine>[XMLSafeString [lrange $Test 2 end]]</FullCommandLine>"
puts $Out "\t\t<Results>"
if { $Purify([lindex $Test 0],Status) != "notrun" } \
{
foreach Message $Purify(Messages) \
{
puts $Out "\t\t\t<Defect Type=\"$Message\">$Purify([lindex $Test 0],$Message)</Defect>"
}
} \
else \
{
foreach Message $Purify(Messages) \
{
puts $Out "\t\t\t<Defect type=\"$Message\">0</Defect>"
}
}
puts $Out "\t\t</Results>"
if { [file exists $PLog] } \
{
set PurifyLog [open $PLog r]
puts $Out "\t<Log>"
# For the moment, Don't include the build log
# puts $Out [Base64Encode [read $BuildLog ]]
switch $MemoryChecker {
Purify {
puts $Out [XMLSafeString [read $PurifyLog]]
}
}
close $PurifyLog
puts $Out "\t</Log>"
}
puts $Out "\t</Test>"
cd $OldDir
}
puts $Out "\t<EndDateTime>[AbbreviateTimeZone [clock format [clock seconds]]]</EndDateTime>"
puts $Out "</DynamicAnalysis>"
puts $Out "</Site>"
set total [expr double($ReportPassed + $ReportFailed + $ReportNotRun)]
puts "\tPurify completed"
foreach Message $Purify(Messages) \
{
puts "\t\t$Message - $Purify($Message,Count)"
}
file delete $TempFile
close $Out
}
|