unix.exp 3.29 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
set nl "\r?\n"
set any "\[ -\]"
set deep_any "\\\[ -\\\]"
Per Cederqvist's avatar
Per Cederqvist committed
4
5
6
7
8
9
10
11
set hollerith "\[0-9\]*H$any*"

set maxint 2147483647

# These magic numbers are also present in the file
# src/server/testsuite/config/Makefile.am
set clientport 53262
set muxport 53263
Per Cederqvist's avatar
Per Cederqvist committed
12
13
14
15
16
17
18
19
20
21
22
23
24

set stty_init "-echo -onlcr -ocrnl -istrip"

proc l2g_start {} {
    global spawn_id
    global l2g

    spawn $l2g
}

proc l2g_stop {} {
    global spawn_id

25
26
    # FIXME: send explicit quit command and check that there is no
    # trailing unexpected output before the "ok, I die" response.
Per Cederqvist's avatar
Per Cederqvist committed
27
    close
28
    wait
Per Cederqvist's avatar
Per Cederqvist committed
29
30
31
32
}

proc l2g_send {str} {
    unanchored_expect "^l2g> " "prompt before $str"
33
    verbose "sending $str"
Per Cederqvist's avatar
Per Cederqvist committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    send "$str\n"
}

proc simple_expect {regex {testname ""}} {
    global test
    global any
    global nl

    set test $testname
    if {$test == ""} {
	set test "looking for $regex"
    }
    expect {
	-re "^$regex$nl" {pass "$test"}
	timeout 	 {fail "$test (timeout)"}
	eof 		 {fail "$test (eof)"; wait}
	buffer_full 	{fail "$test (buffer_full)"}
	-re "($any*)$nl" {
	    fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')"
	}
54
	-re "($any*)l2g> " {
Per Cederqvist's avatar
Per Cederqvist committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	    fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')"
	}
    }
    unset test
}

proc unanchored_expect {regex testname} {
    global test
    global any
    global nl

    set test $testname
    expect {
	-re "$regex" 	{pass "$test"}
	timeout 	{fail "$test (timeout)"}
	buffer_full 	{fail "$test (buffer_full)"}
	eof 		{fail "$test (eof)"; wait}
	-re "($any*)$nl" {
	    fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')"
Per Cederqvist's avatar
Per Cederqvist committed
74
	    exp_continue
Per Cederqvist's avatar
Per Cederqvist committed
75
76
77
78
79
80
81
	}
	-re "($any*)l2g>" {
	    fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')"
	}
    }
    unset test
}
Per Cederqvist's avatar
Per Cederqvist committed
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

proc lyskomd_start {} {
    global spawn_id
    global server_id
    global test
    global nl

    spawn ../lyskomd -d config/lyskomd-config
    set server_id $spawn_id
    set expect_active($server_id) ""
    set expect_always($server_id) ""

    talk_to lyskomd
    set test "server started"
    expect {
	-re "MSG: garb ready. 0 texts deleted.$nl" {pass "$test"}
	timeout         {fail "$test (timeout)"}
	buffer_full 	{fail "$test (buffer_full)"}
	eof 		{fail "$test (eof)"; wait}
    }
}

proc lyskomd_death {} {
    global spawn_id
    global server_id
    global test
    global nl

    talk_to lyskomd
    set test "server died"
    expect {
	-re "..*" { exp_continue }
	timeout  { fail "$test (timeout)" }
	eof      { pass "$test"; wait }
    }
}

proc client_start {nr} {
    global client_id
    global clientport
    global spawn_id
    global test
    global nl

    spawn tcpconnect -rv localhost $clientport
    set client_id($nr) $spawn_id

    talk_to client $nr

    set test "client $nr started"
    expect {
	-re ".Connected to..*port $clientport.$nl" {pass "$test"}
	timeout {fail "$test (timeout)"}
	eof     {fail "$test (eof)"}
	buffer_full {fail "$test (buffer_full)"}
    }
}

proc talk_to {what {nr ""}} {
    global spawn_id
    global server_id
    global client_id

    switch $what {
	lyskomd {
	    set spawn_id $server_id
	}
	client {
	    set spawn_id $client_id($nr)
	}
	default {
	    error "attempting to talk to $what"
	}
    }

    verbose "TALKING TO $spawn_id $what $nr"
}

proc holl {str} {
    return "[string length $str]H$str"
}