aboutsummaryrefslogtreecommitdiff
path: root/contrib/bluegnu2.0.3/lib/testSessionFramework.itcl
blob: 7f96880db7dea7270414e7b10e005172da9fcde8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
#
#
#
#
# unknown -- called by expect if a proc is called that doesn't exist
#

# Set auto_load to take BLUEGNULIB first on search path
#
set auto_path "$env(BLUEGNULIB) $auto_path"

# find tclIndex file in the test suite directory structure
# $env(TESTSUITEROOT) and in the path up to the root
#
if {! [info exists env(TESTSUITEROOT)]} {
    set env(TESTSUITEROOT) [exec /bin/sh -c pwd]
}
set PWD $env(TESTSUITEROOT)

if {[info exists env(TESTSETS)]} {
    if {[lsearch -exact [split $env(TESTSETS) ":"] $PWD] < 0} {
	set env(TESTSETS) $PWD:$env(TESTSETS)
    }
} else {
    set env(TESTSETS) $PWD
}
cd $PWD


# First thing to do is calculate the verbose level and the debug flag
# as well as the definition of the associated procedures:
#      verbose and debug.
#
# Check the Debug level
if [info exists env(DEBUG)] {
    switch -regexp [string toupper $env(DEBUG)] {
	1 - ^T(R(U(E)?)?)?$ - ^Y(E(S)?)?$ {
	    set bDebug 1
	}
	default {
	    set bDebug 0
	}
    }
} else {
    set bDebug 0
}

# Calculate verbose level
# Complete a first path over the argument list
#    Calculate the Verbose Level
set verbose 0
foreach __arg $argv {
    switch -regexp -- $__arg {
	{^-[-]?v(e(r(b(o(s(e)?)?)?)?)?)?$} {
	    incr verbose
	}
	default {
	    lappend __lArgs $__arg
	}
    }
}
if {[catch {set argv $__lArgs}]} {
    set argv {}
}

