2021-09-27 13:10:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
passt: Relicense to GPL 2.0, or any later version
In practical terms, passt doesn't benefit from the additional
protection offered by the AGPL over the GPL, because it's not
suitable to be executed over a computer network.
Further, restricting the distribution under the version 3 of the GPL
wouldn't provide any practical advantage either, as long as the passt
codebase is concerned, and might cause unnecessary compatibility
dilemmas.
Change licensing terms to the GNU General Public License Version 2,
or any later version, with written permission from all current and
past contributors, namely: myself, David Gibson, Laine Stump, Andrea
Bolognani, Paul Holzinger, Richard W.M. Jones, Chris Kuhn, Florian
Weimer, Giuseppe Scrivano, Stefan Hajnoczi, and Vasiliy Ulyanov.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2023-04-05 18:11:44 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2021-09-27 13:10:35 +00:00
|
|
|
#
|
|
|
|
# PASST - Plug A Simple Socket Transport
|
|
|
|
# for qemu/UNIX domain socket mode
|
|
|
|
#
|
|
|
|
# PASTA - Pack A Subtle Tap Abstraction
|
|
|
|
# for network namespace/tap device mode
|
|
|
|
#
|
|
|
|
# test/lib/setup - Set up and tear down passt and pasta environments
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Red Hat GmbH
|
|
|
|
# Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
|
2022-07-06 07:29:00 +00:00
|
|
|
INITRAMFS="${BASEPATH}/mbuto.img"
|
2021-10-21 02:54:05 +00:00
|
|
|
VCPUS="$( [ $(nproc) -ge 8 ] && echo 6 || echo $(( $(nproc) / 2 + 1 )) )"
|
2021-09-27 13:10:35 +00:00
|
|
|
__mem_kib="$(sed -n 's/MemTotal:[ ]*\([0-9]*\) kB/\1/p' /proc/meminfo)"
|
2021-10-21 02:54:05 +00:00
|
|
|
VMEM="$((${__mem_kib} / 1024 / 4))"
|
2023-04-06 03:28:06 +00:00
|
|
|
NSTOOL="${BASEPATH}/nstool"
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
# setup_build() - Set up pane layout for build tests
|
|
|
|
setup_build() {
|
2022-09-12 10:56:18 +00:00
|
|
|
context_setup_host host
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
layout_host
|
|
|
|
}
|
|
|
|
|
2022-07-06 07:29:00 +00:00
|
|
|
# setup_passt() - Start qemu and passt
|
2021-09-27 13:10:35 +00:00
|
|
|
setup_passt() {
|
2022-09-12 10:56:18 +00:00
|
|
|
context_setup_host host
|
2022-09-12 10:56:19 +00:00
|
|
|
context_setup_host passt
|
2022-09-12 10:56:22 +00:00
|
|
|
context_setup_host qemu
|
2022-09-12 10:56:18 +00:00
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
layout_passt
|
|
|
|
|
|
|
|
# Ports:
|
|
|
|
#
|
|
|
|
# guest | host
|
|
|
|
# --------------|---------------------
|
|
|
|
# 10001 as server | forwarded to guest
|
|
|
|
# 10003 | as server
|
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/passt.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
|
|
|
|
2022-09-12 10:56:19 +00:00
|
|
|
context_run passt "make clean"
|
|
|
|
context_run passt "make valgrind"
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg passt "valgrind --max-stackframe=$((4 * 1024 * 1024)) --trace-children=yes --vgdb=no --error-exitcode=1 --suppressions=test/valgrind.supp ./passt ${__opts} -s ${STATESETUP}/passt.socket -f -t 10001 -u 10001 -P ${STATESETUP}/passt.pid"
|
2022-09-26 10:43:38 +00:00
|
|
|
|
|
|
|
# pidfile isn't created until passt is listening
|
|
|
|
wait_for [ -f "${STATESETUP}/passt.pid" ]
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-09-12 10:56:22 +00:00
|
|
|
GUEST_CID=94557
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg qemu 'qemu-system-$(uname -m)' \
|
2022-07-06 07:28:58 +00:00
|
|
|
' -machine accel=kvm' \
|
|
|
|
' -m '${VMEM}' -cpu host -smp '${VCPUS} \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -kernel ' "/boot/vmlinuz-$(uname -r)" \
|
2022-07-06 07:29:00 +00:00
|
|
|
' -initrd '${INITRAMFS}' -nographic -serial stdio' \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -nodefaults' \
|
2022-11-04 01:16:21 +00:00
|
|
|
' -append "console=ttyS0 mitigations=off apparmor=0" ' \
|
|
|
|
' -device virtio-net-pci,netdev=s0 ' \
|
|
|
|
" -netdev stream,id=s0,server=off,addr.type=unix,addr.path=${STATESETUP}/passt.socket " \
|
2022-09-13 04:35:26 +00:00
|
|
|
" -pidfile ${STATESETUP}/qemu.pid" \
|
2022-09-12 10:56:22 +00:00
|
|
|
" -device vhost-vsock-pci,guest-cid=$GUEST_CID"
|
|
|
|
|
|
|
|
context_setup_guest guest $GUEST_CID
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup_pasta() - Create a network and user namespace, connect pasta to it
|
|
|
|
setup_pasta() {
|
2022-09-12 10:56:18 +00:00
|
|
|
context_setup_host host
|
2022-09-12 10:56:19 +00:00
|
|
|
context_setup_host passt
|
2022-09-12 10:56:21 +00:00
|
|
|
context_setup_host unshare
|
2022-09-12 10:56:18 +00:00
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
layout_pasta
|
|
|
|
|
2023-04-06 03:28:06 +00:00
|
|
|
context_run_bg unshare "unshare -rUnpf ${NSTOOL} ${STATESETUP}/ns.hold hold"
|
|
|
|
__target_pid=$(${NSTOOL} ${STATESETUP}/ns.hold pid)
|
2022-03-02 04:00:21 +00:00
|
|
|
|
2022-09-12 10:56:21 +00:00
|
|
|
context_setup_nsenter ns -U -n -p --preserve-credentials -t ${__target_pid}
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
# Ports:
|
|
|
|
#
|
|
|
|
# ns | host
|
|
|
|
# ------------------|---------------------
|
|
|
|
# 10002 as server | spliced to ns
|
|
|
|
# 10003 spliced to init | as server
|
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-09-13 04:35:26 +00:00
|
|
|
context_run_bg passt "./pasta ${__opts} -f -t 10002 -T 10003 -u 10002 -U 10003 -P ${STATESETUP}/passt.pid ${__target_pid}"
|
2022-09-26 10:43:38 +00:00
|
|
|
|
|
|
|
# pidfile isn't created until pasta is ready
|
|
|
|
wait_for [ -f "${STATESETUP}/passt.pid" ]
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup_passt_in_ns() - Set up namespace (with pasta), run qemu and passt into it
|
|
|
|
setup_passt_in_ns() {
|
2022-09-12 10:56:18 +00:00
|
|
|
context_setup_host host
|
2022-09-12 10:56:24 +00:00
|
|
|
context_setup_host pasta
|
2022-09-12 10:56:18 +00:00
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
layout_passt_in_pasta
|
|
|
|
|
|
|
|
# Ports:
|
|
|
|
#
|
|
|
|
# guest | ns | host
|
|
|
|
# -------------|--------------------|-----------------
|
|
|
|
# 10001 as server | forwarded to guest | spliced to ns
|
|
|
|
# 10002 | as server | spliced to ns
|
|
|
|
# 10003 | spliced to init | as server
|
|
|
|
# 10011 as server | forwarded to guest | spliced to ns
|
|
|
|
# 10012 | as server | spliced to ns
|
|
|
|
# 10013 | spliced to init | as server
|
2021-10-21 02:54:05 +00:00
|
|
|
#
|
|
|
|
# 10021 as server | forwarded to guest |
|
|
|
|
# 10031 as server | forwarded to guest |
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_with_passt.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2023-04-06 03:28:06 +00:00
|
|
|
context_run_bg pasta "./pasta ${__opts} -t 10001,10002,10011,10012 -T 10003,10013 -u 10001,10002,10011,10012 -U 10003,10013 -P ${STATESETUP}/pasta.pid --config-net ${NSTOOL} ${STATESETUP}/ns.hold hold"
|
2022-09-26 10:43:38 +00:00
|
|
|
wait_for [ -f "${STATESETUP}/pasta.pid" ]
|
2023-04-06 03:28:06 +00:00
|
|
|
__ns_pid=$(${NSTOOL} ${STATESETUP}/ns.hold pid)
|
2022-09-12 10:56:24 +00:00
|
|
|
|
|
|
|
context_setup_nsenter qemu "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
|
|
|
context_setup_nsenter ns "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
|
|
|
context_setup_nsenter passt "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/passt_in_pasta.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-03-15 19:16:13 +00:00
|
|
|
if [ ${VALGRIND} -eq 1 ]; then
|
2022-09-12 10:56:24 +00:00
|
|
|
context_run passt "make clean"
|
|
|
|
context_run passt "make valgrind"
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg passt "valgrind --max-stackframe=$((4 * 1024 * 1024)) --trace-children=yes --vgdb=no --error-exitcode=1 --suppressions=test/valgrind.supp ./passt -f ${__opts} -s ${STATESETUP}/passt.socket -t 10001,10011,10021,10031 -u 10001,10011,10021,10031 -P ${STATESETUP}/passt.pid"
|
2022-03-15 19:16:13 +00:00
|
|
|
else
|
2022-09-12 10:56:24 +00:00
|
|
|
context_run passt "make clean"
|
|
|
|
context_run passt "make"
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg passt "./passt -f ${__opts} -s ${STATESETUP}/passt.socket -t 10001,10011,10021,10031 -u 10001,10011,10021,10031 -P ${STATESETUP}/passt.pid"
|
2022-03-15 19:16:13 +00:00
|
|
|
fi
|
2022-09-26 10:43:38 +00:00
|
|
|
wait_for [ -f "${STATESETUP}/passt.pid" ]
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-09-12 10:56:24 +00:00
|
|
|
GUEST_CID=94557
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg qemu 'qemu-system-$(uname -m)' \
|
2022-07-06 07:28:58 +00:00
|
|
|
' -machine accel=kvm' \
|
|
|
|
' -M accel=kvm:tcg' \
|
|
|
|
' -m '${VMEM}' -cpu host -smp '${VCPUS} \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -kernel ' "/boot/vmlinuz-$(uname -r)" \
|
2022-07-06 07:29:00 +00:00
|
|
|
' -initrd '${INITRAMFS}' -nographic -serial stdio' \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -nodefaults' \
|
2022-11-04 01:16:21 +00:00
|
|
|
' -append "console=ttyS0 mitigations=off apparmor=0" ' \
|
|
|
|
' -device virtio-net-pci,netdev=s0 ' \
|
|
|
|
" -netdev stream,id=s0,server=off,addr.type=unix,addr.path=${STATESETUP}/passt.socket " \
|
2022-09-13 04:35:26 +00:00
|
|
|
" -pidfile ${STATESETUP}/qemu.pid" \
|
2022-09-12 10:56:24 +00:00
|
|
|
" -device vhost-vsock-pci,guest-cid=$GUEST_CID"
|
|
|
|
|
|
|
|
context_setup_guest guest $GUEST_CID
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup_two_guests() - Set up two namespace, run qemu and passt in both of them
|
|
|
|
setup_two_guests() {
|
2022-09-12 10:56:18 +00:00
|
|
|
context_setup_host host
|
2022-09-12 10:56:23 +00:00
|
|
|
context_setup_host pasta_1
|
|
|
|
context_setup_host pasta_2
|
2022-09-12 10:56:18 +00:00
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
layout_two_guests
|
|
|
|
|
|
|
|
# Ports:
|
|
|
|
#
|
|
|
|
# guest #1 | guest #2 | ns #1 | ns #2 | host
|
|
|
|
# --------- |-----------|-----------|------------|------------
|
|
|
|
# 10001 as server | | to guest | to init | to ns #1
|
|
|
|
# 10002 | | as server | | to ns #1
|
|
|
|
# 10003 | | to init | to init | as server
|
|
|
|
# 10004 | as server | to init | to guest | to ns #2
|
|
|
|
# 10005 | | | as server | to ns #2
|
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_1.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2023-04-06 03:28:06 +00:00
|
|
|
context_run_bg pasta_1 "./pasta ${__opts} --trace -l /tmp/pasta1.log -P ${STATESETUP}/pasta_1.pid -t 10001,10002 -T 10003,10004 -u 10001,10002 -U 10003,10004 --config-net ${NSTOOL} ${STATESETUP}/ns1.hold hold"
|
|
|
|
__ns1_pid=$(${NSTOOL} ${STATESETUP}/ns1.hold pid)
|
2022-09-12 10:56:23 +00:00
|
|
|
context_setup_nsenter passt_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_2.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2023-04-06 03:28:06 +00:00
|
|
|
context_run_bg pasta_2 "./pasta ${__opts} --trace -l /tmp/pasta2.log -P ${STATESETUP}/pasta_2.pid -t 10004,10005 -T 10003,10001 -u 10004,10005 -U 10003,10001 --config-net ${NSTOOL} ${STATESETUP}/ns2.hold hold"
|
|
|
|
__ns2_pid=$(${NSTOOL} ${STATESETUP}/ns2.hold pid)
|
2022-09-12 10:56:23 +00:00
|
|
|
context_setup_nsenter passt_2 -U -n -p --preserve-credentials -t ${__ns2_pid}
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-09-12 10:56:23 +00:00
|
|
|
context_setup_nsenter qemu_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
|
|
|
context_setup_nsenter qemu_2 -U -n -p --preserve-credentials -t ${__ns2_pid}
|
|
|
|
|
|
|
|
__ifname="$(context_run qemu_1 "ip -j link show | jq -rM '.[] | select(.link_type == \"ether\").ifname'")"
|
|
|
|
|
2022-11-04 01:08:48 +00:00
|
|
|
sleep 1
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/passt_1.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
|
|
|
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg passt_1 "./passt -s ${STATESETUP}/passt_1.socket -P ${STATESETUP}/passt_1.pid -f ${__opts} -t 10001 -u 10001"
|
2022-09-26 10:43:38 +00:00
|
|
|
wait_for [ -f "${STATESETUP}/passt_1.pid" ]
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
__opts=
|
2022-09-13 04:35:25 +00:00
|
|
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/passt_2.pcap"
|
2021-09-27 13:10:35 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
2022-03-14 23:59:09 +00:00
|
|
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg passt_2 "./passt -s ${STATESETUP}/passt_2.socket -P ${STATESETUP}/passt_2.pid -f ${__opts} -t 10004 -u 10004"
|
2022-09-26 10:43:38 +00:00
|
|
|
wait_for [ -f "${STATESETUP}/passt_2.pid" ]
|
2022-09-12 10:56:23 +00:00
|
|
|
|
|
|
|
GUEST_1_CID=94557
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg qemu_1 'qemu-system-$(uname -m)' \
|
2022-07-06 07:28:58 +00:00
|
|
|
' -M accel=kvm:tcg' \
|
|
|
|
' -m '${VMEM}' -cpu host -smp '${VCPUS} \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -kernel ' "/boot/vmlinuz-$(uname -r)" \
|
2022-07-06 07:29:00 +00:00
|
|
|
' -initrd '${INITRAMFS}' -nographic -serial stdio' \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -nodefaults' \
|
2022-11-04 01:16:21 +00:00
|
|
|
' -append "console=ttyS0 mitigations=off apparmor=0" ' \
|
|
|
|
' -device virtio-net-pci,netdev=s0 ' \
|
|
|
|
" -netdev stream,id=s0,server=off,addr.type=unix,addr.path=${STATESETUP}/passt_1.socket " \
|
2022-09-13 04:35:26 +00:00
|
|
|
" -pidfile ${STATESETUP}/qemu_1.pid" \
|
2022-09-12 10:56:23 +00:00
|
|
|
" -device vhost-vsock-pci,guest-cid=$GUEST_1_CID"
|
|
|
|
|
|
|
|
GUEST_2_CID=94558
|
2022-11-04 01:16:21 +00:00
|
|
|
context_run_bg qemu_2 'qemu-system-$(uname -m)' \
|
2022-07-06 07:28:58 +00:00
|
|
|
' -M accel=kvm:tcg' \
|
|
|
|
' -m '${VMEM}' -cpu host -smp '${VCPUS} \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -kernel ' "/boot/vmlinuz-$(uname -r)" \
|
2022-07-06 07:29:00 +00:00
|
|
|
' -initrd '${INITRAMFS}' -nographic -serial stdio' \
|
2022-01-26 06:32:56 +00:00
|
|
|
' -nodefaults' \
|
2022-11-04 01:16:21 +00:00
|
|
|
' -append "console=ttyS0 mitigations=off apparmor=0" ' \
|
|
|
|
' -device virtio-net-pci,netdev=s0 ' \
|
|
|
|
" -netdev stream,id=s0,server=off,addr.type=unix,addr.path=${STATESETUP}/passt_2.socket " \
|
2022-09-13 04:35:26 +00:00
|
|
|
" -pidfile ${STATESETUP}/qemu_2.pid" \
|
2022-09-12 10:56:23 +00:00
|
|
|
" -device vhost-vsock-pci,guest-cid=$GUEST_2_CID"
|
|
|
|
|
|
|
|
context_setup_guest guest_1 ${GUEST_1_CID}
|
|
|
|
context_setup_guest guest_2 ${GUEST_2_CID}
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 10:56:18 +00:00
|
|
|
# teardown_context_watch() - Remove contexts and stop panes watching them
|
|
|
|
# $1: Pane number watching
|
|
|
|
# $@: Context names
|
|
|
|
teardown_context_watch() {
|
|
|
|
__pane="$1"
|
|
|
|
shift
|
|
|
|
for __c; do
|
|
|
|
context_teardown "${__c}"
|
|
|
|
done
|
|
|
|
tmux send-keys -t ${__pane} "C-c"
|
|
|
|
}
|
|
|
|
|
2022-08-18 06:13:53 +00:00
|
|
|
# teardown_build() - Nothing to do, yet
|
|
|
|
teardown_build() {
|
2022-09-12 10:56:18 +00:00
|
|
|
teardown_context_watch ${PANE_HOST} host
|
2022-08-18 06:13:53 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 19:16:13 +00:00
|
|
|
# teardown_passt() - Kill qemu, remove passt PID file
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown_passt() {
|
2022-09-13 04:35:26 +00:00
|
|
|
kill $(cat "${STATESETUP}/qemu.pid")
|
2022-09-12 10:56:22 +00:00
|
|
|
|
2022-09-13 04:35:26 +00:00
|
|
|
rm "${STATESETUP}/passt.pid"
|
2022-09-12 10:56:18 +00:00
|
|
|
|
|
|
|
teardown_context_watch ${PANE_HOST} host
|
2022-09-12 10:56:19 +00:00
|
|
|
teardown_context_watch ${PANE_PASST} passt
|
2022-09-12 10:56:22 +00:00
|
|
|
teardown_context_watch ${PANE_GUEST} qemu guest
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
test: Add log file tests for pasta plus corresponding layout and setup
To test log files on a tmpfs mount, we need to unshare the mount
namespace, which means using a context for the passt pane is not
really practical at the moment, as we can't open a shell there, so
we would have to encapsulate all the commands under 'unshare -rUm',
plus the "inner" pasta command, running in turn a tcp_rr server.
It might be worth fixing this by e.g. detecting we are trying to
spawn an interactive shell and adding a special path in the context
setup with some form of stdin redirection -- I'm not sure it's doable
though.
For this reason, add a new layout, using a context only for the host
pane, while keeping the old command dispatch mechanism for the passt
pane.
We also need a new setup function that doesn't start pasta: we want
to start and restart it with different options.
Further, we need a 'pint' directive, to send an interrupt to the
passt pane: add that in lib/test.
All the tests before the one involving tmpfs and a detached mount
namespace were also tested with the context mechanism. To make an
eventual conversion easier, pass tcp_crr directly as a command on
pasta's command line where feasible.
While at it, fix the comment to the teardown_pasta() function.
The new test set can be semi-conveniently run as:
./run pasta_options/log_to_file
and it checks basic log creation, size of the log file after flooding
it with debug entries, rotations, and basic consistency after
rotations, on both an existing filesystem and a tmpfs, chosen as
it doesn't support collapsing data ranges via fallocate(), hence
triggering the fall-back mechanism for logging rotation.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-10-07 00:16:08 +00:00
|
|
|
# teardown_pasta() - Exit namespace, kill pasta process
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown_pasta() {
|
2023-04-06 03:28:06 +00:00
|
|
|
${NSTOOL} "${STATESETUP}/ns.hold" stop
|
2022-09-12 10:56:21 +00:00
|
|
|
context_wait unshare
|
2022-09-12 10:56:18 +00:00
|
|
|
|
|
|
|
teardown_context_watch ${PANE_HOST} host
|
2022-09-12 10:56:19 +00:00
|
|
|
teardown_context_watch ${PANE_PASST} passt
|
2022-09-12 10:56:21 +00:00
|
|
|
teardown_context_watch ${PANE_NS} unshare ns
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 19:16:13 +00:00
|
|
|
# teardown_passt_in_ns() - Exit namespace, kill qemu and pasta, remove pid file
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown_passt_in_ns() {
|
2022-09-13 04:35:26 +00:00
|
|
|
context_run ns kill $(cat "${STATESETUP}/qemu.pid")
|
2022-09-12 10:56:24 +00:00
|
|
|
context_wait qemu
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2023-04-06 03:28:06 +00:00
|
|
|
${NSTOOL} "${STATESETUP}/ns.hold" stop
|
2022-09-12 10:56:24 +00:00
|
|
|
context_wait pasta
|
2021-09-27 13:10:35 +00:00
|
|
|
|
2022-09-13 04:35:26 +00:00
|
|
|
rm "${STATESETUP}/passt.pid" "${STATESETUP}/pasta.pid"
|
2022-09-12 10:56:18 +00:00
|
|
|
|
|
|
|
teardown_context_watch ${PANE_HOST} host
|
2022-09-12 10:56:24 +00:00
|
|
|
teardown_context_watch ${PANE_PASST} pasta passt
|
|
|
|
teardown_context_watch ${PANE_NS} ns
|
|
|
|
teardown_context_watch ${PANE_GUEST} qemu guest
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# teardown_two_guests() - Exit namespaces, kill qemu processes, passt and pasta
|
|
|
|
teardown_two_guests() {
|
2023-04-06 03:28:06 +00:00
|
|
|
__ns1_pid=$(${NSTOOL} "${STATESETUP}/ns1.hold" pid)
|
|
|
|
__ns2_pid=$(${NSTOOL} "${STATESETUP}/ns2.hold" pid)
|
2022-09-13 04:35:26 +00:00
|
|
|
nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/qemu_1.pid")
|
|
|
|
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/qemu_2.pid")
|
2022-09-12 10:56:23 +00:00
|
|
|
context_wait qemu_1
|
|
|
|
context_wait qemu_2
|
|
|
|
|
2022-09-13 04:35:26 +00:00
|
|
|
nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/passt_1.pid")
|
|
|
|
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/passt_2.pid")
|
2022-09-12 10:56:23 +00:00
|
|
|
context_wait passt_1
|
|
|
|
context_wait passt_2
|
2023-04-06 03:28:06 +00:00
|
|
|
${NSTOOL} "${STATESETUP}/ns1.hold" stop
|
|
|
|
${NSTOOL} "${STATESETUP}/ns2.hold" stop
|
2022-09-12 10:56:23 +00:00
|
|
|
context_wait pasta_1
|
|
|
|
context_wait pasta_2
|
|
|
|
|
2022-09-13 04:35:26 +00:00
|
|
|
rm -f "${STATESETUP}/passt__[12].pid" "${STATESETUP}/pasta_[12].pid"
|
2022-09-12 10:56:18 +00:00
|
|
|
|
|
|
|
teardown_context_watch ${PANE_HOST} host
|
2022-09-12 10:56:23 +00:00
|
|
|
teardown_context_watch ${PANE_GUEST_1} qemu_1 guest_1
|
|
|
|
teardown_context_watch ${PANE_GUEST_2} qemu_2 guest_2
|
|
|
|
teardown_context_watch ${PANE_PASST_1} pasta_1 passt_1
|
|
|
|
teardown_context_watch ${PANE_PASST_2} pasta_2 passt_2
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 14:45:26 +00:00
|
|
|
# teardown_demo_passt() - Exit namespace, kill qemu, passt and pasta
|
|
|
|
teardown_demo_passt() {
|
|
|
|
tmux send-keys -t ${PANE_GUEST} "C-c"
|
|
|
|
pane_wait GUEST
|
|
|
|
|
2022-07-21 12:01:28 +00:00
|
|
|
tmux send-keys -t ${PANE_GUEST} "C-d"
|
2021-09-29 14:45:26 +00:00
|
|
|
tmux send-keys -t ${PANE_PASST} "C-c"
|
|
|
|
|
|
|
|
pane_wait GUEST
|
|
|
|
pane_wait HOST
|
|
|
|
pane_wait PASST
|
2022-02-21 12:35:45 +00:00
|
|
|
|
|
|
|
tmux kill-pane -a -t 0
|
|
|
|
tmux send-keys -t 0 "C-c"
|
2021-09-29 14:45:26 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 12:35:45 +00:00
|
|
|
# teardown_demo_pasta() - Exit perf and namespace from remaining pane
|
2021-09-29 14:45:26 +00:00
|
|
|
teardown_demo_pasta() {
|
2022-02-21 12:35:45 +00:00
|
|
|
tmux send-keys -t ${PANE_NS} "q"
|
|
|
|
pane_wait NS
|
2021-09-29 14:45:26 +00:00
|
|
|
tmux send-keys -t ${PANE_NS} "C-d"
|
|
|
|
pane_wait NS
|
2022-02-21 12:35:45 +00:00
|
|
|
|
|
|
|
tmux kill-pane -a -t 0
|
|
|
|
tmux send-keys -t 0 "C-c"
|
|
|
|
}
|
|
|
|
|
|
|
|
# teardown_demo_podman() - Exit namespaces
|
|
|
|
teardown_demo_podman() {
|
|
|
|
tmux send-keys -t ${PANE_NS1} "C-d"
|
|
|
|
tmux send-keys -t ${PANE_NS2} "C-d"
|
|
|
|
pane_wait NS1
|
|
|
|
pane_wait NS2
|
|
|
|
|
|
|
|
tmux kill-pane -a -t 0
|
|
|
|
tmux send-keys -t 0 "C-c"
|
2021-09-29 14:45:26 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
# setup() - Run setup_*() functions
|
|
|
|
# $*: Suffix list of setup_*() functions to be called
|
|
|
|
setup() {
|
|
|
|
for arg do
|
2022-09-13 04:35:19 +00:00
|
|
|
STATESETUP="${STATEBASE}/${arg}"
|
|
|
|
mkdir -p "${STATESETUP}"
|
2021-09-27 13:10:35 +00:00
|
|
|
eval setup_${arg}
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# teardown() - Run teardown_*() functions
|
|
|
|
# $*: Suffix list of teardown_*() functions to be called
|
|
|
|
teardown() {
|
|
|
|
for arg do
|
|
|
|
eval teardown_${arg}
|
|
|
|
done
|
|
|
|
}
|