-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_el_lib.tcl
executable file
·146 lines (117 loc) · 2.73 KB
/
test_el_lib.tcl
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
#!/usr/bin/env tclsh8.5
#
# libexpect is compiled with tclsh version 8.5
#
# expect-lite library demo script
#
# by Craig Miller 5 Feb 2011
#
# Add library to search path
lappend auto_path "."
# Load el_lib
package require expect-lite
puts "el_lib loaded"
# Initialize EL library
# _el_init_library <cli init string>
# Loads libexpect, initializes el global variables, spawns bash session
#
expectlite::_el_init_library "*EXP_INFO IP=10.5.5.5 "
puts "el_lib initialized"
# create spawn sessions and set prompt to identify the session
spawn bash
send "export PS1='0\$ '\n"
set session(default) $spawn_id
spawn bash
send "export PS1='1\$ '\n"
set session(dut1) $spawn_id
spawn bash
send "export PS1='2\$ '\n"
set session(dut2) $spawn_id
spawn bash
send "export PS1='3\$ '\n"
set session(dut3) $spawn_id
# remove global to simulate STAF
unset spawn_id
# Import the session array into EL
# _el_import_session_ids <session list, alternating name spawn_id>
# e.g. _el_import_session_ids dut3 exp9 dut1 exp7 dut2 exp8 def exp6
# Note: TCL does not actually pass arrays, therefore a list is passed
#
expectlite::_el_import_session_ids [array get session]
#
# Import more vars into EL (as constants)
#
# don't stop on *INTERACT in script
expectlite::_el_import_const "DUT=mydut *NOFAIL {my=this or that}"
expectlite::_el_import_const "DUT2=thatdut "
################ initialization complete. Begin of script ############
proc test_funct { str } {
puts "calling test_funct param=$str"
sleep 3
return 0
}
puts "argv0 is:$argv0"
# read this file as el script, reference by buf_stack pointer
set cmd_file $argv0
set cmd_list_ptr [expectlite::_el_buffer $cmd_file]
# show first 20 lines of EL script
#expectlite::_el_buffer_show 20 $expectlite::_el_buf(stack) 1
# call el script exec
set RESULT [ expectlite::_el_script_exec "" $cmd_list_ptr ]
# Print result of test
switch $RESULT {
0 { puts "\nTest Passed" }
1 { puts "\nTest Failed" }
2 { puts "\nTest Abend" }
}
#stop TCLSH from reading EL Script
exit 0
########## Embedded EL Scrtpt ###############
; === start script $IP
#*NOINCLUDE
*TIMESTAMP ISO
$IP=2001:db8::DEAD
#~junk
>
@2
~tcl_functions.inc
>date
<20[12][3-9]
>pwd
*NODEBUG
*FORK
>
*NOTIMESTAMP
*INTERACT
$count=0
$max=3
%GEN_LOOP
>
?if $test_complete == Done ?%BREAK_LOOP1
# increment variable
+$count
?if $count <= $max ?%GEN_LOOP
%BREAK_LOOP1
>
$i=2
[ $i < 5
>
?if $i == 4 ?%BREAK_LOOP
# increment variable
+$i
]
%BREAK_LOOP
?if $i == 5 ? [
;; while loop got to 5
]::[
;; while loop stopped correctly at 4
]
; === test IPv6 addressing
$platform=ppc
? $platform == i386 ? $my_addr=2001:db8::f00d :: $my_addr=2001:db8::feed
? $my_addr!=2001:db8::feed ? *FAIL
*SHOW VARS
*TCL puts "\nARGV:$argv0"
*TCL puts [test_funct $cmd_list_ptr]
>echo "pau"
>