~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh (Version linux-6.12-rc7) and /tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh (Version linux-4.15.18)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3                                                     3 
  4 SYSFS=                                              4 SYSFS=
  5 # Kselftest framework requirement - SKIP code  << 
  6 ksft_skip=4                                    << 
  7 retval=0                                       << 
  8                                                     5 
  9 prerequisite()                                      6 prerequisite()
 10 {                                                   7 {
 11         msg="skip all tests:"                       8         msg="skip all tests:"
 12                                                     9 
 13         if [ $UID != 0 ]; then                     10         if [ $UID != 0 ]; then
 14                 echo $msg must be run as root      11                 echo $msg must be run as root >&2
 15                 exit $ksft_skip                !!  12                 exit 0
 16         fi                                         13         fi
 17                                                    14 
 18         taskset -p 01 $$                           15         taskset -p 01 $$
 19                                                    16 
 20         SYSFS=`mount -t sysfs | head -1 | awk      17         SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
 21                                                    18 
 22         if [ ! -d "$SYSFS" ]; then                 19         if [ ! -d "$SYSFS" ]; then
 23                 echo $msg sysfs is not mounted     20                 echo $msg sysfs is not mounted >&2
 24                 exit $ksft_skip                !!  21                 exit 0
 25         fi                                         22         fi
 26                                                    23 
 27         if ! ls $SYSFS/devices/system/cpu/cpu*     24         if ! ls $SYSFS/devices/system/cpu/cpu* > /dev/null 2>&1; then
 28                 echo $msg cpu hotplug is not s     25                 echo $msg cpu hotplug is not supported >&2
 29                 exit $ksft_skip                !!  26                 exit 0
 30         fi                                         27         fi
 31                                                    28 
 32         echo "CPU online/offline summary:"         29         echo "CPU online/offline summary:"
 33         online_cpus=`cat $SYSFS/devices/system     30         online_cpus=`cat $SYSFS/devices/system/cpu/online`
 34         online_max=${online_cpus##*-}              31         online_max=${online_cpus##*-}
 35                                                    32 
 36         if [[ "$online_cpus" = "$online_max" ]     33         if [[ "$online_cpus" = "$online_max" ]]; then
 37                 echo "$msg: since there is onl     34                 echo "$msg: since there is only one cpu: $online_cpus"
 38                 exit $ksft_skip                !!  35                 exit 0
 39         fi                                         36         fi
 40                                                    37 
 41         present_cpus=`cat $SYSFS/devices/syste << 
 42         present_max=${present_cpus##*-}        << 
 43         echo "present_cpus = $present_cpus pre << 
 44                                                << 
 45         echo -e "\t Cpus in online state: $onl     38         echo -e "\t Cpus in online state: $online_cpus"
 46                                                    39 
 47         offline_cpus=`cat $SYSFS/devices/syste     40         offline_cpus=`cat $SYSFS/devices/system/cpu/offline`
 48         if [[ "a$offline_cpus" = "a" ]]; then      41         if [[ "a$offline_cpus" = "a" ]]; then
 49                 offline_cpus=0                     42                 offline_cpus=0
 50         else                                       43         else
 51                 offline_max=${offline_cpus##*-     44                 offline_max=${offline_cpus##*-}
 52         fi                                         45         fi
 53         echo -e "\t Cpus in offline state: $of     46         echo -e "\t Cpus in offline state: $offline_cpus"
 54 }                                                  47 }
 55                                                    48 
 56 #                                                  49 #
 57 # list all hot-pluggable CPUs                      50 # list all hot-pluggable CPUs
 58 #                                                  51 #
 59 hotpluggable_cpus()                                52 hotpluggable_cpus()
 60 {                                                  53 {
 61         local state=${1:-.\*}                      54         local state=${1:-.\*}
 62                                                    55 
 63         for cpu in $SYSFS/devices/system/cpu/c     56         for cpu in $SYSFS/devices/system/cpu/cpu*; do
 64                 if [ -f $cpu/online ] && grep      57                 if [ -f $cpu/online ] && grep -q $state $cpu/online; then
 65                         echo ${cpu##/*/cpu}        58                         echo ${cpu##/*/cpu}
 66                 fi                                 59                 fi
 67         done                                       60         done
 68 }                                                  61 }
 69                                                    62 
 70 hotplaggable_offline_cpus()                        63 hotplaggable_offline_cpus()
 71 {                                                  64 {
 72         hotpluggable_cpus 0                        65         hotpluggable_cpus 0
 73 }                                                  66 }
 74                                                    67 
 75 hotpluggable_online_cpus()                         68 hotpluggable_online_cpus()
 76 {                                                  69 {
 77         hotpluggable_cpus 1                        70         hotpluggable_cpus 1
 78 }                                                  71 }
 79                                                    72 
 80 cpu_is_online()                                    73 cpu_is_online()
 81 {                                                  74 {
 82         grep -q 1 $SYSFS/devices/system/cpu/cp     75         grep -q 1 $SYSFS/devices/system/cpu/cpu$1/online
 83 }                                                  76 }
 84                                                    77 
 85 cpu_is_offline()                                   78 cpu_is_offline()
 86 {                                                  79 {
 87         grep -q 0 $SYSFS/devices/system/cpu/cp     80         grep -q 0 $SYSFS/devices/system/cpu/cpu$1/online
 88 }                                                  81 }
 89                                                    82 
 90 online_cpu()                                       83 online_cpu()
 91 {                                                  84 {
 92         echo 1 > $SYSFS/devices/system/cpu/cpu     85         echo 1 > $SYSFS/devices/system/cpu/cpu$1/online
 93 }                                                  86 }
 94                                                    87 
 95 offline_cpu()                                      88 offline_cpu()
 96 {                                                  89 {
 97         echo 0 > $SYSFS/devices/system/cpu/cpu     90         echo 0 > $SYSFS/devices/system/cpu/cpu$1/online
 98 }                                                  91 }
 99                                                    92 
100 online_cpu_expect_success()                        93 online_cpu_expect_success()
101 {                                                  94 {
102         local cpu=$1                               95         local cpu=$1
103                                                    96 
104         if ! online_cpu $cpu; then                 97         if ! online_cpu $cpu; then
105                 echo $FUNCNAME $cpu: unexpecte     98                 echo $FUNCNAME $cpu: unexpected fail >&2
106                 retval=1                       !!  99                 exit 1
107         elif ! cpu_is_online $cpu; then           100         elif ! cpu_is_online $cpu; then
108                 echo $FUNCNAME $cpu: unexpecte    101                 echo $FUNCNAME $cpu: unexpected offline >&2
109                 retval=1                       !! 102                 exit 1
110         fi                                        103         fi
111 }                                                 104 }
112                                                   105 
113 online_cpu_expect_fail()                          106 online_cpu_expect_fail()
114 {                                                 107 {
115         local cpu=$1                              108         local cpu=$1
116                                                   109 
117         if online_cpu $cpu 2> /dev/null; then     110         if online_cpu $cpu 2> /dev/null; then
118                 echo $FUNCNAME $cpu: unexpecte    111                 echo $FUNCNAME $cpu: unexpected success >&2
119                 retval=1                       !! 112                 exit 1
120         elif ! cpu_is_offline $cpu; then          113         elif ! cpu_is_offline $cpu; then
121                 echo $FUNCNAME $cpu: unexpecte    114                 echo $FUNCNAME $cpu: unexpected online >&2
122                 retval=1                       !! 115                 exit 1
123         fi                                        116         fi
124 }                                                 117 }
125                                                   118 
126 offline_cpu_expect_success()                      119 offline_cpu_expect_success()
127 {                                                 120 {
128         local cpu=$1                              121         local cpu=$1
129                                                   122 
130         if ! offline_cpu $cpu; then               123         if ! offline_cpu $cpu; then
131                 echo $FUNCNAME $cpu: unexpecte    124                 echo $FUNCNAME $cpu: unexpected fail >&2
132                 retval=1                       !! 125                 exit 1
133         elif ! cpu_is_offline $cpu; then          126         elif ! cpu_is_offline $cpu; then
134                 echo $FUNCNAME $cpu: unexpecte    127                 echo $FUNCNAME $cpu: unexpected offline >&2
135                 retval=1                       !! 128                 exit 1
136         fi                                        129         fi
137 }                                                 130 }
138                                                   131 
139 offline_cpu_expect_fail()                         132 offline_cpu_expect_fail()
140 {                                                 133 {
141         local cpu=$1                              134         local cpu=$1
142                                                   135 
143         if offline_cpu $cpu 2> /dev/null; then    136         if offline_cpu $cpu 2> /dev/null; then
144                 echo $FUNCNAME $cpu: unexpecte    137                 echo $FUNCNAME $cpu: unexpected success >&2
145                 retval=1                       !! 138                 exit 1
146         elif ! cpu_is_online $cpu; then           139         elif ! cpu_is_online $cpu; then
147                 echo $FUNCNAME $cpu: unexpecte    140                 echo $FUNCNAME $cpu: unexpected offline >&2
148                 retval=1                       !! 141                 exit 1
149         fi                                        142         fi
150 }                                                 143 }
151                                                   144 
152 online_all_hot_pluggable_cpus()                !! 145 error=-12
153 {                                              << 
154         for cpu in `hotplaggable_offline_cpus` << 
155                 online_cpu_expect_success $cpu << 
156         done                                   << 
157 }                                              << 
158                                                << 
159 offline_all_hot_pluggable_cpus()               << 
160 {                                              << 
161         local reserve_cpu=$online_max          << 
162         for cpu in `hotpluggable_online_cpus`; << 
163                 # Reserve one cpu oneline at l << 
164                 if [ $cpu -eq $reserve_cpu ];t << 
165                         continue               << 
166                 fi                             << 
167                 offline_cpu_expect_success $cp << 
168         done                                   << 
169 }                                              << 
170                                                << 
171 allcpus=0                                         146 allcpus=0
                                                   >> 147 priority=0
172 online_cpus=0                                     148 online_cpus=0
173 online_max=0                                      149 online_max=0
174 offline_cpus=0                                    150 offline_cpus=0
175 offline_max=0                                     151 offline_max=0
176 present_cpus=0                                 << 
177 present_max=0                                  << 
178                                                   152 
179 while getopts ah opt; do                       !! 153 while getopts e:ahp: opt; do
180         case $opt in                              154         case $opt in
                                                   >> 155         e)
                                                   >> 156                 error=$OPTARG
                                                   >> 157                 ;;
181         a)                                        158         a)
182                 allcpus=1                         159                 allcpus=1
183                 ;;                                160                 ;;
184         h)                                        161         h)
185                 echo "Usage $0 [ -a ]"         !! 162                 echo "Usage $0 [ -a ] [ -e errno ] [ -p notifier-priority ]"
186                 echo -e "\t default offline on    163                 echo -e "\t default offline one cpu"
187                 echo -e "\t run with -a option    164                 echo -e "\t run with -a option to offline all cpus"
188                 exit                              165                 exit
189                 ;;                                166                 ;;
                                                   >> 167         p)
                                                   >> 168                 priority=$OPTARG
                                                   >> 169                 ;;
