1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
#!/bin/sh -e
#
# SPDX-License-Identifier: GPL-2.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, run passt and pasta with trace options
TRACE=${TRACE:-0}
# If set, tell passt and pasta to take packet captures
PCAP=${PCAP:-0}
COMMIT="$(git log --oneline --no-decorate -1)"
. lib/util
. lib/context
. lib/setup
. lib/setup_ugly
. lib/term
. lib/perf_report
. lib/layout
. lib/layout_ugly
. lib/test
. lib/video
# cleanup() - Remove temporary files
cleanup() {
[ ${DEBUG} -eq 1 ] || rm -rf "${STATEBASE}"
}
# run() - Call setup functions, run tests, handle exit from test session
run() {
mkfifo $STATEBASE/log_pipe
term
perf_init
[ ${CI} -eq 1 ] && video_start ci
setup build
test build/all
test build/cppcheck
test build/clang_tidy
teardown build
setup pasta
test pasta/ndp
test pasta/dhcp
test pasta/tcp
test pasta/udp
test passt/shutdown
teardown pasta
setup pasta_options
test pasta_options/log_to_file
teardown pasta_options
setup build
test pasta_podman/bats
teardown build
setup memory
test memory/passt
teardown memory
setup passt
test passt/ndp
test passt/dhcp
test passt/tcp
test passt/udp
test passt/shutdown
teardown passt
VALGRIND=1
setup passt_in_ns
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
teardown passt_in_ns
setup two_guests
test two_guests/basic
teardown two_guests
VALGRIND=0
setup passt_in_ns
test passt/ndp
test passt/dhcp
test perf/passt_tcp
test perf/passt_udp
test perf/pasta_tcp
test perf/pasta_udp
test passt_in_ns/shutdown
teardown passt_in_ns
# TODO: Make those faster by at least pre-installing gcc and make on
# non-x86 images, then re-enable.
skip_distro() {
setup distro
test distro/debian
test distro/fedora
test distro/opensuse
test distro/ubuntu
teardown distro
}
perf_finish
[ ${CI} -eq 1 ] && video_stop
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
}
# 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
}
# demo() - Simpler path for demo purposes
demo() {
mkfifo $STATEBASE/log_pipe
FAST=0
term_demo
layout_demo_passt
video_start demo_passt
test demo/passt
video_stop
teardown demo_passt
layout_demo_pasta
video_start demo_pasta
test demo/pasta
video_stop
teardown demo_pasta
layout_demo_podman
video_start demo_podman
test demo/podman
video_stop
teardown_demo_podman
return 0
}
[ "$(basename "${0}")" = "ci" ] && CI=1
[ "$(basename "${0}")" = "run_demo" ] && DEMO=1
if [ "${1}" = "from_term" ]; then
shift
exec > ${LOGDIR}/script.log 2>&1
[ ${DEBUG} -eq 1 ] && set -x
cd ..
if [ ${DEMO} -eq 1 ]; then
demo
elif [ -n "${1}" ]; then
run_selected ${*}
else
run
fi
tmux kill-session -t passt_test
exit
else
rm -rf "${LOGDIR}"
mkdir -p "${LOGDIR}"
:> "${LOGFILE}"
STATEBASE="$(mktemp -d --tmpdir passt-tests-XXXXXX)"
trap "cleanup" EXIT
run_term ${*}
fi
[ ${DEMO} -eq 1 ] && exit 0
tail -n1 ${LOGFILE}
echo "Log at ${LOGFILE}"
exit $(tail -n1 ${LOGFILE} | sed -n 's/.*FAIL: \(.*\)$/\1/p')
|