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