-
Notifications
You must be signed in to change notification settings - Fork 6
/
entrypoint.sh
executable file
Β·2047 lines (1674 loc) Β· 47.6 KB
/
entrypoint.sh
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# The goal is to launch (MPTCP) kernel selftests and more.
# But also to provide a dev env for kernel developers or testers.
# We should manage all errors in this script
set -e
is_ci() {
[ "${CI}" = "true" ]
}
is_github_action() {
[ "${GITHUB_ACTIONS}" = "true" ]
}
trace_needed() {
[ "${INPUT_TRACE}" = "1" ]
}
set_trace_on() {
if trace_needed; then
set -x
fi
}
set_trace_off() {
if trace_needed; then
set +x
fi
}
with_clang() {
[ "${INPUT_CLANG}" = "1" ]
}
set_trace_on
# The behaviour can be changed with 'input' env var
: "${INPUT_CCACHE_MAXSIZE:=5G}"
: "${INPUT_CCACHE_DIR:=""}"
: "${INPUT_NO_BLOCK:=0}"
: "${INPUT_PACKETDRILL_NO_SYNC:=0}"
: "${INPUT_PACKETDRILL_NO_MORE_TOLERANCE:=0}"
: "${INPUT_PACKETDRILL_STABLE:=0}"
: "${INPUT_RUN_LOOP_CONTINUE:=0}"
: "${INPUT_RUN_TESTS_ONLY:=""}"
: "${INPUT_RUN_TESTS_EXCEPT:=""}"
: "${INPUT_SELFTESTS_DIR:=""}"
: "${INPUT_SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES:=1}"
: "${INPUT_SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY:=0}"
: "${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE:=1}"
: "${INPUT_HOSTNAME:="mptcpdev"}"
: "${INPUT_CPUS:=""}"
: "${INPUT_RAM:=""}"
: "${INPUT_GCOV:=""}"
: "${INPUT_NET_BRIDGES:=""}"
: "${INPUT_MAC_ADDRESS_PREFIX:=""}"
: "${INPUT_VSOCK_CID:="3"}"
: "${INPUT_CI_RESULTS_DIR:=""}"
: "${INPUT_CI_PRINT_EXIT_CODE:=1}"
: "${INPUT_CI_TIMEOUT_SEC:=5400}"
: "${INPUT_EXPECT_TIMEOUT:="-1"}"
: "${INPUT_BUILD_SKIP_PERF:=1}"
if [ -z "${INPUT_MODE}" ]; then
INPUT_MODE="${1}"
shift || true # none set
fi
# to be able to set an extra env var
if [[ "${INPUT_EXTRA_ENV}" =~ ^"INPUT_"[A-Z0-9_]+"="[a-zA-Z0-9_]+$ ]]; then
eval "${INPUT_EXTRA_ENV}"
fi
: "${PACKETDRILL_GIT_BRANCH:=mptcp-net-next}"
: "${VIRTME_ARCH:="$(uname -m)"}"
TIMESTAMPS_SEC_START=$(date +%s)
# CI only: estimated time before (clone + boot) and after (artifacts) running this script
VIRTME_CI_ESTIMATED_EXTRA_TIME="540"
# max time to boot: it should take less than one minute with a debug kernel, *5 to be safe
VIRTME_EXPECT_BOOT_TIMEOUT="300"
# max time to shutdown: it should take one second
VIRTME_EXPECT_SHUTDOWN_TIMEOUT="60"
KERNEL_SRC="${PWD}"
# used to pass environment variables to the VM
BASH_PROFILE="/root/.bash_profile"
VIRTME_WORKDIR="${KERNEL_SRC}/.virtme"
VIRTME_SCRIPTS_DIR="${VIRTME_WORKDIR}/scripts"
VIRTME_HEADERS_DIR="${VIRTME_WORKDIR}/headers"
VIRTME_SCRIPT="${VIRTME_SCRIPTS_DIR}/tests.sh"
VIRTME_SCRIPT_END="__VIRTME_END__"
VIRTME_SCRIPT_UNEXPECTED_STOP="Unexpected stop of the VM"
VIRTME_SCRIPT_TIMEOUT="${VIRTME_SCRIPTS_DIR}/tests.timeout"
VIRTME_RUN_SCRIPT="${VIRTME_SCRIPTS_DIR}/virtme.sh"
VIRTME_RUN_EXPECT="${VIRTME_SCRIPTS_DIR}/virtme.expect"
SELFTESTS_DIR="${INPUT_SELFTESTS_DIR:-tools/testing/selftests/net/mptcp}"
SELFTESTS_CONFIG="${SELFTESTS_DIR}/config"
BPFTESTS_DIR="${INPUT_BPFTESTS_DIR:-tools/testing/selftests/bpf}"
BPFTESTS_CONFIG="${BPFTESTS_DIR}/config"
export CCACHE_MAXSIZE="${INPUT_CCACHE_MAXSIZE}"
VIRTME_CONFIGKERNEL="virtme-configkernel"
VIRTME_RUN="virtme-run"
VIRTME_RUN_OPTS=(
--arch "${VIRTME_ARCH}"
--name "${INPUT_HOSTNAME}"
--mods=auto
--rw # Don't use "rwdir", it will use 9p ; in a container, we can use rw
--pwd
--show-command
--verbose --show-boot-console
--kopt mitigations=off
)
VIRTME_RUN_QEMU_OPTS=()
# results dir
RESULTS_DIR_BASE="${VIRTME_WORKDIR}/results"
RESULTS_DIR=
# log files
OUTPUT_VIRTME=
TESTS_SUMMARY=
CONCLUSION=
KMEMLEAK=
LCOV_FILE=
LCOV_TXT=
LCOV_HTML=
EXIT_STATUS=0
EXIT_REASONS=()
EXIT_TITLE="KVM Validation"
EXPECT=0
VIRTME_EXEC_RUN="${INPUT_VIRTME_EXEC_RUN:-"${KERNEL_SRC}/.virtme-exec-run"}"
VIRTME_EXEC_PRE="${KERNEL_SRC}/.virtme-exec-pre"
VIRTME_EXEC_POST="${KERNEL_SRC}/.virtme-exec-post"
VIRTME_PREPARE_POST="${KERNEL_SRC}/.virtme-prepare-post"
COLOR_RED="\E[1;31m"
COLOR_GREEN="\E[1;32m"
COLOR_YELLOW="\E[1;33m"
COLOR_BLUE="\E[1;34m"
COLOR_RESET="\E[0m"
# $1: color, $2: text
print_color() {
echo -e "${START_PRINT:-}${*}${COLOR_RESET}"
}
print() {
print_color "${COLOR_GREEN}${*}"
}
printinfo() {
print_color "${COLOR_BLUE}${*}"
}
printerr() {
print_color "${COLOR_RED}${*}" >&2
}
if is_github_action; then
# $1: description
log_section_start() {
echo -e "\n::group::${COLOR_YELLOW}${*}${COLOR_RESET}"
}
log_section_end() {
echo -e "::endgroup::\n"
}
else
# $1: description
log_section_start() {
printinfo "${@}"
}
log_section_end() {
true
}
fi
# $1: mode
is_mode_normal() {
[[ "${1}" == *"normal" ]]
}
# $1: mode
is_mode_debug() {
[[ "${1}" == *"debug" ]]
}
# $1: mode
is_mode_btf() {
[[ "${1}" == "btf-"* ]]
}
# $1: mode
_get_results_dir() {
echo "${RESULTS_DIR_BASE}/$(git rev-parse --short HEAD || echo "UNKNOWN")/${1}"
}
# $1: pid
kill_wait() {
local pid="${1}"
if [ -z "${pid}" ]; then
return
fi
kill "${pid}"
while [ -d "/proc/${pid}" ]; do
sleep 0.1
done
}
# $1: bridge name
_add_bridge() { local router static
local br="${1}"
local i="${br//[^0-9]/}" # only the numbers
local prefix="10.0.${i}"
local conf="/tmp/udhcpd-${br}.conf"
local pidfile="/var/run/udhcpd-${br}.pid"
local leases="/var/lib/misc/udhcpd-${br}.leases"
VIRTME_RUN_OPTS+=("--net=bridge=${br}")
if [ -n "${INPUT_MAC_ADDRESS_PREFIX}" ]; then
static="static_lease ${INPUT_MAC_ADDRESS_PREFIX%=*}:0${i} ${prefix}.${INPUT_MAC_ADDRESS_PREFIX#*=}"
fi
# already launched?
if grep -wq "${br}" /etc/qemu/bridge.conf; then
if [ -n "${static}" ]; then
echo "${static}" >> "${conf}"
kill_wait "$(<"${pidfile}")"
busybox udhcpd "${conf}"
fi
return 0
fi
echo "allow ${br}" >> /etc/qemu/bridge.conf
brctl addbr "${br}"
ip addr add "${prefix}.1/24" dev "${br}"
ip link set "${br}" up
# one default address
if [ "${i}" = "0" ]; then
router="opt router ${prefix}.1"
fi
cat <<-EOF > "${conf}"
start ${prefix}.2
end ${prefix}.254
interface ${br}
pidfile ${pidfile}
lease_file ${leases}
opt subnet 255.255.255.0
${router}
${static}
EOF
touch "${leases}" # to avoid a warning
busybox udhcpd "${conf}"
}
_setup_bridges() {
chmod u+s /usr/lib/qemu/qemu-bridge-helper
mkdir -p /etc/qemu
touch /etc/qemu/bridge.conf
chmod 755 /etc/qemu/bridge.conf
sysctl -w net.bridge.bridge-nf-call-ip6tables=0
sysctl -w net.bridge.bridge-nf-call-iptables=0
sysctl -w net.bridge.bridge-nf-call-arptables=0
# only v4 for the moment
if ! iptables -t nat -C POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE 2>/dev/null; then
iptables -t nat -A POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE
fi
if [ -n "${INPUT_MAC_ADDRESS_PREFIX}" ]; then
VIRTME_RUN_OPTS+=("--net-mac-address" "${INPUT_MAC_ADDRESS_PREFIX%=*}:00")
fi
local br
for br in "${@}"; do
_add_bridge "${br}"
done
}
setup_env() { local mode
mode="${1}"
log_section_start "Setup environment"
EXIT_TITLE="${EXIT_TITLE}: ${mode}" # only one mode
if [ -n "${INPUT_RUN_TESTS_ONLY}" ]; then
EXIT_TITLE="${EXIT_TITLE} (only ${INPUT_RUN_TESTS_ONLY})"
fi
if [ -n "${INPUT_RUN_TESTS_EXCEPT}" ]; then
EXIT_TITLE="${EXIT_TITLE} (except ${INPUT_RUN_TESTS_EXCEPT})"
fi
# Avoid 'unsafe repository' error: we need to get the rev/tag later from
# this docker image
git config --global --replace-all safe.directory "${KERNEL_SRC}" || true
# Set a name, just in case for automations
git config --global user.name "MPTCP Virtme Docker"
git config --global user.email "[email protected]"
# Avoid a long advice
git config --global advice.detachedHead false
VIRTME_BUILD_DIR="${VIRTME_WORKDIR}/build"
with_clang && VIRTME_BUILD_DIR+="-clang"
is_mode_debug "${mode}" && VIRTME_BUILD_DIR+="-debug"
is_mode_btf "${mode}" && VIRTME_BUILD_DIR+="-btf"
[ -n "${INPUT_BUILD_SUFFIX}" ] && VIRTME_BUILD_DIR+="-${INPUT_BUILD_SUFFIX}"
VIRTME_PERF_DIR="${VIRTME_BUILD_DIR}/tools/perf"
VIRTME_TOOLS_SBIN_DIR="${VIRTME_BUILD_DIR}/tools/sbin"
VIRTME_CACHE_DIR="${VIRTME_BUILD_DIR}/.cache"
VIRTME_KCONFIG="${VIRTME_BUILD_DIR}/.config"
if [ -n "${INPUT_CCACHE_DIR}" ]; then
export CCACHE_DIR="${VIRTME_WORKDIR}/${INPUT_CCACHE_DIR}"
else
export CCACHE_DIR="${VIRTME_WORKDIR}/ccache"
with_clang && CCACHE_DIR+="-clang"
is_mode_debug "${mode}" && CCACHE_DIR+="-debug"
is_mode_btf "${mode}" && CCACHE_DIR+="-btf"
[ -n "${INPUT_BUILD_SUFFIX}" ] && CCACHE_DIR+="-${INPUT_BUILD_SUFFIX}"
fi
read -ra MAKE_ARGS <<< "${INPUT_MAKE_ARGS}"
with_clang && MAKE_ARGS+=(LLVM=1 LLVM_IAS=1 CC=clang ARCH="${VIRTME_ARCH}")
MAKE_ARGS_O=("${MAKE_ARGS[@]}" O="${VIRTME_BUILD_DIR}")
export KBUILD_OUTPUT="${VIRTME_BUILD_DIR}"
export KCONFIG_CONFIG="${VIRTME_KCONFIG}"
if [ "${INPUT_CLEAN}" = 1 ]; then
rm -rf "${VIRTME_BUILD_DIR}" "${VIRTME_PERF_DIR}"
fi
mkdir -p \
"${VIRTME_BUILD_DIR}" \
"${VIRTME_SCRIPTS_DIR}" \
"${VIRTME_HEADERS_DIR}" \
"${VIRTME_PERF_DIR}" \
"${VIRTME_CACHE_DIR}" \
"${CCACHE_DIR}"
chmod 777 "${VIRTME_CACHE_DIR}" # to let users writting files there, e.g. clangd
if is_ci; then
# Root dir: not to have to go down dirs to get artifacts
RESULTS_DIR="${KERNEL_SRC}${INPUT_CI_RESULTS_DIR:+/${INPUT_CI_RESULTS_DIR}}"
mkdir -p "${RESULTS_DIR}"
: "${INPUT_CPUS:=$(nproc)}" # use all available resources
: "${INPUT_GCOV:=1}"
# The CI doesn't need to access to the outside world, so no '--net'
else
# avoid override
RESULTS_DIR="$(_get_results_dir "${mode}")"
rm -rf "${RESULTS_DIR}"
mkdir -p "${RESULTS_DIR}"
: "${INPUT_CPUS:=2}" # limit to 2 cores for now
: "${INPUT_GCOV:=0}"
# add net support, can be useful, but delay the start of the tests (~1 sec?)
if [ -z "${INPUT_NET_BRIDGES}" ]; then
VIRTME_RUN_OPTS+=("--net")
fi
# To connect to the VM using VSock
# TODO: remove if condition when virtme-ng supports it
if "${VIRTME_RUN}" -h | grep -q VSOCK; then
VIRTME_RUN_OPTS+=("--server" "--port" "${INPUT_VSOCK_CID}")
fi
fi
if [ -n "${INPUT_NET_BRIDGES}" ]; then
local bridges
IFS=',' read -ra bridges <<< "${INPUT_NET_BRIDGES}"
_setup_bridges "${bridges[@]}"
fi
: "${INPUT_RAM:="$((2048 * (1 + INPUT_GCOV)))M"}" # More needed for GCOV, not to swap
VIRTME_RUN_OPTS+=(
--kdir "${VIRTME_BUILD_DIR}"
--cpus "${INPUT_CPUS}"
--memory "${INPUT_RAM}"
)
OUTPUT_VIRTME="${RESULTS_DIR}/output.log"
TESTS_SUMMARY="${RESULTS_DIR}/summary.txt"
CONCLUSION="${RESULTS_DIR}/conclusion.txt"
KMEMLEAK="${RESULTS_DIR}/kmemleak.txt"
LCOV_FILE="${RESULTS_DIR}/kernel.lcov"
LCOV_TXT="${RESULTS_DIR}/coverage.txt"
LCOV_HTML="${RESULTS_DIR}/lcov"
KVERSION=$(make -C "${KERNEL_SRC}" -s kernelversion) ## 5.17.0 or 5.17.0-rc8
KVER_MAJ=${KVERSION%%.*} ## 5
KVER_MIN=${KVERSION#*.} ## 17.0*
KVER_MIC=${KVER_MIN#*.} ## 0
KVER_MIN=${KVER_MIN%%.*} ## 17
# without rc, it means we probably already merged with net-next
if [[ ! "${KVERSION}" =~ rc ]] && [ "${KVER_MIC}" = 0 ]; then
KVER_MIN=$((KVER_MIN + 1))
# max .19 because Linus has 20 fingers
if [ ${KVER_MIN} -gt 19 ]; then
KVER_MAJ=$((KVER_MAJ + 1))
KVER_MIN=0
fi
fi
if [ "${KVER_MAJ}" -lt 5 ] ||
{ [ "${KVER_MAJ}" -eq 5 ] && [ "${KVER_MIN}" -le 10 ]; }; then
# virtiofs doesn't seem to be supported on old kernels
VIRTME_RUN_OPTS+=(--force-9p)
fi
log_section_end
}
_get_last_iproute_version() {
curl https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/refs/tags 2>/dev/null | \
grep "/tag/?h=v[0-9]" | \
cut -d\' -f2 | cut -d= -f2 | \
sort -Vu | \
tail -n1
}
check_last_iproute() { local last curr
# only check on CI
if ! is_ci; then
return 0
fi
# skip the check for stable, fine not to have the latest version
if [ "${INPUT_PACKETDRILL_STABLE}" = "1" ]; then
return 0
fi
log_section_start "Check IPRoute2 version"
last="$(_get_last_iproute_version)"
curr="v$(ip -V | sed 's/.*iproute2-\([0-9.]\+\).*/\1/')"
if [ "${curr}" = "${last}" ]; then
printinfo "IPRoute2: using the last version: ${last}"
else
printerr "WARN: IPRoute2: not the last version: ${curr} < ${last}"
fi
log_section_end
}
_check_source_exec_one() {
local src="${1}"
local reason="${2}"
if [ -f "${src}" ]; then
printinfo "This script file exists and will be used ${reason}: $(basename "${src}")"
cat -n "${src}"
if is_ci || [ "${INPUT_NO_BLOCK}" = "1" ]; then
printinfo "Check source exec: not blocking"
else
print "Press Enter to continue (use 'INPUT_NO_BLOCK=1' to avoid this)"
read -r
fi
fi
}
check_source_exec_all() {
log_section_start "Check extented exec files"
_check_source_exec_one "${VIRTME_EXEC_PRE}" "before the tests suite"
_check_source_exec_one "${VIRTME_EXEC_RUN}" "to replace the execution of the whole tests suite"
_check_source_exec_one "${VIRTME_EXEC_POST}" "after the tests suite"
log_section_end
}
_make_j() {
make -j"$(nproc)" -l"$(nproc)" "${@}"
}
_make() {
_make_j "${MAKE_ARGS[@]}" "${@}"
}
_make_o() {
_make_j "${MAKE_ARGS_O[@]}" "${@}"
}
# $1: source ; $2: target
_add_symlink() {
local src="${1}"
local dst="${2}"
if [ -e "${dst}" ] && [ ! -L "${dst}" ]; then
printerr "${dst} already exists and is not a symlink, please remove it"
return 1
fi
ln -sf "${src}" "${dst}"
}
# $1: mode ; [rest: extra kconfig]
gen_kconfig() { local mode kconfig=() vck rc=0
mode="${1}"
shift
log_section_start "Generate kernel config"
vck=(--arch "${VIRTME_ARCH}" --defconfig --custom "${SELFTESTS_CONFIG}")
if is_mode_debug "${mode}"; then
kconfig+=(
-e NET_NS_REFCNT_TRACKER # useful for 'net' tests
-d SLUB_DEBUG_ON # perf impact is too important
-e BOOTPARAM_SOFTLOCKUP_PANIC # instead of blocking
-e BOOTPARAM_HUNG_TASK_PANIC # instead of blocking
# -e RCU_EXPERT -e PROVE_RCU_LIST # fixed in v6.12 # TODO: fix issues first
)
local debug_config="kernel/configs/debug.config"
# Introduced in v5.17
if [ ! -s "${debug_config}" ]; then
debug_config="${VIRTME_CACHE_DIR}/debug.config"
curl "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/kernel/configs/debug.config" > "${debug_config}"
fi
vck+=(--custom "${debug_config}")
else
# low-overhead sampling-based memory safety error detector.
# Only in non-debug: KASAN is more precise
kconfig+=(-e KFENCE)
fi
# stop at the first oops, no need to continue in a bad state
kconfig+=(-e PANIC_ON_OOPS)
# Debug info for developers
kconfig+=(-e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e GDB_SCRIPTS)
if with_clang; then
kconfig+=(-e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT)
else
# decode_stacktrace.sh script reports '??:?' with GCC and DWARF5
kconfig+=(-e DEBUG_INFO_DWARF4)
fi
# Compressed (old/new option)
kconfig+=(-e DEBUG_INFO_COMPRESSED -e DEBUG_INFO_COMPRESSED_ZLIB)
# We need more debug info but it is slow to generate
if is_mode_btf "${mode}"; then
vck+=(--custom "${BPFTESTS_CONFIG}")
kconfig+=(-e DEBUG_INFO_BTF_MODULES -e MODULE_ALLOW_BTF_MISMATCH)
# Fix ./include/linux/if.h:28:10: fatal error:
# sys/socket.h: no such file or directory
kconfig+=(-d IA32_EMULATION)
elif is_ci || [ "${mode}" != "debsym" ]; then
kconfig+=(-e DEBUG_INFO_REDUCED -e DEBUG_INFO_SPLIT)
fi
# GCov for the CI
if [ "${INPUT_GCOV}" = 1 ]; then
kconfig+=(-e GCOV_KERNEL -e GCOV_PROFILE_MPTCP)
fi
# Debug tools for developers
kconfig+=(
-e DYNAMIC_DEBUG --set-val CONSOLE_LOGLEVEL_DEFAULT 8
-e FTRACE -e FUNCTION_TRACER -e DYNAMIC_FTRACE
-e FTRACE_SYSCALLS -e HIST_TRIGGERS
)
# Extra sanity checks in networking: for the moment, small checks
kconfig+=(-e DEBUG_NET)
# Extra options needed for MPTCP KUnit tests
kconfig+=(-m KUNIT -e KUNIT_DEBUGFS -d KUNIT_ALL_TESTS -m MPTCP_KUNIT_TEST)
# Options for BPF
kconfig+=(-e BPF_JIT -e BPF_SYSCALL)
# Extra options needed for packetdrill
# note: we still need SHA1 for fallback tests with v0
kconfig+=(-e TUN -e CRYPTO_USER_API_HASH -e CRYPTO_SHA1)
# Useful to reproduce issue
kconfig+=(-e NET_SCH_TBF)
# Disable retpoline to accelerate tests
kconfig+=(-d RETPOLINE)
# Disable components we don't need
kconfig+=(
-d PCCARD -d MACINTOSH_DRIVERS -d SOUND -d USB_SUPPORT
-d NEW_LEDS -d SURFACE_PLATFORMS -d DRM -d FB
)
# extra config
if [ -s "${1:-}" ]; then
local i
for i in "${@}"; do
vck+=(--custom "${i}")
done
else
kconfig+=("${@}")
fi
# KBUILD_OUTPUT is used by virtme
"${VIRTME_CONFIGKERNEL}" "${vck[@]}" "${MAKE_ARGS_O[@]}" || rc=${?}
./scripts/config --file "${VIRTME_KCONFIG}" "${kconfig[@]}" || rc=${?}
_make_o olddefconfig || rc=${?}
if is_ci; then
# Useful to help reproducing issues later
zstd -19 -T0 "${VIRTME_KCONFIG}" -o "${RESULTS_DIR}/config.zstd" || rc=${?}
fi
log_section_end
return ${rc}
}
build_kernel() { local rc=0
log_section_start "Build kernel"
if [ "${INPUT_GCOV}" = 1 ]; then
KCFLAGS="-fprofile-update=atomic" _make_o || rc=${?}
else
_make_o || rc=${?}
fi
# virtme will mount a tmpfs there + symlink to .virtme_mods
mkdir -p /lib/modules
log_section_end
return ${rc}
}
build_compile_commands() { local rc=0
log_section_start "Build compile_commands.json"
_make_o compile_commands.json || rc=${?}
log_section_end
return ${rc}
}
install_kernel_headers() { local rc=0
log_section_start "Install kernel headers"
# for BPFTrace and cie
cp -r include/ "${VIRTME_BUILD_DIR}"
_make_o headers_install INSTALL_HDR_PATH="${VIRTME_HEADERS_DIR}" || rc=${?}
log_section_end
return ${rc}
}
build_perf() { local rc=0
if [ "${INPUT_BUILD_SKIP_PERF}" = 1 ]; then
printinfo "Skip Perf build"
return 0
fi
log_section_start "Build Perf"
cd tools/perf
_make O="${VIRTME_PERF_DIR}" DESTDIR=/usr install || rc=${?}
cd "${KERNEL_SRC}"
log_section_end
return ${rc}
}
build() {
if [ "${INPUT_BUILD_SKIP}" = 1 ]; then
printinfo "Skip kernel build"
return 0
fi
ccache_stat
build_kernel
if with_clang; then
build_compile_commands || true # nice to have
fi
install_kernel_headers
build_perf
ccache_stat
}
build_selftests() { local rc=0
if [ "${INPUT_BUILD_SKIP_SELFTESTS}" = 1 ]; then
printinfo "Skip selftests build"
return 0
fi
log_section_start "Build the selftests $(basename "${SELFTESTS_DIR}")"
_make_o KHDR_INCLUDES="-I${VIRTME_HEADERS_DIR}/include" -C "${SELFTESTS_DIR}" || rc=${?}
log_section_end
return ${rc}
}
build_bpftests() { local rc=0
if [ "${INPUT_BUILD_SKIP_BPFTESTS}" = 1 ]; then
printinfo "Skip bpftests build"
return 0
fi
log_section_start "Build BPFTests"
_make_o KHDR_INCLUDES="-I${VIRTME_HEADERS_DIR}/include" -C "${BPFTESTS_DIR}" || rc=${?}
log_section_end
return ${rc}
}
build_packetdrill() { local old_pwd kversion branch rc=0
if [ "${INPUT_BUILD_SKIP_PACKETDRILL}" = 1 ]; then
printinfo "Skip Packetdrill build"
return 0
fi
log_section_start "Build Packetdrill"
old_pwd="${PWD}"
# make sure we have the last stable tests
cd /opt/packetdrill/
if [ "${INPUT_PACKETDRILL_NO_SYNC}" = "1" ]; then
printinfo "Packetdrill: no sync"
else
git fetch origin
branch="${PACKETDRILL_GIT_BRANCH}"
if [ "${INPUT_PACKETDRILL_STABLE}" = "1" ]; then
kversion="mptcp-${KVER_MAJ}.${KVER_MIN}"
# set the new branch only if it exists. If not, take the dev one
if git show-ref --quiet "refs/remotes/origin/${kversion}"; then
branch="${kversion}"
fi
fi
git checkout -f "origin/${branch}"
fi
cd gtests/net/packetdrill/
./configure
_make || rc=${?}
if [ "${INPUT_PACKETDRILL_NO_MORE_TOLERANCE}" = "1" ]; then
printinfo "Packetdrill: not modifying the tolerance"
else
cd ../mptcp
# reduce debug logs: too much
set_trace_off
local pf val new_val
for pf in $(git grep -l "^--tolerance_usecs="); do
# shellcheck disable=SC2013 # to filter duplicated ones
for val in $(grep "^--tolerance_usecs=" "${pf}" | cut -d= -f2 | sort -u); do
if is_mode_debug "${mode}"; then
# Increase tolerance in debug mode:
# the environment can be very slow
new_val=$((val * 8))
else
# Triple the time in normal mode:
# public CI can be quite loaded...
new_val=$((val * 3))
fi
sed -i "s/^--tolerance_usecs=${val}$/--tolerance_usecs=${new_val}/g" "${pf}"
done
done
set_trace_on
fi
cd "${old_pwd}"
log_section_end
return ${rc}
}
build_tests() { local mode
mode="${1}"
build_selftests
if is_mode_btf "${mode}"; then
build_bpftests
fi
build_packetdrill
}
prepare() {
printinfo "Prepare the environment"
cat <<EOF > "${BASH_PROFILE}"
export KERNEL_BUILD_DIR="${VIRTME_BUILD_DIR}"
export KERNEL_SRC_DIR="${KERNEL_SRC}"
export PATH="\${PATH}:${VIRTME_TOOLS_SBIN_DIR}"
EOF
# add colours to the prompt if OK
if [ "${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE}" = 1 ]; then
# shellcheck disable=SC2016 # escaped on purpose
local ps1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
echo "PS1='${ps1}'" >> "${BASH_PROFILE}"
fi
if [ -f "${VIRTME_PREPARE_POST}" ]; then
# shellcheck source=/dev/null
source "${VIRTME_PREPARE_POST}"
fi
}
run() {
printinfo "Run the virtme script: manual"
"${VIRTME_RUN}" "${VIRTME_RUN_OPTS[@]}" ${VIRTME_RUN_QEMU_OPTS:+--qemu-opts "${VIRTME_RUN_QEMU_OPTS[@]}"}
}
run_expect() { local mode timestamps_sec_stop no_tap=1
mode="${1}"
EXPECT=1
if is_ci; then
no_tap=0 # we want subtests
timestamps_sec_stop=$(date +%s)
# max - compilation time - before/after script
VIRTME_EXPECT_TEST_TIMEOUT=$((INPUT_CI_TIMEOUT_SEC - (timestamps_sec_stop - TIMESTAMPS_SEC_START) - VIRTME_CI_ESTIMATED_EXTRA_TIME))
else
# disable timeout
VIRTME_EXPECT_TEST_TIMEOUT="${INPUT_EXPECT_TIMEOUT}"
fi
# force a stop in case of panic, but avoid a reboot in "expect" mode
VIRTME_RUN_OPTS+=(--kopt panic=-1)
VIRTME_RUN_QEMU_OPTS+=(-no-reboot)
printinfo "Run the virtme script: expect (timeout: ${VIRTME_EXPECT_TEST_TIMEOUT})"
cat <<EOF > "${VIRTME_SCRIPT}"
#! /bin/bash
if [ "${INPUT_TRACE}" = "1" ]; then
set -x
fi
# To get debug info for stalled tests
(${VIRTME_SCRIPT_TIMEOUT} &)
# useful for virtme-exec-run
TAP_PREFIX="${KERNEL_SRC}/tools/testing/selftests/kselftest/prefix.pl"
RESULTS_DIR="${RESULTS_DIR}"
OUTPUT_VIRTME="${OUTPUT_VIRTME}"
KUNIT_CORE_LOADED=0
MAX_THREADS=${INPUT_MAX_THREADS:-$((INPUT_CPUS * 2))}
export SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES="${INPUT_SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES}"
export SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY="${INPUT_SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY}"
export SELFTESTS_MPTCP_LIB_COLOR_FORCE="${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE}"
export SELFTESTS_MPTCP_LIB_NO_TAP="${no_tap}"
set_max_threads() {
# if QEmu without KVM support
if [[ "${mode}" == *"debug" ]] ||
{ [ "\$(cat /sys/devices/virtual/dmi/id/sys_vendor)" = "QEMU" ] &&
[ "\$(cat /sys/devices/system/clocksource/clocksource0/current_clocksource)" != "kvm-clock" ]; }; then
MAX_THREADS=$((MAX_THREADS / 2)) # avoid too many concurrent work
fi
}
if [ "${GITHUB_ACTIONS}" = "true" ]; then
# \$1: description
log_section_start() {
echo -e "\n::group::${COLOR_YELLOW}\${*}${COLOR_RESET}"
}
log_section_end() {
echo -e "::endgroup::\n"
}
else
# \$1: description
log_section_start() {
echo -e "${COLOR_BLUE}\${*}${COLOR_RESET}"
}
log_section_end() {
true
}
fi
# \$1: name of the test
_can_run() { local tname
tname="\${1}"
# only some tests?
if [ -n "${INPUT_RUN_TESTS_ONLY}" ]; then
if ! echo "${INPUT_RUN_TESTS_ONLY}" | grep -wq "\${tname}"; then
return 1
fi
fi
# not some tests?
if [ -n "${INPUT_RUN_TESTS_EXCEPT}" ]; then
if echo "${INPUT_RUN_TESTS_EXCEPT}" | grep -wq "\${tname}"; then
return 1
fi
fi
return 0
}
can_run() {
# Use the function name of the caller without the prefix
_can_run "\${FUNCNAME[1]#*_}"
}
# \$1: file ; \$2+: commands
_tap() { local out out_subtests tmp fname rc ok nok msg cmt ts_s_start ts_s_stop
out="\${1}.tap"
out_subtests="\${1}_subtests.tap"
fname="\$(basename \${1})"
shift
rm -f "\${out}" "\${out_subtests}"
# With TAP, we have first the summary, then the diagnostic
tmp="\${out}.tmp"
ok="ok 1 test: \${fname}"
nok="not \${ok}"
ts_s_start=\$(date +%s)
# init
{
echo "TAP version 13"
echo "1..1"
} | tee "\${out}"
# Exec the command and pipe in tap prefix + store for later
"\${@}" 2>&1 | "\${TAP_PREFIX}" | tee "\${tmp}"
# output to stdout now to see the progression
rc=\${PIPESTATUS[0]}
ts_s_stop=\$(date +%s)
# summary
case \${rc} in
0)
msg="\${ok}"
;;
1)
msg="\${nok}"
cmt=FAIL
;;
2)
msg="\${nok}"
cmt=XFAIL
;;
3)
msg="\${nok}"
cmt=XPASS
;;
4)