2022-05-12 02:42:50 +00:00
|
|
|
#!/bin/sh -e
|
2021-09-27 13:10:35 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#
|
|
|
|
# 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/run - Entry point to run test cases and demo
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Red Hat GmbH
|
|
|
|
# Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
|
|
|
|
# Start an X terminal and capture a video of the test run (also set for ./ci)
|
|
|
|
CI=${CI:-0}
|
|
|
|
|
|
|
|
# Start an X terminal and show the demo (also set for ./demo)
|
|
|
|
DEMO=${DEMO:-0}
|
|
|
|
|
|
|
|
# Base path for output files
|
|
|
|
BASEPATH=${BASEPATH:-"$(pwd)"}
|
|
|
|
|
|
|
|
# Location of log files for test run
|
|
|
|
LOGDIR=${LOGDIR:-"${BASEPATH}/test_logs"}
|
|
|
|
LOGFILE=${LOGFILE:-"${LOGDIR}/test.log"}
|
|
|
|
|
|
|
|
# If set, skip typing delays while issuing commands in panes
|
|
|
|
FAST=${FAST:-1}
|
|
|
|
|
|
|
|
# If set, run passt and pasta with debug options
|
|
|
|
DEBUG=${DEBUG:-0}
|
|
|
|
|
|
|
|
# If set, tell passt and pasta to take packet captures
|
|
|
|
PCAP=${PCAP:-0}
|
|
|
|
|
|
|
|
COMMIT="$(git log --oneline --no-decorate -1)"
|
|
|
|
|
|
|
|
. lib/util
|
|
|
|
. lib/setup
|
2022-10-31 09:25:30 +00:00
|
|
|
. lib/setup_ugly
|
2022-09-12 10:56:17 +00:00
|
|
|
. lib/context
|
2021-09-27 13:10:35 +00:00
|
|
|
. lib/term
|
|
|
|
. lib/perf_report
|
|
|
|
. lib/layout
|
2022-10-31 09:25:30 +00:00
|
|
|
. lib/layout_ugly
|
2021-09-27 13:10:35 +00:00
|
|
|
. lib/test
|
|
|
|
. lib/video
|
|
|
|
|
|
|
|
# cleanup() - Remove temporary files
|
|
|
|
cleanup() {
|
2022-09-13 04:35:19 +00:00
|
|
|
[ ${DEBUG} -eq 1 ] || rm -rf "${STATEBASE}"
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# run() - Call setup functions, run tests, handle exit from test session
|
|
|
|
run() {
|
2022-09-13 04:35:20 +00:00
|
|
|
mkfifo $STATEBASE/log_pipe
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
term
|
|
|
|
perf_init
|
2022-02-22 17:29:45 +00:00
|
|
|
[ ${CI} -eq 1 ] && video_start ci
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
setup build
|
2022-07-06 07:29:06 +00:00
|
|
|
test build/all
|
2022-08-18 06:13:50 +00:00
|
|
|
test build/cppcheck
|
|
|
|
test build/clang_tidy
|
2022-08-18 06:13:53 +00:00
|
|
|
teardown build
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
setup pasta
|
2022-09-13 04:35:16 +00:00
|
|
|
test pasta/ndp
|
|
|
|
test pasta/dhcp
|
|
|
|
test pasta/tcp
|
|
|
|
test pasta/udp
|
|
|
|
test passt/shutdown
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown pasta
|
|
|
|
|
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
|
|
|
setup pasta_options
|
|
|
|
test pasta_options/log_to_file
|
|
|
|
teardown pasta_options
|
|
|
|
|
test: Add memory/passt test cases
These show a summary of memory usage in kernel and userspace with
different port forwarding configurations, details of userspace usage
using 'nm' (passt only uses statically allocated memory), and details
of kernel memory from slab reporting facilities.
This adds a new test image, mbuto.mem.img, with harcoded IPv4 and
IPv6 addresses and routes, and just the tools we need to start and
stop passt, to report from /proc/slabinfo, /proc/meminfo, and to
print and parse symbol sizes using nm(1).
passt can't pivot_root() for sandboxing purposes on ramfs, so we need
to create another filesystem and chroot into it, first.
We don't want to use pane context functions, as we're checking memory
usage for sockets: resort to screen-scraping.
Configure a dummy interface to provide passt with an appearance of
working IPv4 and IPv6 connectivity, contributed by David.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
2022-10-31 11:20:59 +00:00
|
|
|
setup memory
|
|
|
|
test memory/passt
|
|
|
|
teardown memory
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
setup passt
|
2022-09-13 04:35:16 +00:00
|
|
|
test passt/ndp
|
|
|
|
test passt/dhcp
|
|
|
|
test passt/tcp
|
|
|
|
test passt/udp
|
|
|
|
test passt/shutdown
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown passt
|
|
|
|
|
2022-03-15 19:16:13 +00:00
|
|
|
VALGRIND=1
|
2021-09-27 13:10:35 +00:00
|
|
|
setup passt_in_ns
|
2022-09-13 04:35:16 +00:00
|
|
|
test passt/ndp
|
|
|
|
test passt/dhcp
|
|
|
|
test passt_in_ns/icmp
|
|
|
|
test passt_in_ns/tcp
|
|
|
|
test passt_in_ns/udp
|
|
|
|
test passt_in_ns/shutdown
|
2022-03-15 19:16:13 +00:00
|
|
|
teardown passt_in_ns
|
|
|
|
|
2022-10-14 04:25:27 +00:00
|
|
|
setup two_guests
|
|
|
|
test two_guests/basic
|
|
|
|
teardown two_guests
|
|
|
|
|
2022-03-15 19:16:13 +00:00
|
|
|
VALGRIND=0
|
|
|
|
setup passt_in_ns
|
2022-09-13 04:35:16 +00:00
|
|
|
test passt/ndp
|
|
|
|
test passt/dhcp
|
2022-07-06 07:29:06 +00:00
|
|
|
test perf/passt_tcp
|
|
|
|
test perf/passt_udp
|
|
|
|
test perf/pasta_tcp
|
|
|
|
test perf/pasta_udp
|
2022-09-13 04:35:16 +00:00
|
|
|
test passt_in_ns/shutdown
|
2021-09-27 13:10:35 +00:00
|
|
|
teardown passt_in_ns
|
|
|
|
|
2022-10-26 05:03:56 +00:00
|
|
|
# TODO: Make those faster by at least pre-installing gcc and make on
|
|
|
|
# non-x86 images, then re-enable.
|
|
|
|
skip_distro() {
|
2022-10-14 04:25:27 +00:00
|
|
|
setup distro
|
|
|
|
test distro/debian
|
|
|
|
test distro/fedora
|
|
|
|
test distro/opensuse
|
|
|
|
test distro/ubuntu
|
|
|
|
teardown distro
|
2022-10-26 05:03:56 +00:00
|
|
|
}
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
perf_finish
|
2022-02-22 17:29:45 +00:00
|
|
|
[ ${CI} -eq 1 ] && video_stop
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
log "PASS: ${STATUS_PASS}, FAIL: ${STATUS_FAIL}"
|
|
|
|
|
|
|
|
pause_continue \
|
|
|
|
"Press any key to keep test session open" \
|
|
|
|
"Closing in " \
|
|
|
|
"Interrupted, press any key to quit" \
|
|
|
|
9
|
|
|
|
|
2022-05-17 12:18:41 +00:00
|
|
|
return 0
|
2021-09-27 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 15:19:12 +00:00
|
|
|
# run_selected() - Run list of tests, with setup/teardown based on test path
|
|
|
|
# $@: List of tests
|
|
|
|
run_selected() {
|
|
|
|
mkfifo $STATEBASE/log_pipe
|
|
|
|
|
|
|
|
term
|
|
|
|
VALGRIND=1
|
|
|
|
|
|
|
|
__setup=
|
|
|
|
for __test; do
|
|
|
|
if [ "${__test%%/*}" != "${__setup}" ]; then
|
|
|
|
[ -n "${__setup}" ] && teardown "${__setup}"
|
|
|
|
__setup="${__test%%/*}"
|
|
|
|
setup "${__setup}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
test "${__test}"
|
|
|
|
done
|
|
|
|
teardown "${__setup}"
|
|
|
|
|
|
|
|
log "PASS: ${STATUS_PASS}, FAIL: ${STATUS_FAIL}"
|
|
|
|
|
|
|
|
pause_continue \
|
|
|
|
"Press any key to keep test session open" \
|
|
|
|
"Closing in " \
|
|
|
|
"Interrupted, press any key to quit" \
|
|
|
|
9
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
# demo() - Simpler path for demo purposes
|
|
|
|
demo() {
|
2022-09-13 04:35:20 +00:00
|
|
|
mkfifo $STATEBASE/log_pipe
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
FAST=0
|
|
|
|
|
|
|
|
term_demo
|
|
|
|
|
|
|
|
layout_demo_passt
|
2022-02-22 17:29:45 +00:00
|
|
|
video_start demo_passt
|
2022-07-06 07:29:06 +00:00
|
|
|
test demo/passt
|
2022-02-22 17:29:45 +00:00
|
|
|
video_stop
|
2021-09-29 14:45:26 +00:00
|
|
|
teardown demo_passt
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
layout_demo_pasta
|
2022-02-22 17:29:45 +00:00
|
|
|
video_start demo_pasta
|
2022-07-06 07:29:06 +00:00
|
|
|
test demo/pasta
|
2022-02-22 17:29:45 +00:00
|
|
|
video_stop
|
2022-02-21 12:35:45 +00:00
|
|
|
teardown demo_pasta
|
|
|
|
|
|
|
|
layout_demo_podman
|
2022-02-22 17:29:45 +00:00
|
|
|
video_start demo_podman
|
2022-07-06 07:29:06 +00:00
|
|
|
test demo/podman
|
2022-02-22 17:29:45 +00:00
|
|
|
video_stop
|
2022-02-21 12:35:45 +00:00
|
|
|
teardown_demo_podman
|
2021-09-27 13:10:35 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "$(basename "${0}")" = "ci" ] && CI=1
|
|
|
|
[ "$(basename "${0}")" = "run_demo" ] && DEMO=1
|
|
|
|
|
|
|
|
if [ "${1}" = "from_term" ]; then
|
2022-10-06 15:19:12 +00:00
|
|
|
shift
|
|
|
|
|
2022-08-18 06:13:57 +00:00
|
|
|
exec > ${LOGDIR}/script.log 2>&1
|
|
|
|
[ ${DEBUG} -eq 1 ] && set -x
|
2021-09-27 13:10:35 +00:00
|
|
|
cd ..
|
|
|
|
if [ ${DEMO} -eq 1 ]; then
|
|
|
|
demo
|
2022-10-06 15:19:12 +00:00
|
|
|
elif [ -n "${1}" ]; then
|
|
|
|
run_selected ${*}
|
2021-09-27 13:10:35 +00:00
|
|
|
else
|
|
|
|
run
|
|
|
|
fi
|
|
|
|
tmux kill-session -t passt_test
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
rm -rf "${LOGDIR}"
|
|
|
|
mkdir -p "${LOGDIR}"
|
|
|
|
:> "${LOGFILE}"
|
2022-09-13 04:35:19 +00:00
|
|
|
STATEBASE="$(mktemp -d --tmpdir passt-tests-XXXXXX)"
|
2021-09-27 13:10:35 +00:00
|
|
|
trap "cleanup" EXIT
|
2022-10-06 15:19:12 +00:00
|
|
|
run_term ${*}
|
2021-09-27 13:10:35 +00:00
|
|
|
fi
|
|
|
|
|
2021-09-29 14:45:26 +00:00
|
|
|
[ ${DEMO} -eq 1 ] && exit 0
|
|
|
|
|
2021-09-27 13:10:35 +00:00
|
|
|
tail -n1 ${LOGFILE}
|
|
|
|
echo "Log at ${LOGFILE}"
|
|
|
|
exit $(tail -n1 ${LOGFILE} | sed -n 's/.*FAIL: \(.*\)$/\1/p')
|