190         esac                                      170         esac
191 done                                              171 done
192                                                   172 
                                                   >> 173 if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
                                                   >> 174         echo "error code must be -4095 <= errno < 0" >&2
                                                   >> 175         exit 1
                                                   >> 176 fi
                                                   >> 177 
193 prerequisite                                      178 prerequisite
194                                                   179 
195 #                                                 180 #
196 # Safe test (default) - offline and online one    181 # Safe test (default) - offline and online one cpu
197 #                                                 182 #
198 if [ $allcpus -eq 0 ]; then                       183 if [ $allcpus -eq 0 ]; then
199         echo "Limited scope test: one hotplug     184         echo "Limited scope test: one hotplug cpu"
200         echo -e "\t (leaves cpu in the origina    185         echo -e "\t (leaves cpu in the original state):"
201         echo -e "\t online to offline to onlin    186         echo -e "\t online to offline to online: cpu $online_max"
202         offline_cpu_expect_success $online_max    187         offline_cpu_expect_success $online_max
203         online_cpu_expect_success $online_max     188         online_cpu_expect_success $online_max
204                                                   189 
205         if [[ $offline_cpus -gt 0 ]]; then        190         if [[ $offline_cpus -gt 0 ]]; then
206                 echo -e "\t online to offline  !! 191                 echo -e "\t offline to online to offline: cpu $offline_max"
207                 online_cpu_expect_success $pre !! 192                 online_cpu_expect_success $offline_max
208                 offline_cpu_expect_success $pr !! 193                 offline_cpu_expect_success $offline_max
209                 online_cpu $present_max        << 
210         fi                                        194         fi
211         exit $retval                           !! 195         exit 0
212 else                                              196 else
213         echo "Full scope test: all hotplug cpu    197         echo "Full scope test: all hotplug cpus"
214         echo -e "\t online all offline cpus"      198         echo -e "\t online all offline cpus"
215         echo -e "\t offline all online cpus"      199         echo -e "\t offline all online cpus"
216         echo -e "\t online all offline cpus"      200         echo -e "\t online all offline cpus"
217 fi                                                201 fi
218                                                   202 
219 online_all_hot_pluggable_cpus                  !! 203 #
                                                   >> 204 # Online all hot-pluggable CPUs
                                                   >> 205 #
                                                   >> 206 for cpu in `hotplaggable_offline_cpus`; do
                                                   >> 207         online_cpu_expect_success $cpu
                                                   >> 208 done
                                                   >> 209 
                                                   >> 210 #
                                                   >> 211 # Offline all hot-pluggable CPUs
                                                   >> 212 #
                                                   >> 213 for cpu in `hotpluggable_online_cpus`; do
                                                   >> 214         offline_cpu_expect_success $cpu
                                                   >> 215 done
                                                   >> 216 
                                                   >> 217 #
                                                   >> 218 # Online all hot-pluggable CPUs again
                                                   >> 219 #
                                                   >> 220 for cpu in `hotplaggable_offline_cpus`; do
                                                   >> 221         online_cpu_expect_success $cpu
                                                   >> 222 done
                                                   >> 223 
                                                   >> 224 #
                                                   >> 225 # Test with cpu notifier error injection
                                                   >> 226 #
                                                   >> 227 
                                                   >> 228 DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'`
                                                   >> 229 NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/cpu
                                                   >> 230 
                                                   >> 231 prerequisite_extra()
                                                   >> 232 {
                                                   >> 233         msg="skip extra tests:"
                                                   >> 234 
                                                   >> 235         /sbin/modprobe -q -r cpu-notifier-error-inject
                                                   >> 236         /sbin/modprobe -q cpu-notifier-error-inject priority=$priority
                                                   >> 237 
                                                   >> 238         if [ ! -d "$DEBUGFS" ]; then
                                                   >> 239                 echo $msg debugfs is not mounted >&2
                                                   >> 240                 exit 0
                                                   >> 241         fi
                                                   >> 242 
                                                   >> 243         if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
                                                   >> 244                 echo $msg cpu-notifier-error-inject module is not available >&2
                                                   >> 245                 exit 0
                                                   >> 246         fi
                                                   >> 247 }
                                                   >> 248 
                                                   >> 249 prerequisite_extra
                                                   >> 250 
                                                   >> 251 #
                                                   >> 252 # Offline all hot-pluggable CPUs
                                                   >> 253 #
                                                   >> 254 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
                                                   >> 255 for cpu in `hotpluggable_online_cpus`; do
                                                   >> 256         offline_cpu_expect_success $cpu
                                                   >> 257 done
220                                                   258 
221 offline_all_hot_pluggable_cpus                 !! 259 #
                                                   >> 260 # Test CPU hot-add error handling (offline => online)
                                                   >> 261 #
                                                   >> 262 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error
                                                   >> 263 for cpu in `hotplaggable_offline_cpus`; do
                                                   >> 264         online_cpu_expect_fail $cpu
                                                   >> 265 done
222                                                   266 
223 online_all_hot_pluggable_cpus                  !! 267 #
                                                   >> 268 # Online all hot-pluggable CPUs
                                                   >> 269 #
                                                   >> 270 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error
                                                   >> 271 for cpu in `hotplaggable_offline_cpus`; do
                                                   >> 272         online_cpu_expect_success $cpu
                                                   >> 273 done
                                                   >> 274 
                                                   >> 275 #
                                                   >> 276 # Test CPU hot-remove error handling (online => offline)
                                                   >> 277 #
                                                   >> 278 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
                                                   >> 279 for cpu in `hotpluggable_online_cpus`; do
                                                   >> 280         offline_cpu_expect_fail $cpu
                                                   >> 281 done
224                                                   282 
225 exit $retval                                   !! 283 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
                                                   >> 284 /sbin/modprobe -q -r cpu-notifier-error-inject
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php