# Define the procedures: verbose & debug
#
# verbose [-n] [-log] [--] message [level]
#
# Print MESSAGE if the verbose level is >= LEVEL.
# The default value of LEVEL is 1.
# "-n" says to not print a trailing newline.
# "-log" says to add the text to the log file even if it won't be printed.
# Note that the apparent behaviour of `send_user' dictates that if the message
# is printed it is also added to the log file.
# Use "--" if MESSAGE begins with "-".
#
# This is defined here rather than in framework.exp so we can use it
# while still loading in the support files.
#
proc verbose {args} {
    debug {======= verbose $args} 3
    global verbose

    set newline 1
    set logfile 0

    set i 0
    if {[string index [lindex $args 0] 0] == "-"} {
	for { set i 0 } { $i < [llength $args] } { incr i } {
	    if { [lindex $args $i] == "--" } {
		incr i
		break
	    } elseif { [lindex $args $i] == "-n" } {
		set newline 0
	    } elseif { [lindex $args $i] == "-log" } {
		set logfile 1
	    } elseif { [string index [lindex $args $i] 0] == "-" } {
		return [::BlueGnu::clone_output "ERROR: verbose:\
			illegal argument: [lindex $args $i]"]
	    } else {
		break
	    }
	}
    }
    if {[llength $args] == $i} {
	return [::BlueGnu::clone_output "ERROR: verbose: nothing to print"]
    }


    set level 1
    if {[llength $args] == $i + 2} {
	if [catch {set level [expr [lindex $args [expr $i+1]]]} szErrMsg] {
	    return [::BlueGnu::clone_output "ERROR: verbose: level number\
		    >$szErrMsg<"]
	}
    } elseif {[llength $args] > $i + 2} {
	return [::BlueGnu::clone_output "ERROR: verbose: Too many arguments"]
    }
    set message [lindex $args $i]
    
    if {$level <= $verbose} {
	# There is no need for the "--" argument here, but play it safe.
	# We assume send_user also sends the text to the log file (which
	# appears to be the case though the docs aren't clear on this).
	if 0 {
	    if {[string compare \
		    [namespace eval ::BlueGnu \
		    {set ::BlueGnu::sum_file}] stdout] != 0} {
		set szCmd [list uplevel puts [namespace eval ::BlueGnu \
			{set ::BlueGnu::sum_file}]]
		lappend szCmd "\"$message\""
		debug {==## 1 >$szCmd<} 9
		if {[catch {eval $szCmd}]} {
		    puts [namespace eval ::BlueGnu \
			    {set ::BlueGnu::sum_file}] $message
		}
	    }
	}
	if [catch {set message \
		"[uplevel set __szTmp \"$message\"]"} szErrMsg] {
	    set message "$message == ERROR: >$szErrMsg<"
	}
	if {$newline} {
	    #append message "\n"
	}
	debug {$message} 0
	return [::BlueGnu::clone_output "$message"]
    } elseif {$logfile} {
	if [catch {set message \
		"[uplevel set __szTmp \"$message\"]"} szErrMsg] {
	    set message "$message == ERROR: >$szErrMsg<"
	}
	if {$newline} {
	    append message "\n"
	}
	debug {$message} 0
	return [send_log $message]
    }
    return ""
}

if {$bDebug} {
    proc debug {text {level 1}} {
	global verbose

	if {$level <= $verbose} {
	    set szCmd [list uplevel ::BlueGnu::clone_output]
	    set szA $level; set iMax [uplevel info level]
	    for {set i 0} {$i < $iMax} \
		    {incr i} {append szA ">"}
	    lappend szCmd "\"$szA$text\""
	    eval $szCmd
	}
    }
} else {
    proc debug {text {level 1}} {
    }
}

# This procedure will find a file in the directory structure
# any where below the current working directory
# any where on the search path
# or up the directory tree
#
proc locateFile {szFileName {szSubDirectory "."}} {
    debug {======= locateFile $szFileName $szSubDirectory} 3
    global env
    # remove a trailing "/" from sub directory name
    regexp {(.*)/$} $szSubDirectory dummy szSubDirectory

    set newList {}
    set searchList {.}
    set tmpDir [pwd]
    while {[string compare [set dir [file dirname $tmpDir]] "/"] != 0} {
	lappend searchList $dir
	set tmpDir $dir
    }
    foreach dir [split $env(TESTSETS) ":"] {
	lappend searchList $dir
    }
    foreach dirList $searchList {
	foreach test [searchForFile $szFileName $dirList $szSubDirectory] {
	    # only files that are readable and
	    # not a directory, symbolic link or device
	    # are added to the list
	    if {[file isfile $test] && [file readable $test]} {
		# add only if not already exists in list
		if {[lsearch -exact $newList $test] < 0} {
		    lappend newList $test
		}
	    }
	}
    }
    debug {======= returning newList: >$newList<} 4
    return $newList
}

proc locateDir {szFileName {szSubDirectory "."}} {
    debug {======= locateDir $szFileName $szSubDirectory} 3
    global env
    # remove a trailing "/" from sub directory name
    regexp {(.*)/$} $szSubDirectory dummy szSubDirectory

    set newList {}
    set searchList {.}
    set tmpDir [pwd]
    while {[string compare [set dir [file dirname $tmpDir]] "/"] != 0} {
	lappend searchList $dir
	set tmpDir $dir
    }
    foreach dir [split $env(TESTSETS) ":"] {
	lappend searchList $dir
    }
    foreach dirList $searchList {
	foreach test [searchForFile $szFileName $dirList $szSubDirectory] {
	    # only files that are directories
	    # are added to the list
	    if {[file isdirectory $test]} {
		# add only if not already exists in list
		if {[lsearch -exact $newList $test] < 0} {
		    lappend newList $test
		}
	    }
	}
    }
    debug {======= returning newList: >$newList<} 4
    return $newList
}

proc searchForFile {szFileName dirList szSubDirectory} {
    debug {======= searchForFile $szFileName $dirList $szSubDirectory} 3
    # find sub directory in or below the current working directory
    set szDirSrc ""
    foreach file [file split $szSubDirectory] {
	if {[string compare $file "."] == 0} {
	    if {! [info exists newList]} {
		set newList {}
	    }
	    continue
	} else {
	    foreach dir $dirList {
		catch {unset newList}
		foreach newDir [findFile $dir $file] {
		    lappend newList $newDir
		}
	    }
	}
	if {[catch {set dirList $newList}]} {
	    set dirList {}
	}
    }
    debug {        dirList = >$dirList<} 4
    set fileList {}
    foreach dir $dirList {
	set newList [findFile $dir $szFileName]
	if {[llength $newList] > 0} {
	    set fileList [concat $fileList $newList]
	}
    }
    debug {        fileList = >$fileList<} 4
    if {[llength $fileList] != 0} {
	# NO test found, next step in searching
	#return $fileList
    }

    set newList {}
    set PWD [pwd]
    foreach dir $fileList {
	debug {        dir = >$dir<} 4
	cd [file dirname $dir]
	lappend newList "[pwd]/[file tail $dir]"
	cd $PWD
    }

    debug {        newList = >$newList<} 4
    return $newList
}

proc findFile {szDirectory szFileName} {
    global locatedFile env

    debug {======= findFile $szDirectory $szFileName} 3
    if {! [info exists locatedFile($szDirectory/$szFileName)]} {
	if {[file readable $szDirectory/$szFileName]} {
	    set locatedFile($szDirectory/$szFileName) $szDirectory/$szFileName
	} else {
	    if {$szDirectory == "." || \
		    [lsearch -exact [split $env(TESTSETS) ":"] \
		    $szDirectory] >= 0} {
		set locatedFile($szDirectory/$szFileName) \
			[split [exec find $szDirectory -name $szFileName \
			-print] "\n"]
	    } else {
		return {}
	    }
	}
    }
    return $locatedFile($szDirectory/$szFileName)
}

# appendArguments
#
# This procedure will append the string pathed in arguments to every
# element of fileList
# return a list with the same number of element in which each
# element has the arguments appended
#
proc appendArguments {fileList arguments} {
    set newList {}
    debug {======= appendArguments $fileList $arguments} 3
    debug {        length argument list: >[llength $arguments]<} 4
    if {[string length $arguments] > 0} {
	foreach file $fileList {
	    regexp {([^[=]+)([[][^]]*[]])?(.*)} $file dummy szT szID szA
	    debug {dummy: >$dummy<} 4
	    debug {szT  : >$szT<} 4
	    if {[string length $szID] > 0} {
		#regexp {[[]([^]]+)[]]} $szID dummy szID
	    }
	    debug {szID : >$szID<} 4
	    if {[string length $szA] > 0} {
		regexp {=(.*)} $szA dummy szA
	    }
	    debug {szA  : >$szA<} 4
	    #set lFile [split $file "="]
	    if {[string length $szA] > 0} {
		set szSep " "
	    } else {
		set szSep "="
	    }
	    lappend newList ${file}${szSep}$arguments
	}
	return $newList
    }
    return $fileList
}

# appendTestCaseID
#
# This procedure will append the string pathed in arguments to every
# element of fileList
# return a list with the same number of element in which each
# element has the arguments appended
#
proc appendTestCaseID {fileList {szTestCaseID ""}} {
    set newList {}
    debug {======= appendTestCaseID $fileList >$szTestCaseID<} 3
    set bMultiFiles [expr [llength $fileList] > 1]
    set i 1
    foreach file $fileList {
	regexp {([^[=]+)([[][^]]*[]])?(.*)} $file dummy szT szID szA
	debug {dummy: >$dummy<} 4
	debug {szT  : >$szT<} 4
	if {[string length $szID] > 0} {
	    regexp {[[]([^]]+)[]]} $szID dummy szID
	}
	debug {szID : >$szID<} 4
	if {[string length $szA] > 0} {
	    #regexp {=(.*)} $szA dummy szA
	}
	debug {szA  : >$szA<} 4
	if {[string length $szID] > 0} {
	    set szID [string trim "${szID}${szTestCaseID}"]
	} else {
	    set szID ${szTestCaseID}
	}
	if {[llength [split $szID "="]] > 1} {
	    set szSep " "
	} else {
	    set szSep "="
	}
	if {[string length $szID] == 0} {
		lappend newList "${szT}$szA"
		continue
	}
	if {$bMultiFiles} {
	    set szI [format "${szSep}seqNr=%03d" $i]
	} else {
	    set szI ""
	}
	lappend newList "${szT}\[${szID}${szI}\]$szA"
	incr i
    }
    return $newList
}

