selftests: cgroup: Run test_core under interfering stress
authorMichal Koutný <mkoutny@suse.com>
Fri, 4 Oct 2019 10:57:43 +0000 (12:57 +0200)
committerTejun Heo <tj@kernel.org>
Mon, 7 Oct 2019 14:11:54 +0000 (07:11 -0700)
test_core tests various cgroup creation/removal and task migration
paths. Run the tests repeatedly with interfering noise (for lockdep
checks). Currently, forking noise and subsystem enabled/disabled
switching are the implemented noises.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/testing/selftests/cgroup/Makefile
tools/testing/selftests/cgroup/test_stress.sh [new file with mode: 0755]
tools/testing/selftests/cgroup/with_stress.sh [new file with mode: 0755]

index 1c9179400be0847a84a092742eaba49e4b9c32bf..66aafe1f57468137a2eeb0f92a75c9f816c86421 100644 (file)
@@ -3,6 +3,8 @@ CFLAGS += -Wall -pthread
 
 all:
 
+TEST_FILES     := with_stress.sh
+TEST_PROGS     := test_stress.sh
 TEST_GEN_PROGS = test_memcontrol
 TEST_GEN_PROGS += test_core
 TEST_GEN_PROGS += test_freezer
diff --git a/tools/testing/selftests/cgroup/test_stress.sh b/tools/testing/selftests/cgroup/test_stress.sh
new file mode 100755 (executable)
index 0000000..15d9d58
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+./with_stress.sh -s subsys -s fork ./test_core
diff --git a/tools/testing/selftests/cgroup/with_stress.sh b/tools/testing/selftests/cgroup/with_stress.sh
new file mode 100755 (executable)
index 0000000..e28c350
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+stress_fork()
+{
+       while true ; do
+               /usr/bin/true
+               sleep 0.01
+       done
+}
+
+stress_subsys()
+{
+       local verb=+
+       while true ; do
+               echo $verb$subsys_ctrl >$sysfs/cgroup.subtree_control
+               [ $verb = "+" ] && verb=- || verb=+
+               # incommensurable period with other stresses
+               sleep 0.011
+       done
+}
+
+init_and_check()
+{
+       sysfs=`mount -t cgroup2 | head -1 | awk '{ print $3 }'`
+       if [ ! -d "$sysfs" ]; then
+               echo "Skipping: cgroup2 is not mounted" >&2
+               exit $ksft_skip
+       fi
+
+       if ! echo +$subsys_ctrl >$sysfs/cgroup.subtree_control ; then
+               echo "Skipping: cannot enable $subsys_ctrl in $sysfs" >&2
+               exit $ksft_skip
+       fi
+
+       if ! echo -$subsys_ctrl >$sysfs/cgroup.subtree_control ; then
+               echo "Skipping: cannot disable $subsys_ctrl in $sysfs" >&2
+               exit $ksft_skip
+       fi
+}
+
+declare -a stresses
+declare -a stress_pids
+duration=5
+rc=0
+subsys_ctrl=cpuset
+sysfs=
+
+while getopts c:d:hs: opt; do
+       case $opt in
+       c)
+               subsys_ctrl=$OPTARG
+               ;;
+       d)
+               duration=$OPTARG
+               ;;
+       h)
+               echo "Usage $0 [ -s stress ] ... [ -d duration ] [-c controller] cmd args .."
+               echo -e "\t default duration $duration seconds"
+               echo -e "\t default controller $subsys_ctrl"
+               exit
+               ;;
+       s)
+               func=stress_$OPTARG
+               if [ "x$(type -t $func)" != "xfunction" ] ; then
+                       echo "Unknown stress $OPTARG"
+                       exit 1
+               fi
+               stresses+=($func)
+               ;;
+       esac
+done
+shift $((OPTIND - 1))
+
+init_and_check
+
+for s in ${stresses[*]} ; do
+       $s &
+       stress_pids+=($!)
+done
+
+
+time=0
+start=$(date +%s)
+
+while [ $time -lt $duration ] ; do
+       $*
+       rc=$?
+       [ $rc -eq 0 ] || break
+       time=$(($(date +%s) - $start))
+done
+
+for pid in ${stress_pids[*]} ; do
+       kill -SIGTERM $pid
+       wait $pid
+done
+
+exit $rc