--- /dev/null
+# -*- 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
+}
--- /dev/null
+#!/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 "$@"
+++ /dev/null
-#!/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 "$@"
-
+++ /dev/null
-#!/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 "$@"
-
#!/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
--- /dev/null
+#!/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 "$@"