# processArgs
#
# This procedure expect all optional arguments to be name=value pairs
# It will set all variable named to the value given within 
# the procedure body
# It will return an empty list or a list of all remaining not name=value
# pair in the argument list
#
proc processArgs {args} {
    debug {======= processArgs $args} 3

    set llArgs $args
    set args {}

    # set default errorCode=NONE
    uplevel set errorCode NONE
    # now process all name=value pair arguments
    ####### There may be a better way to do this see pre 8.0 code
    foreach lArgs $llArgs {
	foreach arg $lArgs {
	    set NVP [split $arg "="]
	    if {[llength $NVP] > 1} {
		debug {uplevel set [lindex $NVP 0] \
			[list [join [lrange $NVP 1 end] "="]]} 3
		uplevel set [lindex $NVP 0] \
			[list [join [lrange $NVP 1 end] "="]]
	    } else {
		lappend args $arg
	    }
	}
    }
    debug {        processArgs returns: $args} 3
    return $args
}

# processInternalArgs
#
# This procedure expect all optional arguments to be {name value} pairs
# It will set all variable named to the value given within 
# the procedure body
# It will return an empty list or a list of all remaining not name=value
# pair in the argument list
#
proc processInternalArgs {lArgs} {
    debug {======= processInternalArgs $lArgs} 3
    set arglist {}

    # set default errorCode=NONE
    uplevel set errorCode NONE
    # now process all {name value} pair arguments
    foreach arg $lArgs {
	if {[llength $arg] == 2} {
	    debug {uplevel set [lindex $arg 0] \
		    [list [join [lrange $arg 1 end] "="]]} 3
	    uplevel set [lindex $arg 0] \
		    [list [join [lrange $arg 1 end] "="]]
	} else {
	    lappend arglist $arg
	}
    }
    debug {processInternalArgs returns: $arglist} 3
    return $arglist
}

# processTestScriptArgs
#
# This procedure expect all optional arguments to be {name value} pairs
# It will set all variable named to the value given within 
# the procedure body
# It will return an empty list or a list of all remaining not name=value
# pair in the argument list
#
# This is a copy of the procedure "processInternalArgs" without an argument
# however this procedure may become different
#
#
proc processTestScriptArgs {} {
    upvar lArgs lArgs
    set arglist {}

    # set default errorCode=NONE
    uplevel set errorCode NONE
    debug {======= processTestScriptArgs $lArgs} 3
    # now process all {name value} pair arguments
    foreach arg $lArgs {
	if {[llength $arg] == 2} {
	    debug {uplevel set [lindex $arg 0] \
		    [list [join [lrange $arg 1 end] "="]]} 4
	    uplevel set [lindex $arg 0] \
		    [list [join [lrange $arg 1 end] "="]]
	} else {
	    lappend arglist $arg
	}
    }
    debug {        processInternalArgs returns: $arglist} 4
    return $arglist
}

