Skip to content

Commit 07d37a8

Browse files
committed
Merge branch 'latest' into net
Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
2 parents 2ae0d17 + c4a2c65 commit 07d37a8

File tree

5 files changed

+177
-11
lines changed

5 files changed

+177
-11
lines changed

Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
FROM ubuntu:24.04
2+
FROM ubuntu:24.10
33

44
LABEL name=mptcp-upstream-virtme-docker
55

@@ -20,16 +20,18 @@ RUN apt-get update && \
2020
pkg-config libmnl-dev \
2121
clang clangd clang-tidy lld llvm llvm-dev libcap-dev \
2222
gdb gdb-multiarch crash dwarves strace trace-cmd \
23-
iptables ebtables nftables vim psmisc bash-completion less jq \
24-
gettext-base libevent-dev libtraceevent-dev libnewt0.52 libslang2 libutempter0 python3-newt tmux \
23+
iptables ebtables nftables bridge-utils socat \
24+
vim psmisc bash-completion less jq \
25+
gettext-base libevent-dev libtraceevent-dev libnewt0.52 libslang2 libutempter0 python3-newt tmux gawk \
2526
libdwarf-dev libbfd-dev libnuma-dev libzstd-dev libunwind-dev libdw-dev libslang2-dev python3-dev python3-setuptools binutils-dev libiberty-dev libbabeltrace-dev systemtap-sdt-dev libperl-dev python3-docutils \
2627
libtap-formatter-junit-perl lcov libjson-xs-perl \
2728
zstd \
2829
wget xz-utils lftp cpio u-boot-tools \
2930
cscope \
3031
bpftrace \
3132
golang \
32-
mptcpize \
33+
mptcpize iperf3 netperf \
34+
bmon ifstat \
3335
&& \
3436
apt-get clean
3537

