d5f74e42 |
1 | # Copyright (c) 2013-2014 OPEN CASCADE SAS |
40093367 |
2 | # |
973c2be1 |
3 | # This file is part of Open CASCADE Technology software library. |
40093367 |
4 | # |
d5f74e42 |
5 | # This library is free software; you can redistribute it and/or modify it under |
6 | # the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | # by the Free Software Foundation, with special exception defined in the file |
8 | # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | # distribution for complete text of the license and disclaimer of any warranty. |
40093367 |
10 | # |
973c2be1 |
11 | # Alternatively, this file may be used under the terms of Open CASCADE |
12 | # commercial license or contractual agreement. |
40093367 |
13 | |
14 | ############################################################################ |
15 | # This file defines scripts for execution of OCCT tests. |
16 | # It should be loaded automatically when DRAW is started, and provides |
351bbcba |
17 | # top-level commands starting with 'test'. Type 'help test' to get their |
18 | # synopsys. |
40093367 |
19 | # See OCCT Tests User Guide for description of the test system. |
20 | # |
21 | # Note: procedures with names starting with underscore are for internal use |
22 | # inside the test system. |
23 | ############################################################################ |
24 | |
25 | # Default verbose level for command _run_test |
26 | set _tests_verbose 0 |
27 | |
28 | # regexp for parsing test case results in summary log |
29 | set _test_case_regexp {^CASE\s+([\w.-]+)\s+([\w.-]+)\s+([\w.-]+)\s*:\s*([\w]+)(.*)} |
30 | |
31 | # Basic command to run indicated test case in DRAW |
b725d7c5 |
32 | help test { |
33 | Run specified test case |
433673e0 |
34 | Use: test group grid casename [options...] |
35 | Allowed options are: |
36 | -echo: all commands and results are echoed immediately, |
37 | but log is not saved and summary is not produced |
38 | It is also possible to use "1" instead of "-echo" |
39 | If echo is OFF, log is stored in memory and only summary |
40 | is output (the log can be obtained with command "dlog get") |
41 | -outfile filename: set log file (should be non-existing), |
42 | it is possible to save log file in text file or |
43 | in html file(with snapshot), for that "filename" |
44 | should have ".html" extension |
45 | -overwrite: force writing log in existing file |
46 | -beep: play sound signal at the end of the test |
5fd3308a |
47 | -errors: show all lines from the log report that are recognized as errors |
48 | This key will be ignored if the "-echo" key is already set. |
b725d7c5 |
49 | } |
433673e0 |
50 | proc test {group grid casename {args {}}} { |
51 | # set default values of arguments |
52 | set echo 0 |
5fd3308a |
53 | set errors 0 |
433673e0 |
54 | set logfile "" |
55 | set overwrite 0 |
56 | set signal 0 |
57 | |
40093367 |
58 | # get test case paths (will raise error if input is invalid) |
59 | _get_test $group $grid $casename dir gridname casefile |
60 | |
433673e0 |
61 | # check arguments |
62 | for {set narg 0} {$narg < [llength $args]} {incr narg} { |
63 | set arg [lindex $args $narg] |
433673e0 |
64 | # if echo specified as "-echo", convert it to bool |
65 | if { $arg == "-echo" || $arg == "1" } { |
6d368502 |
66 | set echo t |
67 | continue |
433673e0 |
68 | } |
69 | |
70 | # output log file |
71 | if { $arg == "-outfile" } { |
6d368502 |
72 | incr narg |
73 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
74 | set logfile [lindex $args $narg] |
75 | } else { |
76 | error "Option -outfile requires argument" |
77 | } |
78 | continue |
433673e0 |
79 | } |
80 | |
81 | # allow overwrite existing log |
82 | if { $arg == "-overwrite" } { |
6d368502 |
83 | set overwrite 1 |
84 | continue |
433673e0 |
85 | } |
86 | |
87 | # sound signal at the end of the test |
88 | if { $arg == "-beep" } { |
6d368502 |
89 | set signal t |
90 | continue |
433673e0 |
91 | } |
92 | |
5fd3308a |
93 | # if errors specified as "-errors", convert it to bool |
94 | if { $arg == "-errors" } { |
6d368502 |
95 | set errors t |
96 | continue |
5fd3308a |
97 | } |
98 | |
433673e0 |
99 | # unsupported option |
100 | error "Error: unsupported option \"$arg\"" |
101 | } |
40093367 |
102 | # run test |
c97067ad |
103 | uplevel _run_test $dir $group $gridname $casefile $echo |
40093367 |
104 | |
105 | # check log |
433673e0 |
106 | if { !$echo } { |
5fd3308a |
107 | _check_log $dir $group $gridname $casename $errors [dlog get] summary html_log |
433673e0 |
108 | |
109 | # create log file |
110 | if { ! $overwrite && [file isfile $logfile] } { |
111 | error "Error: Specified log file \"$logfile\" exists; please remove it before running test or use -overwrite option" |
112 | } |
113 | if {$logfile != ""} { |
6d368502 |
114 | if {[file extension $logfile] == ".html"} { |
115 | if {[regexp {vdump ([^\s\n]+)} $html_log dump snapshot]} { |
116 | catch {file copy -force $snapshot [file rootname $logfile][file extension $snapshot]} |
117 | } |
118 | _log_html $logfile $html_log "Test $group $grid $casename" |
119 | } else { |
120 | _log_save $logfile "[dlog get]\n$summary" "Test $group $grid $casename" |
433673e0 |
121 | } |
433673e0 |
122 | } |
5df3a117 |
123 | } |
40093367 |
124 | |
433673e0 |
125 | # play sound signal at the end of test |
126 | if {$signal} { |
6d368502 |
127 | puts "\7\7\7\7" |
433673e0 |
128 | } |
40093367 |
129 | return |
130 | } |
131 | |
132 | # Basic command to run indicated test case in DRAW |
b725d7c5 |
133 | help testgrid { |
134 | Run all tests, or specified group, or one grid |
87f42a3f |
135 | Use: testgrid [groupmask [gridmask [casemask]]] [options...] |
b725d7c5 |
136 | Allowed options are: |
20f720f1 |
137 | -exclude N: exclude group, subgroup or single test case from executing, where |
138 | N is name of group, subgroup or case. Excluded items should be separated by comma. |
139 | Option should be used as the first argument after list of executed groups, grids, and test cases. |
b725d7c5 |
140 | -parallel N: run N parallel processes (default is number of CPUs, 0 to disable) |
9753e6de |
141 | -refresh N: save summary logs every N seconds (default 600, minimal 1, 0 to disable) |
b725d7c5 |
142 | -outdir dirname: set log directory (should be empty or non-existing) |
143 | -overwrite: force writing logs in existing non-empty directory |
144 | -xml filename: write XML report for Jenkins (in JUnit-like format) |
433673e0 |
145 | -beep: play sound signal at the end of the tests |
b502ddc1 |
146 | -regress dirname: re-run only a set of tests that have been detected as regressions on some previous run. |
f9797095 |
147 | -skipped dirname: re-run only a set of tests that have been skipped on some previous run. |
b502ddc1 |
148 | Here "dirname" is path to directory containing results of previous run. |
f9797095 |
149 | -skip N: skip first N tests (useful to restart after abort) |
87f42a3f |
150 | Groups, grids, and test cases to be executed can be specified by list of file |
151 | masks, separated by spaces or comma; default is all (*). |
40093367 |
152 | } |
b725d7c5 |
153 | proc testgrid {args} { |
40093367 |
154 | global env tcl_platform _tests_verbose |
155 | |
156 | ###################################################### |
157 | # check arguments |
158 | ###################################################### |
159 | |
160 | # check that environment variable defining paths to test scripts is defined |
161 | if { ! [info exists env(CSF_TestScriptsPath)] || |
6d368502 |
162 | [llength $env(CSF_TestScriptsPath)] <= 0 } { |
40093367 |
163 | error "Error: Environment variable CSF_TestScriptsPath is not defined" |
164 | } |
165 | |
166 | # treat options |
b725d7c5 |
167 | set parallel [_get_nb_cpus] |
40093367 |
168 | set refresh 60 |
b725d7c5 |
169 | set logdir "" |
40093367 |
170 | set overwrite 0 |
171 | set xmlfile "" |
433673e0 |
172 | set signal 0 |
20f720f1 |
173 | set exc_group 0 |
174 | set exc_grid 0 |
175 | set exc_case 0 |
b502ddc1 |
176 | set regress 0 |
f9797095 |
177 | set skipped 0 |
178 | set logdir_regr "" |
179 | set logdir_skip "" |
180 | set nbskip 0 |
40093367 |
181 | for {set narg 0} {$narg < [llength $args]} {incr narg} { |
6d368502 |
182 | set arg [lindex $args $narg] |
183 | |
184 | # parallel execution |
185 | if { $arg == "-parallel" } { |
186 | incr narg |
187 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
188 | set parallel [expr [lindex $args $narg]] |
189 | } else { |
190 | error "Option -parallel requires argument" |
191 | } |
192 | continue |
193 | } |
194 | |
195 | # refresh logs time |
196 | if { $arg == "-refresh" } { |
197 | incr narg |
198 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
199 | set refresh [expr [lindex $args $narg]] |
200 | } else { |
201 | error "Option -refresh requires argument" |
202 | } |
203 | continue |
204 | } |
205 | |
206 | # output directory |
207 | if { $arg == "-outdir" } { |
208 | incr narg |
209 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
210 | set logdir [lindex $args $narg] |
211 | } else { |
212 | error "Option -outdir requires argument" |
213 | } |
214 | continue |
215 | } |
216 | |
217 | # allow overwrite logs |
218 | if { $arg == "-overwrite" } { |
219 | set overwrite 1 |
220 | continue |
221 | } |
222 | |
223 | # refresh logs time |
224 | if { $arg == "-xml" } { |
225 | incr narg |
226 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
227 | set xmlfile [lindex $args $narg] |
228 | } |
229 | if { $xmlfile == "" } { |
230 | set xmlfile TESTS-summary.xml |
231 | } |
232 | continue |
233 | } |
234 | |
235 | # sound signal at the end of the test |
236 | if { $arg == "-beep" } { |
237 | set signal t |
238 | continue |
239 | } |
240 | |
b502ddc1 |
241 | # re-run only a set of tests that have been detected as regressions on some previous run |
f9797095 |
242 | if { $arg == "-regress" || $arg == "-skipped" } { |
b502ddc1 |
243 | incr narg |
244 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
f9797095 |
245 | if { $arg == "-regress" } { |
246 | set logdir_regr [file normalize [string trim [lindex $args $narg]]] |
247 | set regress 1 |
248 | } else { |
249 | set logdir_skip [file normalize [string trim [lindex $args $narg]]] |
250 | set skipped 1 |
251 | } |
b502ddc1 |
252 | } else { |
f9797095 |
253 | error "Option $arg requires argument" |
254 | } |
255 | continue |
256 | } |
257 | |
258 | # skip N first tests |
259 | if { $arg == "-skip" } { |
260 | incr narg |
261 | if { $narg < [llength $args] && [string is integer [lindex $args $narg]] } { |
262 | set nbskip [lindex $args $narg] |
263 | } else { |
264 | error "Option -skip requires integer argument" |
b502ddc1 |
265 | } |
266 | continue |
267 | } |
268 | |
20f720f1 |
269 | # exclude group, subgroup or single test case from executing |
270 | if { $arg == "-exclude" } { |
271 | incr narg |
272 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
273 | set argts $args |
274 | set idx_begin [string first " -ex" $argts] |
275 | if { ${idx_begin} != "-1" } { |
276 | set argts [string replace $argts 0 $idx_begin] |
277 | } |
278 | set idx_exclude [string first "exclude" $argts] |
279 | if { ${idx_exclude} != "-1" } { |
280 | set argts [string replace $argts 0 $idx_exclude+7] |
281 | } |
282 | set idx [string first " -" $argts] |
283 | if { ${idx} != "-1" } { |
284 | set argts [string replace $argts $idx end] |
285 | } |
286 | set argts [split $argts ,] |
287 | foreach argt $argts { |
288 | if { [llength $argt] == 1 } { |
289 | lappend exclude_group $argt |
290 | set exc_group 1 |
291 | } elseif { [llength $argt] == 2 } { |
292 | lappend exclude_grid $argt |
293 | set exc_grid 1 |
294 | incr narg |
295 | } elseif { [llength $argt] == 3 } { |
296 | lappend exclude_case $argt |
297 | set exc_case 1 |
298 | incr narg |
299 | incr narg |
300 | } |
301 | } |
302 | } else { |
303 | error "Option -exclude requires argument" |
304 | } |
305 | continue |
306 | } |
307 | |
6d368502 |
308 | # unsupported option |
309 | if { [regexp {^-} $arg] } { |
310 | error "Error: unsupported option \"$arg\"" |
311 | } |
312 | |
313 | # treat arguments not recognized as options as group and grid names |
314 | if { ! [info exists groupmask] } { |
315 | set groupmask [split $arg ,] |
316 | } elseif { ! [info exists gridmask] } { |
317 | set gridmask [split $arg ,] |
318 | } elseif { ! [info exists casemask] } { |
319 | set casemask [split $arg ,] |
320 | } else { |
321 | error "Error: cannot interpret argument $narg ($arg)" |
322 | } |
40093367 |
323 | } |
324 | |
325 | # check that target log directory is empty or does not exist |
326 | set logdir [file normalize [string trim $logdir]] |
327 | if { $logdir == "" } { |
6d368502 |
328 | # if specified logdir is empty string, generate unique name like |
ffc26091 |
329 | # results/<branch>_<timestamp> |
330 | set prefix "" |
b725d7c5 |
331 | if { ! [catch {exec git branch} gitout] && |
b502ddc1 |
332 | [regexp {[*] ([\w-]+)} $gitout res branch] } { |
ffc26091 |
333 | set prefix "${branch}_" |
b725d7c5 |
334 | } |
6d368502 |
335 | set logdir "results/${prefix}[clock format [clock seconds] -format {%Y-%m-%dT%H%M}]" |
096ef695 |
336 | |
6d368502 |
337 | set logdir [file normalize $logdir] |
40093367 |
338 | } |
339 | if { [file isdirectory $logdir] && ! $overwrite && ! [catch {glob -directory $logdir *}] } { |
6d368502 |
340 | error "Error: Specified log directory \"$logdir\" is not empty; please clean it before running tests" |
40093367 |
341 | } |
342 | if { [catch {file mkdir $logdir}] || ! [file writable $logdir] } { |
6d368502 |
343 | error "Error: Cannot create directory \"$logdir\", or it is not writable" |
40093367 |
344 | } |
345 | |
87f42a3f |
346 | # masks for search of test groups, grids, and cases |
347 | if { ! [info exists groupmask] } { set groupmask * } |
348 | if { ! [info exists gridmask ] } { set gridmask * } |
349 | if { ! [info exists casemask ] } { set casemask * } |
350 | |
b502ddc1 |
351 | # Find test cases with FAILED and IMPROVEMENT statuses in previous run |
352 | # if option "regress" is given |
353 | set rerun_group_grid_case {} |
354 | |
f9797095 |
355 | if { ${regress} > 0 || ${skipped} > 0 } { |
b502ddc1 |
356 | if { "${groupmask}" != "*"} { |
357 | lappend rerun_group_grid_case [list $groupmask $gridmask $casemask] |
358 | } |
359 | } else { |
360 | lappend rerun_group_grid_case [list $groupmask $gridmask $casemask] |
361 | } |
362 | |
363 | if { ${regress} > 0 } { |
f9797095 |
364 | if { [file exists ${logdir_regr}/tests.log] } { |
365 | set fd [open ${logdir_regr}/tests.log] |
b502ddc1 |
366 | while { [gets $fd line] >= 0 } { |
367 | if {[regexp {CASE ([^\s]+) ([^\s]+) ([^\s]+): FAILED} $line dump group grid casename] || |
368 | [regexp {CASE ([^\s]+) ([^\s]+) ([^\s]+): IMPROVEMENT} $line dump group grid casename]} { |
369 | lappend rerun_group_grid_case [list $group $grid $casename] |
370 | } |
371 | } |
372 | close $fd |
373 | } else { |
f9797095 |
374 | error "Error: file ${logdir_regr}/tests.log is not found, check your input arguments!" |
375 | } |
376 | } |
377 | if { ${skipped} > 0 } { |
378 | if { [file exists ${logdir_skip}/tests.log] } { |
379 | set fd [open ${logdir_skip}/tests.log] |
380 | while { [gets $fd line] >= 0 } { |
381 | if {[regexp {CASE ([^\s]+) ([^\s]+) ([^\s]+): SKIPPED} $line dump group grid casename] } { |
382 | lappend rerun_group_grid_case [list $group $grid $casename] |
383 | } |
384 | } |
385 | close $fd |
386 | } else { |
387 | error "Error: file ${logdir_skip}/tests.log is not found, check your input arguments!" |
b502ddc1 |
388 | } |
389 | } |
390 | |
40093367 |
391 | ###################################################### |
392 | # prepare list of tests to be performed |
393 | ###################################################### |
394 | |
395 | # list of tests, each defined by a list of: |
396 | # test scripts directory |
397 | # group (subfolder) name |
398 | # grid (subfolder) name |
399 | # test case name |
400 | # path to test case file |
401 | set tests_list {} |
402 | |
b502ddc1 |
403 | foreach group_grid_case ${rerun_group_grid_case} { |
404 | set groupmask [lindex $group_grid_case 0] |
405 | set gridmask [lindex $group_grid_case 1] |
406 | set casemask [lindex $group_grid_case 2] |
40093367 |
407 | |
b502ddc1 |
408 | # iterate by all script paths |
409 | foreach dir [lsort -unique [_split_path $env(CSF_TestScriptsPath)]] { |
410 | # protection against empty paths |
411 | set dir [string trim $dir] |
412 | if { $dir == "" } { continue } |
40093367 |
413 | |
b502ddc1 |
414 | if { $_tests_verbose > 0 } { _log_and_puts log "Examining tests directory $dir" } |
40093367 |
415 | |
b502ddc1 |
416 | # check that directory exists |
417 | if { ! [file isdirectory $dir] } { |
418 | _log_and_puts log "Warning: directory $dir listed in CSF_TestScriptsPath does not exist, skipped" |
6d368502 |
419 | continue |
420 | } |
421 | |
b502ddc1 |
422 | # search all directories in the current dir with specified mask |
423 | if [catch {glob -directory $dir -tail -types d {*}$groupmask} groups] { continue } |
6d368502 |
424 | |
20f720f1 |
425 | # exclude selected groups from all groups |
426 | if { ${exc_group} > 0 } { |
427 | foreach exclude_group_element ${exclude_group} { |
428 | set idx [lsearch $groups "${exclude_group_element}"] |
429 | if { ${idx} != "-1" } { |
430 | set groups [lreplace $groups $idx $idx] |
431 | } else { |
432 | continue |
433 | } |
434 | } |
435 | } |
436 | |
b502ddc1 |
437 | # iterate by groups |
438 | if { $_tests_verbose > 0 } { _log_and_puts log "Groups to be executed: $groups" } |
439 | foreach group [lsort -dictionary $groups] { |
440 | if { $_tests_verbose > 0 } { _log_and_puts log "Examining group directory $group" } |
6d368502 |
441 | |
b502ddc1 |
442 | # file grids.list must exist: it defines sequence of grids in the group |
443 | if { ! [file exists $dir/$group/grids.list] } { |
444 | _log_and_puts log "Warning: directory $dir/$group does not contain file grids.list, skipped" |
6d368502 |
445 | continue |
446 | } |
447 | |
b502ddc1 |
448 | # read grids.list file and make a list of grids to be executed |
449 | set gridlist {} |
450 | set fd [open $dir/$group/grids.list] |
451 | set nline 0 |
452 | while { [gets $fd line] >= 0 } { |
453 | incr nline |
6d368502 |
454 | |
b502ddc1 |
455 | # skip comments and empty lines |
456 | if { [regexp "\[ \t\]*\#.*" $line] } { continue } |
457 | if { [string trim $line] == "" } { continue } |
6d368502 |
458 | |
b502ddc1 |
459 | # get grid id and name |
460 | if { ! [regexp "^\(\[0-9\]+\)\[ \t\]*\(\[A-Za-z0-9_.-\]+\)\$" $line res gridid grid] } { |
461 | _log_and_puts log "Warning: cannot recognize line $nline in file $dir/$group/grids.list as \"gridid gridname\"; ignored" |
462 | continue |
87f42a3f |
463 | } |
6d368502 |
464 | |
b502ddc1 |
465 | # check that grid fits into the specified mask |
466 | foreach mask $gridmask { |
467 | if { $mask == $gridid || [string match $mask $grid] } { |
468 | lappend gridlist $grid |
469 | } |
470 | } |
6d368502 |
471 | } |
b502ddc1 |
472 | close $fd |
473 | |
20f720f1 |
474 | # exclude selected grids from all grids |
475 | if { ${exc_grid} > 0 } { |
476 | foreach exclude_grid_element ${exclude_grid} { |
477 | set exclude_elem [lindex $exclude_grid_element end] |
478 | set idx [lsearch $gridlist "${exclude_elem}"] |
479 | if { ${idx} != "-1" } { |
480 | set gridlist [lreplace $gridlist $idx $idx] |
481 | } else { |
482 | continue |
483 | } |
484 | } |
485 | } |
486 | |
b502ddc1 |
487 | # iterate by all grids |
488 | foreach grid $gridlist { |
489 | |
490 | # check if this grid is aliased to another one |
491 | set griddir $dir/$group/$grid |
492 | if { [file exists $griddir/cases.list] } { |
493 | set fd [open $griddir/cases.list] |
494 | if { [gets $fd line] >= 0 } { |
495 | set griddir [file normalize $dir/$group/$grid/[string trim $line]] |
496 | } |
497 | close $fd |
498 | } |
6d368502 |
499 | |
b502ddc1 |
500 | # check if grid directory actually exists |
501 | if { ! [file isdirectory $griddir] } { |
502 | _log_and_puts log "Error: tests directory for grid $grid ($griddir) is missing; skipped" |
6d368502 |
503 | continue |
87f42a3f |
504 | } |
40093367 |
505 | |
b502ddc1 |
506 | # create directory for logging test results |
507 | if { $logdir != "" } { file mkdir $logdir/$group/$grid } |
508 | |
509 | # iterate by all tests in the grid directory |
510 | if { [catch {glob -directory $griddir -type f {*}$casemask} testfiles] } { continue } |
20f720f1 |
511 | |
512 | # exclude selected test cases from all testfiles |
513 | if { ${exc_case} > 0 } { |
514 | foreach exclude_case_element ${exclude_case} { |
515 | set exclude_casegroup_elem [lindex $exclude_case_element end-2] |
516 | set exclude_casegrid_elem [lindex $exclude_case_element end-1] |
517 | set exclude_elem [lindex $exclude_case_element end] |
518 | if { ${exclude_casegrid_elem} == "${grid}" } { |
519 | set idx [lsearch $testfiles "${dir}/${exclude_casegroup_elem}/${exclude_casegrid_elem}/${exclude_elem}"] |
520 | if { ${idx} != "-1" } { |
521 | set testfiles [lreplace $testfiles $idx $idx] |
522 | } else { |
523 | continue |
524 | } |
525 | } |
526 | } |
527 | } |
528 | |
b502ddc1 |
529 | foreach casefile [lsort -dictionary $testfiles] { |
530 | # filter out files with reserved names |
531 | set casename [file tail $casefile] |
532 | if { $casename == "begin" || $casename == "end" || |
533 | $casename == "parse.rules" } { |
534 | continue |
535 | } |
536 | |
f9797095 |
537 | if { $nbskip > 0 } { |
538 | incr nbskip -1 |
539 | } else { |
540 | lappend tests_list [list $dir $group $grid $casename $casefile] |
541 | } |
b502ddc1 |
542 | } |
6d368502 |
543 | } |
544 | } |
545 | } |
40093367 |
546 | } |
547 | if { [llength $tests_list] < 1 } { |
b502ddc1 |
548 | error "Error: no tests are found, check your input arguments and variable CSF_TestScriptsPath!" |
433673e0 |
549 | } else { |
6d368502 |
550 | puts "Running tests (total [llength $tests_list] test cases)..." |
40093367 |
551 | } |
552 | |
553 | ###################################################### |
554 | # run tests |
555 | ###################################################### |
556 | |
557 | # log command arguments and environment |
9753e6de |
558 | lappend log "Command: testgrid $args" |
559 | lappend log "Host: [info hostname]" |
560 | lappend log "Started on: [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]" |
561 | catch {lappend log "DRAW build:\n[dversion]" } |
562 | lappend log "Environment:" |
8a262fa1 |
563 | foreach envar [lsort [array names env]] { |
6d368502 |
564 | lappend log "$envar=\"$env($envar)\"" |
40093367 |
565 | } |
9753e6de |
566 | lappend log "" |
40093367 |
567 | |
568 | set refresh_timer [clock seconds] |
569 | uplevel dchrono _timer reset |
570 | uplevel dchrono _timer start |
571 | |
572 | # if parallel execution is requested, allocate thread pool |
573 | if { $parallel > 0 } { |
6d368502 |
574 | if { ! [info exists tcl_platform(threaded)] || [catch {package require Thread}] } { |
575 | _log_and_puts log "Warning: Tcl package Thread is not available, running in sequential mode" |
576 | set parallel 0 |
577 | } else { |
578 | set worker [tpool::create -minworkers $parallel -maxworkers $parallel] |
579 | # suspend the pool until all jobs are posted, to prevent blocking of the process |
580 | # of starting / processing jobs by running threads |
581 | catch {tpool::suspend $worker} |
582 | if { $_tests_verbose > 0 } { _log_and_puts log "Executing tests in (up to) $parallel threads" } |
9753e6de |
583 | # limit number of jobs in the queue by reasonable value |
584 | # to prevent slowdown due to unnecessary queue processing |
585 | set nbpooled 0 |
586 | set nbpooled_max [expr 10 * $parallel] |
587 | set nbpooled_ok [expr 5 * $parallel] |
6d368502 |
588 | } |
40093367 |
589 | } |
590 | |
591 | # start test cases |
8a262fa1 |
592 | set userbreak 0 |
40093367 |
593 | foreach test_def $tests_list { |
8a262fa1 |
594 | # check for user break |
9753e6de |
595 | if { $userbreak || "[info commands dbreak]" == "dbreak" && [catch dbreak] } { |
8a262fa1 |
596 | set userbreak 1 |
597 | break |
598 | } |
599 | |
6d368502 |
600 | set dir [lindex $test_def 0] |
601 | set group [lindex $test_def 1] |
602 | set grid [lindex $test_def 2] |
603 | set casename [lindex $test_def 3] |
604 | set casefile [lindex $test_def 4] |
605 | |
606 | # command to set tests for generation of image in results directory |
607 | set imgdir_cmd "" |
608 | if { $logdir != "" } { set imgdir_cmd "set imagedir $logdir/$group/$grid" } |
609 | |
610 | # prepare command file for running test case in separate instance of DRAW |
f9797095 |
611 | set file_cmd "$logdir/$group/$grid/${casename}.tcl" |
612 | set fd_cmd [open $file_cmd w] |
6d368502 |
613 | puts $fd_cmd "$imgdir_cmd" |
614 | puts $fd_cmd "set test_image $casename" |
615 | puts $fd_cmd "_run_test $dir $group $grid $casefile t" |
616 | |
617 | # use dlog command to obtain complete output of the test when it is absent (i.e. since OCCT 6.6.0) |
618 | # note: this is not needed if echo is set to 1 in call to _run_test above |
619 | if { ! [catch {dlog get}] } { |
620 | puts $fd_cmd "puts \[dlog get\]" |
621 | } else { |
622 | # else try to use old-style QA_ variables to get more output... |
623 | set env(QA_DUMP) 1 |
624 | set env(QA_DUP) 1 |
625 | set env(QA_print_command) 1 |
626 | } |
627 | |
628 | # final 'exit' is needed when running on Linux under VirtualGl |
629 | puts $fd_cmd "exit" |
630 | close $fd_cmd |
8418c617 |
631 | |
632 | # commant to run DRAW with a command file; |
633 | # note that empty string is passed as standard input to avoid possible |
634 | # hang-ups due to waiting for stdin of the launching process |
f9797095 |
635 | set command "exec <<{} DRAWEXE -f $file_cmd" |
6d368502 |
636 | |
637 | # alternative method to run without temporary file; disabled as it needs too many backslashes |
638 | # else { |
639 | # set command "exec <<\"\" DRAWEXE -c $imgdir_cmd\\\; set test_image $casename\\\; \ |
640 | # _run_test $dir $group $grid $casefile\\\; \ |
641 | # puts \\\[dlog get\\\]\\\; exit" |
642 | # } |
643 | |
644 | # run test case, either in parallel or sequentially |
645 | if { $parallel > 0 } { |
646 | # parallel execution |
647 | set job [tpool::post -nowait $worker "catch \"$command\" output; return \$output"] |
648 | set job_def($job) [list $logdir $dir $group $grid $casename] |
9753e6de |
649 | incr nbpooled |
650 | if { $nbpooled > $nbpooled_max } { |
651 | _testgrid_process_jobs $worker $nbpooled_ok |
652 | } |
6d368502 |
653 | } else { |
654 | # sequential execution |
655 | catch {eval $command} output |
656 | _log_test_case $output $logdir $dir $group $grid $casename log |
657 | |
658 | # update summary log with requested period |
659 | if { $logdir != "" && $refresh > 0 && [expr [clock seconds] - $refresh_timer > $refresh] } { |
660 | # update and dump summary |
661 | _log_summarize $logdir $log |
662 | set refresh_timer [clock seconds] |
663 | } |
664 | } |
40093367 |
665 | } |
666 | |
667 | # get results of started threads |
668 | if { $parallel > 0 } { |
9753e6de |
669 | _testgrid_process_jobs $worker |
6d368502 |
670 | # release thread pool |
9753e6de |
671 | if { $nbpooled > 0 } { |
6d368502 |
672 | tpool::cancel $worker [array names job_def] |
9753e6de |
673 | } |
674 | catch {tpool::resume $worker} |
6d368502 |
675 | tpool::release $worker |
40093367 |
676 | } |
677 | |
678 | uplevel dchrono _timer stop |
679 | set time [lindex [split [uplevel dchrono _timer show] "\n"] 0] |
680 | |
8a262fa1 |
681 | if { $userbreak } { |
9753e6de |
682 | _log_and_puts log "*********** Stopped by user break ***********" |
8a262fa1 |
683 | set time "${time} \nNote: the process is not finished, stopped by user break!" |
684 | } |
685 | |
40093367 |
686 | ###################################################### |
687 | # output summary logs and exit |
688 | ###################################################### |
689 | |
690 | _log_summarize $logdir $log $time |
691 | if { $logdir != "" } { |
6d368502 |
692 | puts "Detailed logs are saved in $logdir" |
40093367 |
693 | } |
694 | if { $logdir != "" && $xmlfile != "" } { |
6d368502 |
695 | # XML output file is assumed relative to log dir unless it is absolute |
696 | if { [ file pathtype $xmlfile] == "relative" } { |
697 | set xmlfile [file normalize $logdir/$xmlfile] |
698 | } |
699 | _log_xml_summary $logdir $xmlfile $log 0 |
700 | puts "XML summary is saved to $xmlfile" |
40093367 |
701 | } |
433673e0 |
702 | # play sound signal at the end of test |
703 | if {$signal} { |
6d368502 |
704 | puts "\7\7\7\7" |
433673e0 |
705 | } |
40093367 |
706 | return |
707 | } |
708 | |
22db40eb |
709 | # Procedure to regenerate summary log from logs of test cases |
710 | help testsummarize { |
711 | Regenerate summary log in the test directory from logs of test cases. |
712 | This can be necessary if test grids are executed separately (e.g. on |
713 | different stations) or some grids have been re-executed. |
714 | Use: testsummarize dir |
715 | } |
716 | proc testsummarize {dir} { |
717 | global _test_case_regexp |
718 | |
719 | if { ! [file isdirectory $dir] } { |
6d368502 |
720 | error "Error: \"$dir\" is not a directory" |
22db40eb |
721 | } |
722 | |
723 | # get summary statements from all test cases in one log |
9753e6de |
724 | set log {} |
22db40eb |
725 | |
726 | # to avoid huge listing of logs, first find all subdirectories and iterate |
727 | # by them, parsing log files in each subdirectory independently |
728 | foreach grid [glob -directory $dir -types d -tails */*] { |
729 | foreach caselog [glob -nocomplain -directory [file join $dir $grid] -types f -tails *.log] { |
730 | set file [file join $dir $grid $caselog] |
731 | set nbfound 0 |
732 | set fd [open $file r] |
6d368502 |
733 | while { [gets $fd line] >= 0 } { |
734 | if { [regexp $_test_case_regexp $line res grp grd cas status message] } { |
22db40eb |
735 | if { "[file join $grid $caselog]" != "[file join $grp $grd ${cas}.log]" } { |
736 | puts "Error: $file contains status line for another test case ($line)" |
737 | } |
6d368502 |
738 | lappend log $line |
739 | incr nbfound |
740 | } |
741 | } |
22db40eb |
742 | close $fd |
743 | |
744 | if { $nbfound != 1 } { |
745 | puts "Error: $file contains $nbfound status lines, expected 1" |
746 | } |
747 | } |
748 | } |
749 | |
750 | _log_summarize $dir $log "Summary regenerated from logs at [clock format [clock seconds]]" |
751 | return |
752 | } |
753 | |
cc6a292d |
754 | # Procedure to compare results of two runs of test cases |
b725d7c5 |
755 | help testdiff { |
756 | Compare results of two executions of tests (CPU times, ...) |
22db40eb |
757 | Use: testdiff dir1 dir2 [groupname [gridname]] [options...] |
b725d7c5 |
758 | Where dir1 and dir2 are directories containing logs of two test runs. |
f2b42160 |
759 | dir1 (A) should point to NEW tests results to be verified and dir2 (B) to REFERENCE results. |
b725d7c5 |
760 | Allowed options are: |
28cab376 |
761 | -image [filename]: compare only images and save its in specified file (default |
762 | name is <dir1>/diffimage-<dir2>.log) |
763 | -cpu [filename]: compare only CPU and save it in specified file (default |
764 | name is <dir1>/diffcpu-<dir2>.log) |
765 | -memory [filename]: compare only memory and save it in specified file (default |
766 | name is <dir1>/diffmemory-<dir2>.log) |
22db40eb |
767 | -save filename: save resulting log in specified file (default name is |
60874ff8 |
768 | <dir1>/diff-<dir2>.log); HTML log is saved with same name |
22db40eb |
769 | and extension .html |
b725d7c5 |
770 | -status {same|ok|all}: filter cases for comparing by their status: |
771 | same - only cases with same status are compared (default) |
772 | ok - only cases with OK status in both logs are compared |
773 | all - results are compared regardless of status |
774 | -verbose level: |
775 | 1 - output only differences |
22db40eb |
776 | 2 - output also list of logs and directories present in one of dirs only |
777 | 3 - (default) output also progress messages |
d5f061b6 |
778 | -highlight_percent value: highlight considerable (>value in %) deviations |
779 | of CPU and memory (default value is 5%) |
cc6a292d |
780 | } |
781 | proc testdiff {dir1 dir2 args} { |
782 | if { "$dir1" == "$dir2" } { |
6d368502 |
783 | error "Input directories are the same" |
cc6a292d |
784 | } |
785 | |
786 | ###################################################### |
787 | # check arguments |
788 | ###################################################### |
789 | |
790 | # treat options |
22db40eb |
791 | set logfile [file join $dir1 "diff-[file tail $dir2].log"] |
28cab376 |
792 | set logfile_image "" |
793 | set logfile_cpu "" |
794 | set logfile_memory "" |
795 | set image false |
796 | set cpu false |
797 | set memory false |
cc6a292d |
798 | set basename "" |
28cab376 |
799 | set save false |
cc6a292d |
800 | set status "same" |
801 | set verbose 3 |
6d368502 |
802 | set highlight_percent 5 |
cc6a292d |
803 | for {set narg 0} {$narg < [llength $args]} {incr narg} { |
6d368502 |
804 | set arg [lindex $args $narg] |
6d368502 |
805 | # log file name |
806 | if { $arg == "-save" } { |
807 | incr narg |
808 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
809 | set logfile [lindex $args $narg] |
810 | } else { |
811 | error "Error: Option -save must be followed by log file name" |
812 | } |
28cab376 |
813 | set save true |
6d368502 |
814 | continue |
815 | } |
28cab376 |
816 | |
817 | # image compared log |
818 | if { $arg == "-image" } { |
819 | incr narg |
820 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
821 | set logfile_image [lindex $args $narg] |
822 | } else { |
823 | set logfile_image [file join $dir1 "diffimage-[file tail $dir2].log"] |
824 | incr narg -1 |
825 | } |
826 | set image true |
827 | continue |
828 | } |
829 | |
830 | # CPU compared log |
831 | if { $arg == "-cpu" } { |
832 | incr narg |
833 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
834 | set logfile_cpu [lindex $args $narg] |
835 | } else { |
836 | set logfile_cpu [file join $dir1 "diffcpu-[file tail $dir2].log"] |
837 | incr narg -1 |
838 | } |
839 | set cpu true |
840 | continue |
841 | } |
842 | |
843 | # memory compared log |
844 | if { $arg == "-memory" } { |
845 | incr narg |
846 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
847 | set logfile_memory [lindex $args $narg] |
848 | } else { |
849 | set logfile_memory [file join $dir1 "diffmemory-[file tail $dir2].log"] |
850 | incr narg -1 |
851 | } |
852 | set memory true |
853 | continue |
854 | } |
855 | |
6d368502 |
856 | # status filter |
857 | if { $arg == "-status" } { |
858 | incr narg |
859 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
860 | set status [lindex $args $narg] |
861 | } else { |
862 | set status "" |
863 | } |
864 | if { "$status" != "same" && "$status" != "all" && "$status" != "ok" } { |
865 | error "Error: Option -status must be followed by one of \"same\", \"all\", or \"ok\"" |
866 | } |
867 | continue |
868 | } |
869 | |
870 | # verbose level |
871 | if { $arg == "-verbose" } { |
872 | incr narg |
873 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
874 | set verbose [expr [lindex $args $narg]] |
875 | } else { |
876 | error "Error: Option -verbose must be followed by integer verbose level" |
877 | } |
878 | continue |
879 | } |
880 | |
881 | # highlight_percent |
882 | if { $arg == "-highlight_percent" } { |
883 | incr narg |
884 | if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } { |
885 | set highlight_percent [expr [lindex $args $narg]] |
886 | } else { |
887 | error "Error: Option -highlight_percent must be followed by integer value" |
888 | } |
889 | continue |
890 | } |
891 | |
892 | if { [regexp {^-} $arg] } { |
893 | error "Error: unsupported option \"$arg\"" |
894 | } |
22db40eb |
895 | |
896 | # non-option arguments form a subdirectory path |
6d368502 |
897 | set basename [file join $basename $arg] |
cc6a292d |
898 | } |
28cab376 |
899 | |
900 | if {$image != false || $cpu != false || $memory != false} { |
901 | if {$save != false} { |
902 | error "Error: Option -save can not be used with image/cpu/memory options" |
903 | } |
904 | } |
cc6a292d |
905 | |
906 | # run diff procedure (recursive) |
28cab376 |
907 | _test_diff $dir1 $dir2 $basename $image $cpu $memory $status $verbose log log_image log_cpu log_memory |
908 | |
cc6a292d |
909 | # save result to log file |
28cab376 |
910 | if {$image == false && $cpu == false && $memory == false} { |
911 | if { "$logfile" != "" } { |
912 | _log_save $logfile [join $log "\n"] |
913 | _log_html_diff "[file rootname $logfile].html" $log $dir1 $dir2 ${highlight_percent} |
914 | puts "Log is saved to $logfile (and .html)" |
915 | } |
916 | } else { |
917 | foreach mode {image cpu memory} { |
918 | if {"[set logfile_${mode}]" != ""} { |
919 | _log_save "[set logfile_${mode}]" [join "[set log_${mode}]" "\n"] |
920 | _log_html_diff "[file rootname [set logfile_${mode}]].html" "[set log_${mode}]" $dir1 $dir2 ${highlight_percent} |
921 | puts "Log (${mode}) is saved to [set logfile_${mode}] (and .html)" |
922 | } |
923 | } |
cc6a292d |
924 | } |
cc6a292d |
925 | return |
926 | } |
927 | |
351bbcba |
928 | # Procedure to check data file before adding it to repository |
929 | help testfile { |
4eb6e8f4 |
930 | Checks specified data files for putting them into the test data files repository. |
931 | |
932 | Use: testfile filelist |
351bbcba |
933 | |
934 | Will report if: |
935 | - data file (non-binary) is in DOS encoding (CR/LF) |
936 | - same data file (with same or another name) already exists in the repository |
937 | - another file with the same name already exists |
4eb6e8f4 |
938 | Note that names are considered to be case-insensitive (for compatibility |
939 | with Windows). |
351bbcba |
940 | |
941 | Unless the file is already in the repository, tries to load it, reports |
942 | the recognized file format, file size, number of faces and edges in the |
4eb6e8f4 |
943 | loaded shape (if any), information contained its triangulation, and makes |
944 | snapshot (in the temporary directory). |
945 | |
351bbcba |
946 | Finally it advises whether the file should be put to public section of the |
947 | repository. |
4eb6e8f4 |
948 | |
949 | Use: testfile -check |
950 | |
951 | If "-check" is given as an argument, then procedure will check files already |
952 | located in the repository (for possible duplicates and for DOS encoding). |
351bbcba |
953 | } |
954 | proc testfile {filelist} { |
955 | global env |
956 | |
957 | # check that CSF_TestDataPath is defined |
958 | if { ! [info exists env(CSF_TestDataPath)] } { |
959 | error "Environment variable CSF_TestDataPath must be defined!" |
960 | } |
961 | |
4eb6e8f4 |
962 | set checkrepo f |
963 | if { "$filelist" == "-check" } { set checkrepo t } |
964 | |
351bbcba |
965 | # build registry of existing data files (name -> path) and (size -> path) |
4eb6e8f4 |
966 | puts "Collecting info on test data files repository..." |
351bbcba |
967 | foreach dir [_split_path $env(CSF_TestDataPath)] { |
968 | while {[llength $dir] != 0} { |
969 | set curr [lindex $dir 0] |
970 | set dir [lrange $dir 1 end] |
971 | eval lappend dir [glob -nocomplain -directory $curr -type d *] |
972 | foreach file [glob -nocomplain -directory $curr -type f *] { |
973 | set name [file tail $file] |
974 | set name_lower [string tolower $name] |
4eb6e8f4 |
975 | set size [file size $file] |
351bbcba |
976 | |
977 | # check that the file is not in DOS encoding |
4eb6e8f4 |
978 | if { $checkrepo } { |
979 | if { [_check_dos_encoding $file] } { |
980 | puts "Warning: file $file is in DOS encoding; was this intended?" |
351bbcba |
981 | } |
4eb6e8f4 |
982 | _check_file_format $file |
983 | |
984 | # check if file with the same name is present twice or more |
985 | if { [info exists names($name_lower)] } { |
986 | puts "Error: more than one file with name $name is present in the repository:" |
987 | if { [_diff_files $file $names($name_lower)] } { |
988 | puts "(files are different by content)" |
989 | } else { |
990 | puts "(files are same by content)" |
991 | } |
992 | puts "--> $file" |
993 | puts "--> $names($name_lower)" |
994 | continue |
995 | } |
351bbcba |
996 | |
4eb6e8f4 |
997 | # check if file with the same content exists |
998 | if { [info exists sizes($size)] } { |
999 | foreach other $sizes($size) { |
1000 | if { ! [_diff_files $file $other] } { |
1001 | puts "Warning: two files with the same content found:" |
1002 | puts "--> $file" |
1003 | puts "--> $other" |
1004 | } |
351bbcba |
1005 | } |
1006 | } |
1007 | } |
1008 | |
1009 | # add the file to the registry |
4eb6e8f4 |
1010 | lappend names($name_lower) $file |
351bbcba |
1011 | lappend sizes($size) $file |
6d368502 |
1012 | } |
1013 | } |
351bbcba |
1014 | } |
4eb6e8f4 |
1015 | if { $checkrepo || [llength $filelist] <= 0 } { return } |
351bbcba |
1016 | |
1017 | # check the new files |
1018 | set has_images f |
1019 | puts "Checking new file(s)..." |
1020 | foreach file $filelist { |
351bbcba |
1021 | set name [file tail $file] |
1022 | set name_lower [string tolower $name] |
4eb6e8f4 |
1023 | set found f |
351bbcba |
1024 | |
1025 | # check for presence of the file with same name |
1026 | if { [info exists names($name_lower)] } { |
4eb6e8f4 |
1027 | set found f |
1028 | foreach other $names($name_lower) { |
1029 | # avoid comparing the file with itself |
1030 | if { [file normalize $file] == [file normalize $other] } { |
1031 | continue |
1032 | } |
1033 | # compare content |
1034 | if { [_diff_files $file $other] } { |
1035 | puts "\n* $file: error\n name is already used by existing file\n --> $other" |
1036 | } else { |
1037 | puts "\n* $file: already present \n --> $other" |
1038 | } |
1039 | set found t |
1040 | break |
351bbcba |
1041 | } |
4eb6e8f4 |
1042 | if { $found } { continue } |
1043 | } |
1044 | |
1045 | # get size of the file; if it is in DOS encoding and less than 1 MB, |
1046 | # estimate also its size in UNIX encoding to be able to find same |
1047 | # file if already present but in UNIX encoding |
1048 | set sizeact [file size $file] |
1049 | set sizeunx "" |
1050 | set isdos [_check_dos_encoding $file] |
1051 | if { $isdos && $sizeact < 10000000 } { |
1052 | set fd [open $file r] |
1053 | fconfigure $fd -translation crlf |
1054 | set sizeunx [string length [read $fd]] |
1055 | close $fd |
351bbcba |
1056 | } |
1057 | |
1058 | # check if file with the same content exists |
4eb6e8f4 |
1059 | foreach size "$sizeact $sizeunx" { |
1060 | if { [info exists sizes($size)] } { |
351bbcba |
1061 | foreach other $sizes($size) { |
4eb6e8f4 |
1062 | # avoid comparing the file with itself |
1063 | if { [file normalize $file] == [file normalize $other] } { |
1064 | continue |
1065 | } |
1066 | # compare content |
351bbcba |
1067 | if { ! [_diff_files $file $other] } { |
4eb6e8f4 |
1068 | puts "\n* $file: duplicate \n already present under name [file tail $other]\n --> $other" |
6d368502 |
1069 | set found t |
1070 | break |
351bbcba |
1071 | } |
1072 | } |
4eb6e8f4 |
1073 | if { $found } { break } |
1074 | } |
1075 | } |
1076 | if { $found } { continue } |
1077 | |
1078 | # file is not present yet, so to be analyzed |
1079 | puts "\n* $file: new file" |
1080 | |
1081 | # add the file to the registry as if it were added to the repository, |
1082 | # to report possible duplicates among the currently processed files |
1083 | lappend names($name_lower) $file |
1084 | if { "$sizeunx" != "" } { |
1085 | lappend sizes($sizeunx) $file |
1086 | } else { |
1087 | lappend sizes($sizeact) $file |
1088 | } |
1089 | |
1090 | # first of all, complain if it is in DOS encoding |
1091 | if { $isdos } { |
1092 | puts " Warning: DOS encoding detected, consider converting to" |
1093 | puts " UNIX unless DOS line ends are needed for the test" |
351bbcba |
1094 | } |
1095 | |
1096 | # try to read the file |
1097 | set format [_check_file_format $file] |
1098 | if { [catch {uplevel load_data_file $file $format a}] } { |
4eb6e8f4 |
1099 | puts " Warning: Cannot read as $format file" |
351bbcba |
1100 | continue |
1101 | } |
1102 | |
4eb6e8f4 |
1103 | # warn if shape contains triangulation |
1104 | pload MODELING |
1105 | if { "$format" != "STL" && |
1106 | [regexp {contains\s+([0-9]+)\s+triangles} [uplevel trinfo a] res nbtriangles] && |
1107 | $nbtriangles != 0 } { |
1108 | puts " Warning: shape contains triangulation ($nbtriangles triangles)," |
1109 | puts " consider removing them unless they are needed for the test!" |
1110 | } |
1111 | |
351bbcba |
1112 | # get number of faces and edges |
1113 | set edges 0 |
1114 | set faces 0 |
1115 | set nbs [uplevel nbshapes a] |
1116 | regexp {EDGE[ \t:]*([0-9]+)} $nbs res edges |
1117 | regexp {FACE[ \t:]*([0-9]+)} $nbs res faces |
1118 | |
1119 | # classify; first check file size and number of faces and edges |
1120 | if { $size < 95000 && $faces < 20 && $edges < 100 } { |
1121 | set dir public |
1122 | } else { |
1123 | set dir private |
351bbcba |
1124 | } |
1125 | |
1126 | # add stats |
4eb6e8f4 |
1127 | puts " $format size=[expr $size / 1024] KiB, nbfaces=$faces, nbedges=$edges -> $dir" |
351bbcba |
1128 | |
60874ff8 |
1129 | set tmpdir [_get_temp_dir] |
1130 | file mkdir $tmpdir/$dir |
351bbcba |
1131 | |
1132 | # make snapshot |
1133 | pload AISV |
1134 | uplevel vdisplay a |
4eb6e8f4 |
1135 | uplevel vsetdispmode 1 |
351bbcba |
1136 | uplevel vfit |
1137 | uplevel vzfit |
60874ff8 |
1138 | uplevel vdump $tmpdir/$dir/[file rootname [file tail $file]].png |
351bbcba |
1139 | set has_images t |
1140 | } |
1141 | if { $has_images } { |
60874ff8 |
1142 | puts "Snapshots are saved in subdirectory [_get_temp_dir]" |
351bbcba |
1143 | } |
1144 | } |
1145 | |
22db40eb |
1146 | # Procedure to locate data file for test given its name. |
1147 | # The search is performed assuming that the function is called |
1148 | # from the test case script; the search order is: |
1149 | # - subdirectory "data" of the test script (grid) folder |
1150 | # - subdirectories in environment variable CSF_TestDataPath |
1151 | # - subdirectory set by datadir command |
1152 | # If file is not found, raises Tcl error. |
1153 | proc locate_data_file {filename} { |
1154 | global env groupname gridname casename |
1155 | |
1156 | # check if the file is located in the subdirectory data of the script dir |
1157 | set scriptfile [info script] |
c61c864f |
1158 | if { "$scriptfile" != "" } { |
1159 | set path [file join [file dirname "$scriptfile"] data "$filename"] |
1160 | if { [file exists "$path"] } { |
1161 | return [file normalize "$path"] |
6d368502 |
1162 | } |
22db40eb |
1163 | } |
1164 | |
1165 | # check sub-directories in paths indicated by CSF_TestDataPath |
1166 | if { [info exists env(CSF_TestDataPath)] } { |
6d368502 |
1167 | foreach dir [_split_path $env(CSF_TestDataPath)] { |
c61c864f |
1168 | set dir [list "$dir"] |
1169 | while {[llength "$dir"] != 0} { |
1170 | set name [lindex "$dir" 0] |
1171 | set dir [lrange "$dir" 1 end] |
343f7e4d |
1172 | |
80482e01 |
1173 | # skip directories starting with dot |
c61c864f |
1174 | set aTail [file tail "$name"] |
1175 | if { [regexp {^[.]} "$aTail"] } { continue } |
1176 | if { [file exists "$name/$filename"] } { |
1177 | return [file normalize "$name/$filename"] |
6d368502 |
1178 | } |
c61c864f |
1179 | eval lappend dir [glob -nocomplain -directory "$name" -type d *] |
6d368502 |
1180 | } |
1181 | } |
22db40eb |
1182 | } |
1183 | |
1184 | # check current datadir |
c61c864f |
1185 | if { [file exists "[uplevel datadir]/$filename"] } { |
1186 | return [file normalize "[uplevel datadir]/$filename"] |
22db40eb |
1187 | } |
1188 | |
1189 | # raise error |
c97067ad |
1190 | error [join [list "File $filename could not be found" \ |
6d368502 |
1191 | "(should be in paths indicated by CSF_TestDataPath environment variable, " \ |
22db40eb |
1192 | "or in subfolder data in the script directory)"] "\n"] |
1193 | } |
1194 | |
40093367 |
1195 | # Internal procedure to find test case indicated by group, grid, and test case names; |
1196 | # returns: |
1197 | # - dir: path to the base directory of the tests group |
1198 | # - gridname: actual name of the grid |
1199 | # - casefile: path to the test case script |
1200 | # if no such test is found, raises error with appropriate message |
1201 | proc _get_test {group grid casename _dir _gridname _casefile} { |
1202 | upvar $_dir dir |
1203 | upvar $_gridname gridname |
1204 | upvar $_casefile casefile |
1205 | |
1206 | global env |
1207 | |
1208 | # check that environment variable defining paths to test scripts is defined |
1209 | if { ! [info exists env(CSF_TestScriptsPath)] || |
1210 | [llength $env(CSF_TestScriptsPath)] <= 0 } { |
1211 | error "Error: Environment variable CSF_TestScriptsPath is not defined" |
1212 | } |
1213 | |
1214 | # iterate by all script paths |
1215 | foreach dir [_split_path $env(CSF_TestScriptsPath)] { |
6d368502 |
1216 | # protection against empty paths |
1217 | set dir [string trim $dir] |
1218 | if { $dir == "" } { continue } |
40093367 |
1219 | |
1220 | # check that directory exists |
1221 | if { ! [file isdirectory $dir] } { |
1222 | puts "Warning: directory $dir listed in CSF_TestScriptsPath does not exist, skipped" |
6d368502 |
1223 | continue |
40093367 |
1224 | } |
1225 | |
1226 | # check if test group with given name exists in this dir |
1227 | # if not, continue to the next test dir |
1228 | if { ! [file isdirectory $dir/$group] } { continue } |
1229 | |
1230 | # check that grid with given name (possibly alias) exists; stop otherwise |
1231 | set gridname $grid |
1232 | if { ! [file isdirectory $dir/$group/$gridname] } { |
1233 | # check if grid is named by alias rather than by actual name |
1234 | if { [file exists $dir/$group/grids.list] } { |
1235 | set fd [open $dir/$group/grids.list] |
1236 | while { [gets $fd line] >= 0 } { |
1237 | if { [regexp "\[ \t\]*\#.*" $line] } { continue } |
1238 | if { [regexp "^$grid\[ \t\]*\(\[A-Za-z0-9_.-\]+\)\$" $line res gridname] } { |
1239 | break |
1240 | } |
1241 | } |
1242 | close $fd |
6d368502 |
1243 | } |
1244 | } |
40093367 |
1245 | if { ! [file isdirectory $dir/$group/$gridname] } { continue } |
1246 | |
1247 | # get actual file name of the script; stop if it cannot be found |
1248 | set casefile $dir/$group/$gridname/$casename |
1249 | if { ! [file exists $casefile] } { |
1250 | # check if this grid is aliased to another one |
1251 | if { [file exists $dir/$group/$gridname/cases.list] } { |
1252 | set fd [open $dir/$group/$gridname/cases.list] |
1253 | if { [gets $fd line] >= 0 } { |
1254 | set casefile [file normalize $dir/$group/$gridname/[string trim $line]/$casename] |
1255 | } |
6d368502 |
1256 | close $fd |
1257 | } |
40093367 |
1258 | } |
1259 | if { [file exists $casefile] } { |
1260 | # normal return |
1261 | return |
1262 | } |
1263 | } |
1264 | |
1265 | # coming here means specified test is not found; report error |
1266 | error [join [list "Error: test case $group / $grid / $casename is not found in paths listed in variable" \ |
6d368502 |
1267 | "CSF_TestScriptsPath (current value is \"$env(CSF_TestScriptsPath)\")"] "\n"] |
40093367 |
1268 | } |
1269 | |
1270 | # Internal procedure to run test case indicated by base directory, |
1271 | # grid and grid names, and test case file path. |
1272 | # The log can be obtained by command "dlog get". |
5df3a117 |
1273 | proc _run_test {scriptsdir group gridname casefile echo} { |
40093367 |
1274 | global env |
1275 | |
1276 | # start timer |
1277 | uplevel dchrono _timer reset |
1278 | uplevel dchrono _timer start |
433673e0 |
1279 | catch {uplevel meminfo h} membase |
40093367 |
1280 | |
1281 | # enable commands logging; switch to old-style mode if dlog command is not present |
1282 | set dlog_exists 1 |
1283 | if { [catch {dlog reset}] } { |
6d368502 |
1284 | set dlog_exists 0 |
5df3a117 |
1285 | } elseif { $echo } { |
1286 | decho on |
40093367 |
1287 | } else { |
6d368502 |
1288 | dlog reset |
1289 | dlog on |
1290 | rename puts puts-saved |
1291 | proc puts args { |
1292 | global _tests_verbose |
1293 | |
1294 | # log only output to stdout and stderr, not to file! |
1295 | if {[llength $args] > 1} { |
1296 | set optarg [lindex $args end-1] |
1297 | if { $optarg == "stdout" || $optarg == "stderr" || $optarg == "-newline" } { |
1298 | dlog add [lindex $args end] |
1299 | } else { |
1300 | eval puts-saved $args |
1301 | } |
1302 | } else { |
1303 | dlog add [lindex $args end] |
1304 | } |
1305 | } |
40093367 |
1306 | } |
1307 | |
40093367 |
1308 | # evaluate test case |
936f43da |
1309 | set tmp_imagedir 0 |
40093367 |
1310 | if [catch { |
60874ff8 |
1311 | # set variables identifying test case |
6d368502 |
1312 | uplevel set casename [file tail $casefile] |
1313 | uplevel set groupname $group |
1314 | uplevel set gridname $gridname |
1315 | uplevel set dirname $scriptsdir |
40093367 |
1316 | |
6d368502 |
1317 | # set path for saving of log and images (if not yet set) to temp dir |
1318 | if { ! [uplevel info exists imagedir] } { |
1319 | uplevel set test_image \$casename |
a3ef6605 |
1320 | |
1321 | # create subdirectory in temp named after group and grid with timestamp |
1322 | set rootlogdir [_get_temp_dir] |
1323 | |
1324 | set imagedir "${group}-${gridname}-${::casename}-[clock format [clock seconds] -format {%Y-%m-%dT%Hh%Mm%Ss}]" |
1325 | set imagedir [file normalize ${rootlogdir}/$imagedir] |
1326 | |
1327 | if { [catch {file mkdir $imagedir}] || ! [file writable $imagedir] || |
1328 | ! [catch {glob -directory $imagedir *}] } { |
6d368502 |
1329 | # puts "Warning: Cannot create directory \"$imagedir\", or it is not empty; \"${rootlogdir}\" is used" |
a3ef6605 |
1330 | set imagedir $rootlogdir |
1331 | } |
1332 | |
d16b64f1 |
1333 | uplevel set imagedir \"$imagedir\" |
936f43da |
1334 | set tmp_imagedir 1 |
6d368502 |
1335 | } |
60874ff8 |
1336 | |
6d368502 |
1337 | # execute test scripts |
40093367 |
1338 | if { [file exists $scriptsdir/$group/begin] } { |
6d368502 |
1339 | puts "Executing $scriptsdir/$group/begin..."; flush stdout |
912761ea |
1340 | uplevel source -encoding utf-8 $scriptsdir/$group/begin |
6d368502 |
1341 | } |
1342 | if { [file exists $scriptsdir/$group/$gridname/begin] } { |
1343 | puts "Executing $scriptsdir/$group/$gridname/begin..."; flush stdout |
912761ea |
1344 | uplevel source -encoding utf-8 $scriptsdir/$group/$gridname/begin |
6d368502 |
1345 | } |
1346 | |
1347 | puts "Executing $casefile..."; flush stdout |
912761ea |
1348 | uplevel source -encoding utf-8 $casefile |
6d368502 |
1349 | |
1350 | if { [file exists $scriptsdir/$group/$gridname/end] } { |
1351 | puts "Executing $scriptsdir/$group/$gridname/end..."; flush stdout |
912761ea |
1352 | uplevel source -encoding utf-8 $scriptsdir/$group/$gridname/end |
6d368502 |
1353 | } |
1354 | if { [file exists $scriptsdir/$group/end] } { |
1355 | puts "Executing $scriptsdir/$group/end..."; flush stdout |
912761ea |
1356 | uplevel source -encoding utf-8 $scriptsdir/$group/end |
6d368502 |
1357 | } |
40093367 |
1358 | } res] { |
6d368502 |
1359 | puts "Tcl Exception: $res" |
40093367 |
1360 | } |
1361 | |
40093367 |
1362 | # stop logging |
1363 | if { $dlog_exists } { |
5df3a117 |
1364 | if { $echo } { |
6d368502 |
1365 | decho off |
5df3a117 |
1366 | } else { |
1367 | rename puts {} |
6d368502 |
1368 | rename puts-saved puts |
1369 | dlog off |
1370 | } |
40093367 |
1371 | } |
1372 | |
8418c617 |
1373 | # stop cpulimit killer if armed by the test |
1374 | cpulimit |
1375 | |
22db40eb |
1376 | # add memory and timing info |
1377 | set stats "" |
433673e0 |
1378 | if { ! [catch {uplevel meminfo h} memuse] } { |
936f43da |
1379 | append stats "MEMORY DELTA: [expr ($memuse - $membase) / 1024] KiB\n" |
22db40eb |
1380 | } |
40093367 |
1381 | uplevel dchrono _timer stop |
1382 | set time [uplevel dchrono _timer show] |
936f43da |
1383 | if { [regexp -nocase {CPU user time:[ \t]*([0-9.e-]+)} $time res cpu_usr] } { |
6d368502 |
1384 | append stats "TOTAL CPU TIME: $cpu_usr sec\n" |
22db40eb |
1385 | } |
1386 | if { $dlog_exists && ! $echo } { |
6d368502 |
1387 | dlog add $stats |
22db40eb |
1388 | } else { |
6d368502 |
1389 | puts $stats |
40093367 |
1390 | } |
936f43da |
1391 | |
1392 | # unset global vars |
1393 | uplevel unset casename groupname gridname dirname |
1394 | if { $tmp_imagedir } { uplevel unset imagedir test_image } |
40093367 |
1395 | } |
1396 | |
1397 | # Internal procedure to check log of test execution and decide if it passed or failed |
5fd3308a |
1398 | proc _check_log {dir group gridname casename errors log {_summary {}} {_html_log {}}} { |
40093367 |
1399 | global env |
1400 | if { $_summary != "" } { upvar $_summary summary } |
1401 | if { $_html_log != "" } { upvar $_html_log html_log } |
9753e6de |
1402 | set summary {} |
1403 | set html_log {} |
5fd3308a |
1404 | set errors_log {} |
40093367 |
1405 | |
6d368502 |
1406 | if [catch { |
1407 | |
1408 | # load definition of 'bad words' indicating test failure |
1409 | # note that rules are loaded in the order of decreasing priority (grid - group - common), |
1410 | # thus grid rules will override group ones |
1411 | set badwords {} |
1412 | foreach rulesfile [list $dir/$group/$gridname/parse.rules $dir/$group/parse.rules $dir/parse.rules] { |
1413 | if [catch {set fd [open $rulesfile r]}] { continue } |
1414 | while { [gets $fd line] >= 0 } { |
1415 | # skip comments and empty lines |
1416 | if { [regexp "\[ \t\]*\#.*" $line] } { continue } |
1417 | if { [string trim $line] == "" } { continue } |
1418 | # extract regexp |
1419 | if { ! [regexp {^([^/]*)/([^/]*)/(.*)$} $line res status rexp comment] } { |
1420 | puts "Warning: cannot recognize parsing rule \"$line\" in file $rulesfile" |
1421 | continue |
1422 | } |
1423 | set status [string trim $status] |
1424 | if { $comment != "" } { append status " ([string trim $comment])" } |
1425 | set rexp [regsub -all {\\b} $rexp {\\y}] ;# convert regexp from Perl to Tcl style |
1426 | lappend badwords [list $status $rexp] |
1427 | } |
1428 | close $fd |
1429 | } |
1430 | if { [llength $badwords] <= 0 } { |
1431 | puts "Warning: no definition of error indicators found (check files parse.rules)" |
1432 | } |
1433 | |
1434 | # analyse log line-by-line |
1435 | set todos {} ;# TODO statements |
1436 | set requs {} ;# REQUIRED statements |
1437 | set todo_incomplete -1 |
1438 | set status "" |
1439 | foreach line [split $log "\n"] { |
1440 | # check if line defines specific treatment of some messages |
1441 | if [regexp -nocase {^[ \s]*TODO ([^:]*):(.*)$} $line res platforms pattern] { |
1442 | if { ! [regexp -nocase {\mAll\M} $platforms] && |
863f782a |
1443 | ! [regexp -nocase "\\m[checkplatform]\\M" $platforms] } { |
6d368502 |
1444 | lappend html_log [_html_highlight IGNORE $line] |
1445 | continue ;# TODO statement is for another platform |
1446 | } |
1447 | |
1448 | # record TODOs that mark unstable cases |
1449 | if { [regexp {[\?]} $platforms] } { |
1450 | set todos_unstable([llength $todos]) 1 |
1451 | } |
1452 | |
1453 | # convert legacy regexps from Perl to Tcl style |
1454 | set pattern [regsub -all {\\b} [string trim $pattern] {\\y}] |
1455 | |
1456 | # special case: TODO TEST INCOMPLETE |
1457 | if { [string trim $pattern] == "TEST INCOMPLETE" } { |
1458 | set todo_incomplete [llength $todos] |
1459 | } |
1460 | |
1461 | lappend todos [list $pattern [llength $html_log] $line] |
1462 | lappend html_log [_html_highlight BAD $line] |
1463 | continue |
1464 | } |
1465 | if [regexp -nocase {^[ \s]*REQUIRED ([^:]*):[ \s]*(.*)$} $line res platforms pattern] { |
1466 | if { ! [regexp -nocase {\mAll\M} $platforms] && |
863f782a |
1467 | ! [regexp -nocase "\\m[checkplatform]\\M" $platforms] } { |
6d368502 |
1468 | lappend html_log [_html_highlight IGNORE $line] |
1469 | continue ;# REQUIRED statement is for another platform |
1470 | } |
1471 | lappend requs [list $pattern [llength $html_log] $line] |
1472 | lappend html_log [_html_highlight OK $line] |
1473 | continue |
1474 | } |
1475 | |
1476 | # check for presence of required messages |
1477 | set ismarked 0 |
1478 | for {set i 0} {$i < [llength $requs]} {incr i} { |
1479 | set pattern [lindex $requs $i 0] |
1480 | if { [regexp $pattern $line] } { |
1481 | incr required_count($i) |
1482 | lappend html_log [_html_highlight OK $line] |
1483 | set ismarked 1 |
1484 | continue |
1485 | } |
1486 | } |
1487 | if { $ismarked } { |
1488 | continue |
1489 | } |
1490 | |
1491 | # check for presence of messages indicating test result |
1492 | foreach bw $badwords { |
1493 | if { [regexp [lindex $bw 1] $line] } { |
1494 | # check if this is known bad case |
1495 | set is_known 0 |
1496 | for {set i 0} {$i < [llength $todos]} {incr i} { |
1497 | set pattern [lindex $todos $i 0] |
1498 | if { [regexp $pattern $line] } { |
1499 | set is_known 1 |
1500 | incr todo_count($i) |
1501 | lappend html_log [_html_highlight BAD $line] |
1502 | break |
1503 | } |
1504 | } |
1505 | |
1506 | # if it is not in todo, define status |
1507 | if { ! $is_known } { |
1508 | set stat [lindex $bw 0 0] |
1509 | if {$errors} { |
1510 | lappend errors_log $line |
1511 | } |
1512 | lappend html_log [_html_highlight $stat $line] |
1513 | if { $status == "" && $stat != "OK" && ! [regexp -nocase {^IGNOR} $stat] } { |
1514 | set status [lindex $bw 0] |
1515 | } |
1516 | } |
1517 | set ismarked 1 |
1518 | break |
1519 | } |
1520 | } |
1521 | if { ! $ismarked } { |
1522 | lappend html_log $line |
1523 | } |
1524 | } |
1525 | |
1526 | # check for presence of TEST COMPLETED statement |
1527 | if { $status == "" && ! [regexp {TEST COMPLETED} $log] } { |
1528 | # check whether absence of TEST COMPLETED is known problem |
1529 | if { $todo_incomplete >= 0 } { |
1530 | incr todo_count($todo_incomplete) |
1531 | } else { |
1532 | set status "FAILED (no final message is found)" |
1533 | } |
1534 | } |
1535 | |
1536 | # report test as failed if it doesn't contain required pattern |
1537 | if { $status == "" } { |
1538 | for {set i 0} {$i < [llength $requs]} {incr i} { |
1539 | if { ! [info exists required_count($i)] } { |
1540 | set linenum [lindex $requs $i 1] |
1541 | set html_log [lreplace $html_log $linenum $linenum [_html_highlight FAILED [lindex $requs $i 2]]] |
1542 | set status "FAILED (REQUIRED statement no. [expr $i + 1] is not found)" |
1543 | } |
1544 | } |
1545 | } |
1546 | |
1547 | # check declared bad cases and diagnose possible improvement |
1548 | # (bad case declared but not detected). |
1549 | # Note that absence of the problem marked by TODO with question mark |
1550 | # (unstable) is not reported as improvement. |
1551 | if { $status == "" } { |
1552 | for {set i 0} {$i < [llength $todos]} {incr i} { |
1553 | if { ! [info exists todos_unstable($i)] && |
1554 | (! [info exists todo_count($i)] || $todo_count($i) <= 0) } { |
1555 | set linenum [lindex $todos $i 1] |
1556 | set html_log [lreplace $html_log $linenum $linenum [_html_highlight IMPROVEMENT [lindex $todos $i 2]]] |
1557 | set status "IMPROVEMENT (expected problem TODO no. [expr $i + 1] is not detected)" |
1558 | break; |
1559 | } |
1560 | } |
1561 | } |
1562 | |
1563 | # report test as known bad if at least one of expected problems is found |
1564 | if { $status == "" && [llength [array names todo_count]] > 0 } { |
1565 | set status "BAD (known problem)" |
1566 | } |
1567 | |
1568 | # report normal OK |
1569 | if { $status == "" } {set status "OK" } |
1570 | |
1571 | } res] { |
1572 | set status "FAILED ($res)" |
1573 | } |
40093367 |
1574 | |
1575 | # put final message |
1576 | _log_and_puts summary "CASE $group $gridname $casename: $status" |
9753e6de |
1577 | set summary [join $summary "\n"] |
5fd3308a |
1578 | if {$errors} { |
6d368502 |
1579 | foreach error $errors_log { |
1580 | _log_and_puts summary " $error" |
1581 | } |
5fd3308a |
1582 | } |
9753e6de |
1583 | set html_log "[_html_highlight [lindex $status 0] $summary]\n[join $html_log \n]" |
40093367 |
1584 | } |
1585 | |
1586 | # Auxiliary procedure putting message to both cout and log variable (list) |
1587 | proc _log_and_puts {logvar message} { |
1588 | if { $logvar != "" } { |
6d368502 |
1589 | upvar $logvar log |
1590 | lappend log $message |
40093367 |
1591 | } |
1592 | puts $message |
1593 | } |
1594 | |
1595 | # Auxiliary procedure to log result on single test case |
1596 | proc _log_test_case {output logdir dir group grid casename logvar} { |
1597 | upvar $logvar log |
5fd3308a |
1598 | set show_errors 0 |
f9797095 |
1599 | |
40093367 |
1600 | # check result and make HTML log |
5fd3308a |
1601 | _check_log $dir $group $grid $casename $show_errors $output summary html_log |
9753e6de |
1602 | lappend log $summary |
40093367 |
1603 | |
1604 | # save log to file |
1605 | if { $logdir != "" } { |
6d368502 |
1606 | _log_html $logdir/$group/$grid/$casename.html $html_log "Test $group $grid $casename" |
1607 | _log_save $logdir/$group/$grid/$casename.log "$output\n$summary" "Test $group $grid $casename" |
40093367 |
1608 | } |
f9797095 |
1609 | |
1610 | # remove intermediate command file used to run test |
1611 | if { [file exists $logdir/$group/$grid/${casename}.tcl] } { |
1612 | file delete $logdir/$group/$grid/${casename}.tcl |
1613 | } |
40093367 |
1614 | } |
1615 | |
1616 | # Auxiliary procedure to save log to file |
1617 | proc _log_save {file log {title {}}} { |
1618 | # create missing directories as needed |
1619 | catch {file mkdir [file dirname $file]} |
1620 | |
1621 | # try to open a file |
1622 | if [catch {set fd [open $file w]} res] { |
6d368502 |
1623 | error "Error saving log file $file: $res" |
40093367 |
1624 | } |
1625 | |
1626 | # dump log and close |
1627 | puts $fd "$title\n" |
1628 | puts $fd $log |
1629 | close $fd |
1630 | return |
1631 | } |
1632 | |
22db40eb |
1633 | # Auxiliary procedure to make a (relative if possible) URL to a file for |
1634 | # inclusion a reference in HTML log |
1635 | proc _make_url {htmldir file} { |
1636 | set htmlpath [file split [file normalize $htmldir]] |
1637 | set filepath [file split [file normalize $file]] |
1638 | for {set i 0} {$i < [llength $htmlpath]} {incr i} { |
1639 | if { "[lindex $htmlpath $i]" != "[lindex $filepath $i]" } { |
1640 | if { $i == 0 } { break } |
1641 | return "[string repeat "../" [expr [llength $htmlpath] - $i - 1]][eval file join [lrange $filepath $i end]]" |
1642 | } |
1643 | } |
1644 | |
1645 | # if relative path could not be made, return full file URL |
1646 | return "file://[file normalize $file]" |
1647 | } |
1648 | |
40093367 |
1649 | # Auxiliary procedure to save log to file |
1650 | proc _log_html {file log {title {}}} { |
1651 | # create missing directories as needed |
1652 | catch {file mkdir [file dirname $file]} |
1653 | |
1654 | # try to open a file |
1655 | if [catch {set fd [open $file w]} res] { |
6d368502 |
1656 | error "Error saving log file $file: $res" |
40093367 |
1657 | } |
1658 | |
1659 | # print header |
43070f2f |
1660 | puts $fd "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" |
1661 | puts $fd "<title>$title</title></head><body><h1>$title</h1>" |
40093367 |
1662 | |
ffc26091 |
1663 | # add images if present; these should have either PNG, GIF, or JPG extension, |
1664 | # and start with name of the test script, with optional suffix separated |
1665 | # by underscore or dash |
40093367 |
1666 | set imgbasename [file rootname [file tail $file]] |
ffc26091 |
1667 | foreach img [lsort [glob -nocomplain -directory [file dirname $file] -tails \ |
1668 | ${imgbasename}.gif ${imgbasename}.png ${imgbasename}.jpg \ |
1669 | ${imgbasename}_*.gif ${imgbasename}_*.png ${imgbasename}_*.jpg \ |
1670 | ${imgbasename}-*.gif ${imgbasename}-*.png ${imgbasename}-*.jpg]] { |
6d368502 |
1671 | puts $fd "<p>[file tail $img]<br><img src=\"$img\"/><p>" |
40093367 |
1672 | } |
1673 | |
b725d7c5 |
1674 | # print log body, trying to add HTML links to script files on lines like |
1675 | # "Executing <filename>..." |
40093367 |
1676 | puts $fd "<pre>" |
b725d7c5 |
1677 | foreach line [split $log "\n"] { |
1678 | if { [regexp {Executing[ \t]+([a-zA-Z0-9._/:-]+[^.])} $line res script] && |
1679 | [file exists $script] } { |
22db40eb |
1680 | set line [regsub $script $line "<a href=\"[_make_url $file $script]\">$script</a>"] |
b725d7c5 |
1681 | } |
1682 | puts $fd $line |
1683 | } |
40093367 |
1684 | puts $fd "</pre></body></html>" |
1685 | |
1686 | close $fd |
1687 | return |
1688 | } |
1689 | |
1690 | # Auxiliary method to make text with HTML highlighting according to status |
1691 | proc _html_color {status} { |
1692 | # choose a color for the cell according to result |
1693 | if { $status == "OK" } { |
6d368502 |
1694 | return lightgreen |
40093367 |
1695 | } elseif { [regexp -nocase {^FAIL} $status] } { |
77887d30 |
1696 | return ff8080 |
40093367 |
1697 | } elseif { [regexp -nocase {^BAD} $status] } { |
6d368502 |
1698 | return yellow |
40093367 |
1699 | } elseif { [regexp -nocase {^IMP} $status] } { |
6d368502 |
1700 | return orange |
40093367 |
1701 | } elseif { [regexp -nocase {^SKIP} $status] } { |
6d368502 |
1702 | return gray |
40093367 |
1703 | } elseif { [regexp -nocase {^IGNOR} $status] } { |
6d368502 |
1704 | return gray |
40093367 |
1705 | } else { |
6d368502 |
1706 | puts "Warning: no color defined for status $status, using red as if FAILED" |
1707 | return red |
40093367 |
1708 | } |
1709 | } |
1710 | |
1711 | # Format text line in HTML to be colored according to the status |
1712 | proc _html_highlight {status line} { |
1713 | return "<table><tr><td bgcolor=\"[_html_color $status]\">$line</td></tr></table>" |
1714 | } |
1715 | |
1716 | # Internal procedure to generate HTML page presenting log of the tests |
1717 | # execution in tabular form, with links to reports on individual cases |
4514dc74 |
1718 | proc _log_html_summary {logdir log totals regressions improvements skipped total_time} { |
40093367 |
1719 | global _test_case_regexp |
1720 | |
9753e6de |
1721 | # create missing directories as needed |
1722 | file mkdir $logdir |
40093367 |
1723 | |
1724 | # try to open a file and start HTML |
1725 | if [catch {set fd [open $logdir/summary.html w]} res] { |
6d368502 |
1726 | error "Error creating log file: $res" |
40093367 |
1727 | } |
1728 | |
1729 | # write HRML header, including command to refresh log if still in progress |
43070f2f |
1730 | puts $fd "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" |
40093367 |
1731 | puts $fd "<title>Tests summary</title>" |
1732 | if { $total_time == "" } { |
6d368502 |
1733 | puts $fd "<meta http-equiv=\"refresh\" content=\"10\">" |
40093367 |
1734 | } |
1735 | puts $fd "<meta http-equiv=\"pragma\" content=\"NO-CACHE\">" |
1736 | puts $fd "</head><body>" |
1737 | |
1738 | # put summary |
1739 | set legend(OK) "Test passed OK" |
1740 | set legend(FAILED) "Test failed (regression)" |
1741 | set legend(BAD) "Known problem" |
1742 | set legend(IMPROVEMENT) "Possible improvement (expected problem not detected)" |
1743 | set legend(SKIPPED) "Test skipped due to lack of data file" |
1744 | puts $fd "<h1>Summary</h1><table>" |
1745 | foreach nbstat $totals { |
6d368502 |
1746 | set status [lindex $nbstat 1] |
1747 | if { [info exists legend($status)] } { |
1748 | set comment $legend($status) |
1749 | } else { |
1750 | set comment "User-defined status" |
1751 | } |
1752 | puts $fd "<tr><td align=\"right\">[lindex $nbstat 0]</td><td bgcolor=\"[_html_color $status]\">$status</td><td>$comment</td></tr>" |
40093367 |
1753 | } |
1754 | puts $fd "</table>" |
1755 | |
1756 | # time stamp and elapsed time info |
f9797095 |
1757 | puts $fd "<p>Generated on [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}] on [info hostname]\n<p>" |
40093367 |
1758 | if { $total_time != "" } { |
8a262fa1 |
1759 | puts $fd [join [split $total_time "\n"] "<p>"] |
40093367 |
1760 | } else { |
6d368502 |
1761 | puts $fd "<p>NOTE: This is intermediate summary; the tests are still running! This page will refresh automatically until tests are finished." |
40093367 |
1762 | } |
1763 | |
1764 | # print regressions and improvements |
4514dc74 |
1765 | foreach featured [list $regressions $improvements $skipped] { |
6d368502 |
1766 | if { [llength $featured] <= 1 } { continue } |
1767 | set status [string trim [lindex $featured 0] { :}] |
1768 | puts $fd "<h2>$status</h2>" |
1769 | puts $fd "<table>" |
1770 | set groupgrid "" |
1771 | foreach test [lrange $featured 1 end] { |
93808a4a |
1772 | if { ! [regexp {^(.*)\s+([\w\-.]+)$} $test res gg name] } { |
6d368502 |
1773 | set gg UNKNOWN |
1774 | set name "Error building short list; check details" |
1775 | } |
1776 | if { $gg != $groupgrid } { |
1777 | if { $groupgrid != "" } { puts $fd "</tr>" } |
1778 | set groupgrid $gg |
1779 | puts $fd "<tr><td>$gg</td>" |
1780 | } |
1781 | puts $fd "<td bgcolor=\"[_html_color $status]\"><a href=\"[regsub -all { } $gg /]/${name}.html\">$name</a></td>" |
1782 | } |
1783 | if { $groupgrid != "" } { puts $fd "</tr>" } |
1784 | puts $fd "</table>" |
40093367 |
1785 | } |
1786 | |
9753e6de |
1787 | # put detailed log with TOC |
1788 | puts $fd "<hr><h1>Details</h1>" |
1789 | puts $fd "<div style=\"float:right; padding: 10px; border-style: solid; border-color: blue; border-width: 2px;\">" |
40093367 |
1790 | |
1791 | # process log line-by-line |
1792 | set group {} |
1793 | set letter {} |
9753e6de |
1794 | set body {} |
1795 | foreach line [lsort -dictionary $log] { |
6d368502 |
1796 | # check that the line is case report in the form "CASE group grid name: result (explanation)" |
1797 | if { ! [regexp $_test_case_regexp $line res grp grd casename result message] } { |
1798 | continue |
1799 | } |
1800 | |
1801 | # start new group |
1802 | if { $grp != $group } { |
1803 | if { $letter != "" } { lappend body "</tr></table>" } |
1804 | set letter {} |
1805 | set group $grp |
1806 | set grid {} |
1807 | puts $fd "<a href=\"#$group\">$group</a><br>" |
1808 | lappend body "<h2><a name=\"$group\">Group $group</a></h2>" |
1809 | } |
1810 | |
1811 | # start new grid |
1812 | if { $grd != $grid } { |
1813 | if { $letter != "" } { lappend body "</tr></table>" } |
1814 | set letter {} |
1815 | set grid $grd |
1816 | puts $fd " <a href=\"#$group-$grid\">$grid</a><br>" |
1817 | lappend body "<h2><a name=\"$group-$grid\">Grid $group $grid</a></h2>" |
1818 | } |
1819 | |
1820 | # check if test case name is <letter><digit>; |
1821 | # if not, set alnum to period "." to recognize non-standard test name |
1822 | if { ! [regexp {\A([A-Za-z]{1,2})([0-9]{1,2})\Z} $casename res alnum number] && |
9753e6de |
1823 | ! [regexp {\A([A-Za-z0-9]+)_([0-9]+)\Z} $casename res alnum number] } { |
6d368502 |
1824 | set alnum $casename |
1825 | } |
40093367 |
1826 | |
6d368502 |
1827 | # start new row when letter changes or for non-standard names |
1828 | if { $alnum != $letter || $alnum == "." } { |
1829 | if { $letter != "" } { |
1830 | lappend body "</tr><tr>" |
1831 | } else { |
1832 | lappend body "<table><tr>" |
1833 | } |
1834 | set letter $alnum |
1835 | } |
40093367 |
1836 | |
6d368502 |
1837 | lappend body "<td bgcolor=\"[_html_color $result]\"><a href=\"$group/$grid/${casename}.html\">$casename</a></td>" |
40093367 |
1838 | } |
9753e6de |
1839 | puts $fd "</div>\n[join $body "\n"]</tr></table>" |
40093367 |
1840 | |
1841 | # add remaining lines of log as plain text |
1842 | puts $fd "<h2>Plain text messages</h2>\n<pre>" |
9753e6de |
1843 | foreach line $log { |
6d368502 |
1844 | if { ! [regexp $_test_case_regexp $line] } { |
1845 | puts $fd "$line" |
1846 | } |
40093367 |
1847 | } |
1848 | puts $fd "</pre>" |
1849 | |
1850 | # close file and exit |
1851 | puts $fd "</body>" |
1852 | close $fd |
1853 | return |
1854 | } |
1855 | |
1856 | # Procedure to dump summary logs of tests |
1857 | proc _log_summarize {logdir log {total_time {}}} { |
1858 | |
1859 | # sort log records alphabetically to have the same behavior on Linux and Windows |
1860 | # (also needed if tests are run in parallel) |
9753e6de |
1861 | set loglist [lsort -dictionary $log] |
40093367 |
1862 | |
1863 | # classify test cases by status |
1864 | foreach line $loglist { |
6d368502 |
1865 | if { [regexp {^CASE ([^:]*): ([[:alnum:]]+).*$} $line res caseid status] } { |
1866 | lappend stat($status) $caseid |
1867 | } |
40093367 |
1868 | } |
1869 | set totals {} |
1870 | set improvements {Improvements:} |
1871 | set regressions {Failed:} |
4514dc74 |
1872 | set skipped {Skipped:} |
40093367 |
1873 | if { [info exists stat] } { |
6d368502 |
1874 | foreach status [lsort [array names stat]] { |
1875 | lappend totals [list [llength $stat($status)] $status] |
1876 | |
4514dc74 |
1877 | # separately count improvements (status starting with IMP), skipped (status starting with SKIP) and regressions (all except IMP, OK, BAD, and SKIP) |
6d368502 |
1878 | if { [regexp -nocase {^IMP} $status] } { |
1879 | eval lappend improvements $stat($status) |
4514dc74 |
1880 | } elseif { [regexp -nocase {^SKIP} $status] } { |
1881 | eval lappend skipped $stat($status) |
6d368502 |
1882 | } elseif { $status != "OK" && ! [regexp -nocase {^BAD} $status] && ! [regexp -nocase {^SKIP} $status] } { |
1883 | eval lappend regressions $stat($status) |
1884 | } |
1885 | } |
40093367 |
1886 | } |
1887 | |
1888 | # if time is specified, add totals |
1889 | if { $total_time != "" } { |
6d368502 |
1890 | if { [llength $improvements] > 1 } { |
1891 | _log_and_puts log [join $improvements "\n "] |
1892 | } |
1893 | if { [llength $regressions] > 1 } { |
1894 | _log_and_puts log [join $regressions "\n "] |
1895 | } |
4514dc74 |
1896 | if { [llength $skipped] > 1 } { |
1897 | _log_and_puts log [join $skipped "\n "] |
1898 | } |
6d368502 |
1899 | if { [llength $improvements] == 1 && [llength $regressions] == 1 } { |
1900 | _log_and_puts log "No regressions" |
1901 | } |
1902 | _log_and_puts log "Total cases: [join $totals {, }]" |
1903 | _log_and_puts log $total_time |
40093367 |
1904 | } |
1905 | |
1906 | # save log to files |
1907 | if { $logdir != "" } { |
4514dc74 |
1908 | _log_html_summary $logdir $log $totals $regressions $improvements $skipped $total_time |
6d368502 |
1909 | _log_save $logdir/tests.log [join $log "\n"] "Tests summary" |
40093367 |
1910 | } |
1911 | |
1912 | return |
1913 | } |
1914 | |
1915 | # Internal procedure to generate XML log in JUnit style, for further |
1916 | # consumption by Jenkins or similar systems. |
1917 | # |
1918 | # The output is intended to conform to XML schema supported by Jenkins found at |
1919 | # https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd |
1920 | # |
1921 | # The mapping of the fields is inspired by annotated schema of Apache Ant JUnit XML format found at |
1922 | # http://windyroad.org/dl/Open%20Source/JUnit.xsd |
1923 | proc _log_xml_summary {logdir filename log include_cout} { |
1924 | global _test_case_regexp |
1925 | |
1926 | catch {file mkdir [file dirname $filename]} |
1927 | |
1928 | # try to open a file and start XML |
1929 | if [catch {set fd [open $filename w]} res] { |
6d368502 |
1930 | error "Error creating XML summary file $filename: $res" |
40093367 |
1931 | } |
1932 | puts $fd "<?xml version='1.0' encoding='utf-8'?>" |
1933 | puts $fd "<testsuites>" |
1934 | |
1935 | # prototype for command to generate test suite tag |
1936 | set time_and_host "timestamp=\"[clock format [clock seconds] -format {%Y-%m-%dT%H:%M:%S}]\" hostname=\"[info hostname]\"" |
1937 | set cmd_testsuite {puts $fd "<testsuite name=\"$group $grid\" tests=\"$nbtests\" failures=\"$nbfail\" errors=\"$nberr\" time=\"$time\" skipped=\"$nbskip\" $time_and_host>\n$testcases\n</testsuite>\n"} |
1938 | |
1939 | # sort log and process it line-by-line |
1940 | set group {} |
9753e6de |
1941 | foreach line [lsort -dictionary $log] { |
6d368502 |
1942 | # check that the line is case report in the form "CASE group grid name: result (explanation)" |
1943 | if { ! [regexp $_test_case_regexp $line res grp grd casename result message] } { |
1944 | continue |
1945 | } |
1946 | set message [string trim $message " \t\r\n()"] |
1947 | |
1948 | # start new testsuite for each grid |
1949 | if { $grp != $group || $grd != $grid } { |
1950 | |
1951 | # write previous test suite |
1952 | if [info exists testcases] { eval $cmd_testsuite } |
1953 | |
1954 | set testcases {} |
1955 | set nbtests 0 |
1956 | set nberr 0 |
1957 | set nbfail 0 |
1958 | set nbskip 0 |
1959 | set time 0. |
1960 | |
1961 | set group $grp |
1962 | set grid $grd |
1963 | } |
1964 | |
1965 | incr nbtests |
1966 | |
1967 | # parse test log and get its CPU time |
1968 | set testout {} |
1969 | set add_cpu {} |
1970 | if { [catch {set fdlog [open $logdir/$group/$grid/${casename}.log r]} ret] } { |
1971 | puts "Error: cannot open $logdir/$group/$grid/${casename}.log: $ret" |
1972 | } else { |
1973 | while { [gets $fdlog logline] >= 0 } { |
1974 | if { $include_cout } { |
1975 | append testout "$logline\n" |
1976 | } |
1977 | if [regexp -nocase {TOTAL CPU TIME:\s*([\d.]+)\s*sec} $logline res cpu] { |
1978 | set add_cpu " time=\"$cpu\"" |
1979 | set time [expr $time + $cpu] |
1980 | } |
1981 | } |
1982 | close $fdlog |
1983 | } |
1984 | if { ! $include_cout } { |
40093367 |
1985 | set testout "$line\n" |
6d368502 |
1986 | } |
1987 | |
1988 | # record test case with its output and status |
1989 | # Mapping is: SKIPPED, BAD, and OK to OK, all other to failure |
1990 | append testcases "\n <testcase name=\"$casename\"$add_cpu status=\"$result\">\n" |
1991 | append testcases "\n <system-out>\n$testout </system-out>" |
1992 | if { $result != "OK" } { |
1993 | if { [regexp -nocase {^SKIP} $result] } { |
1994 | incr nberr |
1995 | append testcases "\n <error name=\"$result\" message=\"$message\"/>" |
1996 | } elseif { [regexp -nocase {^BAD} $result] } { |
1997 | incr nbskip |
1998 | append testcases "\n <skipped>$message</skipped>" |
1999 | } else { |
2000 | incr nbfail |
2001 | append testcases "\n <failure name=\"$result\" message=\"$message\"/>" |
2002 | } |
2003 | } |
2004 | append testcases "\n </testcase>" |
40093367 |
2005 | } |
2006 | |
2007 | # write last test suite |
2008 | if [info exists testcases] { eval $cmd_testsuite } |
2009 | |
2010 | # the end |
2011 | puts $fd "</testsuites>" |
2012 | close $fd |
2013 | return |
2014 | } |
2015 | |
40093367 |
2016 | # Auxiliary procedure to split path specification (usually defined by |
2017 | # environment variable) into list of directories or files |
2018 | proc _split_path {pathspec} { |
2019 | global tcl_platform |
2020 | |
2021 | # first replace all \ (which might occur on Windows) by / |
2022 | regsub -all "\\\\" $pathspec "/" pathspec |
2023 | |
2024 | # split path by platform-specific separator |
2025 | return [split $pathspec [_path_separator]] |
2026 | } |
2027 | |
2028 | # Auxiliary procedure to define platform-specific separator for directories in |
2029 | # path specification |
2030 | proc _path_separator {} { |
2031 | global tcl_platform |
2032 | |
2033 | # split path by platform-specific separator |
2034 | if { $tcl_platform(platform) == "windows" } { |
6d368502 |
2035 | return ";" |
40093367 |
2036 | } else { |
6d368502 |
2037 | return ":" |
40093367 |
2038 | } |
2039 | } |
2040 | |
cc6a292d |
2041 | # Procedure to make a diff and common of two lists |
2042 | proc _list_diff {list1 list2 _in1 _in2 _common} { |
2043 | upvar $_in1 in1 |
2044 | upvar $_in2 in2 |
2045 | upvar $_common common |
2046 | |
2047 | set in1 {} |
2048 | set in2 {} |
2049 | set common {} |
2050 | foreach item $list1 { |
6d368502 |
2051 | if { [lsearch -exact $list2 $item] >= 0 } { |
2052 | lappend common $item |
cc6a292d |
2053 | } else { |
6d368502 |
2054 | lappend in1 $item |
2055 | } |
cc6a292d |
2056 | } |
2057 | foreach item $list2 { |
6d368502 |
2058 | if { [lsearch -exact $common $item] < 0 } { |
2059 | lappend in2 $item |
2060 | } |
cc6a292d |
2061 | } |
2062 | return |
2063 | } |
2064 | |
2065 | # procedure to load a file to Tcl string |
2066 | proc _read_file {filename} { |
2067 | set fd [open $filename r] |
2068 | set result [read -nonewline $fd] |
2069 | close $fd |
2070 | return $result |
2071 | } |
2072 | |
22db40eb |
2073 | # procedure to construct name for the mage diff file |
2074 | proc _diff_img_name {dir1 dir2 casepath imgfile} { |
2075 | return [file join $dir1 $casepath "diff-[file tail $dir2]-$imgfile"] |
2076 | } |
2077 | |
936f43da |
2078 | # auxiliary procedure to produce string comparing two values |
2079 | proc _diff_show_ratio {value1 value2} { |
6ae07908 |
2080 | if {[expr double ($value2)] == 0.} { |
2081 | return "$value1 / $value2" |
2082 | } else { |
2083 | return "$value1 / $value2 \[[format "%+5.2f%%" [expr 100 * ($value1 - $value2) / double($value2)]]\]" |
2084 | } |
936f43da |
2085 | } |
2086 | |
44fae8b1 |
2087 | # procedure to check cpu user time |
2088 | proc _check_time {regexp_msg} { |
2089 | upvar log log |
2090 | upvar log1 log1 |
2091 | upvar log2 log2 |
2092 | upvar log_cpu log_cpu |
2093 | upvar cpu cpu |
2094 | upvar basename basename |
2095 | upvar casename casename |
2096 | set time1_list [dict create] |
2097 | set time2_list [dict create] |
2098 | set cpu_find UNDEFINED |
2099 | |
2100 | foreach line1 [split $log1 "\n"] { |
2101 | if { [regexp "${regexp_msg}" $line1 dump chronometer_name cpu_find] } { |
2102 | dict set time1_list "${chronometer_name}" "${cpu_find}" |
2103 | } |
2104 | } |
2105 | |
2106 | foreach line2 [split $log2 "\n"] { |
2107 | if { [regexp "${regexp_msg}" $line2 dump chronometer_name cpu_find] } { |
2108 | dict set time2_list "${chronometer_name}" "${cpu_find}" |
2109 | } |
2110 | } |
2111 | |
2112 | if { [llength [dict keys $time1_list]] != [llength [dict keys $time2_list]] } { |
2113 | puts "Error: number of dchrono/chrono COUNTER are different in the same test cases" |
2114 | } else { |
2115 | foreach key [dict keys $time1_list] { |
2116 | set time1 [dict get $time1_list $key] |
2117 | set time2 [dict get $time2_list $key] |
2118 | |
2119 | # compare CPU user time with 10% precision (but not less 0.5 sec) |
2120 | if { [expr abs ($time1 - $time2) > 0.5 + 0.05 * abs ($time1 + $time2)] } { |
2121 | if {$cpu != false} { |
2122 | _log_and_puts log_cpu "COUNTER $key: [split $basename /] $casename: [_diff_show_ratio $time1 $time2]" |
2123 | } else { |
2124 | _log_and_puts log "COUNTER $key: [split $basename /] $casename: [_diff_show_ratio $time1 $time2]" |
2125 | } |
2126 | } |
2127 | } |
2128 | } |
2129 | } |
2130 | |
cc6a292d |
2131 | # Procedure to compare results of two runs of test cases |
28cab376 |
2132 | proc _test_diff {dir1 dir2 basename image cpu memory status verbose _logvar _logimage _logcpu _logmemory {_statvar ""}} { |
cc6a292d |
2133 | upvar $_logvar log |
28cab376 |
2134 | upvar $_logimage log_image |
2135 | upvar $_logcpu log_cpu |
2136 | upvar $_logmemory log_memory |
cc6a292d |
2137 | |
22db40eb |
2138 | # make sure to load diffimage command |
2139 | uplevel pload VISUALIZATION |
2140 | |
cc6a292d |
2141 | # prepare variable (array) for collecting statistics |
2142 | if { "$_statvar" != "" } { |
2143 | upvar $_statvar stat |
2144 | } else { |
2145 | set stat(cpu1) 0 |
2146 | set stat(cpu2) 0 |
22db40eb |
2147 | set stat(mem1) 0 |
2148 | set stat(mem2) 0 |
cc6a292d |
2149 | set log {} |
28cab376 |
2150 | set log_image {} |
2151 | set log_cpu {} |
2152 | set log_memory {} |
cc6a292d |
2153 | } |
2154 | |
2155 | # first check subdirectories |
2156 | set path1 [file join $dir1 $basename] |
2157 | set path2 [file join $dir2 $basename] |
2158 | set list1 [glob -directory $path1 -types d -tails -nocomplain *] |
2159 | set list2 [glob -directory $path2 -types d -tails -nocomplain *] |
2160 | if { [llength $list1] >0 || [llength $list2] > 0 } { |
2161 | _list_diff $list1 $list2 in1 in2 common |
2162 | if { "$verbose" > 1 } { |
2163 | if { [llength $in1] > 0 } { _log_and_puts log "Only in $path1: $in1" } |
2164 | if { [llength $in2] > 0 } { _log_and_puts log "Only in $path2: $in2" } |
2165 | } |
2166 | foreach subdir $common { |
2167 | if { "$verbose" > 2 } { |
6d368502 |
2168 | _log_and_puts log "Checking [file join $basename $subdir]" |
2169 | } |
28cab376 |
2170 | _test_diff $dir1 $dir2 [file join $basename $subdir] $image $cpu $memory $status $verbose log log_image log_cpu log_memory stat |
cc6a292d |
2171 | } |
2172 | } else { |
2173 | # check log files (only if directory has no subdirs) |
2174 | set list1 [glob -directory $path1 -types f -tails -nocomplain *.log] |
2175 | set list2 [glob -directory $path2 -types f -tails -nocomplain *.log] |
2176 | _list_diff $list1 $list2 in1 in2 common |
2177 | if { "$verbose" > 1 } { |
2178 | if { [llength $in1] > 0 } { _log_and_puts log "Only in $path1: $in1" } |
2179 | if { [llength $in2] > 0 } { _log_and_puts log "Only in $path2: $in2" } |
2180 | } |
936f43da |
2181 | set gcpu1 0 |
2182 | set gcpu2 0 |
2183 | set gmem1 0 |
2184 | set gmem2 0 |
cc6a292d |
2185 | foreach logfile $common { |
2186 | # load two logs |
6d368502 |
2187 | set log1 [_read_file [file join $dir1 $basename $logfile]] |
2188 | set log2 [_read_file [file join $dir2 $basename $logfile]] |
22db40eb |
2189 | set casename [file rootname $logfile] |
28cab376 |
2190 | |
cc6a292d |
2191 | # check execution statuses |
28cab376 |
2192 | if {$image == false && $cpu == false && $memory == false} { |
2193 | set status1 UNDEFINED |
2194 | set status2 UNDEFINED |
2195 | if { ! [regexp {CASE [^:]*:\s*([\w]+)} $log1 res1 status1] || |
2196 | ! [regexp {CASE [^:]*:\s*([\w]+)} $log2 res2 status2] || |
2197 | "$status1" != "$status2" } { |
2198 | _log_and_puts log "STATUS [split $basename /] $casename: $status1 / $status2" |
2199 | # if test statuses are different, further comparison makes |
2200 | # no sense unless explicitly requested |
2201 | if { "$status" != "all" } { |
2202 | continue |
2203 | } |
2204 | } |
2205 | if { "$status" == "ok" && "$status1" != "OK" } { |
cc6a292d |
2206 | continue |
6d368502 |
2207 | } |
2208 | } |
44fae8b1 |
2209 | |
2210 | if { ! $image } { |
2211 | # check CPU user time in test cases |
2212 | set checkCPURegexp "COUNTER (.+): (\[-0-9.+eE\]+)" |
2213 | if { [regexp "${checkCPURegexp}" $log1] && |
2214 | [regexp "${checkCPURegexp}" $log2] } { |
2215 | _check_time "${checkCPURegexp}" |
2216 | } |
2217 | } |
28cab376 |
2218 | |
cc6a292d |
2219 | # check CPU times |
28cab376 |
2220 | if {$cpu != false || ($image == false && $cpu == false && $memory == false)} { |
2221 | set cpu1 UNDEFINED |
2222 | set cpu2 UNDEFINED |
2223 | if { [regexp {TOTAL CPU TIME:\s*([\d.]+)} $log1 res1 cpu1] && |
2224 | [regexp {TOTAL CPU TIME:\s*([\d.]+)} $log2 res1 cpu2] } { |
2225 | set stat(cpu1) [expr $stat(cpu1) + $cpu1] |
2226 | set stat(cpu2) [expr $stat(cpu2) + $cpu2] |
2227 | set gcpu1 [expr $gcpu1 + $cpu1] |
2228 | set gcpu2 [expr $gcpu2 + $cpu2] |
2229 | |
2230 | # compare CPU times with 10% precision (but not less 0.5 sec) |
2231 | if { [expr abs ($cpu1 - $cpu2) > 0.5 + 0.05 * abs ($cpu1 + $cpu2)] } { |
2232 | if {$cpu != false} { |
2233 | _log_and_puts log_cpu "CPU [split $basename /] $casename: [_diff_show_ratio $cpu1 $cpu2]" |
2234 | } else { |
2235 | _log_and_puts log "CPU [split $basename /] $casename: [_diff_show_ratio $cpu1 $cpu2]" |
2236 | } |
2237 | } |
cc6a292d |
2238 | } |
6d368502 |
2239 | } |
22db40eb |
2240 | |
2241 | # check memory delta |
28cab376 |
2242 | if {$memory != false || ($image == false && $cpu == false && $memory == false)} { |
2243 | set mem1 UNDEFINED |
2244 | set mem2 UNDEFINED |
2245 | if { [regexp {MEMORY DELTA:\s*([\d.]+)} $log1 res1 mem1] && |
2246 | [regexp {MEMORY DELTA:\s*([\d.]+)} $log2 res1 mem2] } { |
2247 | set stat(mem1) [expr $stat(mem1) + $mem1] |
2248 | set stat(mem2) [expr $stat(mem2) + $mem2] |
2249 | set gmem1 [expr $gmem1 + $mem1] |
2250 | set gmem2 [expr $gmem2 + $mem2] |
2251 | |
2252 | # compare memory usage with 10% precision (but not less 16 KiB) |
2253 | if { [expr abs ($mem1 - $mem2) > 16 + 0.05 * abs ($mem1 + $mem2)] } { |
2254 | if {$memory != false} { |
2255 | _log_and_puts log_memory "MEMORY [split $basename /] $casename: [_diff_show_ratio $mem1 $mem2]" |
2256 | } else { |
2257 | _log_and_puts log "MEMORY [split $basename /] $casename: [_diff_show_ratio $mem1 $mem2]" |
2258 | } |
2259 | } |
22db40eb |
2260 | } |
6d368502 |
2261 | } |
22db40eb |
2262 | |
2263 | # check images |
28cab376 |
2264 | if {$image != false || ($image == false && $cpu == false && $memory == false)} { |
f2b42160 |
2265 | set aCaseDiffColorTol 0 |
2266 | if { [regexp {IMAGE_COLOR_TOLERANCE:\s*([\d.]+)} $log1 res1 imgtol1] } { set aCaseDiffColorTol $imgtol1 } |
28cab376 |
2267 | set imglist1 [glob -directory $path1 -types f -tails -nocomplain ${casename}.{png,gif} ${casename}-*.{png,gif} ${casename}_*.{png,gif}] |
2268 | set imglist2 [glob -directory $path2 -types f -tails -nocomplain ${casename}.{png,gif} ${casename}-*.{png,gif} ${casename}_*.{png,gif}] |
2269 | _list_diff $imglist1 $imglist2 imgin1 imgin2 imgcommon |
2270 | if { "$verbose" > 1 } { |
2271 | if { [llength $imgin1] > 0 } { |
2272 | if {$image != false} { |
2273 | _log_and_puts log_image "Only in $path1: $imgin1" |
2274 | } else { |
2275 | _log_and_puts log "Only in $path1: $imgin1" |
2276 | } |
2277 | } |
2278 | if { [llength $imgin2] > 0 } { |
2279 | if {$image != false} { |
2280 | _log_and_puts log_image "Only in $path2: $imgin2" |
2281 | } else { |
2282 | _log_and_puts log "Only in $path2: $imgin2" |
2283 | } |
2284 | } |
2285 | } |
2286 | foreach imgfile $imgcommon { |
2287 | # if { $verbose > 1 } { _log_and_puts log "Checking [split basename /] $casename: $imgfile" } |
2288 | set diffile [_diff_img_name $dir1 $dir2 $basename $imgfile] |
2289 | if { [catch {diffimage [file join $dir1 $basename $imgfile] \ |
2290 | [file join $dir2 $basename $imgfile] \ |
f2b42160 |
2291 | -toleranceOfColor 0.0 -blackWhite off -borderFilter off $diffile} diff] } { |
28cab376 |
2292 | if {$image != false} { |
2293 | _log_and_puts log_image "IMAGE [split $basename /] $casename: $imgfile cannot be compared" |
2294 | } else { |
2295 | _log_and_puts log "IMAGE [split $basename /] $casename: $imgfile cannot be compared" |
2296 | } |
2297 | file delete -force $diffile ;# clean possible previous result of diffimage |
2298 | } elseif { $diff != 0 } { |
f2b42160 |
2299 | set diff [string trimright $diff \n] |
2300 | if {$aCaseDiffColorTol != 0} { |
2301 | # retry with color tolerance |
2302 | if { [catch {diffimage [file join $dir1 $basename $imgfile] \ |
2303 | [file join $dir2 $basename $imgfile] \ |
2304 | -toleranceOfColor $aCaseDiffColorTol -blackWhite off -borderFilter off $diffile} diff2] } { |
2305 | if {$image != false} { |
2306 | _log_and_puts log_image "IMAGE [split $basename /] $casename: $imgfile cannot be compared" |
2307 | } else { |
2308 | _log_and_puts log "IMAGE [split $basename /] $casename: $imgfile cannot be compared" |
2309 | } |
2310 | continue |
2311 | } elseif { $diff2 == 0 } { |
2312 | # exclude image diff within tolerance but still keep info in the log |
2313 | set toLogImageCase false |
2314 | file delete -force $diffile |
2315 | if {$image != false} { |
2316 | _log_and_puts log_image "IMAGE [split $basename /] $casename: $imgfile is similar \[$diff different pixels\]" |
2317 | } else { |
2318 | _log_and_puts log "IMAGE [split $basename /] $casename: $imgfile is similar \[$diff different pixels\]" |
2319 | } |
2320 | continue |
2321 | } |
2322 | } |
2323 | |
28cab376 |
2324 | if {$image != false} { |
f2b42160 |
2325 | _log_and_puts log_image "IMAGE [split $basename /] $casename: $imgfile differs \[$diff different pixels\]" |
28cab376 |
2326 | } else { |
f2b42160 |
2327 | _log_and_puts log "IMAGE [split $basename /] $casename: $imgfile differs \[$diff different pixels\]" |
28cab376 |
2328 | } |
2329 | } else { |
2330 | file delete -force $diffile ;# clean useless artifact of diffimage |
2331 | } |
22db40eb |
2332 | } |
2333 | } |
6d368502 |
2334 | } |
936f43da |
2335 | |
2336 | # report CPU and memory difference in group if it is greater than 10% |
28cab376 |
2337 | if {$cpu != false || ($image == false && $cpu == false && $memory == false)} { |
2338 | if { [expr abs ($gcpu1 - $gcpu2) > 0.5 + 0.005 * abs ($gcpu1 + $gcpu2)] } { |
2339 | if {$cpu != false} { |
2340 | _log_and_puts log_cpu "CPU [split $basename /]: [_diff_show_ratio $gcpu1 $gcpu2]" |
2341 | } else { |
2342 | _log_and_puts log "CPU [split $basename /]: [_diff_show_ratio $gcpu1 $gcpu2]" |
2343 | } |
2344 | } |
936f43da |
2345 | } |
28cab376 |
2346 | if {$memory != false || ($image == false && $cpu == false && $memory == false)} { |
2347 | if { [expr abs ($gmem1 - $gmem2) > 16 + 0.005 * abs ($gmem1 + $gmem2)] } { |
2348 | if {$memory != false} { |
2349 | _log_and_puts log_memory "MEMORY [split $basename /]: [_diff_show_ratio $gmem1 $gmem2]" |
2350 | } else { |
2351 | _log_and_puts log "MEMORY [split $basename /]: [_diff_show_ratio $gmem1 $gmem2]" |
2352 | } |
2353 | } |
936f43da |
2354 | } |
cc6a292d |
2355 | } |
2356 | |
2357 | if { "$_statvar" == "" } { |
28cab376 |
2358 | if {$memory != false || ($image == false && $cpu == false && $memory == false)} { |
2359 | if {$memory != false} { |
2360 | _log_and_puts log_memory "Total MEMORY difference: [_diff_show_ratio $stat(mem1) $stat(mem2)]" |
2361 | } else { |
2362 | _log_and_puts log "Total MEMORY difference: [_diff_show_ratio $stat(mem1) $stat(mem2)]" |
2363 | } |
2364 | } |
2365 | if {$cpu != false || ($image == false && $cpu == false && $memory == false)} { |
2366 | if {$cpu != false} { |
2367 | _log_and_puts log_cpu "Total CPU difference: [_diff_show_ratio $stat(cpu1) $stat(cpu2)]" |
2368 | } else { |
2369 | _log_and_puts log "Total CPU difference: [_diff_show_ratio $stat(cpu1) $stat(cpu2)]" |
2370 | } |
2371 | } |
cc6a292d |
2372 | } |
2373 | } |
b725d7c5 |
2374 | |
22db40eb |
2375 | # Auxiliary procedure to save log of results comparison to file |
d5f061b6 |
2376 | proc _log_html_diff {file log dir1 dir2 highlight_percent} { |
22db40eb |
2377 | # create missing directories as needed |
2378 | catch {file mkdir [file dirname $file]} |
2379 | |
2380 | # try to open a file |
2381 | if [catch {set fd [open $file w]} res] { |
6d368502 |
2382 | error "Error saving log file $file: $res" |
22db40eb |
2383 | } |
2384 | |
2385 | # print header |
43070f2f |
2386 | puts $fd "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" |
2387 | puts $fd "<title>Diff $dir1 vs. $dir2</title></head><body>" |
433673e0 |
2388 | puts $fd "<h1>Comparison of test results:</h1>" |
f2b42160 |
2389 | puts $fd "<h2>Version A \[NEW\] - $dir1</h2>" |
2390 | puts $fd "<h2>Version B \[REF\] - $dir2</h2>" |
22db40eb |
2391 | |
c231f393 |
2392 | # add script for switching between images on click |
2393 | puts $fd "" |
2394 | puts $fd "<script type=\"text/javascript\">" |
2395 | puts $fd " function diffimage_toggle(img,url1,url2)" |
2396 | puts $fd " {" |
66d61d8a |
2397 | puts $fd " if (img.show2nd) { img.src = url1; img.show2nd = false; }" |
2398 | puts $fd " else { img.src = url2; img.show2nd = true; }" |
c231f393 |
2399 | puts $fd " }" |
66d61d8a |
2400 | puts $fd " function diffimage_reset(img,url) { img.src = url; img.show2nd = true; }" |
c231f393 |
2401 | puts $fd "</script>" |
2402 | puts $fd "" |
2403 | |
2404 | # print log body |
22db40eb |
2405 | puts $fd "<pre>" |
2406 | set logpath [file split [file normalize $file]] |
9753e6de |
2407 | foreach line $log { |
d5f061b6 |
2408 | # put a line; highlight considerable (> ${highlight_percent}%) deviations of CPU and memory |
936f43da |
2409 | if { [regexp "\[\\\[](\[0-9.e+-]+)%\[\]]" $line res value] && |
d5f061b6 |
2410 | [expr abs($value)] > ${highlight_percent} } { |
77887d30 |
2411 | puts $fd "<table><tr><td bgcolor=\"[expr $value > 0 ? \"ff8080\" : \"lightgreen\"]\">$line</td></tr></table>" |
f2b42160 |
2412 | } elseif { [regexp {IMAGE[ \t]+([^:]+):[ \t]+([A-Za-z0-9_.-]+) is similar} $line res case img] } { |
2413 | if { [catch {eval file join "" [lrange $case 0 end-1]} gridpath] } { |
2414 | # note: special handler for the case if test grid directoried are compared directly |
2415 | set gridpath "" |
2416 | } |
2417 | set aCaseName [lindex $case end] |
2418 | puts $fd "<table><tr><td bgcolor=\"orange\"><a href=\"[_make_url $file [file join $dir1 $gridpath $aCaseName.html]]\">$line</a></td></tr></table>" |
2419 | } elseif { [regexp {IMAGE[ \t]+([^:]+):[ \t]+([A-Za-z0-9_.-]+)} $line res case img] } { |
2420 | # add images |
936f43da |
2421 | puts $fd $line |
22db40eb |
2422 | if { [catch {eval file join "" [lrange $case 0 end-1]} gridpath] } { |
6d368502 |
2423 | # note: special handler for the case if test grid directoried are compared directly |
2424 | set gridpath "" |
22db40eb |
2425 | } |
17b45a29 |
2426 | set aCaseName [lindex $case end] |
c231f393 |
2427 | set img1url [_make_url $file [file join $dir1 $gridpath $img]] |
2428 | set img2url [_make_url $file [file join $dir2 $gridpath $img]] |
2429 | set img1 "<a href=\"[_make_url $file [file join $dir1 $gridpath $aCaseName.html]]\"><img src=\"$img1url\"></a>" |
2430 | set img2 "<a href=\"[_make_url $file [file join $dir2 $gridpath $aCaseName.html]]\"><img src=\"$img2url\"></a>" |
22db40eb |
2431 | |
2432 | set difffile [_diff_img_name $dir1 $dir2 $gridpath $img] |
c231f393 |
2433 | set imgdurl [_make_url $file $difffile] |
22db40eb |
2434 | if { [file exists $difffile] } { |
c231f393 |
2435 | set imgd "<img src=\"$imgdurl\" onmouseout=diffimage_reset(this,\"$imgdurl\") onclick=diffimage_toggle(this,\"$img1url\",\"$img2url\")>" |
22db40eb |
2436 | } else { |
2437 | set imgd "N/A" |
2438 | } |
2439 | |
c231f393 |
2440 | puts $fd "<table><tr><th><abbr title=\"$dir1\">Version A</abbr></th><th><abbr title=\"$dir2\">Version B</abbr></th><th>Diff (click to toggle)</th></tr>" |
22db40eb |
2441 | puts $fd "<tr><td>$img1</td><td>$img2</td><td>$imgd</td></tr></table>" |
f2b42160 |
2442 | } else { |
2443 | puts $fd $line |
22db40eb |
2444 | } |
2445 | } |
2446 | puts $fd "</pre></body></html>" |
2447 | |
2448 | close $fd |
2449 | return |
2450 | } |
2451 | |
b725d7c5 |
2452 | # get number of CPUs on the system |
2453 | proc _get_nb_cpus {} { |
2454 | global tcl_platform env |
2455 | |
2456 | if { "$tcl_platform(platform)" == "windows" } { |
2457 | # on Windows, take the value of the environment variable |
2458 | if { [info exists env(NUMBER_OF_PROCESSORS)] && |
2459 | ! [catch {expr $env(NUMBER_OF_PROCESSORS) > 0} res] && $res >= 0 } { |
2460 | return $env(NUMBER_OF_PROCESSORS) |
2461 | } |
2462 | } elseif { "$tcl_platform(os)" == "Linux" } { |
2463 | # on Linux, take number of logical processors listed in /proc/cpuinfo |
2464 | if { [catch {open "/proc/cpuinfo" r} fd] } { |
2465 | return 0 ;# should never happen, but... |
2466 | } |
2467 | set nb 0 |
6d368502 |
2468 | while { [gets $fd line] >= 0 } { |
2469 | if { [regexp {^processor[ \t]*:} $line] } { |
2470 | incr nb |
2471 | } |
2472 | } |
b725d7c5 |
2473 | close $fd |
2474 | return $nb |
2475 | } elseif { "$tcl_platform(os)" == "Darwin" } { |
2476 | # on MacOS X, call sysctl command |
2477 | if { ! [catch {exec sysctl hw.ncpu} ret] && |
2478 | [regexp {^hw[.]ncpu[ \t]*:[ \t]*([0-9]+)} $ret res nb] } { |
2479 | return $nb |
2480 | } |
2481 | } |
2482 | |
2483 | # if cannot get good value, return 0 as default |
2484 | return 0 |
2485 | } |
351bbcba |
2486 | |
2487 | # check two files for difference |
2488 | proc _diff_files {file1 file2} { |
2489 | set fd1 [open $file1 "r"] |
2490 | set fd2 [open $file2 "r"] |
2491 | |
2492 | set differ f |
2493 | while {! $differ} { |
2494 | set nb1 [gets $fd1 line1] |
2495 | set nb2 [gets $fd2 line2] |
2496 | if { $nb1 != $nb2 } { set differ t; break } |
2497 | if { $nb1 < 0 } { break } |
2498 | if { [string compare $line1 $line2] } { |
2499 | set differ t |
2500 | } |
2501 | } |
2502 | |
2503 | close $fd1 |
2504 | close $fd2 |
2505 | |
2506 | return $differ |
2507 | } |
2508 | |
2509 | # Check if file is in DOS encoding. |
2510 | # This check is done by presence of \r\n combination at the end of the first |
2511 | # line (i.e. prior to any other \n symbol). |
2512 | # Note that presence of non-ascii symbols typically used for recognition |
2513 | # of binary files is not suitable since some IGES and STEP files contain |
2514 | # non-ascii symbols. |
2515 | # Special check is added for PNG files which contain \r\n in the beginning. |
2516 | proc _check_dos_encoding {file} { |
2517 | set fd [open $file rb] |
2518 | set isdos f |
2519 | if { [gets $fd line] && [regexp {.*\r$} $line] && |
2520 | ! [regexp {^.PNG} $line] } { |
2521 | set isdos t |
2522 | } |
2523 | close $fd |
2524 | return $isdos |
2525 | } |
2526 | |
2527 | # procedure to recognize format of a data file by its first symbols (for OCCT |
2528 | # BREP and geometry DRAW formats, IGES, and STEP) and extension (all others) |
2529 | proc _check_file_format {file} { |
2530 | set fd [open $file rb] |
2531 | set line [read $fd 1024] |
2532 | close $fd |
2533 | |
2534 | set warn f |
2535 | set ext [file extension $file] |
2536 | set format unknown |
2537 | if { [regexp {^DBRep_DrawableShape} $line] } { |
2538 | set format BREP |
2539 | if { "$ext" != ".brep" && "$ext" != ".rle" && |
2540 | "$ext" != ".draw" && "$ext" != "" } { |
2541 | set warn t |
2542 | } |
2543 | } elseif { [regexp {^DrawTrSurf_} $line] } { |
2544 | set format DRAW |
2545 | if { "$ext" != ".rle" && |
2546 | "$ext" != ".draw" && "$ext" != "" } { |
2547 | set warn t |
2548 | } |
2549 | } elseif { [regexp {^[ \t]*ISO-10303-21} $line] } { |
2550 | set format STEP |
2551 | if { "$ext" != ".step" && "$ext" != ".stp" } { |
2552 | set warn t |
2553 | } |
2554 | } elseif { [regexp {^.\{72\}S[0 ]\{6\}1} $line] } { |
2555 | set format IGES |
2556 | if { "$ext" != ".iges" && "$ext" != ".igs" } { |
2557 | set warn t |
2558 | } |
2559 | } elseif { "$ext" == ".igs" } { |
2560 | set format IGES |
2561 | } elseif { "$ext" == ".stp" } { |
2562 | set format STEP |
2563 | } else { |
2564 | set format [string toupper [string range $ext 1 end]] |
2565 | } |
2566 | |
2567 | if { $warn } { |
2568 | puts "$file: Warning: extension ($ext) does not match format ($format)" |
2569 | } |
2570 | |
2571 | return $format |
2572 | } |
2573 | |
2574 | # procedure to load file knowing its format |
2575 | proc load_data_file {file format shape} { |
2576 | switch $format { |
6d368502 |
2577 | BREP { uplevel restore $file $shape } |
2578 | DRAW { uplevel restore $file $shape } |
2579 | IGES { pload XSDRAW; uplevel igesbrep $file $shape * } |
2580 | STEP { pload XSDRAW; uplevel stepread $file __a *; uplevel renamevar __a_1 $shape } |
4eb6e8f4 |
2581 | STL { pload XSDRAW; uplevel readstl $shape $file triangulation } |
6d368502 |
2582 | default { error "Cannot read $format file $file" } |
351bbcba |
2583 | } |
2584 | } |
60874ff8 |
2585 | |
2586 | # procedure to get name of temporary directory, |
2587 | # ensuring it is existing and writeable |
2588 | proc _get_temp_dir {} { |
723754e2 |
2589 | global env tcl_platform |
60874ff8 |
2590 | |
2591 | # check typical environment variables |
2592 | foreach var {TempDir Temp Tmp} { |
2593 | # check different case |
2594 | foreach name [list [string toupper $var] $var [string tolower $var]] { |
2595 | if { [info exists env($name)] && [file isdirectory $env($name)] && |
2596 | [file writable $env($name)] } { |
2597 | return [regsub -all {\\} $env($name) /] |
2598 | } |
2599 | } |
2600 | } |
2601 | |
2602 | # check platform-specific locations |
2603 | set fallback tmp |
2604 | if { "$tcl_platform(platform)" == "windows" } { |
2605 | set paths "c:/TEMP c:/TMP /TEMP /TMP" |
2606 | if { [info exists env(HOMEDRIVE)] && [info exists env(HOMEPATH)] } { |
338434c7 |
2607 | set fallback [regsub -all {\\} "$env(HOMEDRIVE)$env(HOMEPATH)/tmp" /] |
60874ff8 |
2608 | } |
2609 | } else { |
2610 | set paths "/tmp /var/tmp /usr/tmp" |
2611 | if { [info exists env(HOME)] } { |
2612 | set fallback "$env(HOME)/tmp" |
2613 | } |
2614 | } |
2615 | foreach dir $paths { |
723754e2 |
2616 | if { [file isdirectory $dir] && [file writable $dir] } { |
60874ff8 |
2617 | return $dir |
2618 | } |
2619 | } |
2620 | |
2621 | # fallback case: use subdir /tmp of home or current dir |
2622 | file mkdir $fallback |
2623 | return $fallback |
2624 | } |
9753e6de |
2625 | |
2626 | # extract of code from testgrid command used to process jobs running in |
2627 | # parallel until number of jobs in the queue becomes equal or less than |
2628 | # specified value |
2629 | proc _testgrid_process_jobs {worker {nb_ok 0}} { |
2630 | # bind local vars to variables of the caller procedure |
2631 | upvar log log |
2632 | upvar logdir logdir |
2633 | upvar job_def job_def |
2634 | upvar nbpooled nbpooled |
2635 | upvar userbreak userbreak |
2636 | upvar refresh refresh |
2637 | upvar refresh_timer refresh_timer |
2638 | |
2639 | catch {tpool::resume $worker} |
2640 | while { ! $userbreak && $nbpooled > $nb_ok } { |
2641 | foreach job [tpool::wait $worker [array names job_def]] { |
2642 | eval _log_test_case \[tpool::get $worker $job\] $job_def($job) log |
2643 | unset job_def($job) |
2644 | incr nbpooled -1 |
2645 | } |
2646 | |
2647 | # check for user break |
2648 | if { "[info commands dbreak]" == "dbreak" && [catch dbreak] } { |
2649 | set userbreak 1 |
2650 | } |
2651 | |
2652 | # update summary log with requested period |
2653 | if { $logdir != "" && $refresh > 0 && [clock seconds] > $refresh_timer + $refresh } { |
6d368502 |
2654 | _log_summarize $logdir $log |
2655 | set refresh_timer [clock seconds] |
9753e6de |
2656 | } |
2657 | } |
2658 | catch {tpool::suspend $worker} |
2659 | } |
ccadc126 |
2660 | |
2661 | help checkcolor { |
2662 | Check pixel color. |
2663 | Use: checkcolor x y red green blue |
2664 | x y - pixel coordinates |
2665 | red green blue - expected pixel color (values from 0 to 1) |
2666 | Function check color with tolerance (5x5 area) |
2667 | } |
2668 | # Procedure to check color using command vreadpixel with tolerance |
2669 | proc checkcolor { coord_x coord_y rd_get gr_get bl_get } { |
2670 | puts "Coordinate x = $coord_x" |
2671 | puts "Coordinate y = $coord_y" |
2672 | puts "RED color of RGB is $rd_get" |
2673 | puts "GREEN color of RGB is $gr_get" |
2674 | puts "BLUE color of RGB is $bl_get" |
2675 | |
2676 | if { $coord_x <= 1 || $coord_y <= 1 } { |
6d368502 |
2677 | puts "Error : minimal coordinate is x = 2, y = 2. But we have x = $coord_x y = $coord_y" |
2678 | return -1 |
ccadc126 |
2679 | } |
2680 | |
2681 | set color "" |
2682 | catch { [set color "[vreadpixel ${coord_x} ${coord_y} rgb]"] } |
2683 | if {"$color" == ""} { |
6d368502 |
2684 | puts "Error : Pixel coordinates (${position_x}; ${position_y}) are out of view" |
ccadc126 |
2685 | } |
2686 | set rd [lindex $color 0] |
2687 | set gr [lindex $color 1] |
2688 | set bl [lindex $color 2] |
2689 | set rd_int [expr int($rd * 1.e+05)] |
2690 | set gr_int [expr int($gr * 1.e+05)] |
2691 | set bl_int [expr int($bl * 1.e+05)] |
2692 | set rd_ch [expr int($rd_get * 1.e+05)] |
2693 | set gr_ch [expr int($gr_get * 1.e+05)] |
2694 | set bl_ch [expr int($bl_get * 1.e+05)] |
2695 | |
2696 | if { $rd_ch != 0 } { |
6d368502 |
2697 | set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch] |
ccadc126 |
2698 | } else { |
6d368502 |
2699 | set tol_rd $rd_int |
ccadc126 |
2700 | } |
2701 | if { $gr_ch != 0 } { |
6d368502 |
2702 | set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch] |
ccadc126 |
2703 | } else { |
6d368502 |
2704 | set tol_gr $gr_int |
ccadc126 |
2705 | } |
2706 | if { $bl_ch != 0 } { |
6d368502 |
2707 | set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch] |
ccadc126 |
2708 | } else { |
6d368502 |
2709 | set tol_bl $bl_int |
ccadc126 |
2710 | } |
2711 | |
2712 | set status 0 |
2713 | if { $tol_rd > 0.2 } { |
6d368502 |
2714 | puts "Warning : RED light of additive color model RGB is invalid" |
2715 | set status 1 |
ccadc126 |
2716 | } |
2717 | if { $tol_gr > 0.2 } { |
6d368502 |
2718 | puts "Warning : GREEN light of additive color model RGB is invalid" |
2719 | set status 1 |
ccadc126 |
2720 | } |
2721 | if { $tol_bl > 0.2 } { |
6d368502 |
2722 | puts "Warning : BLUE light of additive color model RGB is invalid" |
2723 | set status 1 |
ccadc126 |
2724 | } |
2725 | |
2726 | if { $status != 0 } { |
6d368502 |
2727 | puts "Warning : Colors of default coordinate are not equal" |
ccadc126 |
2728 | } |
2729 | |
2730 | global stat |
2731 | if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } { |
6d368502 |
2732 | set info [_checkpoint $coord_x $coord_y $rd_ch $gr_ch $bl_ch] |
2733 | set stat [lindex $info end] |
2734 | if { ${stat} != 1 } { |
2735 | puts "Error : Colors are not equal in default coordinate and in the near coordinates too" |
2736 | return $stat |
2737 | } else { |
2738 | puts "Point with valid color was found" |
2739 | return $stat |
2740 | } |
ccadc126 |
2741 | } else { |
6d368502 |
2742 | set stat 1 |
ccadc126 |
2743 | } |
2744 | } |
2745 | |
2746 | # Procedure to check color in the point near default coordinate |
2747 | proc _checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} { |
2748 | set x_start [expr ${coord_x} - 2] |
2749 | set y_start [expr ${coord_y} - 2] |
2750 | set mistake 0 |
2751 | set i 0 |
2752 | while { $mistake != 1 && $i <= 5 } { |
6d368502 |
2753 | set j 0 |
2754 | while { $mistake != 1 && $j <= 5 } { |
2755 | set position_x [expr ${x_start} + $j] |
2756 | set position_y [expr ${y_start} + $i] |
2757 | puts $position_x |
2758 | puts $position_y |
2759 | |
2760 | set color "" |
2761 | catch { [set color "[vreadpixel ${position_x} ${position_y} rgb]"] } |
2762 | if {"$color" == ""} { |
2763 | puts "Warning : Pixel coordinates (${position_x}; ${position_y}) are out of view" |
2764 | incr j |
2765 | continue |
2766 | } |
2767 | set rd [lindex $color 0] |
2768 | set gr [lindex $color 1] |
2769 | set bl [lindex $color 2] |
2770 | set rd_int [expr int($rd * 1.e+05)] |
2771 | set gr_int [expr int($gr * 1.e+05)] |
2772 | set bl_int [expr int($bl * 1.e+05)] |
2773 | |
2774 | if { $rd_ch != 0 } { |
2775 | set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch] |
2776 | } else { |
2777 | set tol_rd $rd_int |
2778 | } |
2779 | if { $gr_ch != 0 } { |
2780 | set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch] |
2781 | } else { |
2782 | set tol_gr $gr_int |
2783 | } |
2784 | if { $bl_ch != 0 } { |
2785 | set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch] |
2786 | } else { |
2787 | set tol_bl $bl_int |
2788 | } |
2789 | |
2790 | if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } { |
2791 | puts "Warning : Point with true color was not found near default coordinates" |
2792 | set mistake 0 |
2793 | } else { |
2794 | set mistake 1 |
2795 | } |
ccadc126 |
2796 | incr j |
6d368502 |
2797 | } |
2798 | incr i |
ccadc126 |
2799 | } |
2800 | return $mistake |
2801 | } |
a2f76b15 |
2802 | |
2803 | # Procedure to check if sequence of values in listval follows linear trend |
2804 | # adding the same delta on each step. |
2805 | # |
2806 | # The function does statistical estimation of the mean variation of the |
2807 | # values of the sequence, and dispersion, and returns true only if both |
2808 | # dispersion and deviation of the mean from expected delta are within |
2809 | # specified tolerance. |
2810 | # |
2811 | # If mean variation differs from expected delta on more than two dispersions, |
2812 | # the check fails and procedure raises error with specified message. |
2813 | # |
2814 | # Otherwise the procedure returns false meaning that more iterations are needed. |
2815 | # Note that false is returned in any case if length of listval is less than 3. |
2816 | # |
2817 | # See example of use to check memory leaks in bugs/caf/bug23489 |
2818 | # |
2819 | proc checktrend {listval delta tolerance message} { |
2820 | set nbval [llength $listval] |
2821 | if { $nbval < 3} { |
2822 | return 0 |
2823 | } |
2824 | |
2825 | # calculate mean value |
2826 | set mean 0. |
2827 | set prev [lindex $listval 0] |
2828 | foreach val [lrange $listval 1 end] { |
2829 | set mean [expr $mean + ($val - $prev)] |
2830 | set prev $val |
2831 | } |
2832 | set mean [expr $mean / ($nbval - 1)] |
2833 | |
2834 | # calculate dispersion |
2835 | set sigma 0. |
2836 | set prev [lindex $listval 0] |
2837 | foreach val [lrange $listval 1 end] { |
2838 | set d [expr ($val - $prev) - $mean] |
2839 | set sigma [expr $sigma + $d * $d] |
2840 | set prev $val |
2841 | } |
2842 | set sigma [expr sqrt ($sigma / ($nbval - 2))] |
2843 | |
2844 | puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma" |
2845 | |
2846 | # check if deviation is definitely too big |
2847 | if { abs ($mean - $delta) > $tolerance + 2. * $sigma } { |
2848 | puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta" |
2849 | error "$message" |
2850 | } |
2851 | |
2852 | # check if deviation is clearly within a range |
2853 | return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance] |
2854 | } |