# Command execution command
# This command is like the catch command, however it can do some additional
# testing and in case of an error it will return a error class.
#
proc doCmd {szCmd args} {
    global errorInfo errorCode
    if {! [info exists errorInfo]} {
	set errorInfo "<errorInfo has not been defined>"
    }

    debug {======= doCmd >$szCmd< >$args<} 3
    foreach arg $args {
	set vv [split $arg "="]
	if {[llength $vv] == 2} {
	    debug {   ==>> Expected value: [lindex $vv 0]=[eval list \
		    [lindex $vv 1]]} 5
	    set [lindex $vv 0] [eval list [lindex $vv 1]]
	} elseif {[llength $vv] == 1} {
	    if {! [info exists errorObj]} {
		debug {   ==>> upvar $vv errorObj} 5
		if "! [uplevel info exists $vv]" {
		    debug {   ==>> creating: $vv (uplevel)} 5
		    uplevel [list set $vv {}]
		}
		upvar $vv errorObj
	    }
	}
    }
    if {[catch {uplevel 1 $szCmd} szErrMsg]} {
	debug {======= ErrMsg : \n$szErrMsg\n======= from:\n$szCmd} 5
	set errorObj ""
	if {[string compare $errorCode NONE] == 0} {
	    set errorCode UNDEFINED
	}
	set errorInfoSave $errorInfo
	set errorCodeSave $errorCode
	catch {set errorObj [uplevel infoWhich \{$szErrMsg\}]}
	set errorInfo $errorInfoSave
	set errorCode $errorCodeSave
	debug {   ==>> errorObj: >$errorObj<} 5
	if {[string compare $errorObj ""] == 0} {
	    set errorObj [uplevel \
		    ::BlueGnu::Error #auto \{$errorCode\} \
		    \{$szErrMsg\} \{$errorInfo\}]
	    debug {errorObj: >$errorObj<} 5
	    set errorObj [uplevel infoWhich \{$errorObj\}]
	    debug {errorObj: >$errorObj<} 5
	    debug {Command: [string trim $szCmd]} 5
	    debug {ErrMsg : \n$szErrMsg} 5
	    debug {====================} 5
	    global errorInfo
	    debug {ErrInfo: $errorInfo\n====================} 5
	}
	set bReturn 1
	if {[info exists errorCode]} {
	    debug {        errorCode= $errorCode} 5
	    debug {            Class= [$errorObj info class]} 5
	    catch {debug {       isa BC_RTN= [$errorObj isa BC_RTN]} 5}
	    catch {debug {        isa ERROR= [$errorObj isa Error]} 5}
	    catch {
		if [$errorObj isa BC_RTN] {
		    if {[set i \
			    [lsearch -exact $errorCode \
			    [list [$errorObj SEVERITY] \
			    [$errorObj FACILITY] [$errorObj CODE]]]] >= 0} {
			setup_xfail
			set bReturn 0
		    }
		    fail "Expected errorCode=$errorCode, got:\
			    [$errorObj getShortMsg]\
			    \{[$errorObj SEVERITY] [$errorObj FACILITY]\
			    [$errorObj CODE]\} for >$szCmd<"
		    #verbose { errorCode: [$errorObj errorCode]}
		    #verbose {       why: [$errorObj why]}
		    #verbose {verboseWhy: [$errorObj verboseWhy]} 2
		}
	    }
	    catch {
		if [$errorObj isa Error] {
		    debug {            Error= [$errorObj errorCode]} 5
		    if {[set i \
			    [lsearch -exact $errorCode \
			    [$errorObj errorCode]]] >= 0} {
			setup_xfail
			set bReturn 0
		    }
		    fail "Expected errorCode=$errorCode, got:\
			    [$errorObj errorCode] for >$szCmd<"
		    verbose { errorCode: [$errorObj errorCode]}
		    verbose {       why: [$errorObj why]}
		    verbose {verboseWhy: [$errorObj verboseWhy]} 2
		}
	    }
	}
	return $bReturn
    } else {
	set bReturn 0
	set NOT ""
	if {[info exists errorCode]} {
	    if {[lsearch -exact $errorCode "NONE"] < 0} {
		setup_xfail
		set NOT "not "
		set bReturn 1
	    }
	    pass "errorCode=NONE ${NOT}found in expected set\
		    of errorCodes=\{$errorCode\} for >$szCmd<"
	}
	if {[info exists return]} {
	    debug {Return: >$return<} 3
	    set bResult 0
	    set iFalse 0
	    set iFalseFound 0
	    set iTrue 0
	    set iTrueFound 0
	    foreach lResult $return {
		if {[llength $lResult] == 2} {
		    set bFlag [string toupper [lindex $lResult 0]]
		    set szResult [lindex $lResult 1]
		} else {
		    set bFlag ""
		    set szResult [lindex $lResult 0]
		}
		debug {Checking >$szErrMsg< against $bFlag >$szResult<} 3
		switch $bFlag {
		    0 - NOT - NO - FALSE {
			# no matches allowed
			incr iFalse
			debug {Should not match >$szErrMsg< != >$szResult<} 4
			if {[string compare $szErrMsg $szResult] != 0} {
			    pass "The NOT Expected Result >$szResult<\
				    was not found for >$szCmd<"
			    incr iFalseFound
			} else {
			    fail "The NOT Expected Result >$szResult<\
				    was found for >$szCmd<"
			}
		    }
		    1 - {} - YES - TRUE {
			# only one match allowed
			incr iTrue
			debug {Should match >$szErrMsg< == >$szResult<} 4
			if {[string compare $szErrMsg $szResult] == 0} {
			    pass "Expected Result >$szResult<\
				    found for >$szCmd<"
			    incr iTrueFound
			}
		    }
		    default {
			perror "doCmd result flag: 1, 0, <empty>,\
				NOT, YES, NO, TRUE, FALSE"
		    }
		}
	    }
	    set bResult [expr $iFalse == $iFalseFound]
	    if {$iTrue > 0} {
		set bResult [expr $bResult && ($iTrueFound == 1)]
	    }
	    if {! $bResult} {
		fail "Expected Result(s) >$return<\n     \
			 did not match with: >$szErrMsg< for >$szCmd<"
		set bReturn 1
	    }
	}
	if {[info exists errorObj]} {
	    set errorObj $szErrMsg
	}
    }
    return $bReturn
}


