Skip to content
Snippets Groups Projects
Commit a92c9158 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(attach): New constant.

(line_leader): New variable.
(meta_line_leader): New variable.
(l2g_start): Set l2g_id, expect_active and expect_always.
(fix_expect_after): New proc.
(simple_expect): New argument: meta.  Handle line leaders.
	Removed tests for unexpected lines, which should now be handled
	via expect_active.
(unanchored_expect): Added missing quotes.
(lyskomd_start): Handle attach.  Set expect_active and
	expect_always to something sane.
(client_start): Use tcpconnect.py and line leaders to make it
	easier to debug the test cases.  Set expect_active and
	expect_always to something sane.
(talk_to): Handle l2g.  Handle line leaders.  Call fix_expect_after.
parent 9ebb1dc1
No related branches found
No related tags found
No related merge requests found
# Set this to 1 to cause the test suite to wait while you attach to
# the process that is being tested.
set attach 0
# Set this to 1 if test-l2g was linked with Electric Fence.
set efence 0
# Some useful constants.
set nl "\r?\n" set nl "\r?\n"
set any "\[ -\]" set any "\[ -\]"
set deep_any "\\\[ -\\\]" set deep_any "\\\[ -\\\]"
set hollerith "\[0-9\]*H$any*" set hollerith "\[0-9\]*H$any*"
set any_time "\[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]*"
set maxint 2147483647 set maxint 2147483647
...@@ -10,9 +19,12 @@ set maxint 2147483647 ...@@ -10,9 +19,12 @@ set maxint 2147483647
set clientport 53262 set clientport 53262
set muxport 53263 set muxport 53263
# Fix the tty settings for minimum impact on the data flow.
set stty_init "-echo -onlcr -ocrnl -istrip" set stty_init "-echo -onlcr -ocrnl -istrip"
set efence 0 # State variables.
set line_leader ""
set meta_line_leader ""
proc efence_blurb {} { proc efence_blurb {} {
global efence global efence
...@@ -28,8 +40,18 @@ proc l2g_start {} { ...@@ -28,8 +40,18 @@ proc l2g_start {} {
global spawn_id global spawn_id
global l2g global l2g
global efence global efence
global l2g_id
global deep_any
global nl
spawn $l2g spawn $l2g
set l2g_id $spawn_id
set expect_active($l2g_id) \
" -i $l2g_id eof { fail \"\$test (eof on l2g); wait\" } -re \"^($deep_any*)$nl\" { fail \"\$test (unexpected line '\$expect_out(1,string)')\" } -re \"($deep_any*)l2g> \" { fail \"\$test (unexpected incomplete line '\$expect_out(1,string)')\" } "
set expect_always($l2g_id) \
" -i $l2g_id buffer_full { fail \"\$test (buffer_full on l2g)\" }"
talk_to l2g
if {$efence} { if {$efence} {
l2g_send "I9" l2g_send "I9"
...@@ -53,26 +75,47 @@ proc l2g_send {str} { ...@@ -53,26 +75,47 @@ proc l2g_send {str} {
send "$str\n" send "$str\n"
} }
proc simple_expect {regex {testname ""}} { proc fix_expect_after {} {
global expect_always
global expect_active
global spawn_id
set stmt "expect_after"
foreach k [array names expect_always] {
set stmt "$stmt $expect_always($k)"
}
if {[info exists spawn_id] && [info exists expect_active($spawn_id)]} {
set stmt "$stmt $expect_active($spawn_id)"
}
set stmt "$stmt timeout { fail \"\$test (timeout)\" }"
verbose "evaluating $stmt" 2
eval $stmt
}
proc simple_expect {regex {testname ""} {is_meta ""}} {
global test global test
global any global any
global nl global nl
global line_leader
global meta_line_leader
if {$is_meta == "meta"} {
set ll $meta_line_leader
} else {
set ll $line_leader
}
set test $testname set test $testname
if {$test == ""} { if {$test == ""} {
set test "looking for $regex" set test "looking for $regex"
} }
expect { expect {
-re "^$regex$nl" {pass "$test"} -re "^$ll$regex$nl" {pass "$test"}
timeout {fail "$test (timeout)"} timeout {fail "$test (timeout)"}
eof {fail "$test (eof)"; wait} eof {fail "$test (eof)"; wait}
buffer_full {fail "$test (buffer_full)"} buffer_full {fail "$test (buffer_full)"}
-re "($any*)$nl" {
fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')"
}
-re "($any*)l2g> " {
fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')"
}
} }
unset test unset test
} }
...@@ -89,11 +132,11 @@ proc unanchored_expect {regex testname} { ...@@ -89,11 +132,11 @@ proc unanchored_expect {regex testname} {
buffer_full {fail "$test (buffer_full)"} buffer_full {fail "$test (buffer_full)"}
eof {fail "$test (eof)"; wait} eof {fail "$test (eof)"; wait}
-re "($any*)$nl" { -re "($any*)$nl" {
fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')" fail "$test (unexpected line '\$expect_out(1,string)' waiting for '$regex')"
exp_continue exp_continue
} }
-re "($any*)l2g>" { -re "($any*)l2g>" {
fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')" fail "$test (unexpected incomplete line '\$expect_out(1,string)' waiting for '$regex')"
} }
} }
unset test unset test
...@@ -104,11 +147,17 @@ proc lyskomd_start {} { ...@@ -104,11 +147,17 @@ proc lyskomd_start {} {
global server_id global server_id
global test global test
global nl global nl
global attach
global timeout
spawn ../lyskomd -d config/lyskomd-config set pid [spawn ../lyskomd -d config/lyskomd-config]
set server_id $spawn_id set server_id $spawn_id
set expect_active($server_id) "" set expect_active($server_id) ""
set expect_always($server_id) "" set expect_always($server_id) ""
set expect_active($server_id) \
" -i $server_id eof { fail \"\$test (eof on lyskomd); wait\" }"
set expect_always($server_id) \
" -i $server_id buffer_full { fail \"\$test (buffer_full on lyskomd)\" }"
talk_to lyskomd talk_to lyskomd
set test "server started" set test "server started"
...@@ -118,6 +167,15 @@ proc lyskomd_start {} { ...@@ -118,6 +167,15 @@ proc lyskomd_start {} {
buffer_full {fail "$test (buffer_full)"} buffer_full {fail "$test (buffer_full)"}
eof {fail "$test (eof)"; wait} eof {fail "$test (eof)"; wait}
} }
if {$attach} {
send_user "Please attach to lyskomd process $pid and press RETURN\n"
set timeout 3600
expect_user {
-re .
}
send_user "Continuing with timeout set to $timeout\n"
}
} }
proc lyskomd_death {} { proc lyskomd_death {} {
...@@ -141,25 +199,33 @@ proc client_start {nr} { ...@@ -141,25 +199,33 @@ proc client_start {nr} {
global spawn_id global spawn_id
global test global test
global nl global nl
global expect_always
global expect_active
global srcdir
spawn tcpconnect -rv localhost $clientport spawn python $srcdir/tcpconnect.py localhost $clientport MRK:client$nr
set client_id($nr) $spawn_id set client_id($nr) $spawn_id
set expect_active($client_id($nr)) " "
set expect_always($client_id($nr)) \
" -i $client_id($nr) eof { fail \"\$test (eof on client$nr); wait\" } -i $client_id($nr) buffer_full { fail \"\$test (buffer_full on client$nr)\" } "
talk_to client $nr talk_to client $nr
set test "client $nr started" simple_expect "Connecting to localhost $clientport" \
expect { "client connects" meta
-re ".Connected to..*port $clientport.$nl" {pass "$test"} simple_expect "Connected" "client connected" meta
timeout {fail "$test (timeout)"}
eof {fail "$test (eof)"}
buffer_full {fail "$test (buffer_full)"}
}
} }
proc talk_to {what {nr ""}} { proc talk_to {what {nr ""}} {
global spawn_id global spawn_id
global server_id global server_id
global client_id global client_id
global l2g_id
global line_leader
global meta_line_leader
set line_leader ""
set meta_line_leader ""
switch $what { switch $what {
lyskomd { lyskomd {
...@@ -167,13 +233,23 @@ proc talk_to {what {nr ""}} { ...@@ -167,13 +233,23 @@ proc talk_to {what {nr ""}} {
} }
client { client {
set spawn_id $client_id($nr) set spawn_id $client_id($nr)
set line_leader "MRK:client$nr"
}
l2g {
set spawn_id $l2g_id
} }
default { default {
error "attempting to talk to $what" error "attempting to talk to $what"
} }
} }
if {$line_leader != ""} {
set meta_line_leader "${line_leader}meta: "
set line_leader "${line_leader}: "
}
verbose "TALKING TO $spawn_id $what $nr" verbose "TALKING TO $spawn_id $what $nr"
fix_expect_after
} }
proc holl {str} { proc holl {str} {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment