2 if { [array get Draw_Groups "TOPOLOGY Check commands"] == "" } {
5 # set env(CSF_DrawPluginQADefaults) $env(CASROOT)/src/DrawResources/.
7 # pload -DrawPluginQA QAcommands
10 # to prevent loops limit to 16 minutes
13 #set script_dir [file dirname [info script]]/script
14 # if { [info exist WorkDirectory] == 0 } {
15 # set WorkDirectory "/tmp"
16 # if { [array get env TEMP] != "" } {
17 # set WorkDirectory "$env(TEMP)"
21 if { [info exists imagedir] == 0 } {
24 if { [info exists test_image] == 0 } {
28 # Procedure to check equality of two reals with tolerance (relative and absolute)
29 proc checkreal {name value expected tol_abs tol_rel} {
30 if { abs ($value - $expected) > $tol_abs + $tol_rel * abs ($expected) } {
31 puts "Error: $name = $value is not equal to expected $expected"
33 puts "Check of $name OK: value = $value, expected = $expected"
40 # Procedure to check color in the point near default coordinate
42 proc checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} {
43 set x_start [expr ${coord_x} - 2]
44 set y_start [expr ${coord_y} - 2]
47 while { $mistake != 1 && $i <= 5 } {
49 while { $mistake != 1 && $j <= 5 } {
50 set position_x [expr ${x_start} + $j]
51 set position_y [expr ${y_start} + $i]
55 if { [info exists color2d] } {
56 set color [ QAAISGetPixelColor2d ${position_x} ${position_y} ]
58 set color [ QAGetPixelColor ${position_x} ${position_y} ]
60 regexp {RED +: +([-0-9.+eE]+)} $color full rd
61 regexp {GREEN +: +([-0-9.+eE]+)} $color full gr
62 regexp {BLUE +: +([-0-9.+eE]+)} $color full bl
63 set rd_int [expr int($rd * 1.e+05)]
64 set gr_int [expr int($gr * 1.e+05)]
65 set bl_int [expr int($bl * 1.e+05)]
68 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
73 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
78 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
83 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
84 puts "Warning : Point with true color was not found near default coordinates"
96 # Procedure to check color using command QAgetPixelColor with tolerance
97 proc checkcolor { coord_x coord_y rd_get gr_get bl_get } {
98 puts "Coordinate x = $coord_x"
99 puts "Coordinate y = $coord_y"
100 puts "RED color of RGB is $rd_get"
101 puts "GREEN color of RGB is $gr_get"
102 puts "BLUE color of RGB is $bl_get"
104 if { $coord_x <= 1 || $coord_y <= 1 } {
105 puts "Error : minimal coordinate is x = 2, y = 2. But we have x = $coord_x y = $coord_y"
109 if { [info exists color2d] } {
110 set color [ QAAISGetPixelColor2d ${coord_x} ${coord_y} ]
112 set color [ QAGetPixelColor ${coord_x} ${coord_y} ]
115 regexp {RED +: +([-0-9.+eE]+)} $color full rd
116 regexp {GREEN +: +([-0-9.+eE]+)} $color full gr
117 regexp {BLUE +: +([-0-9.+eE]+)} $color full bl
118 set rd_int [expr int($rd * 1.e+05)]
119 set gr_int [expr int($gr * 1.e+05)]
120 set bl_int [expr int($bl * 1.e+05)]
121 set rd_ch [expr int($rd_get * 1.e+05)]
122 set gr_ch [expr int($gr_get * 1.e+05)]
123 set bl_ch [expr int($bl_get * 1.e+05)]
126 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
131 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
136 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
141 if { $tol_rd > 0.2 } {
142 puts "Warning : RED light of additive color model RGB is invalid"
145 if { $tol_gr > 0.2 } {
146 puts "Warning : GREEN light of additive color model RGB is invalid"
149 if { $tol_bl > 0.2 } {
150 puts "Warning : BLUE light of additive color model RGB is invalid"
154 if { $status != 0 } {
155 puts "Warning : Colors of default coordinate are not equal"
159 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
160 set info [checkpoint $coord_x $coord_y $rd_ch $gr_ch $bl_ch]
161 set stat [lindex $info end]
162 if { ${stat} != 1 } {
163 puts "Error : Colors are not equal in default coordinate and in the near coordinates too"
166 puts "Point with valid color was found"
175 # Procedure to check if sequence of values in listval follows linear trend
176 # adding the same delta on each step.
178 # The function does statistical estimation of the mean variation of the
179 # values of the sequence, and dispersion, and returns true only if both
180 # dispersion and deviation of the mean from expected delta are within
181 # specified tolerance.
183 # If mean variation differs from expected delta on more than two dispersions,
184 # the check fails and procedure raises error with specified message.
186 # Otherwise the procedure returns false meaning that more iterations are needed.
187 # Note that false is returned in any case if length of listval is less than 3.
189 # See example of use to check memory leaks in bugs/caf/bug23489
191 proc checktrend {listval delta tolerance message} {
192 set nbval [llength $listval]
197 # calculate mean value
199 set prev [lindex $listval 0]
200 foreach val [lrange $listval 1 end] {
201 set mean [expr $mean + ($val - $prev)]
204 set mean [expr $mean / $nbval]
206 # calculate dispersion
208 set prev [lindex $listval 0]
209 foreach val [lrange $listval 1 end] {
210 set d [expr ($val - $prev) - $mean]
211 set sigma [expr $sigma + $d * $d]
214 set sigma [expr sqrt ($sigma / ($nbval - 1))]
216 puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma"
218 # check if deviation is definitely too big
219 if { abs ($mean - $delta) > 2. * $sigma } {
220 puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
224 # check if deviation is clearly within a range
225 return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance]