chiark / gitweb /
test: Fix fd plumbing
[secnet.git] / test / invoke
index 69aa0da67b63cf999dcf60db6cb00db5c459e59f..fb9ce2ca1b389673765f631f45956c065cc7a895 100755 (executable)
@@ -34,17 +34,19 @@ proc mkconf {which} {
        set netlinkfh($which.$tr) [set fh [open $pipefp.$tr r+]]
        fconfigure $fh -blocking 0 -buffering none -translation binary
     }
-    fileevent $netlinkfh($which.t) readable [list netlink-readable $which]
+    fileevent $netlinkfh($which.r) readable [list netlink-readable $which]
     set fakeuf test/$which.fake-userv
     set fakeuh [open $fakeuf w 0755]
     puts $fakeuh "#!/bin/sh
 set -e
-cat >$pipefp.t &
-exec 3<>$pipefp.r
-exec <$pipefp.r
+exec 3<&0
+cat <&3 3<&- >$pipefp.r &
+exec 3<>$pipefp.t
+exec <$pipefp.t
 exec 3<&-
 exec cat
 "
+    close $fakeuh
     set cfg "
        netlink userv-ipif {
            name \"netlink\";
@@ -90,6 +92,7 @@ exec cat
 }
 
 proc spawn-secnet {which} {
+    global netlinkfh
     upvar #0 pids($which) pid
     set cf test/$which.conf
     set ch [open $cf w]
@@ -100,7 +103,41 @@ proc spawn-secnet {which} {
     if {!$pid} {
        execl ./secnet $argl
     }
+    puts -nonewline $netlinkfh($which.t) "\xc0"
+}
+
+proc netlink-readable {which} {
+    global ok
+    upvar #0 netlinkfh($which.r) fh
+    read $fh; # empty the buffer
+    switch -exact $which {
+       outside {
+           puts OK
+           set ok 1; # what a bodge
+           return
+       }
+       inside {
+           error "inside rx'd!"
+       }
+    }
+}
+
+proc bgerror {message} {
+    global errorInfo errorCode
+    catch {
+       puts stderr "
+----------------------------------------
+$errorInfo
+
+$errorCode
+$message
+----------------------------------------
+    "
+    }
+    exit 1
 }
 
 spawn-secnet inside
 spawn-secnet outside
+
+vwait ok