Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: selftests - create a separate hotplug target for full range test

On some systems, hot-plug tests could hang forever waiting for cpu and
memory to be ready to be offlined. A special hot-plug target is created
to run full range of hot-plug tests. In default mode, hot-plug tests run
in safe mode with a limited scope. In limited mode, cpu-hotplug test is
run on a single cpu as opposed to all hotplug capable cpus, and memory
hotplug test is run on 2% of hotplug capable memory instead of 10%. In
addition to the above change, cpu-hotplug is chnged to change processor
affinity to cpu 0 so it doesn't impact itself while the test runs.

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Shuah Khan and committed by
Greg Kroah-Hartman
ddddda9b 6e7e6c34

+105 -6
+18
tools/testing/selftests/Makefile
··· 12 12 TARGETS += user 13 13 TARGETS += sysctl 14 14 15 + TARGETS_HOTPLUG = cpu-hotplug 16 + TARGETS_HOTPLUG += memory-hotplug 17 + 15 18 all: 16 19 for TARGET in $(TARGETS); do \ 17 20 make -C $$TARGET; \ ··· 23 20 run_tests: all 24 21 for TARGET in $(TARGETS); do \ 25 22 make -C $$TARGET run_tests; \ 23 + done; 24 + 25 + hotplug: 26 + for TARGET in $(TARGETS_HOTPLUG); do \ 27 + make -C $$TARGET; \ 28 + done; 29 + 30 + run_hotplug: hotplug 31 + for TARGET in $(TARGETS_HOTPLUG); do \ 32 + make -C $$TARGET run_full_test; \ 33 + done; 34 + 35 + clean_hotplug: 36 + for TARGET in $(TARGETS_HOTPLUG); do \ 37 + make -C $$TARGET clean; \ 26 38 done; 27 39 28 40 clean:
+23 -4
tools/testing/selftests/README.txt
··· 4 4 directory. These are intended to be small unit tests to exercise individual 5 5 code paths in the kernel. 6 6 7 - Running the selftests 8 - ===================== 7 + On some systems, hot-plug tests could hang forever waiting for cpu and 8 + memory to be ready to be offlined. A special hot-plug target is created 9 + to run full range of hot-plug tests. In default mode, hot-plug tests run 10 + in safe mode with a limited scope. In limited mode, cpu-hotplug test is 11 + run on a single cpu as opposed to all hotplug capable cpus, and memory 12 + hotplug test is run on 2% of hotplug capable memory instead of 10%. 13 + 14 + Running the selftests (hotplug tests are run in limited mode) 15 + ============================================================= 9 16 10 17 To build the tests: 11 18 ··· 25 18 26 19 - note that some tests will require root privileges. 27 20 28 - 29 - To run only tests targetted for a single subsystem: 21 + To run only tests targeted for a single subsystem: (including 22 + hotplug targets in limited mode) 30 23 31 24 $ make -C tools/testing/selftests TARGETS=cpu-hotplug run_tests 32 25 33 26 See the top-level tools/testing/selftests/Makefile for the list of all possible 34 27 targets. 35 28 29 + Running the full range hotplug selftests 30 + ======================================== 31 + 32 + To build the tests: 33 + 34 + $ make -C tools/testing/selftests hotplug 35 + 36 + To run the tests: 37 + 38 + $ make -C tools/testing/selftests run_hotplug 39 + 40 + - note that some tests will require root privileges. 36 41 37 42 Contributing new tests 38 43 ======================
+3
tools/testing/selftests/cpu-hotplug/Makefile
··· 3 3 run_tests: 4 4 @/bin/bash ./on-off-test.sh || echo "cpu-hotplug selftests: [FAIL]" 5 5 6 + run_full_test: 7 + @/bin/bash ./on-off-test.sh -a || echo "cpu-hotplug selftests: [FAIL]" 8 + 6 9 clean:
+50 -2
tools/testing/selftests/cpu-hotplug/on-off-test.sh
··· 11 11 exit 0 12 12 fi 13 13 14 + taskset -p 01 $$ 15 + 14 16 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 15 17 16 18 if [ ! -d "$SYSFS" ]; then ··· 24 22 echo $msg cpu hotplug is not supported >&2 25 23 exit 0 26 24 fi 25 + 26 + echo "CPU online/offline summary:" 27 + online_cpus=`cat $SYSFS/devices/system/cpu/online` 28 + online_max=${online_cpus##*-} 29 + echo -e "\t Cpus in online state: $online_cpus" 30 + 31 + offline_cpus=`cat $SYSFS/devices/system/cpu/offline` 32 + if [[ "a$offline_cpus" = "a" ]]; then 33 + offline_cpus=0 34 + else 35 + offline_max=${offline_cpus##*-} 36 + fi 37 + echo -e "\t Cpus in offline state: $offline_cpus" 27 38 } 28 39 29 40 # ··· 128 113 } 129 114 130 115 error=-12 116 + allcpus=0 131 117 priority=0 118 + online_cpus=0 119 + online_max=0 120 + offline_cpus=0 121 + offline_max=0 132 122 133 - while getopts e:hp: opt; do 123 + while getopts e:ahp: opt; do 134 124 case $opt in 135 125 e) 136 126 error=$OPTARG 137 127 ;; 128 + a) 129 + allcpus=1 130 + ;; 138 131 h) 139 - echo "Usage $0 [ -e errno ] [ -p notifier-priority ]" 132 + echo "Usage $0 [ -a ] [ -e errno ] [ -p notifier-priority ]" 133 + echo -e "\t default offline one cpu" 134 + echo -e "\t run with -a option to offline all cpus" 140 135 exit 141 136 ;; 142 137 p) ··· 161 136 fi 162 137 163 138 prerequisite 139 + 140 + # 141 + # Safe test (default) - offline and online one cpu 142 + # 143 + if [ $allcpus -eq 0 ]; then 144 + echo "Limited scope test: one hotplug cpu" 145 + echo -e "\t (leaves cpu in the original state):" 146 + echo -e "\t online to offline to online: cpu $online_max" 147 + offline_cpu_expect_success $online_max 148 + online_cpu_expect_success $online_max 149 + 150 + if [[ $offline_cpus -gt 0 ]]; then 151 + echo -e "\t offline to online to offline: cpu $offline_max" 152 + online_cpu_expect_success $offline_max 153 + offline_cpu_expect_success $offline_max 154 + fi 155 + exit 0 156 + else 157 + echo "Full scope test: all hotplug cpus" 158 + echo -e "\t online all offline cpus" 159 + echo -e "\t offline all online cpus" 160 + echo -e "\t online all offline cpus" 161 + fi 164 162 165 163 # 166 164 # Online all hot-pluggable CPUs
+3
tools/testing/selftests/memory-hotplug/Makefile
··· 1 1 all: 2 2 3 3 run_tests: 4 + @/bin/bash ./on-off-test.sh -r 2 || echo "memory-hotplug selftests: [FAIL]" 5 + 6 + run_full_test: 4 7 @/bin/bash ./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]" 5 8 6 9 clean:
+8
tools/testing/selftests/memory-hotplug/on-off-test.sh
··· 142 142 143 143 prerequisite 144 144 145 + echo "Test scope: $ratio% hotplug memory" 146 + echo -e "\t online all hotplug memory in offline state" 147 + echo -e "\t offline $ratio% hotplug memory in online state" 148 + echo -e "\t online all hotplug memory in offline state" 149 + 145 150 # 146 151 # Online all hot-pluggable memory 147 152 # 148 153 for memory in `hotplaggable_offline_memory`; do 154 + echo offline-online $memory 149 155 online_memory_expect_success $memory 150 156 done 151 157 ··· 160 154 # 161 155 for memory in `hotpluggable_online_memory`; do 162 156 if [ $((RANDOM % 100)) -lt $ratio ]; then 157 + echo online-offline $memory 163 158 offline_memory_expect_success $memory 164 159 fi 165 160 done ··· 169 162 # Online all hot-pluggable memory again 170 163 # 171 164 for memory in `hotplaggable_offline_memory`; do 165 + echo offline-online $memory 172 166 online_memory_expect_success $memory 173 167 done 174 168