@@ -51,9 +51,13 @@ set_trace_on
51
51
: " ${INPUT_SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES:= 1} "
52
52
: " ${INPUT_SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY:= 0} "
53
53
: " ${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE:= 1} "
54
+ : " ${INPUT_HOSTNAME:= " mptcpdev" } "
54
55
: " ${INPUT_CPUS:= " " } "
55
56
: " ${INPUT_RAM:= " " } "
56
57
: " ${INPUT_GCOV:= " " } "
58
+ : " ${INPUT_NET_BRIDGES:= " " } "
59
+ : " ${INPUT_MAC_ADDRESS_PREFIX:= " " } "
60
+ : " ${INPUT_VSOCK_CID:= " 3" } "
57
61
: " ${INPUT_CI_RESULTS_DIR:= " " } "
58
62
: " ${INPUT_CI_PRINT_EXIT_CODE:= 1} "
59
63
: " ${INPUT_CI_TIMEOUT_SEC:= 5400} "
@@ -98,6 +102,7 @@ VIRTME_SCRIPT_UNEXPECTED_STOP="Unexpected stop of the VM"
98
102
VIRTME_SCRIPT_TIMEOUT=" ${VIRTME_SCRIPTS_DIR} /tests.timeout"
99
103
VIRTME_RUN_SCRIPT=" ${VIRTME_SCRIPTS_DIR} /virtme.sh"
100
104
VIRTME_RUN_EXPECT=" ${VIRTME_SCRIPTS_DIR} /virtme.expect"
105
+ VIRTME_CONSOLE=" ${VIRTME_SCRIPTS_DIR} /console.sh"
101
106
102
107
SELFTESTS_DIR=" ${INPUT_SELFTESTS_DIR:- tools/ testing/ selftests/ net/ mptcp} "
103
108
SELFTESTS_CONFIG=" ${SELFTESTS_DIR} /config"
@@ -110,14 +115,15 @@ VIRTME_CONFIGKERNEL="virtme-configkernel"
110
115
VIRTME_RUN=" virtme-run"
111
116
VIRTME_RUN_OPTS=(
112
117
--arch " ${VIRTME_ARCH} "
113
- --name " mptcpdev " # hostname
118
+ --name " ${INPUT_HOSTNAME} "
114
119
--mods=auto
115
120
--rw # Don't use "rwdir", it will use 9p ; in a container, we can use rw
116
121
--pwd
117
122
--show-command
118
123
--verbose --show-boot-console
119
124
--kopt mitigations=off
120
125
)
126
+ VIRTME_RUN_QEMU_OPTS=()
121
127
122
128
# results dir
123
129
RESULTS_DIR_BASE=" ${VIRTME_WORKDIR} /results"
@@ -204,6 +210,94 @@ _get_results_dir() {
204
210
echo " ${RESULTS_DIR_BASE} /$( git rev-parse --short HEAD || echo " UNKNOWN" ) /${1} "
205
211
}
206
212
213
+ # $1: pid
214
+ kill_wait () {
215
+ local pid=" ${1} "
216
+ if [ -z " ${pid} " ]; then
217
+ return
218
+ fi
219
+
220
+ kill " ${pid} "
221
+ while [ -d " /proc/${pid} " ]; do
222
+ sleep 0.1
223
+ done
224
+ }
225
+
226
+ # $1: bridge name
227
+ _add_bridge () { local router static
228
+ local br=" ${1} "
229
+
230
+ local i=" ${br// [^0-9]/ } " # only the numbers
231
+ local prefix=" 10.0.${i} "
232
+ local conf=" /tmp/udhcpd-${br} .conf"
233
+ local pidfile=" /var/run/udhcpd-${br} .pid"
234
+ local leases=" /var/lib/misc/udhcpd-${br} .leases"
235
+
236
+ VIRTME_RUN_OPTS+=(" --net=bridge=${br} " )
237
+
238
+ if [ -n " ${INPUT_MAC_ADDRESS_PREFIX} " ]; then
239
+ static=" static_lease ${INPUT_MAC_ADDRESS_PREFIX% =* } :0${i} ${prefix} .${INPUT_MAC_ADDRESS_PREFIX#* =} "
240
+ fi
241
+
242
+ # already launched?
243
+ if grep -wq " ${br} " /etc/qemu/bridge.conf; then
244
+ if [ -n " ${static} " ]; then
245
+ echo " ${static} " >> " ${conf} "
246
+ kill_wait " $( < " ${pidfile} " ) "
247
+ busybox udhcpd " ${conf} "
248
+ fi
249
+
250
+ return 0
251
+ fi
252
+
253
+ echo " allow ${br} " >> /etc/qemu/bridge.conf
254
+ brctl addbr " ${br} "
255
+ ip addr add " ${prefix} .1/24" dev " ${br} "
256
+ ip link set " ${br} " up
257
+
258
+ # one default address
259
+ if [ " ${i} " = " 0" ]; then
260
+ router=" opt router ${prefix} .1"
261
+ fi
262
+
263
+ cat << -EOF > "${conf} "
264
+ start ${prefix} .2
265
+ end ${prefix} .254
266
+ interface ${br}
267
+ pidfile ${pidfile}
268
+ lease_file ${leases}
269
+ opt subnet 255.255.255.0
270
+ ${router}
271
+ ${static}
272
+ EOF
273
+
274
+ touch " ${leases} " # to avoid a warning
275
+ busybox udhcpd " ${conf} "
276
+ }
277
+
278
+ _setup_bridges () {
279
+ chmod u+s /usr/lib/qemu/qemu-bridge-helper
280
+ mkdir -p /etc/qemu
281
+ touch /etc/qemu/bridge.conf
282
+ chmod 755 /etc/qemu/bridge.conf
283
+ sysctl -w net.bridge.bridge-nf-call-ip6tables=0
284
+ sysctl -w net.bridge.bridge-nf-call-iptables=0
285
+ sysctl -w net.bridge.bridge-nf-call-arptables=0
286
+ # only v4 for the moment
287
+ if ! iptables -t nat -C POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE 2> /dev/null; then
288
+ iptables -t nat -A POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE
289
+ fi
290
+
291
+ if [ -n " ${INPUT_MAC_ADDRESS_PREFIX} " ]; then
292
+ VIRTME_RUN_OPTS+=(" --net-mac-address" " ${INPUT_MAC_ADDRESS_PREFIX% =* } :00" )
293
+ fi
294
+
295
+ local br
296
+ for br in " ${@ } " ; do
297
+ _add_bridge " ${br} "
298
+ done
299
+ }
300
+
207
301
setup_env () { local mode
208
302
mode=" ${1} "
209
303
@@ -284,7 +378,21 @@ setup_env() { local mode
284
378
: " ${INPUT_GCOV:= 0} "
285
379
286
380
# add net support, can be useful, but delay the start of the tests (~1 sec?)
287
- VIRTME_RUN_OPTS+=(" --net" )
381
+ if [ -z " ${INPUT_NET_BRIDGES} " ]; then
382
+ VIRTME_RUN_OPTS+=(" --net" )
383
+ fi
384
+
385
+ # From the docker: vng --vsock-connect
386
+ # TODO: remove if condition when virtme-ng supports it
387
+ if virtme-run --help | grep -q vsock; then
388
+ VIRTME_RUN_OPTS+=(" --vsock" " ${VIRTME_CONSOLE} " " --vsock-cid" " ${INPUT_VSOCK_CID} " )
389
+ fi
390
+ fi
391
+
392
+ if [ -n " ${INPUT_NET_BRIDGES} " ]; then
393
+ local bridges
394
+ IFS=' ,' read -ra bridges <<< " ${INPUT_NET_BRIDGES}"
395
+ _setup_bridges " ${bridges[@]} "
288
396
fi
289
397
290
398
: " ${INPUT_RAM:= " $(( 2048 * (1 + INPUT_GCOV)) )M" } " # More needed for GCOV, not to swap
@@ -726,6 +834,13 @@ export KERNEL_SRC_DIR="${KERNEL_SRC}"
726
834
export PATH="\$ {PATH}:${VIRTME_TOOLS_SBIN_DIR} "
727
835
EOF
728
836
837
+ # add colours to the prompt if OK
838
+ if [ " ${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE} " = 1 ]; then
839
+ # shellcheck disable=SC2016 # escaped on purpose
840
+ local ps1=' ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
841
+ echo " PS1='${ps1} '" >> " ${BASH_PROFILE} "
842
+ fi
843
+
729
844
cat << EOF > "${VIRTME_SCRIPT} "
730
845
#! /bin/bash
731
846
@@ -1200,7 +1315,7 @@ EOF
1200
1315
run () {
1201
1316
printinfo " Run the virtme script: manual"
1202
1317
1203
- " ${VIRTME_RUN} " " ${VIRTME_RUN_OPTS[@]} "
1318
+ " ${VIRTME_RUN} " " ${VIRTME_RUN_OPTS[@]} " ${VIRTME_RUN_QEMU_OPTS : +--qemu-opts " ${VIRTME_RUN_QEMU_OPTS[@]} " }
1204
1319
}
1205
1320
1206
1321
run_expect () {
@@ -1217,7 +1332,8 @@ run_expect() {
1217
1332
fi
1218
1333
1219
1334
# force a stop in case of panic, but avoid a reboot in "expect" mode
1220
- VIRTME_RUN_OPTS+=(--kopt panic=-1 --qemu-opts -no-reboot)
1335
+ VIRTME_RUN_OPTS+=(--kopt panic=-1)
1336
+ VIRTME_RUN_QEMU_OPTS+=(-no-reboot)
1221
1337
1222
1338
printinfo " Run the virtme script: expect (timeout: ${VIRTME_EXPECT_TEST_TIMEOUT} )"
1223
1339
@@ -1250,7 +1366,7 @@ EOF
1250
1366
#! /bin/bash
1251
1367
echo -e "$( log_section_start " Boot VM" ) "
1252
1368
set -x
1253
- "${VIRTME_RUN} " ${VIRTME_RUN_OPTS[@]} 2>&1 | tr -d '\r'
1369
+ "${VIRTME_RUN} " ${VIRTME_RUN_OPTS[@]} ${VIRTME_RUN_QEMU_OPTS : +--qemu-opts ${VIRTME_RUN_QEMU_OPTS[@]} } 2>&1 | tr -d '\r'
1254
1370
EOF
1255
1371
chmod +x " ${VIRTME_RUN_SCRIPT} "
1256
1372
@@ -1754,7 +1870,7 @@ usage() {
1754
1870
echo
1755
1871
echo " - KConfig: optional kernel config: arguments for './scripts/config' or config file"
1756
1872
echo
1757
- echo " Usage: ${0} <make [params] | make.cross [params] | build <mode> | defconfig <mode> | selftests | bpftests | cmd <command> | src <source file> | static | vm-manual | vm-auto | lcov2html >"
1873
+ echo " Usage: ${0} <make [params] | make.cross [params] | build <mode> | defconfig <mode> | selftests | bpftests | cmd <command> | src <source file> | static | vm-manual | vm-auto | connect | lcov2html >"
1758
1874
echo
1759
1875
echo " - make: run the make command with optional parameters"
1760
1876
echo " - make.cross: run Intel's make.cross command with optional parameters"
@@ -1767,6 +1883,7 @@ usage() {
1767
1883
echo " - static: run static analysis, with make W=1 C=1"
1768
1884
echo " - vm-manual: start the VM with what has already been built ('normal' mode by default)"
1769
1885
echo " - vm-auto: same, then run the tests as well ('normal' mode by default)"
1886
+ echo " - connect: connect to a VM's remote shell via a VSock (set INPUT_VSOCK_CID for multiple VMs)."
1770
1887
echo " - lcov2html: generate html from lcov file (required INPUT_GCOV=1)"
1771
1888
echo
1772
1889
echo " This script needs to be ran from the root of kernel source code."
@@ -1888,6 +2005,18 @@ case "${INPUT_MODE}" in
1888
2005
run_expect
1889
2006
analyze " ${@:- normal} "
1890
2007
;;
2008
+ " connect" )
2009
+ read -r rows columns <<< " $(stty size)"
2010
+ cat << -EOF > "${VIRTME_CONSOLE} "
2011
+ #! /bin/bash
2012
+ stty rows ${rows} columns ${columns}
2013
+ cd "\$ {virtme_chdir}"
2014
+ HOME=/root
2015
+ byobu
2016
+ EOF
2017
+ chmod +x " ${VIRTME_CONSOLE} "
2018
+ vng --vsock-connect --vsock-cid " ${1:- ${INPUT_VSOCK_CID} } "
2019
+ ;;
1891
2020
" lcov2html" )
1892
2021
setup_env " ${@:- normal} "
1893
2022
while [ -n " ${1} " ] && [ ! -s " ${1} " ]; do
0 commit comments