chiark / gitweb /
a passing test!
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Aug 2021 21:24:52 +0000 (22:24 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Aug 2021 21:26:26 +0000 (22:26 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
test/common [new file with mode: 0644]
test/go-with-unshare [new file with mode: 0755]
test/run-client [deleted file]
test/run-server [deleted file]
test/t-basic
test/with-unshare [new file with mode: 0755]

diff --git a/test/common b/test/common
new file mode 100644 (file)
index 0000000..428d954
--- /dev/null
@@ -0,0 +1,80 @@
+# -*- shell-script -*-
+# Copyright 2021 Ian Jackson and contributors to Hippotat
+# SPDX-License-Identifier: GPL-3.0-or-later
+# There is NO WARRANTY.
+
+set -x
+
+ssrc="${0%/*}"
+src="${ssrc%/*}"
+test="${ssrc%/*}/test"
+
+fail () { echo >&2 "$0: fail: $*"; exit 1; }
+
+test-prep () {
+
+    case "${0##*/}" in
+    t-*) tname="${0##*/t-}" ;;
+    *) fail "bad test script name $0" ;;
+    esac
+
+    tmp=tmp/$tname
+    rm -rf "$tmp"
+    mkdir -p $tmp
+
+    $test/netns-setup "$tname"
+
+    trap '
+       rc=$?
+       shutdown
+       if [ $rc = 0 ]; then echo "OK $tname"; fi
+    ' 0
+}
+
+kill-pids () {
+    for p in $pids; do kill -9 $p; done
+}
+
+shutdown () {
+    kill-pids
+}
+
+in-ns () {
+    local client_server=$1; shift
+    $exec ip netns exec hippotat-t-$tname-$client_server "$@"
+}
+
+run-client () {
+    in-ns client \
+    target/debug/hippotat --config $test/test.cfg -DD "$@"
+}
+run-server () {
+    in-ns server \
+    target/debug/hippotatd --config $test/test.cfg -DD "$@"
+}
+spawn () {
+    { exec=exec; "$@"; } &
+    pids+=" $!"
+}
+
+in-ns-await-up () {
+    local sc="$1"; shift
+    local addr="$1"; shift
+    local t=1
+    while sleep $(( $t / 10 )).$(( $t % 10 )); do
+       if in-ns $sc ip -o addr show | fgrep " inet $addr "; then
+           return
+       fi
+       t=$(( $t + 1 ))
+       if [ $t -gt 10 ]; then fail "$sc did not come up $addr"; fi
+    done
+}
+
+start-server () {
+    spawn run-server
+    in-ns-await-up server 192.0.2.1
+}
+start-client () {
+    spawn run-client
+    in-ns-await-up client 192.0.2.3
+}
diff --git a/test/go-with-unshare b/test/go-with-unshare
new file mode 100755 (executable)
index 0000000..ef8825e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+# Copyright 2021 Ian Jackson and contributors to Hippotat
+# SPDX-License-Identifier: GPL-3.0-or-later
+# There is NO WARRANTY.
+
+set -e
+. "${0%/*}"/common
+
+case "$1" in
+*/*) ;;
+?*) tname="$1"; shift; set -- "$test/$tname" "$@" ;;
+'') fail 'bad usage: need program or test name' ;;
+esac
+
+$src/test/with-unshare "$@"
diff --git a/test/run-client b/test/run-client
deleted file mode 100755 (executable)
index 9b20eb7..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-# Copyright 2021 Ian Jackson and contributors to Hippotat
-# SPDX-License-Identifier: GPL-3.0-or-later
-# There is NO WARRANTY.
-
-set -e
-slug=$1; if [ $# -gt 0 ]; then shift; fi
-
-if [ "x$1" = x--- ]; then
-       shift
-else
-       set target/debug/hippotat --config src/test/test.cfg --debug "$@"
-fi
-
-ip netns exec hippotat-t-$slug-client "$@"
-
diff --git a/test/run-server b/test/run-server
deleted file mode 100755 (executable)
index 8b99b83..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-# Copyright 2021 Ian Jackson and contributors to Hippotat
-# SPDX-License-Identifier: GPL-3.0-or-later
-# There is NO WARRANTY.
-
-set -e
-slug=$1; if [ $# -gt 0 ]; then shift; fi
-
-if [ "x$1" = x--- ]; then
-       shift
-else
-       set target/debug/hippotatd --config src/test/test.cfg --debug "$@"
-fi
-
-ip netns exec hippotat-t-$slug-server "$@"
-
index 3dbc7826f344def3c69fe6572ab662f70ba00ce8..b1c145e4072c0c629b8f07553276c2ce8b0ce985 100755 (executable)
@@ -1,24 +1,14 @@
 #!/bin/bash
-set -ex
+# Copyright 2021 Ian Jackson and contributors to Hippotat
+# SPDX-License-Identifier: GPL-3.0-or-later
+# There is NO WARRANTY.
 
-# expects to be run inside the uml
+set -e
+. "${0%/*}"/common
+test-prep
 
-fail () { echo >&2 "$0: fail: $*"; exit 1; }
+start-server
+start-client
 
-tname="${0#**/t-}"
-case "$tname" in
-.* | */* | '') fail "bad tname $tname" ;;#
-esac
-
-test="${0%/*}"
-
-tmp=tmp/$tname
-rm -rf "$tmp"
-mkdir -p $tmp
-
-$test/netns-setup "$tname"
-$test/run-server "$tname" &   spid=$!
-$test/run-client "$tname" &   cpid=$1
-
-$test/netns-run-client "$tname" -- ping -c 10 192.0.2.1 >$tmp/ping
+in-ns client ping -c 10 192.0.2.1 >$tmp/ping
 grep ' 0% packet loss' $tmp/ping
diff --git a/test/with-unshare b/test/with-unshare
new file mode 100755 (executable)
index 0000000..f1fdadd
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+# Copyright 2021 Ian Jackson and contributors to Hippotat
+# SPDX-License-Identifier: GPL-3.0-or-later
+# There is NO WARRANTY.
+
+set -e
+. "${0%/*}"/common
+
+
+#case "$1" in
+#T/*)  prog="$src/test/${1#T/}"; shift; set -- "$prog" "$@" ;;
+#esac
+
+unshare -Urnm bash -xec '
+       mount -t tmpfs tmpfs /run
+       PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin"
+       exec "$@"
+' x "$@"