# deleteObjects
#
# This procedure takes multiple arguments each can be a single object
# or a list of objects
# it will delete all these object
# No return value
#
proc deleteObjects {args} {
    debug {======= deleteObjects $args} 3
    foreach arg $args {
	foreach object $arg {
	    debug "        delete object >$object<" 4
    	    delete object $object
	}
    }
    return {}
}

# isObject
# This procedure accepts a fully qualified object name as argument
# and checks if that object exists
proc isObject {object} {
    debug {======= isObject $object} 3
    set tmp [namespace tail $object]
    return [expr [lsearch [namespace eval [namespace qualifier $object] {
	::itcl::find objects
    }
    ] $tmp] >= 0]
}

# checkObject
# This procedure takes an object and a class name is argument
# It checks if the object exists, has a counter part in C++ and
# is of the correct class
#
proc checkObject {object szClassName} {
    debug {======= checkObject $object $szClassName} 3
    if {! [catch {
	set class [uplevel "$object info class"]
	if {[catch {[findObject $object] isa $szClassName} bCl]} {
	    if {[string compare [namespace tail $class] \
		    [namespace tail $szClassName]] == 0} {
		debug {Class [namespace tail $szClassName]\
			match class of object} 4
	    } else {
		error "Miss match"
	    }
	} elseif {! $bCl} {
	    error 1
	}
    } iRet]} {
	return 1
    }

    set obj [findObject $object]
    set class [findClass $szClassName]
    if {[string length $obj] > 0 && [string length $class] > 0} {
	debug {   ==>> object and class passed do exists} 4
	if {[catch {set bISA [$obj isa $class]}]} {
	    debug {Class $szClassName is not inscope to match $object} 4
	    return 0
	}
	if {! $bISA} {
	    debug {$object is not of Class $szClassName} 4
	    return 0
	}
    } else {
	debug {$object and/or $szClassName have not been found!} 4
	return 0
    }
    return 1
}

# findObject
# This procedure take the name of an object, possibly without any qualifier
# and search all namespaces to find the object.
# When a qualifier is specified, it will check if it is complete
# The procedure return the fully qualified name of the object if it exists or
# an empty string otherwise.
#
proc findObject {object {namespace ::}} {
    debug {======= findObject $object $namespace} 3
    set ns [namespace qualifier $object]
    set obj [namespace tail $object]
    set objs [namespace eval $namespace {::itcl::find objects}]
    if {[lsearch $objs $obj] >= 0} {
	regsub "::$" $namespace "" namespace
	return ${namespace}::$obj
    } else {
	set result ""
	foreach cns [namespace children $namespace] {
	    set result [findObject $obj $cns]
	    if {[string length $result] > 0} break
	}
    }
    return $result
}

# findClass
# This procedure take the name of an class, possibly without any qualifier
# and search all namespaces to find the class.
# When a qualifier is specified, it will check if it is complete
# The procedure return the fully qualified name of the Class if it exists or
# an empty string otherwise.
#
proc findClass {class {namespace ::}} {
    debug {======= findClass $class $namespace} 3
    set ns [namespace qualifier $class]
    set obj [namespace tail $class]
    set objs [namespace eval $namespace {::itcl::find classes}]
    if {[lsearch $objs $obj] >= 0} {
	regsub "::$" $namespace "" namespace
	return ${namespace}::$obj
    } else {
	set result ""
	foreach cns [namespace children $namespace] {
	    set result [findClass $obj $cns]
	    if {[string length $result] > 0} break
	}
    }
    return $result
}

# The parseTest command will validate the argument as an existing
# test including testCaseID and arguments.
# It will return a list of all acceptable test script
#
proc parseTest {args} {
    global szCurrentTestDirectory
    debug {======= parseTest $args} 3

    foreach arg $args {
	foreach szTest $arg {
	    regexp {([^[=]+)([[][^]]*[]])?(.*)} $szTest dummy szT szID szA
	    debug {dummy: >$dummy<} 4
	    debug {szT  : >$szT<} 4
	    if {[string length $szID] > 0} {
		#regexp {[[]([^]]+)[]]} $szID dummy szID
	    }
	    debug {szID : >$szID<} 4
	    if {[string length $szA] > 0} {
		#regexp {=(.*)} $szA dummy szA
	    }
	    debug {szA  : >$szA<} 4
	    set szFileName $szT
	    set szDname [file dirname $szFileName]
	    set szFname [file tail $szFileName]
				
	    if {[file exist [set test [file join \
		    $szCurrentTestDirectory \
		    $szFileName]]]} {
		# file should be a test
		debug {    is a test: >$test<!} 3
		lappend testList [file join $szCurrentTestDirectory $szTest]
	    } elseif {[llength [set tests \
		    [locateFile $szFname $szDname]]] > 0} {
		foreach test $tests {
		    if {[file exists $test]} {
			# file should be a test
			debug {       is a test: >$test<!!} 3
			lappend testList ${test}${szID}${szA}
		    } else {
			warning "Test >$test< can't be found"
		    }
		}
	    } else {
		perror "$szFileName is not a test!\
			Does not exists!"
	    }
	}
    }
    if [info exists testList] {
	if [llength $testList] {
	    return $testList
	}
    }
    return [list]
}

