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

selftests: cpu-hotplug: fix case where CPUs offline > CPUs present

The cpu-hotplug test assumes that we can offline the maximum CPU as
described by /sys/devices/system/cpu/offline. However, in the case
where the number of CPUs exceeds like kernel configuration then
the offline count can be greater than the present count and we end
up trying to test the offlining of a CPU that is not available to
offline. Fix this by testing the maximum present CPU instead.

Also, the test currently offlines the CPU and does not online it,
so fix this by onlining the CPU after the test.

Fixes: d89dffa976bc ("fault-injection: add selftests for cpu and memory hotplug")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Shuah Khan <shuah@kernel.org>

authored by

Colin Ian King and committed by
Shuah Khan
2b531b61 3d244c19

+10 -3
+10 -3
tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
··· 37 37 exit $ksft_skip 38 38 fi 39 39 40 + present_cpus=`cat $SYSFS/devices/system/cpu/present` 41 + present_max=${present_cpus##*-} 42 + echo "present_cpus = $present_cpus present_max = $present_max" 43 + 40 44 echo -e "\t Cpus in online state: $online_cpus" 41 45 42 46 offline_cpus=`cat $SYSFS/devices/system/cpu/offline` ··· 155 151 online_max=0 156 152 offline_cpus=0 157 153 offline_max=0 154 + present_cpus=0 155 + present_max=0 158 156 159 157 while getopts e:ahp: opt; do 160 158 case $opt in ··· 196 190 online_cpu_expect_success $online_max 197 191 198 192 if [[ $offline_cpus -gt 0 ]]; then 199 - echo -e "\t offline to online to offline: cpu $offline_max" 200 - online_cpu_expect_success $offline_max 201 - offline_cpu_expect_success $offline_max 193 + echo -e "\t offline to online to offline: cpu $present_max" 194 + online_cpu_expect_success $present_max 195 + offline_cpu_expect_success $present_max 196 + online_cpu $present_max 202 197 fi 203 198 exit 0 204 199 else