@@ -95,7 +97,7 @@ RUN for i in /usr/lib/klibc/bin/*; do \
9597

9698
# CCache for quicker builds with default colours
9799
# Note: use 'ccache -M xG' to increase max size, default is 5GB
98-
ENV PATH=/usr/lib/ccache:${PATH}
100+
ENV PATH=/usr/lib/ccache:/opt/virtme-ng:${PATH}
99101
ENV CCACHE_COMPRESS=true
100102
ENV KBUILD_BUILD_TIMESTAMP="0"
101103
ENV GCC_COLORS=error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ When launching the docker image, you have to specify the mode you want to use:
3737
default).
3838
- `vm-auto`: Start the VM with what has already been built, then run the tests
3939
(`normal` mode by default).
40+
- `connect`: connect to a VM's remote shell via a VSock. For multiple VMs
41+
running in parallel, set a different CID, e.g. `INPUT_VSOCK_CID=42`
4042
- `lcov2html`: Generate HTML from LCOV file(s) (available when tests have been
4143
executed with `INPUT_GCOV=1`).
4244
- `src`: `source` a given script file.
@@ -90,6 +92,29 @@ ln -s /PATH/TO/THIS/REPO/run-tests-dev-clang.sh .virtme-clang.sh
9092

9193
Then simply call `./.virtme.sh` or `.virtme-clang.sh`.
9294

95+
### Remote Shell
96+
97+
To connect to an existing VM with a remote shell, you can use this command:
98+
99+
```bash
100+
docker exec -it \
101+
"$(docker ps --filter "label=name=mptcp-upstream-virtme-docker" -l --format "{{.ID}}")" \
102+
/entrypoint.sh connect
103+
```
104+
105+
(Or use the `connect.sh` script.)
106+
107+
Note, if you want to run multiple VMs in parallel, you will need to set the
108+
right container ID or name found with `docker ps`:
109+
110+
```
111+
$ docker ps
112+
CONTAINER ID IMAGE COMMAND
113+
f055e439a1e7 mptcp/mptcp-upstream-virtme-docker:latest "/entrypoint.sh manual" (...)
114+
50cd8ce27116 mptcp/mptcp-upstream-virtme-docker:latest "/entrypoint.sh manual" (...)
115+
$ docker exec -it f055e439a1e7 /entrypoint.sh connect
116+
```
117+
93118
## Extension
94119

95120
### Files

connect.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash -x
2+
3+
docker exec -it \
4+
"$(docker ps --filter "label=name=mptcp-upstream-virtme-docker" -l --format "{{.ID}}")" \
5+
/entrypoint.sh connect "${@}"

entrypoint.sh

+135-6
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ set_trace_on
5151
: "${INPUT_SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES:=1}"
5252
: "${INPUT_SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY:=0}"
5353
: "${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE:=1}"
54+
: "${INPUT_HOSTNAME:="mptcpdev"}"
5455
: "${INPUT_CPUS:=""}"
5556
: "${INPUT_RAM:=""}"
5657
: "${INPUT_GCOV:=""}"
58+
: "${INPUT_NET_BRIDGES:=""}"
59+
: "${INPUT_MAC_ADDRESS_PREFIX:=""}"
60+
: "${INPUT_VSOCK_CID:="3"}"
5761
: "${INPUT_CI_RESULTS_DIR:=""}"
5862
: "${INPUT_CI_PRINT_EXIT_CODE:=1}"
5963
: "${INPUT_CI_TIMEOUT_SEC:=5400}"
@@ -98,6 +102,7 @@ VIRTME_SCRIPT_UNEXPECTED_STOP="Unexpected stop of the VM"
98102
VIRTME_SCRIPT_TIMEOUT="${VIRTME_SCRIPTS_DIR}/tests.timeout"
99103
VIRTME_RUN_SCRIPT="${VIRTME_SCRIPTS_DIR}/virtme.sh"
100104
VIRTME_RUN_EXPECT="${VIRTME_SCRIPTS_DIR}/virtme.expect"
105+
VIRTME_CONSOLE="${VIRTME_SCRIPTS_DIR}/console.sh"
101106

102107
SELFTESTS_DIR="${INPUT_SELFTESTS_DIR:-tools/testing/selftests/net/mptcp}"
103108
SELFTESTS_CONFIG="${SELFTESTS_DIR}/config"
@@ -110,14 +115,15 @@ VIRTME_CONFIGKERNEL="virtme-configkernel"
110115
VIRTME_RUN="virtme-run"
111116
VIRTME_RUN_OPTS=(
112117
--arch "${VIRTME_ARCH}"
113-
--name "mptcpdev" # hostname
118+
--name "${INPUT_HOSTNAME}"
114119
--mods=auto
115120
--rw # Don't use "rwdir", it will use 9p ; in a container, we can use rw
116121
--pwd
117122
--show-command
118123
--verbose --show-boot-console
119124
--kopt mitigations=off
120125
)
126+
VIRTME_RUN_QEMU_OPTS=()
121127

122128
# results dir
123129
RESULTS_DIR_BASE="${VIRTME_WORKDIR}/results"
@@ -204,6 +210,94 @@ _get_results_dir() {
204210
echo "${RESULTS_DIR_BASE}/$(git rev-parse --short HEAD || echo "UNKNOWN")/${1}"
205211
}
206212

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+
207301
setup_env() { local mode
208302
mode="${1}"
209303

@@ -284,7 +378,21 @@ setup_env() { local mode
284378
: "${INPUT_GCOV:=0}"
285379

286380
# 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[@]}"
288396
fi
289397

290398
: "${INPUT_RAM:="$((2048 * (1 + INPUT_GCOV)))M"}" # More needed for GCOV, not to swap
@@ -726,6 +834,13 @@ export KERNEL_SRC_DIR="${KERNEL_SRC}"
726834
export PATH="\${PATH}:${VIRTME_TOOLS_SBIN_DIR}"
727835
EOF
728836

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+
729844
cat <<EOF > "${VIRTME_SCRIPT}"
730845
#! /bin/bash
731846
@@ -1200,7 +1315,7 @@ EOF
12001315
run() {
12011316
printinfo "Run the virtme script: manual"
12021317

1203-
"${VIRTME_RUN}" "${VIRTME_RUN_OPTS[@]}"
1318+
"${VIRTME_RUN}" "${VIRTME_RUN_OPTS[@]}" ${VIRTME_RUN_QEMU_OPTS:+--qemu-opts "${VIRTME_RUN_QEMU_OPTS[@]}"}
12041319
}
12051320

12061321
run_expect() {
@@ -1217,7 +1332,8 @@ run_expect() {
12171332
fi
12181333

12191334
# 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)
12211337

12221338
printinfo "Run the virtme script: expect (timeout: ${VIRTME_EXPECT_TEST_TIMEOUT})"
12231339

@@ -1250,7 +1366,7 @@ EOF
12501366
#! /bin/bash
12511367
echo -e "$(log_section_start "Boot VM")"
12521368
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'
12541370
EOF
12551371
chmod +x "${VIRTME_RUN_SCRIPT}"
12561372

@@ -1754,7 +1870,7 @@ usage() {
17541870
echo
17551871
echo " - KConfig: optional kernel config: arguments for './scripts/config' or config file"
17561872
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>"
17581874
echo
17591875
echo " - make: run the make command with optional parameters"
17601876
echo " - make.cross: run Intel's make.cross command with optional parameters"
@@ -1767,6 +1883,7 @@ usage() {
17671883
echo " - static: run static analysis, with make W=1 C=1"
17681884
echo " - vm-manual: start the VM with what has already been built ('normal' mode by default)"
17691885
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)."
17701887
echo " - lcov2html: generate html from lcov file (required INPUT_GCOV=1)"
17711888
echo
17721889
echo "This script needs to be ran from the root of kernel source code."
@@ -1888,6 +2005,18 @@ case "${INPUT_MODE}" in
18882005
run_expect
18892006
analyze "${@:-normal}"
18902007
;;
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+
;;
18912020
"lcov2html")
18922021
setup_env "${@:-normal}"
18932022
while [ -n "${1}" ] && [ ! -s "${1}" ]; do

run.sh

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ docker run \
1717
${VIRTME_PACKETDRILL_PATH:+-v "${VIRTME_PACKETDRILL_PATH}:/opt/packetdrill:rw"} \
1818
-v "${HOME_DIR}:/root" \
1919
${VIRTME_SYZKALLER_PATH:+ -v "${VIRTME_SYZKALLER_PATH}:/opt/syzkaller:rw"} \
20+
${VIRTME_NG_PATH:+ -v "${VIRTME_NG_PATH}:/opt/virtme-ng:ro"} \
2021
-w "${PWD}" \
2122
-e "INPUT_CLANG" \
2223
-e "INPUT_TRACE" \
@@ -39,9 +40,13 @@ docker run \
3940
-e "INPUT_PACKETDRILL_STABLE=${VIRTME_PACKETDRILL_STABLE:-0}" \
4041
-e "INPUT_EXPECT_TIMEOUT" \
4142
-e "INPUT_EXTRA_ENV" \
43+
-e "INPUT_HOSTNAME" \
4244
-e "INPUT_CPUS" \
4345
-e "INPUT_RAM" \
4446
-e "INPUT_GCOV" \
47+
-e "INPUT_NET_BRIDGES" \
48+
-e "INPUT_MAC_ADDRESS_PREFIX" \
49+
-e "INPUT_VSOCK_CID" \
4550
-e "VIRTME_ARCH" \
4651
-e "COMPILER" \
4752
--privileged \

0 commit comments

Comments
 (0)