forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/tools/testing/selftests/rcutorture/bin/kvm.sh
....@@ -1,4 +1,5 @@
11 #!/bin/bash
2
+# SPDX-License-Identifier: GPL-2.0+
23 #
34 # Run a series of tests under KVM. By default, this series is specified
45 # by the relevant CFLIST file, but can be overridden by the --configs
....@@ -6,23 +7,9 @@
67 #
78 # Usage: kvm.sh [ options ]
89 #
9
-# This program is free software; you can redistribute it and/or modify
10
-# it under the terms of the GNU General Public License as published by
11
-# the Free Software Foundation; either version 2 of the License, or
12
-# (at your option) any later version.
13
-#
14
-# This program is distributed in the hope that it will be useful,
15
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
-# GNU General Public License for more details.
18
-#
19
-# You should have received a copy of the GNU General Public License
20
-# along with this program; if not, you can access it online at
21
-# http://www.gnu.org/licenses/gpl-2.0.html.
22
-#
2310 # Copyright (C) IBM Corporation, 2011
2411 #
25
-# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
12
+# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
2613
2714 scriptname=$0
2815 args="$*"
....@@ -37,24 +24,32 @@
3724 dryrun=""
3825 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
3926 PATH=${KVM}/bin:$PATH; export PATH
27
+. functions.sh
28
+
29
+TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
4030 TORTURE_DEFCONFIG=defconfig
4131 TORTURE_BOOT_IMAGE=""
4232 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
4333 TORTURE_KCONFIG_ARG=""
34
+TORTURE_KCONFIG_GDB_ARG=""
35
+TORTURE_BOOT_GDB_ARG=""
36
+TORTURE_QEMU_GDB_ARG=""
37
+TORTURE_KCONFIG_KASAN_ARG=""
38
+TORTURE_KCONFIG_KCSAN_ARG=""
4439 TORTURE_KMAKE_ARG=""
4540 TORTURE_QEMU_MEM=512
4641 TORTURE_SHUTDOWN_GRACE=180
4742 TORTURE_SUITE=rcu
43
+TORTURE_TRUST_MAKE=""
4844 resdir=""
4945 configs=""
5046 cpus=0
51
-ds=`date +%Y.%m.%d-%H:%M:%S`
47
+ds=`date +%Y.%m.%d-%H.%M.%S`
5248 jitter="-1"
53
-
54
-. functions.sh
5549
5650 usage () {
5751 echo "Usage: $scriptname optional arguments:"
52
+ echo " --allcpus"
5853 echo " --bootargs kernel-boot-arguments"
5954 echo " --bootimage relative-path-to-kernel-boot-image"
6055 echo " --buildonly"
....@@ -64,23 +59,30 @@
6459 echo " --defconfig string"
6560 echo " --dryrun sched|script"
6661 echo " --duration minutes"
62
+ echo " --gdb"
63
+ echo " --help"
6764 echo " --interactive"
6865 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
6966 echo " --kconfig Kconfig-options"
7067 echo " --kmake-arg kernel-make-arguments"
7168 echo " --mac nn:nn:nn:nn:nn:nn"
72
- echo " --memory megabytes | nnnG"
69
+ echo " --memory megabytes|nnnG"
7370 echo " --no-initrd"
7471 echo " --qemu-args qemu-arguments"
7572 echo " --qemu-cmd qemu-system-..."
7673 echo " --results absolute-pathname"
77
- echo " --torture rcu"
74
+ echo " --torture lock|rcu|rcuscale|refscale|scf"
75
+ echo " --trust-make"
7876 exit 1
7977 }
8078
8179 while test $# -gt 0
8280 do
8381 case "$1" in
82
+ --allcpus)
83
+ cpus=$TORTURE_ALLOTED_CPUS
84
+ max_cpus=$TORTURE_ALLOTED_CPUS
85
+ ;;
8486 --bootargs|--bootarg)
8587 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
8688 TORTURE_BOOTARGS="$2"
....@@ -102,6 +104,12 @@
102104 --cpus)
103105 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
104106 cpus=$2
107
+ TORTURE_ALLOTED_CPUS="$2"
108
+ max_cpus="`identify_qemu_vcpus`"
109
+ if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
110
+ then
111
+ TORTURE_ALLOTED_CPUS=$max_cpus
112
+ fi
105113 shift
106114 ;;
107115 --datestamp)
....@@ -124,6 +132,14 @@
124132 dur=$(($2*60))
125133 shift
126134 ;;
135
+ --gdb)
136
+ TORTURE_KCONFIG_GDB_ARG="CONFIG_DEBUG_INFO=y"; export TORTURE_KCONFIG_GDB_ARG
137
+ TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG
138
+ TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG
139
+ ;;
140
+ --help|-h)
141
+ usage
142
+ ;;
127143 --interactive)
128144 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
129145 ;;
....@@ -136,6 +152,12 @@
136152 checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
137153 TORTURE_KCONFIG_ARG="$2"
138154 shift
155
+ ;;
156
+ --kasan)
157
+ TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
158
+ ;;
159
+ --kcsan)
160
+ TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_VERBOSE=y CONFIG_KCSAN_INTERRUPT_WATCHER=y"; export TORTURE_KCONFIG_KCSAN_ARG
139161 ;;
140162 --kmake-arg)
141163 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
....@@ -176,15 +198,19 @@
176198 shift
177199 ;;
178200 --torture)
179
- checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
201
+ checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\)$' '^--'
180202 TORTURE_SUITE=$2
181203 shift
182
- if test "$TORTURE_SUITE" = rcuperf
204
+ if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale
183205 then
184
- # If you really want jitter for rcuperf, specify
185
- # it after specifying rcuperf. (But why?)
206
+ # If you really want jitter for refscale or
207
+ # rcuscale, specify it after specifying the rcuscale
208
+ # or the refscale. (But why jitter in these cases?)
186209 jitter=0
187210 fi
211
+ ;;
212
+ --trust-make)
213
+ TORTURE_TRUST_MAKE="y"
188214 ;;
189215 *)
190216 echo Unknown argument $1
....@@ -194,11 +220,20 @@
194220 shift
195221 done
196222
223
+if test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
224
+then
225
+ :
226
+else
227
+ echo No initrd and unable to create one, aborting test >&2
228
+ exit 1
229
+fi
230
+
197231 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
198232
233
+defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
199234 if test -z "$configs"
200235 then
201
- configs="`cat $CONFIGFRAG/CFLIST`"
236
+ configs=$defaultconfigs
202237 fi
203238
204239 if test -z "$resdir"
....@@ -207,7 +242,7 @@
207242 fi
208243
209244 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
210
-touch $T/cfgcpu
245
+configs_derep=
211246 for CF in $configs
212247 do
213248 case $CF in
....@@ -220,15 +255,30 @@
220255 CF1=$CF
221256 ;;
222257 esac
258
+ for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
259
+ do
260
+ configs_derep="$configs_derep $CF1"
261
+ done
262
+done
263
+touch $T/cfgcpu
264
+configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
265
+if test -n "$TORTURE_KCONFIG_GDB_ARG"
266
+then
267
+ if test "`echo $configs_derep | wc -w`" -gt 1
268
+ then
269
+ echo "The --config list is: $configs_derep."
270
+ echo "Only one --config permitted with --gdb, terminating."
271
+ exit 1
272
+ fi
273
+fi
274
+for CF1 in $configs_derep
275
+do
223276 if test -f "$CONFIGFRAG/$CF1"
224277 then
225278 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
226279 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
227280 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
228
- for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
229
- do
230
- echo $CF1 $cpu_count >> $T/cfgcpu
231
- done
281
+ echo $CF1 $cpu_count >> $T/cfgcpu
232282 else
233283 echo "The --configs file $CF1 does not exist, terminating."
234284 exit 1
....@@ -290,11 +340,17 @@
290340 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
291341 KVM="$KVM"; export KVM
292342 PATH="$PATH"; export PATH
343
+TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
293344 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
294345 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
295346 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
296347 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
297348 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
349
+TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG
350
+TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG
351
+TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG
352
+TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG
353
+TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
298354 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
299355 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
300356 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
....@@ -302,11 +358,14 @@
302358 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
303359 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
304360 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
361
+TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
305362 if ! test -e $resdir
306363 then
307364 mkdir -p "$resdir" || :
308365 fi
309366 mkdir $resdir/$ds
367
+TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
368
+TORTURE_STOPFILE="$resdir/$ds/STOP"; export TORTURE_STOPFILE
310369 echo Results directory: $resdir/$ds
311370 echo $scriptname $args
312371 touch $resdir/$ds/log
....@@ -347,7 +406,7 @@
347406 print "needqemurun="
348407 jn=1
349408 for (j = first; j < pastlast; j++) {
350
- builddir=KVM "/b1"
409
+ builddir=KVM "/b" j - first + 1
351410 cpusr[jn] = cpus[j];
352411 if (cfrep[cf[j]] == "") {
353412 cfr[jn] = cf[j];
....@@ -363,7 +422,6 @@
363422 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
364423 print "rm -f " builddir ".*";
365424 print "touch " builddir ".wait";
366
- print "mkdir " builddir " > /dev/null 2>&1 || :";
367425 print "mkdir " rd cfr[jn] " || :";
368426 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
369427 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
....@@ -449,6 +507,7 @@
449507 echo
450508 echo " --- `date` Test summary:"
451509 echo Results directory: $resdir/$ds
510
+kcsan-collapse.sh $resdir/$ds
452511 kvm-recheck.sh $resdir/$ds
453512 ___EOF___
454513
....@@ -469,3 +528,9 @@
469528 fi
470529
471530 # Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier
531
+# Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
532
+# Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"
533
+# Control buffer size: --bootargs trace_buf_size=3k
534
+# Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops
535
+# Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu
536
+# Heavy-handed way to also dump on warnings: --bootargs panic_on_warn