xref: /linux/tools/testing/selftests/rcutorture/bin/torture.sh (revision 8b87f67b4c87452e21721887fa8dec1f4c6b2b7c)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Run a series of torture tests, intended for overnight or
5# longer timeframes, and also for large systems.
6#
7# Usage: torture.sh [ options ]
8#
9# Copyright (C) 2020 Facebook, Inc.
10#
11# Authors: Paul E. McKenney <paulmck@kernel.org>
12
13scriptname=$0
14args="$*"
15
16RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
17PATH=${RCUTORTURE}/bin:$PATH; export PATH
18. functions.sh
19
20TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
21MAKE_ALLOTED_CPUS=$((TORTURE_ALLOTED_CPUS*2))
22SCALE_ALLOTED_CPUS=$((TORTURE_ALLOTED_CPUS/2))
23if test "$SCALE_ALLOTED_CPUS" -lt 1
24then
25	SCALE_ALLOTED_CPUS=1
26fi
27VERBOSE_BATCH_CPUS=$((TORTURE_ALLOTED_CPUS/16))
28if test "$VERBOSE_BATCH_CPUS" -lt 2
29then
30	VERBOSE_BATCH_CPUS=0
31fi
32
33# Machine architecture?  ("uname -p" is said to be less portable.)1
34thisarch="`uname -m`"
35if test "${thisarch}" = aarch64
36then
37	ifnotaarch64=no
38else
39	ifnotaarch64=yes
40fi
41
42# Configurations/scenarios.
43configs_rcutorture=
44configs_locktorture=
45configs_scftorture=
46kcsan_kmake_args=
47
48# Default compression, duration, and apportionment.
49compress_concurrency="`identify_qemu_vcpus`"
50duration_base=10
51duration_rcutorture_frac=7
52duration_locktorture_frac=1
53duration_scftorture_frac=2
54
55# "yes" or "no" parameters
56do_allmodconfig=yes
57do_rcutorture=yes
58do_locktorture=yes
59do_scftorture=yes
60do_rcuscale=yes
61do_refscale=yes
62do_kvfree=yes
63do_normal=yes
64explicit_normal=no
65do_kasan=yes
66do_kcsan=no
67do_clocksourcewd="${ifnotaarch64}"
68do_rt=yes
69do_rcutasksflavors="${ifnotaarch64}" # FIXME: Back to "yes" when SMP=n auto-avoided
70do_srcu_lockdep=yes
71do_rcu_rust=no
72
73# doyesno - Helper function for yes/no arguments
74function doyesno () {
75	if test "$1" = "$2"
76	then
77		echo yes
78	else
79		echo no
80	fi
81}
82
83usage () {
84	echo "Usage: $scriptname optional arguments:"
85	echo "       --compress-concurrency concurrency"
86	echo "       --configs-rcutorture \"config-file list w/ repeat factor (3*TINY01)\""
87	echo "       --configs-locktorture \"config-file list w/ repeat factor (10*LOCK01)\""
88	echo "       --configs-scftorture \"config-file list w/ repeat factor (2*CFLIST)\""
89	echo "       --do-all"
90	echo "       --do-allmodconfig / --do-no-allmodconfig / --no-allmodconfig"
91	echo "       --do-clocksourcewd / --do-no-clocksourcewd / --no-clocksourcewd"
92	echo "       --do-kasan / --do-no-kasan / --no-kasan"
93	echo "       --do-kcsan / --do-no-kcsan / --no-kcsan"
94	echo "       --do-kvfree / --do-no-kvfree / --no-kvfree"
95	echo "       --do-locktorture / --do-no-locktorture / --no-locktorture"
96	echo "       --do-none"
97	echo "       --do-rcuscale / --do-no-rcuscale / --no-rcuscale"
98	echo "       --do-rcutasksflavors / --do-no-rcutasksflavors / --no-rcutasksflavors"
99	echo "       --do-rcutorture / --do-no-rcutorture / --no-rcutorture"
100	echo "       --do-refscale / --do-no-refscale / --no-refscale"
101	echo "       --do-rt / --do-no-rt / --no-rt"
102	echo "       --do-rcu-rust / --do-no-rcu-rust / --no-rcu-rust"
103	echo "       --do-scftorture / --do-no-scftorture / --no-scftorture"
104	echo "       --do-srcu-lockdep / --do-no-srcu-lockdep / --no-srcu-lockdep"
105	echo "       --duration [ <minutes> | <hours>h | <days>d ]"
106	echo "       --guest-cpu-limit N"
107	echo "       --kcsan-kmake-arg kernel-make-arguments"
108	exit 1
109}
110
111while test $# -gt 0
112do
113	case "$1" in
114	--compress-concurrency)
115		checkarg --compress-concurrency "(concurrency level)" $# "$2" '^[0-9][0-9]*$' '^error'
116		compress_concurrency=$2
117		shift
118		;;
119	--config-rcutorture|--configs-rcutorture)
120		checkarg --configs-rcutorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
121		configs_rcutorture="$configs_rcutorture $2"
122		shift
123		;;
124	--config-locktorture|--configs-locktorture)
125		checkarg --configs-locktorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
126		configs_locktorture="$configs_locktorture $2"
127		shift
128		;;
129	--config-scftorture|--configs-scftorture)
130		checkarg --configs-scftorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
131		configs_scftorture="$configs_scftorture $2"
132		shift
133		;;
134	--do-all|--doall)
135		do_allmodconfig=yes
136		do_rcutasksflavors="${ifnotaarch64}" # FIXME: Back to "yes" when SMP=n auto-avoided
137		do_rcutorture=yes
138		do_locktorture=yes
139		do_scftorture=yes
140		do_rcuscale=yes
141		do_refscale=yes
142		do_rt=yes
143		do_kvfree=yes
144		do_normal=yes
145		explicit_normal=no
146		do_kasan=yes
147		do_kcsan=yes
148		do_clocksourcewd="${ifnotaarch64}"
149		do_srcu_lockdep=yes
150		;;
151	--do-allmodconfig|--do-no-allmodconfig|--no-allmodconfig)
152		do_allmodconfig=`doyesno "$1" --do-allmodconfig`
153		;;
154	--do-clocksourcewd|--do-no-clocksourcewd|--no-clocksourcewd)
155		do_clocksourcewd=`doyesno "$1" --do-clocksourcewd`
156		;;
157	--do-kasan|--do-no-kasan|--no-kasan)
158		do_kasan=`doyesno "$1" --do-kasan`
159		;;
160	--do-kcsan|--do-no-kcsan|--no-kcsan)
161		do_kcsan=`doyesno "$1" --do-kcsan`
162		;;
163	--do-kvfree|--do-no-kvfree|--no-kvfree)
164		do_kvfree=`doyesno "$1" --do-kvfree`
165		;;
166	--do-locktorture|--do-no-locktorture|--no-locktorture)
167		do_locktorture=`doyesno "$1" --do-locktorture`
168		;;
169	--do-none|--donone)
170		do_allmodconfig=no
171		do_rcutasksflavors=no
172		do_rcutorture=no
173		do_locktorture=no
174		do_scftorture=no
175		do_rcuscale=no
176		do_refscale=no
177		do_rt=no
178		do_kvfree=no
179		do_normal=no
180		explicit_normal=no
181		do_kasan=no
182		do_kcsan=no
183		do_clocksourcewd=no
184		do_srcu_lockdep=no
185		;;
186	--do-normal|--do-no-normal|--no-normal)
187		do_normal=`doyesno "$1" --do-normal`
188		explicit_normal=yes
189		;;
190	--do-rcuscale|--do-no-rcuscale|--no-rcuscale)
191		do_rcuscale=`doyesno "$1" --do-rcuscale`
192		;;
193	--do-rcutasksflavors|--do-no-rcutasksflavors|--no-rcutasksflavors)
194		do_rcutasksflavors=`doyesno "$1" --do-rcutasksflavors`
195		;;
196	--do-rcutorture|--do-no-rcutorture|--no-rcutorture)
197		do_rcutorture=`doyesno "$1" --do-rcutorture`
198		;;
199	--do-refscale|--do-no-refscale|--no-refscale)
200		do_refscale=`doyesno "$1" --do-refscale`
201		;;
202	--do-rt|--do-no-rt|--no-rt)
203		do_rt=`doyesno "$1" --do-rt`
204		;;
205	--do-rcu-rust|--do-no-rcu-rust|--no-rcu-rust)
206		do_rcu_rust=`doyesno "$1" --do-rcu-rust`
207		;;
208	--do-scftorture|--do-no-scftorture|--no-scftorture)
209		do_scftorture=`doyesno "$1" --do-scftorture`
210		;;
211	--do-srcu-lockdep|--do-no-srcu-lockdep|--no-srcu-lockdep)
212		do_srcu_lockdep=`doyesno "$1" --do-srcu-lockdep`
213		;;
214	--duration)
215		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(m\|h\|d\|\)$' '^error'
216		mult=1
217		if echo "$2" | grep -q 'm$'
218		then
219			mult=1
220		elif echo "$2" | grep -q 'h$'
221		then
222			mult=60
223		elif echo "$2" | grep -q 'd$'
224		then
225			mult=1440
226		fi
227		ts=`echo $2 | sed -e 's/[smhd]$//'`
228		duration_base=$(($ts*mult))
229		shift
230		;;
231	--guest-cpu-limit|--guest-cpu-lim)
232		checkarg --guest-cpu-limit "(number)" "$#" "$2" '^[0-9]*$' '^--'
233		if (("$2" <= "$TORTURE_ALLOTED_CPUS" / 2))
234		then
235			SCALE_ALLOTED_CPUS="$2"
236			VERBOSE_BATCH_CPUS="$((SCALE_ALLOTED_CPUS/8))"
237			if (("$VERBOSE_BATCH_CPUS" < 2))
238			then
239				VERBOSE_BATCH_CPUS=0
240			fi
241		else
242			echo "Ignoring value of $2 for --guest-cpu-limit which is greater than (("$TORTURE_ALLOTED_CPUS" / 2))."
243		fi
244		shift
245		;;
246	--kcsan-kmake-arg|--kcsan-kmake-args)
247		checkarg --kcsan-kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
248		kcsan_kmake_args="`echo "$kcsan_kmake_args $2" | sed -e 's/^ *//' -e 's/ *$//'`"
249		shift
250		;;
251	*)
252		echo Unknown argument $1
253		usage
254		;;
255	esac
256	shift
257done
258
259ds="`date +%Y.%m.%d-%H.%M.%S`-torture"
260startdate="`date`"
261starttime="`get_starttime`"
262
263T="`mktemp -d ${TMPDIR-/tmp}/torture.sh.XXXXXX`"
264trap 'rm -rf $T' 0 2
265
266echo " --- " $scriptname $args | tee -a $T/log
267echo " --- Results directory: " $ds | tee -a $T/log
268
269if test "$do_normal" = "no" && test "$do_kasan" = "no" && test "$do_kcsan" = "no"
270then
271	# Match old scripts so that "--do-none --do-rcutorture" does
272	# normal rcutorture testing, but no KASAN or KCSAN testing.
273	if test $explicit_normal = yes
274	then
275		echo " --- Everything disabled, so explicit --do-normal overridden" | tee -a $T/log
276	fi
277	do_normal=yes
278fi
279
280# Calculate rcutorture defaults and apportion time
281if test -z "$configs_rcutorture"
282then
283	configs_rcutorture=CFLIST
284fi
285duration_rcutorture=$((duration_base*duration_rcutorture_frac/10))
286if test "$duration_rcutorture" -eq 0 && test "$do_locktorture" = "yes"
287then
288	echo " --- Zero time for rcutorture, disabling" | tee -a $T/log
289	do_rcutorture=no
290fi
291
292# Calculate locktorture defaults and apportion time
293if test -z "$configs_locktorture"
294then
295	configs_locktorture=CFLIST
296fi
297duration_locktorture=$((duration_base*duration_locktorture_frac/10))
298if test "$duration_locktorture" -eq 0 && test "$do_locktorture" = "yes"
299then
300	echo " --- Zero time for locktorture, disabling" | tee -a $T/log
301	do_locktorture=no
302fi
303
304# Calculate scftorture defaults and apportion time
305if test -z "$configs_scftorture"
306then
307	configs_scftorture=CFLIST
308fi
309duration_scftorture=$((duration_base*duration_scftorture_frac/10))
310if test "$duration_scftorture" -eq 0 && test "$do_scftorture" = "yes"
311then
312	echo " --- Zero time for scftorture, disabling" | tee -a $T/log
313	do_scftorture=no
314fi
315
316# CONFIG_EXPERT=y is currently required for arm64 KCSAN runs.
317kcsan_expert=
318if test "${thisarch}" = aarch64
319then
320	kcsan_expert="CONFIG_EXPERT=y"
321fi
322
323touch $T/failures
324touch $T/successes
325
326# torture_one - Does a single kvm.sh run.
327#
328# Usage:
329#	torture_bootargs="[ kernel boot arguments ]"
330#	torture_one flavor [ kvm.sh arguments ]
331#
332# Note that "flavor" is an arbitrary string.  Supply --torture if needed.
333# Note that quoting is problematic.  So on the command line, pass multiple
334# values with multiple kvm.sh argument instances.
335function torture_one {
336	local cur_bootargs=
337	local boottag=
338
339	echo " --- $curflavor:" Start `date` | tee -a $T/log
340	if test -n "$torture_bootargs"
341	then
342		boottag="--bootargs"
343		cur_bootargs="$torture_bootargs"
344	fi
345	"$@" $boottag "$cur_bootargs" --datestamp "$ds/results-$curflavor" > $T/$curflavor.out 2>&1
346	retcode=$?
347	resdir="`grep '^Results directory: ' $T/$curflavor.out | tail -1 | sed -e 's/^Results directory: //'`"
348	if test -z "$resdir"
349	then
350		cat $T/$curflavor.out | tee -a $T/log
351		echo retcode=$retcode | tee -a $T/log
352	else
353		echo $resdir > $T/last-resdir
354	fi
355	if test "$retcode" == 0
356	then
357		echo "$curflavor($retcode)" $resdir >> $T/successes
358	else
359		echo "$curflavor($retcode)" $resdir >> $T/failures
360	fi
361}
362
363# torture_set - Does a set of tortures with and without KASAN and KCSAN.
364#
365# Usage:
366#	torture_bootargs="[ kernel boot arguments ]"
367#	torture_set flavor [ kvm.sh arguments ]
368#
369# Note that "flavor" is an arbitrary string that does not affect kvm.sh
370# in any way.  So also supply --torture if you need something other than
371# the default.
372function torture_set {
373	local cur_kcsan_kmake_args=
374	local kcsan_kmake_tag=
375	local flavor=$1
376	shift
377	if test "$do_normal" = "yes"
378	then
379		curflavor=$flavor
380		torture_one "$@"
381		if test -e $T/last-resdir
382		then
383			mv $T/last-resdir $T/last-resdir-nodebug || :
384		fi
385	fi
386	if test "$do_kasan" = "yes"
387	then
388		curflavor=${flavor}-kasan
389		torture_one "$@" --kasan
390		if test -e $T/last-resdir
391		then
392			mv $T/last-resdir $T/last-resdir-kasan || :
393		fi
394	fi
395	if test "$do_kcsan" = "yes"
396	then
397		curflavor=${flavor}-kcsan
398		if test -n "$kcsan_kmake_args"
399		then
400			kcsan_kmake_tag="--kmake-args"
401			cur_kcsan_kmake_args="$kcsan_kmake_args"
402		fi
403		chk_rdr_state=
404		if test "${flavor}" = rcutorture
405		then
406			chk_rdr_state="CONFIG_RCU_TORTURE_TEST_CHK_RDR_STATE=y"
407		fi
408		torture_one "$@" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y ${kcsan_expert} ${chk_rdr_state}" $kcsan_kmake_tag $cur_kcsan_kmake_args --kcsan
409		if test -e $T/last-resdir
410		then
411			mv $T/last-resdir $T/last-resdir-kcsan || :
412		fi
413	fi
414}
415
416# make allmodconfig
417if test "$do_allmodconfig" = "yes"
418then
419	echo " --- allmodconfig:" Start `date` | tee -a $T/log
420	amcdir="tools/testing/selftests/rcutorture/res/$ds/allmodconfig"
421	mkdir -p "$amcdir"
422	mktestid.sh "$amcdir"
423	echo " --- make clean" | tee $amcdir/log > "$amcdir/Make.out" 2>&1
424	make -j$MAKE_ALLOTED_CPUS clean >> "$amcdir/Make.out" 2>&1
425	retcode=$?
426	buildphase='"make clean"'
427	if test "$retcode" -eq 0
428	then
429		echo " --- make allmodconfig" | tee -a $amcdir/log >> "$amcdir/Make.out" 2>&1
430		cp .config $amcdir
431		make -j$MAKE_ALLOTED_CPUS allmodconfig >> "$amcdir/Make.out" 2>&1
432		retcode=$?
433		buildphase='"make allmodconfig"'
434	fi
435	if test "$retcode" -eq 0
436	then
437		echo " --- make " | tee -a $amcdir/log >> "$amcdir/Make.out" 2>&1
438		make -j$MAKE_ALLOTED_CPUS >> "$amcdir/Make.out" 2>&1
439		retcode="$?"
440		echo $retcode > "$amcdir/Make.exitcode"
441		if grep -E -q "Stop|ERROR|Error|error:|warning:" < "$amcdir/Make.out"
442		then
443			retcode=99
444		fi
445		buildphase='"make"'
446	fi
447	if test "$retcode" -eq 0
448	then
449		echo "allmodconfig($retcode)" $amcdir >> $T/successes
450		echo Success >> $amcdir/log
451	else
452		echo "allmodconfig($retcode)" $amcdir >> $T/failures
453		echo " --- allmodconfig Test summary:" >> $amcdir/log
454		echo " --- Summary: Exit code $retcode from $buildphase, see Make.out" >> $amcdir/log
455	fi
456fi
457
458# Test building RCU Tasks flavors in isolation, both SMP and !SMP
459if test "$do_rcutasksflavors" = "yes"
460then
461	echo " --- rcutasksflavors:" Start `date` | tee -a $T/log
462	rtfdir="tools/testing/selftests/rcutorture/res/$ds/results-rcutasksflavors"
463	mkdir -p "$rtfdir"
464	cat > $T/rcutasksflavors << __EOF__
465#CHECK#CONFIG_TASKS_RCU=n
466#CHECK#CONFIG_TASKS_RUDE_RCU=n
467#CHECK#CONFIG_TASKS_TRACE_RCU=n
468__EOF__
469	for flavor in CONFIG_TASKS_RCU CONFIG_TASKS_RUDE_RCU CONFIG_TASKS_TRACE_RCU
470	do
471		forceflavor="`echo $flavor | sed -e 's/^CONFIG/CONFIG_FORCE/'`"
472		deselectedflavors="`grep -v $flavor $T/rcutasksflavors | tr '\012' ' ' | tr -s ' ' | sed -e 's/ *$//'`"
473		echo " --- Running RCU Tasks Trace flavor $flavor `date`" >> $rtfdir/log
474		tools/testing/selftests/rcutorture/bin/kvm.sh --datestamp "$ds/results-rcutasksflavors/$flavor" --buildonly --configs "TINY01 TREE04" --kconfig "CONFIG_RCU_EXPERT=y CONFIG_RCU_SCALE_TEST=y CONFIG_KPROBES=n CONFIG_RCU_TRACE=n CONFIG_TRACING=n CONFIG_BLK_DEV_IO_TRACE=n CONFIG_UPROBE_EVENTS=n $forceflavor=y $deselectedflavors" --trust-make > $T/$flavor.out 2>&1
475		retcode=$?
476		if test "$retcode" -ne 0
477		then
478			break
479		fi
480	done
481	if test "$retcode" -eq 0
482	then
483		echo "rcutasksflavors($retcode)" $rtfdir >> $T/successes
484		echo Success >> $rtfdir/log
485	else
486		echo "rcutasksflavors($retcode)" $rtfdir >> $T/failures
487		echo " --- rcutasksflavors Test summary:" >> $rtfdir/log
488		echo " --- Summary: Exit code $retcode from $flavor, see Make.out" >> $rtfdir/log
489	fi
490fi
491
492# --torture rcu
493if test "$do_rcutorture" = "yes"
494then
495	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000"
496	torture_set "rcutorture" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration "$duration_rcutorture" --configs "$configs_rcutorture" --trust-make
497fi
498
499if test "$do_locktorture" = "yes"
500then
501	torture_bootargs="torture.disable_onoff_at_boot"
502	torture_set "locktorture" tools/testing/selftests/rcutorture/bin/kvm.sh --torture lock --allcpus --duration "$duration_locktorture" --configs "$configs_locktorture" --trust-make
503fi
504
505if test "$do_scftorture" = "yes"
506then
507	# Scale memory based on the number of CPUs.
508	scfmem=$((3+SCALE_ALLOTED_CPUS/16))
509	torture_bootargs="scftorture.nthreads=$SCALE_ALLOTED_CPUS torture.disable_onoff_at_boot csdlock_debug=1"
510	torture_set "scftorture" tools/testing/selftests/rcutorture/bin/kvm.sh --torture scf --allcpus --duration "$duration_scftorture" --configs "$configs_scftorture" --kconfig "CONFIG_NR_CPUS=$SCALE_ALLOTED_CPUS" --memory ${scfmem}G --trust-make
511fi
512
513if test "$do_rt" = "yes"
514then
515	# In both runs, disable testing of RCU priority boosting because
516	# -rt doesn't like its interaction with testing of callback
517	# flooding.
518
519	# With all post-boot grace periods forced to normal (default for PREEMPT_RT).
520	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 rcutorture.test_boost=0 rcutorture.preempt_duration=0"
521	torture_set "rcurttorture" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration "$duration_rcutorture" --configs "TREE03" --kconfig "CONFIG_PREEMPT_RT=y CONFIG_EXPERT=y CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_IDLE=y CONFIG_RCU_NOCB_CPU=y" --trust-make
522
523	# With all post-boot grace periods forced to expedited.
524	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 rcutorture.test_boost=0 rcupdate.rcu_normal_after_boot=0 rcupdate.rcu_expedited=1 rcutorture.preempt_duration=0"
525	torture_set "rcurttorture-exp" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration "$duration_rcutorture" --configs "TREE03" --kconfig "CONFIG_PREEMPT_RT=y CONFIG_EXPERT=y CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_FULL=y CONFIG_RCU_NOCB_CPU=y" --trust-make
526fi
527
528if test "$do_rcu_rust" = "yes"
529then
530	echo " --- do-rcu-rust:" Start `date` | tee -a $T/log
531	rrdir="tools/testing/selftests/rcutorture/res/$ds/results-rcu-rust"
532	mkdir -p "$rrdir"
533	mktestid.sh "$rrdir"
534	echo " --- make LLVM=1 rustavailable " | tee -a $rrdir/log > $rrdir/rustavailable.out
535	make LLVM=1 rustavailable > $T/rustavailable.out 2>&1
536	retcode=$?
537	echo $retcode > $rrdir/rustavailable.exitcode
538	cat $T/rustavailable.out | tee -a $rrdir/log >> $rrdir/rustavailable.out 2>&1
539	buildphase=rustavailable
540	if test "$retcode" -eq 0
541	then
542		echo " --- Running 'make mrproper' in order to run kunit." | tee -a $rrdir/log > $rrdir/mrproper.out
543		make mrproper > $rrdir/mrproper.out 2>&1
544		retcode=$?
545		echo $retcode > $rrdir/mrproper.exitcode
546		buildphase=mrproper
547	fi
548	if test "$retcode" -eq 0
549	then
550		echo " --- Running rust_doctests_kernel." | tee -a $rrdir/log > $rrdir/rust_doctests_kernel.out
551		./tools/testing/kunit/kunit.py run --make_options LLVM=1 --make_options CLIPPY=1 --arch arm64 --kconfig_add CONFIG_SMP=y --kconfig_add CONFIG_WERROR=y --kconfig_add CONFIG_RUST=y rust_doctests_kernel >> $rrdir/rust_doctests_kernel.out 2>&1
552		# @@@ Remove "--arch arm64" in order to test on native architecture?
553		# @@@ Analyze $rrdir/rust_doctests_kernel.out contents?
554		retcode=$?
555		echo $retcode > $rrdir/rust_doctests_kernel.exitcode
556		buildphase=rust_doctests_kernel
557	fi
558	if test "$retcode" -eq 0
559	then
560		echo "rcu-rust($retcode)" $rrdir >> $T/successes
561		echo Success >> $rrdir/log
562	else
563		echo "rcu-rust($retcode)" $rrdir >> $T/failures
564		echo " --- rcu-rust Test summary:" >> $rrdir/log
565		echo " --- Summary: Exit code $retcode from $buildphase, see $rrdir/$buildphase.out" >> $rrdir/log
566	fi
567fi
568
569if test "$do_srcu_lockdep" = "yes"
570then
571	echo " --- do-srcu-lockdep:" Start `date` | tee -a $T/log
572	tools/testing/selftests/rcutorture/bin/srcu_lockdep.sh --datestamp "$ds/results-srcu-lockdep" > $T/srcu_lockdep.sh.out 2>&1
573	retcode=$?
574	cp $T/srcu_lockdep.sh.out "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep/log"
575	if test "$retcode" -eq 0
576	then
577		echo "srcu_lockdep($retcode)" "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep" >> $T/successes
578		echo Success >> "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep/log"
579	else
580		echo "srcu_lockdep($retcode)" "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep" >> $T/failures
581		echo " --- srcu_lockdep Test Summary:" >> "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep/log"
582		echo " --- Summary: Exit code $retcode from srcu_lockdep.sh, see ds/results-srcu-lockdep" >> "tools/testing/selftests/rcutorture/res/$ds/results-srcu-lockdep/log"
583	fi
584fi
585
586if test "$do_refscale" = yes
587then
588	primlist="`grep '\.name[ 	]*=' kernel/rcu/refscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`"
589else
590	primlist=
591fi
592firsttime=1
593do_kasan_save="$do_kasan"
594do_kcsan_save="$do_kcsan"
595for prim in $primlist
596do
597	if test -n "$firsttime"
598	then
599		torture_bootargs="refscale.scale_type="$prim" refscale.nreaders=$SCALE_ALLOTED_CPUS refscale.loops=10000 refscale.holdoff=20 torture.disable_onoff_at_boot"
600		torture_set "refscale-$prim" tools/testing/selftests/rcutorture/bin/kvm.sh --torture refscale --allcpus --duration 5 --kconfig "CONFIG_TASKS_TRACE_RCU=y CONFIG_NR_CPUS=$SCALE_ALLOTED_CPUS" --bootargs "refscale.verbose_batched=$VERBOSE_BATCH_CPUS torture.verbose_sleep_frequency=8 torture.verbose_sleep_duration=$VERBOSE_BATCH_CPUS" --trust-make
601		mv $T/last-resdir-nodebug $T/first-resdir-nodebug || :
602		if test -f "$T/last-resdir-kasan"
603		then
604			mv $T/last-resdir-kasan $T/first-resdir-kasan || :
605		fi
606		if test -f "$T/last-resdir-kcsan"
607		then
608			mv $T/last-resdir-kcsan $T/first-resdir-kcsan || :
609		fi
610		firsttime=
611		do_kasan=
612		do_kcsan=
613	else
614		torture_bootargs=
615		for i in $T/first-resdir-*
616		do
617			case "$i" in
618			*-nodebug)
619				torture_suffix=
620				;;
621			*-kasan)
622				torture_suffix="-kasan"
623				;;
624			*-kcsan)
625				torture_suffix="-kcsan"
626				;;
627			esac
628			torture_set "refscale-$prim$torture_suffix" tools/testing/selftests/rcutorture/bin/kvm-again.sh "`cat "$i"`" --duration 5 --bootargs "refscale.scale_type=$prim"
629		done
630	fi
631done
632do_kasan="$do_kasan_save"
633do_kcsan="$do_kcsan_save"
634
635if test "$do_rcuscale" = yes
636then
637	primlist="`grep '\.name[ 	]*=' kernel/rcu/rcuscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`"
638else
639	primlist=
640fi
641firsttime=1
642do_kasan_save="$do_kasan"
643do_kcsan_save="$do_kcsan"
644for prim in $primlist
645do
646	if test -n "$firsttime"
647	then
648		torture_bootargs="rcuscale.scale_type="$prim" rcuscale.nwriters=$SCALE_ALLOTED_CPUS rcuscale.holdoff=20 torture.disable_onoff_at_boot"
649		torture_set "rcuscale-$prim" tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus --duration 5 --kconfig "CONFIG_TASKS_TRACE_RCU=y CONFIG_NR_CPUS=$SCALE_ALLOTED_CPUS" --trust-make
650		mv $T/last-resdir-nodebug $T/first-resdir-nodebug || :
651		if test -f "$T/last-resdir-kasan"
652		then
653			mv $T/last-resdir-kasan $T/first-resdir-kasan || :
654		fi
655		if test -f "$T/last-resdir-kcsan"
656		then
657			mv $T/last-resdir-kcsan $T/first-resdir-kcsan || :
658		fi
659		firsttime=
660		do_kasan=
661		do_kcsan=
662	else
663		torture_bootargs=
664		for i in $T/first-resdir-*
665		do
666			case "$i" in
667			*-nodebug)
668				torture_suffix=
669				;;
670			*-kasan)
671				torture_suffix="-kasan"
672				;;
673			*-kcsan)
674				torture_suffix="-kcsan"
675				;;
676			esac
677			torture_set "rcuscale-$prim$torture_suffix" tools/testing/selftests/rcutorture/bin/kvm-again.sh "`cat "$i"`" --duration 5 --bootargs "rcuscale.scale_type=$prim"
678		done
679	fi
680done
681do_kasan="$do_kasan_save"
682do_kcsan="$do_kcsan_save"
683
684if test "$do_kvfree" = "yes"
685then
686	torture_bootargs="rcuscale.kfree_rcu_test=1 rcuscale.kfree_nthreads=16 rcuscale.holdoff=20 rcuscale.kfree_loops=10000 torture.disable_onoff_at_boot"
687	torture_set "rcuscale-kvfree" tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus --duration $duration_rcutorture --kconfig "CONFIG_NR_CPUS=$SCALE_ALLOTED_CPUS" --memory 2G --trust-make
688fi
689
690if test "$do_clocksourcewd" = "yes"
691then
692	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 tsc=watchdog"
693	torture_set "clocksourcewd-1" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --kconfig "CONFIG_TEST_CLOCKSOURCE_WATCHDOG=y" --trust-make
694
695	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 tsc=watchdog"
696	torture_set "clocksourcewd-2" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --kconfig "CONFIG_TEST_CLOCKSOURCE_WATCHDOG=y" --trust-make
697
698	# In case our work is already done...
699	if test "$do_rcutorture" != "yes"
700	then
701		torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 tsc=watchdog"
702		torture_set "clocksourcewd-3" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --trust-make
703	fi
704fi
705
706echo " --- " $scriptname $args
707echo " --- " Done `date` | tee -a $T/log
708ret=0
709nsuccesses=0
710echo SUCCESSES: | tee -a $T/log
711if test -s "$T/successes"
712then
713	cat "$T/successes" | tee -a $T/log
714	nsuccesses="`wc -l "$T/successes" | awk '{ print $1 }'`"
715fi
716nfailures=0
717echo FAILURES: | tee -a $T/log
718if test -s "$T/failures"
719then
720	awk < "$T/failures" -v sq="'" '
721	{
722		print "echo " sq $0 sq;
723		if ($2 != "")
724			print "sed -e " sq "1,/^ --- .* Test summary:$/d" sq " " $2 "/log | grep Summary: | sed -e " sq "s/^[^S]*/  /" sq;
725		else
726			print "echo " sq "  " sq "Run failed to produce results directory.";
727	}' | sh | tee -a $T/log | tee "$T/failuresum"
728	nfailures="`wc -l "$T/failures" | awk '{ print $1 }'`"
729	grep "^  Summary: " "$T/failuresum" |
730		grep -v '^  Summary: Bugs: [0-9]* (all bugs kcsan)$' > "$T/nonkcsan"
731	if test -s "$T/nonkcsan"
732	then
733		nonkcsanbug="yes"
734	fi
735	ret=2
736fi
737if test "$do_kcsan" = "yes" && test -e tools/testing/selftests/rcutorture/res/$ds
738then
739	TORTURE_KCONFIG_KCSAN_ARG=1 tools/testing/selftests/rcutorture/bin/kcsan-collapse.sh tools/testing/selftests/rcutorture/res/$ds > tools/testing/selftests/rcutorture/res/$ds/kcsan.sum
740fi
741echo Started at $startdate, ended at `date`, duration `get_starttime_duration $starttime`. | tee -a $T/log
742echo Summary: Successes: $nsuccesses Failures: $nfailures. | tee -a $T/log
743tdir="`cat $T/successes $T/failures | awk 'NF > 1 { print $NF }' | head -1 | sed -e 's,/[^/]\+/*$,,'`"
744if test -n "$tdir"
745then
746	find "$tdir" -name 'ConfigFragment.diags' -print > $T/configerrors
747	find "$tdir" -name 'Make.out.diags' -print > $T/builderrors
748fi
749if test -s "$T/configerrors"
750then
751	echo "  Scenarios with .config errors: `wc -l "$T/configerrors" | awk '{ print $1 }'`"
752	nonkcsanbug="yes"
753fi
754if test -s "$T/builderrors"
755then
756	echo "  Scenarios with build errors: `wc -l "$T/builderrors" | awk '{ print $1 }'`"
757	nonkcsanbug="yes"
758fi
759if test -z "$nonkcsanbug" && test -s "$T/failuresum"
760then
761	echo "  All bugs were KCSAN failures."
762fi
763if test -n "$tdir" && test $compress_concurrency -gt 0
764then
765	# KASAN vmlinux files can approach 1GB in size, so compress them.
766	echo Looking for K[AC]SAN files to compress: `date` > "$tdir/log-xz" 2>&1
767	find "$tdir" -type d -name '*-k[ac]san' -print > $T/xz-todo-all
768	find "$tdir" -type f -name 're-run' -print | sed -e 's,/re-run,,' |
769		grep -e '-k[ac]san$' > $T/xz-todo-copy
770	sort $T/xz-todo-all $T/xz-todo-copy | uniq -u > $T/xz-todo
771	ncompresses=0
772	batchno=1
773	if test -s $T/xz-todo
774	then
775		for i in `cat $T/xz-todo`
776		do
777			find $i -name 'vmlinux*' -print
778		done | wc -l | awk '{ print $1 }' > $T/xz-todo-count
779		n2compress="`cat $T/xz-todo-count`"
780		echo Size before compressing $n2compress files: `du -sh $tdir | awk '{ print $1 }'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
781		for i in `cat $T/xz-todo`
782		do
783			echo Compressing vmlinux files in ${i}: `date` >> "$tdir/log-xz" 2>&1
784			for j in $i/*/vmlinux
785			do
786				xz "$j" >> "$tdir/log-xz" 2>&1 &
787				ncompresses=$((ncompresses+1))
788				if test $ncompresses -ge $compress_concurrency
789				then
790					echo Waiting for batch $batchno of $ncompresses compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
791					wait
792					ncompresses=0
793					batchno=$((batchno+1))
794				fi
795			done
796		done
797		if test $ncompresses -gt 0
798		then
799			echo Waiting for final batch $batchno of $ncompresses compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
800		fi
801		wait
802		if test -s $T/xz-todo-copy
803		then
804			# The trick here is that we need corresponding
805			# vmlinux files from corresponding scenarios.
806			echo Linking vmlinux.xz files to re-use scenarios `date` | tee -a "$tdir/log-xz" | tee -a $T/log
807			dirstash="`pwd`"
808			for i in `cat $T/xz-todo-copy`
809			do
810				cd $i
811				find . -name vmlinux -print > $T/xz-todo-copy-vmlinux
812				for v in `cat $T/xz-todo-copy-vmlinux`
813				do
814					rm -f "$v"
815					cp -l `cat $i/re-run`/"$i/$v".xz "`dirname "$v"`"
816				done
817				cd "$dirstash"
818			done
819		fi
820		echo Size after compressing $n2compress files: `du -sh $tdir | awk '{ print $1 }'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
821		echo Total duration `get_starttime_duration $starttime`. | tee -a $T/log
822	else
823		echo No compression needed: `date` >> "$tdir/log-xz" 2>&1
824	fi
825fi
826if test -n "$tdir"
827then
828	cp $T/log "$tdir"
829fi
830exit $ret
831