# The global available runtest procedure
# this procedure will find the current environment
# and execute the runTest procedure in that environment

proc runtest {args} {
    global objCurrentEnvironment szCurrentTestDirectory
    debug {======= runtest $args} 3
    set elResult [list]

    if {[llength $args] > 0} {
	set Env [lindex $args 0]
	debug {   Checking for environment: >$Env<} 3
	debug {      >[infoWhich $Env]<} 5
	debug {   Current Test Directory: >$szCurrentTestDirectory<} 5
	if {[string compare [infoWhich $Env] ""] == 0} {
	    debug {      not an environment} 4
	    if {[info exist objCurrentEnvironment] && \
		    [string compare \
		    [infoWhich $objCurrentEnvironment] ""] != 0} {
		debug {      Found Current Environment\
			>$objCurrentEnvironment<} 5
		set Env $objCurrentEnvironment
	    } else {
		error "NO default environent"
	    }
	} else {
	    debug {     is an environment} 3
	    set args [lrange $args 1 end]
	}
	set T [lindex $args 0]
	set A [lindex $args 1]
	set I [lindex $args 2]
	foreach t [appendTestCaseID [appendArguments [parseTest $T] $A] $I] {
	    debug {   ==>> $objCurrentEnvironment\
		    runTest $t} 3
	    lappend elResult \
		    [$Env runTest $t]
	}
    } else {
	warning "No tests have been passed to runtest procedure!"
    }
    return $elResult
}

proc appendQueue {args} {
    global objCurrentQueue szCurrentTestDirectory
    debug {======= appendQueue $args} 3

    set iRun 0
    set Queue [lindex $args 0]
    if {[string compare [infoWhich $Queue] ""] == 0} {
	if {[info exist objCurrentQueue]} {
	    set Queue $objCurrentQueue
	} else {
	    error "NO default queue"
	}
    } else {
	set args [lrange $args 1 end]
    }
    set T [lindex $args 0]
    set A [lindex $args 1]
    set I [lindex $args 2]
    foreach t [appendTestCaseID [appendArguments [parseTest $T] $A] $I] {
	debug {   ==>> $Queue append $t} 3
	incr iRun
	$Queue append $t
    }
    if {$iRun == 0} {
	warning "NO argument to appendQueue have been processed"
    }
}

proc prependQueue {args} {
    global objCurrentQueue szCurrentTestDirectory
    debug {======= prependQueue $args} 3

    set iRun 0
    set Queue [lindex $args 0]
    if {[string compare [infoWhich [lindex $args 0]] ""] == 0} {
	if {[info exist objCurrentQueue]} {
	    set Queue $objCurrentQueue
	} else {
	    error "NO default queue"
	}
    } else {
	set args [lrange $args 1 end]
    } 
    set T [lindex $args 0]
    set A [lindex $args 1]
    set I [lindex $args 2]
    foreach t [appendTestCaseID [appendArguments [parseTest $T] $A] $I] {
	incr iRun
	lappend comList $t
    }
    debug {   ==>> $Queue prepend $comList} 3
    eval $Queue prepend $comList

    if {$iRun == 0} {
	warning "NO argument to appendQueu have been processed"
    }
}

