File: Test.tcl

package info (click to toggle)
dart 0.20061109-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,668 kB
  • ctags: 247
  • sloc: tcl: 5,652; perl: 256; python: 141; cpp: 79; makefile: 68; sh: 36
file content (413 lines) | stat: -rw-r--r-- 16,287 bytes parent folder | download
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# =========================================================================
# 
#   Program:   Insight Segmentation & Registration Toolkit
#   Module:    $RCSfile: Test.tcl,v $
#   Language:  Tcl
#   Date:      $Date: 2003/04/02 15:40:27 $
#   Version:   $Revision: 1.32 $
# 

# 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.

# This code handles fileevents and idle callbacks
proc ReadFile { p } {
  global done Output
  if { [eof $p] } {
    set done "Completed"
  } else {
    if { [gets $p line] != -1 } {
      append Output "$line\n"
    }
  }
}

proc IdleTimeout {} {
  global done
  set done "Timeout"
}


proc CheckFile { Filename } \
{
  return [expr [file exists $Filename] && [file executable $Filename]]
}

proc Test { Model BuildStampDir } {
  global Dart Output done tcl_platform TestList

  set TempDir [file join [pwd] Testing Temporary]

  set HTMLDir [file join Testing HTML]
  set TempDir [file join [pwd] Testing Temporary]

  set SiteDir [file join $HTMLDir TestingResults Sites $Dart(Site)]
  set BuildNameDir [file join $SiteDir $Dart(BuildName)]
  set TempFile [file join $TempDir Temp.txt]

  set BuildStamp [file tail $BuildStampDir]
  set XMLDir [file join $BuildStampDir XML]

  set Out [open [file join $XMLDir Test.xml] w]

  puts $Out $Dart(XMLHeader)
  puts $Out "<Site BuildName=\"$Dart(BuildName)\" BuildStamp=\"$BuildStamp\" Name=\"$Dart(Site)\">"

  puts $Out {<Testing>}
  puts $Out "\t<StartDateTime>[AbbreviateTimeZone [clock format [clock seconds]]]</StartDateTime>"

  # Find the list of candidate tests
  puts "\tFinding Tests"
  set TestList ""
  set OldDir [pwd]
  cd $Dart(BuildDirectory)
  set TestList [FindTests .]
  cd $OldDir
  puts "\tFound [llength $TestList] tests"

  # Delete any old coverage files
  catch { FileMap [glob -nocomplain *] [list *.da *.gcov] RemoveFile } 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>"
  

  # DartMeasurement regular expressions
  set dartMeasurementRegExp(twoattributes) "<DartMeasurement\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*>(\[^<\]*)(</DartMeasurement>)"
  set dartMeasurementRegExp(threeattributes) "<DartMeasurement\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*>(\[^<\]*)(</DartMeasurement>)"
  set dartMeasurementRegExp(fourattributes) "<DartMeasurement\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*>(\[^<\]*)(</DartMeasurement>)"
  set dartMeasurementRegExp(measurementfile) "<DartMeasurementFile\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*(name|type|encoding|compression)=\"(\[^\"]*)\"\[ \t\r\n\]*>(\[^<\]*)(</DartMeasurementFile>)"
  
  # 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 "Release" as the test 
    # configuration, otherwise use the specified configuration 
    if { $makeConfiguration == "ALL" } {
      set alternateDirectories "Release"
    } else {
      set alternateDirectories $makeConfiguration
    }
      
    puts "\tWill search for executables in configuration subdirectory $alternateDirectories"
  }
  if { [regexp "^(.*devenv.*).*" $Dart(MakeCommand)] } {
    # extract the configuration
    set makeConfiguration [lindex $Dart(MakeCommand) 3]

    # if makeConfiguration is "ALL", then use "Release" as the test 
    # configuration, otherwise use the specified configuration 
    if { $makeConfiguration == "ALL" } {
      set alternateDirectories "Release"
    } 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 Tests, one icon per test, 50 icons per line"
  puts "\t. == Passed\t- == Failed\t* == NotRun"
  set ReportPassed 0
  set ReportFailed 0
  set ReportNotRun 0
  set TestCount 0

  foreach Test $TestList \
  {
    # Each $Test = {TestIdentifier PathFromBuildDirToTest Executable [args]}
    cd [lindex $Test 1]

    set Filename [lindex $Test 2]
    if { [regexp cygtclsh [info nameofexecutable]] == 1} {
      set Filename [exec cygpath -w $Filename]
      set Filename [eval file join [file split $Filename]]
    }

    # 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 Status notrun
    set Result ""
    if { $NewFilename != "" } \
    {
      set done 0
      set Output ""
      set command [list $NewFilename]
      foreach arg [lrange $Test 3 end] {
	lappend command $arg
      }
      # Setup a timer for the test.
      set StartTimeSeconds [clock seconds]
      set Execution [time {
         # The funny open pipe does not like spaces in $TempFile
         # So we quote it.
         if {[catch { set p [open "| $command 2> [list $TempFile]"] }] } {
            set done "BadCommand"
            set Status 1
         } else { 
            # If the gets operation blocks, then the tcl event loop
            # will never get a chance to see the timeout.
            fconfigure $p -blocking 0

            fileevent $p readable [list ReadFile $p]
            set Callback [after [expr int($Dart(TimeOut) * 1000)] IdleTimeout]
            # Wait for a timeout, or the command to complete
            vwait done
         }  }]
      set EndTimeSeconds [clock seconds]
      # Cancel the after callback, and the fileevent.
      if { $done != "BadCommand" } {
         after cancel $Callback
         fileevent $p readable ""
         # Assume we passed, until proven otherwise.
         set Status 0
      }

      # If we timed out, kill the process, if we can.
      if { $done == "Timeout" } {
        set Status 1
        foreach PID [pid $p] {
          if { $tcl_platform(platform) == "windows" } {
            # this is a windows system, use the kill command distributed w/Dart
            catch { exec [file join $Dart(DartRoot) Source Utilities win32 bin kill.exe] $PID }
          } else {
            # this is a unix system, use standard kill command
            catch { exec kill $PID }
          }
        }
      }
      
      # Start creating the result
      set Result ""
      
      # Configure the command pipeline to be blocking before closing,
      # to ensure that close with a useful exit status.
      fconfigure $p -blocking 1
      if { [catch { close $p } r] } {
        if { $r != "" && $done == "Completed" } {
          append Result "<DartMeasurement type=\"text/string\" name=\"Exit Code\">[XMLSafeString [lindex $::errorCode 0]]</DartMeasurement>\n"
          append Result "<DartMeasurement type=\"text/string\" name=\"Exit Value\">[XMLSafeString [lindex $::errorCode 2]]</DartMeasurement>\n"
          if { [lindex $::errorCode 3] != "" } {
            append Result "<DartMeasurement type=\"text/string\" name=\"Exit Explanation\">[XMLSafeString [lindex $::errorCode 3]]</DartMeasurement>\n"
          }
          set Status 1
          set ::errorCode ""
        }
      }

      # XMLSafeString corrupts the uuencoded binary images, by changing the tags
      # need to use PrintableString
      set f [open $TempFile r]
      append Result "Standard Output:\n[PrintableString $Output]\nStandard Error:\n[PrintableString [read $f]]"
      close $f
      
      # If the test runs more than 30 minutes, report the time in seconds
      # Turns out that 35.8 minutes is where the "time" command wraps
      # as it collects in microseconds
      set DeltaTime [expr $EndTimeSeconds - $StartTimeSeconds]
      if { $DeltaTime > 1800 } {
        set ExecutionTime $DeltaTime
      } else {
        set ExecutionTime [expr [lindex $Execution 0] / 1000000.0]
      }
      
      append Result "<DartMeasurement type=\"numeric/double\" name=\"Execution Time\">$ExecutionTime</DartMeasurement>\n"
      append Result "<DartMeasurement type=\"text/string\" name=\"Completion Status\">$done</DartMeasurement>\n"
      # set Status [catch { eval exec $NewFilename [lrange $Test 3 end]} Result]
    }
    if { $Status == 0 } \
    {
      set Status passed
    }
    if { $Status == 1 } \
    {
      set Status failed
    }
    switch $Status \
    {
      notrun { incr ReportNotRun; set icon "*" }
      passed { incr ReportPassed; set icon "." }
      failed { incr ReportFailed; set icon "-" }
    }
    
    if { $TestCount == 0 } {
      puts -nonewline "\t"
      incr TestCount
    }
    puts -nonewline $icon
    if { ( $TestCount % 50 ) == 0 } {
      puts -nonewline [format "  T: %4d\n\t" $TestCount]
    }
    incr TestCount

    # output the header for the test
    puts $Out "\t<Test Status=\"$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>"

    # parse the output of the test to look for Dart XML tags
    set DartResults ""
    set parseDone 0
    while { $parseDone == 0 } {
      set parseDone 1
      if { [regexp $dartMeasurementRegExp(twoattributes) $Result d t1 v1 t2 v2 measurement endtag] } {
        # found a two attribute call to DartMeasurement
        if { $t1 == "name" || $t2 == "name"} {
          if { $t1 == "type" || $t2 == "type"} {
            puts $Out "\t\t\t<NamedMeasurement $t1=\"$v1\" $t2=\"$v2\"><Value>$measurement</Value></NamedMeasurement>"
          }
        }

        # remove pattern from the output
        regsub $dartMeasurementRegExp(twoattributes) $Result "" Result

        set parseDone 0
      } elseif { [regexp $dartMeasurementRegExp(threeattributes) $Result d t1 v1 t2 v2 t3 v3 measurement endtag] } {
        # found a three attribute call to DartMeasurement
        if { $t1 == "name" || $t2 == "name" || $t3 == "name"} {
          if { $t1 == "type" || $t2 == "type" || $t3 == "type"} {
            puts $Out "\t\t\t<NamedMeasurement $t1=\"$v1\" $t2=\"$v2\" $t3=\"$v3\"><Value>$measurement</Value></NamedMeasurement>"
          }
        }
        
        # remove pattern from the output
        regsub $dartMeasurementRegExp(threeattributes) $Result "" Result

        set parseDone 0
      } elseif { [regexp $dartMeasurementRegExp(fourattributes) $Result d t1 v1 t2 v2 t3 v3 t4 v4 measurement endtag] } {
        # found a four attribute call to DartMeasurement
        if { $t1 == "name" || $t2 == "name" || $t3 == "name" || $t4 == "name"} {
          if { $t1 == "type" || $t2 == "type" || $t3 == "type" || $t4 == "type"} {
            puts $Out "\t\t\t<NamedMeasurement $t1=\"$v1\" $t2=\"$v2\" $t3=\"$v3\" $t4=\"$v4\"><Value>$measurement</Value></NamedMeasurement>"
          }
        }
        
        # remove pattern from the output
        regsub $dartMeasurementRegExp(fourattributes) $Result "" Result

        set parseDone 0
      } elseif { [regexp $dartMeasurementRegExp(measurementfile) $Result d t1 v1 t2 v2 measurement endtag] } {
        # found a two attribute call to DartMeasurementFile
        if { $t1 == "name" || $t2 == "name"} {
          if { $t1 == "type" || $t2 == "type"} {
            if { [info tclversion] < 8.1 } {
              puts $Out "\t\t\t<NamedMeasurement name=\"$v1\" type=\"text/string\"><Value>Cannot encode base64 files with this version of tcl: [info tclversion] less than 8.1</Value></NamedMeasurement>"
            } else {

              if { [catch {set mFile [open [string trim $measurement] r]}] == 0} {
                fconfigure $mFile -translation binary
                puts $Out "\t\t\t<NamedMeasurement $t1=\"$v1\" $t2=\"$v2\" encoding=\"base64\">"
                puts $Out "\t\t\t\t<Value>[base64::encode [read $mFile]]</Value>"
                puts $Out "\t\t\t</NamedMeasurement>"
                close $mFile
              } else {
                puts -nonewline $Out "\t\t\t<NamedMeasurement "
                if { $t1 == "name" } {
                  puts $Out "name=\"$v1\" type=\"text/string\"><Value>File $measurement not found.</Value></NamedMeasurement>"
                } elseif { $t2 == "name" } {
                  puts $Out "name=\"$v2\" type=\"text/string\"><Value>File $measurement not found.</Value></NamedMeasurement>"
                }
              }
            }
          }
        }
        
        # remove pattern from the output
        regsub $dartMeasurementRegExp(measurementfile) $Result "" Result

        set parseDone 0
      }
    }


    # output the results of this test
    puts $Out "\t\t\t<Measurement>"
    puts $Out "\t\t\t\t<Value>[XMLSafeString $Result]</Value>"
    puts $Out "\t\t\t</Measurement>"
    puts $Out "\t\t</Results>"
    puts $Out "\t</Test>"

    cd $OldDir

  }

  puts $Out "\t<EndDateTime>[AbbreviateTimeZone [clock format [clock seconds]]]</EndDateTime>"

  puts $Out "</Testing>"
  puts $Out "</Site>"
  set total [expr double($ReportPassed + $ReportFailed + $ReportNotRun)]

  # Cap off the dots
  incr TestCount -1
  puts [format "  T: %4d" $TestCount]

  puts "\tTesting completed"
  if { $total != 0.0 } \
  {
    set Percent [format "%.2f" [expr 100.0 * $ReportNotRun / $total]]
    puts "\t$ReportNotRun Tests Not Run -- $Percent%"
    set Percent [format "%.2f" [expr 100.0 * $ReportFailed / $total]]
    puts "\t$ReportFailed Tests Failed -- $Percent%"
    set Percent [format "%.2f" [expr 100.0 * $ReportPassed / $total]]
    puts "\t$ReportPassed Tests Passed -- $Percent%"
  }

  close $Out
  return;
}