proc perror {args} {
    global errorInfo
    global objCurrentTest
    global objCurrentEnvironment

    # save errorInfo
    set errorInfoSave $errorInfo

    if { [llength $args] > 1 } {
	set $::BlueGnu::errcnt [lindex [uplevel set args] 1]
    } else {
	incr ::BlueGnu::errcnt
    }

    while 1 {
	set szMsg [lindex $args 0]

	if {[catch {$objCurrentTest perror $szMsg} \
		szErrMsg]} {
	    if {[info exists objCurrentTest]} {
		debug {No current test: >$szErrMsg<:\
			current test >$objCurrentTest< message:\n    \
			$szMsg} 3
	    } else {
		debug {PERROR: No current test: >$szErrMsg<:\
			current test >DOES NOT EXIST< message:\n    \
			$szMsg} 3
		debug {        info: >>>$errorInfo<<<} 4
	    }
	} else {
	    break
	}
	catch {
	    set szCmd [concat \"$objCurrentEnvironment\" record_test \
		    ERROR \$szMsg]
	}
	if {[catch {eval $szCmd} szErrMsg]} {
	    verbose {No current environment (ERROR): >$szErrMsg<} 3
	} else {
	    break
	}

	::BlueGnu::clone_output "ERROR: $szMsg"
	namespace eval ::BlueGnu {
	    set errno "ERROR: [uplevel set szMsg]"
	}
	break
    }

    # restore errorInfo
    set errorInfo $errorInfoSave
}

proc warning {args} {
    global errorInfo
    global objCurrentTest
    global objCurrentEnvironment

    # save errorInfo
    set errorInfoSave $errorInfo

    if { [llength $args] > 1 } {
	namespace eval ::BlueGnu {
	    set warncnt [lindex [uplevel set args] 1]
	}
    } else {
	namespace eval ::BlueGnu {
	    incr warncnt
	}
    }

    while 1 {
	set szMsg [lindex $args 0]

	if {[catch {$objCurrentTest warning $szMsg} \
		szErrMsg]} {
	    if {[info exists objCurrentTest]} {
		verbose {No current test: >$szErrMsg<:\
			current test >$objCurrentTest< message:\n    \
			$szMsg} 3
	    } else {
		verbose {WARNING: No current test: >$szErrMsg<:\
			current test >DOES NOT EXIST< message:\n    \
			$szMsg} 3
	    }
	} else {
	    break
	}
	catch {
	    set szCmd [concat \"$objCurrentEnvironment\" record_test \
		    WARNING \$szMsg]
	}
	if {[catch {eval $szCmd} szErrMsg]} {
	    verbose {No current environment (WARNING): >$szErrMsg<} 3
	} else {
	    break
	}
    
	set szMsg [lindex $args 0]
	::BlueGnu::clone_output "WARNING: $szMsg"
	namespace eval ::BlueGnu {
	    set errno "WARNING: [uplevel set szMsg]"
	}
	break
    }
    if 0 {
	uplevel #0 {
	    verbose {uplevel #0 to remove errorInfo}
	    if [info exists errorInfo] {
		unset errorInfo
	    }
	}
    }
    # restore errorInfo
    set errorInfo $errorInfoSave
}

proc note {szMsg} {
    global objCurrentTest

    $objCurrentTest note $szMsg
}

proc pass {szMsg} {
    global objCurrentTest

    $objCurrentTest pass $szMsg
}

proc fail {szMsg} {
    global objCurrentTest

    $objCurrentTest fail $szMsg
}

proc unresolved {szMsg} {
    global objCurrentTest

    $objCurrentTest unresolved $szMsg
}

proc untested {szMsg} {
    global objCurrentTest

    $objCurrentTest untested $szMsg
}

proc unsupported {szMsg} {
    global objCurrentTest

    $objCurrentTest unsupported $szMsg
}

proc get_warning_threshold {} {
    return [namespace eval ::BlueGnu {set warning_threshold}]
}

proc set_warning_threshold {threshold} {
    namespace eval ::BlueGnu {
	set warning_threshold [uplevel set threshold]
    }
}

proc setup_xfail {args} {
    namespace eval ::BlueGnu {set xfail_flag 1}
}

proc clear_xfail {args} {
    namespace eval ::BlueGnu {set xfail_flag 0}
}

proc benchmark {benchmarkFunction args} {
    debug {======= benchmark $benchmarkFunction $args}
    global objCurrentTest
    global errorInfo

    if 0 {
	debug {[foreach var [info vars] {
	    verbose {local var: >$var<}}]
	}
	uplevel {
	    debug {[foreach var [info vars] {
		verbose {uplevel local var: >$var<}}]
	    }
	}
	debug {[foreach var [info globals] {
	    verbose {global var: >$var<}}]
	}
    }

    set errorInfo ""
    set szID [$objCurrentTest ID]
    set szTestCaseID [$objCurrentTest testCaseID]
    set benchmarkObject [$objCurrentTest benchmarkObject]
    set benchmarkClassName [$objCurrentTest benchmarkClassName]
    debug {   ==>>      test ID: >$szID<} 3
    debug {        test case ID: >$szTestCaseID<} 3
    debug {   check test object: >$benchmarkObject<} 3
    if {$benchmarkObject == ""} {
	warning "NO Benchmark Class defines for >$benchmarkClassName<"
	set bResult 0
    } else {
	if [catch {
	    set bResult [eval $benchmarkObject benchmark \
		    $benchmarkFunction $args]
	} errMsg] {
	    warning "NO checking has been done for\
		    ${benchmarkClassName}::benchmark $benchmarkFunction $args"
	    debug {[perror "BenchmarkFunction: >$benchmarkFunction<\
		    has not been defined\
		    in class $benchmarkClassName\n### Error Msg: $errMsg"]} 0
	    debug {### Error Info: $errorInfo} 0
	    set bResult 0
	}
    }
    return $bResult
}

proc envPATH {szAction szDir} {
    debug {======= envPATH $szAction $szDir} 3

    global env
    if [file isdirectory $szDir] {
	# remove directory from Path if it exists
	set envPATH $env(PATH)
	while {[regsub :?$szDir:? $envPATH {:} envPATH]} {
	}
	regsub {^:} $envPATH {} envPATH
	regsub {:$} $envPATH {} envPATH
	set env(PATH) $envPATH
	switch $szAction {
	    prefix -
	    prepend {
		set env(PATH) "$szDir:$env(PATH)"
	    }
	    append {
		append env(PATH) ":$szDir"
	    }
	    default {
	    }
	}
    }
}

# replacement for info which commaond
#
proc infoWhich {name {namespace ::}} {
    debug {======= infoWhich $name $namespace} 3
    if [catch {uplevel set infoWhich__name $name} szErrMsg] {
	debug {        error: $szErrMsg}
	return ""
    }
    uplevel {
	debug {         objects: >[::itcl::find objects]<} 4
	debug {       namespace: >[namespace current]<} 4
	infoWhichYYY
    }
    set name [uplevel set infoWhich__name]
    uplevel unset infoWhich__name
    debug {infoWhich return: >$name<} 4
    return $name
}
proc infoWhichXXX {} {
    uplevel {
	set i [lsearch -regexp [::itcl::find objects] "[namespace tail \
		$infoWhich__name]"]
	if {$i < 0} {
	    set infoWhich__name ""
	} else {
	    set infoWhich__name [lindex [::itcl::find objects] $i]
	    if {! [string match ::* $infoWhich__name]} {
		set infoWhich__name [namespace current]::$infoWhich__name
	    }
	    regsub "^::::" $infoWhich__name "::" infoWhich__name
	}
    }
}
proc infoWhichYYY {} {
    uplevel {
	if [catch {infoWhichXXX} szErrMsg] {
	    verbose "infoWhichYYY error Msg: $szErrMsg"
	    set infoWhich__name ""
	}
    }
}

namespace eval ::BlueGnu {
    variable warning_threshold 0

    variable sum_file stdout
    variable all_flag 0

    variable xfail_flag 0
    variable xfail_prms {}
    #
    # Print output to stdout (or stderr) and to log file
    #
    # If the --all flag (-a) option was used then all messages
    # go the the screen.
    # Without this, all messages that start with a keyword are
    # written only to the
    # detail log file.  All messages that go to the screen will
    # also appear in the
    # detail log.  This should only be used by the framework itself using pass,
    # fail, xpass, xfail, warning, perror, note, untested, unresolved, or
    # unsupported procedures.
    #
    proc clone_output {message} {
	variable sum_file
	variable all_flag

	#everything goes in the summary file
	#
	puts $sum_file "$message"

	# Depending on the type of message, the message is send
	# to other resources
	#
	case [lindex [split $message] 0] in {
	    {"FAIL:" "XPASS:" "UNRESOLVED:" "UNSUPPORTED:" "UNTESTED:"} {
		send_user "$message\n"
		send_log "$message\n"
	    }
	    {"PASS:" "XFAIL:"} {
		if $all_flag {
		    send_user "$message\n"
		}
		send_log "$message\n"
	    }
	    "ERROR:" {
		#send_user "$message\n"
		send_error "$message\n"
		send_log "$message\n"
	    }
	    {"WARNING:" "NOTE:"} {
		if $all_flag {
		    send_error "$message\n"
		}
		send_log "$message\n"
	    }
	    "*******" {
		send_user "$message\n"
		#send_log "$message\n"
		#send_error "$message\n"
	    }
	    default {
		send_user "$message\n"
	    }
	}

	# we always return turn the message unchanged
	#
	return "$message"
    }
}

proc createTarget {args} {
    verbose {In: createTarget >$args<} 3
    set szCmd "::BlueGnu::Target #auto "
    set bID 0
    set bEnv 0
    set bQueue 0
    foreach item $args {
	if {[string compare \
		[lindex [split $item "="] 0] szID] == 0} {
	    set bID 1
	}
	if {[string compare \
		[lindex [split $item "="] 0] objEnvironment] == 0} {
	    set bEnv 1
	}
	if {[string compare \
		[lindex [split $item "="] 0] objQueue] == 0} {
	    set bQueue 1
	}
	append szCmd "\{$item\} "
    }
    if {! $bID} {
	append szCmd "szID=Default "
    }
    if {! $bEnv} {
	append szCmd "objEnvironment=[infoWhich \
		[::BlueGnu::Environment #auto]] "
    }
    if {! $bQueue} {
	append szCmd "objQueue=[infoWhich [::BlueGnu::Queue #auto]] "
    }
    verbose {Command: >$szCmd<} 3
    set target [uplevel #0 "eval $szCmd"]
    verbose {Created target: >$target<} 3
    verbose {              >>>[$target <<]<<<} 4
    verbose {              >>>[[infoWhich $target] <<]<<<} 4
    verbose {    == [join [$target <<] "\n    == "]} 3
    return [infoWhich $target]
}

# Initialize all global variables not yet initialized
#
set szCurrentTestDirectory $env(TESTSUITEROOT)

# Remove all temporary variables from the global space
catch {eval unset [info globals __*]}
debug {Global variables available:\
	\n   [join [lsort [info globals]] "\n   "]} 9
debug {Global procedures available:\
	\n   [join [lsort [info procs]] "\n   "]} 9

foreach dir [split $env(TESTSETS) ":"] {
    if {[string compare $dir $PWD] == 0} {
	foreach indexFile [locateFile tclIndex] {
	    set indexDir [file dirname $indexFile]
	    if {[lsearch -exact [split $auto_path] $indexDir] < 0} {
		set auto_path "$indexDir $auto_path"
	    }
	}
	foreach indexFile [locateFile tclIndex lib] {
	    set indexDir [file dirname $indexFile]
	    if {[lsearch -exact [split $auto_path] $indexDir] < 0} {
		set auto_path "$indexDir $auto_path"
	    }
	}
    } else {
	if {[file exists $dir/tclIndex]} {
	    set auto_path "$dir $auto_path"
	}
    }
}
debug {auto_path has been intialize to:\n      [join $auto_path "\n      "]} 3
verbose {TESTSETS: >$env(TESTSETS)<} 3