~ [ 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-2.4.37.11)


  1 #!/bin/bash                                       
  2 # SPDX-License-Identifier: GPL-2.0                
  3                                                   
  4 SYSFS=                                            
  5 # Kselftest framework requirement - SKIP code     
  6 ksft_skip=4                                       
  7 retval=0                                          
  8                                                   
  9 prerequisite()                                    
 10 {                                                 
 11         msg="skip all tests:"                     
 12                                                   
 13         if [ $UID != 0 ]; then                    
 14                 echo $msg must be run as root     
 15                 exit $ksft_skip                   
 16         fi                                        
 17                                                   
 18         taskset -p 01 $$                          
 19                                                   
 20         SYSFS=`mount -t sysfs | head -1 | awk     
 21                                                   
 22         if [ ! -d "$SYSFS" ]; then                
 23                 echo $msg sysfs is not mounted    
 24                 exit $ksft_skip                   
 25         fi                                        
 26                                                   
 27         if ! ls $SYSFS/devices/system/cpu/cpu*    
 28                 echo $msg cpu hotplug is not s    
 29                 exit $ksft_skip                   
 30         fi                                        
 31                                                   
 32         echo "CPU online/offline summary:"        
 33         online_cpus=`cat $SYSFS/devices/system    
 34         online_max=${online_cpus##*-}             
 35                                                   
 36         if [[ "$online_cpus" = "$online_max" ]    
 37                 echo "$msg: since there is onl    
 38                 exit $ksft_skip                   
 39         fi                                        
 40                                                   
 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    
 46                                                   
 47         offline_cpus=`cat $SYSFS/devices/syste    
 48         if [[ "a$offline_cpus" = "a" ]]; then     
 49                 offline_cpus=0                    
 50         else                                      
 51                 offline_max=${offline_cpus##*-    
 52         fi                                        
 53         echo -e "\t Cpus in offline state: $of    
 54 }                                                 
 55                                                   
 56 #                                                 
 57 # list all hot-pluggable CPUs                     
 58 #                                                 
 59 hotpluggable_cpus()                               
 60 {                                                 
 61         local state=${1:-.\*}                     
 62                                                   
 63         for cpu in $SYSFS/devices/system/cpu/c    
 64                 if [ -f $cpu/online ] && grep     
 65                         echo ${cpu##/*/cpu}       
 66                 fi                                
 67         done                                      
 68 }                                                 
 69                                                   
 70 hotplaggable_offline_cpus()                       
 71 {                                                 
 72         hotpluggable_cpus 0                       
 73 }                                                 
 74                                                   
 75 hotpluggable_online_cpus()                        
 76 {                                                 
 77         hotpluggable_cpus 1                       
 78 }                                                 
 79                                                   
 80 cpu_is_online()                                   
 81 {                                                 
 82         grep -q 1 $SYSFS/devices/system/cpu/cp    
 83 }                                                 
 84                                                   
 85 cpu_is_offline()                                  
 86 {                                                 
 87         grep -q 0 $SYSFS/devices/system/cpu/cp    
 88 }                                                 
 89                                                   
 90 online_cpu()                                      
 91 {                                                 
 92         echo 1 > $SYSFS/devices/system/cpu/cpu    
 93 }                                                 
 94                                                   
 95 offline_cpu()                                     
 96 {                                                 
 97         echo 0 > $SYSFS/devices/system/cpu/cpu    
 98 }                                                 
 99                                                   
100 online_cpu_expect_success()                       
101 {                                                 
102         local cpu=$1                              
103                                                   
104         if ! online_cpu $cpu; then                
105                 echo $FUNCNAME $cpu: unexpecte    
106                 retval=1                          
107         elif ! cpu_is_online $cpu; then           
108                 echo $FUNCNAME $cpu: unexpecte    
109                 retval=1                          
110         fi                                        
111 }                                                 
112                                                   
113 online_cpu_expect_fail()                          
114 {                                                 
115         local cpu=$1                              
116                                                   
117         if online_cpu $cpu 2> /dev/null; then     
118                 echo $FUNCNAME $cpu: unexpecte    
119                 retval=1                          
120         elif ! cpu_is_offline $cpu; then          
121                 echo $FUNCNAME $cpu: unexpecte    
122                 retval=1                          
123         fi                                        
124 }                                                 
125                                                   
126 offline_cpu_expect_success()                      
127 {                                                 
128         local cpu=$1                              
129                                                   
130         if ! offline_cpu $cpu; then               
131                 echo $FUNCNAME $cpu: unexpecte    
132                 retval=1                          
133         elif ! cpu_is_offline $cpu; then          
134                 echo $FUNCNAME $cpu: unexpecte    
135                 retval=1                          
136         fi                                        
137 }                                                 
138                                                   
139 offline_cpu_expect_fail()                         
140 {                                                 
141         local cpu=$1                              
142                                                   
143         if offline_cpu $cpu 2> /dev/null; then    
144                 echo $FUNCNAME $cpu: unexpecte    
145                 retval=1                          
146         elif ! cpu_is_online $cpu; then           
147                 echo $FUNCNAME $cpu: unexpecte    
148                 retval=1                          
149         fi                                        
150 }                                                 
151                                                   
152 online_all_hot_pluggable_cpus()                   
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                                         
172 online_cpus=0                                     
173 online_max=0                                      
174 offline_cpus=0                                    
175 offline_max=0                                     
176 present_cpus=0                                    
177 present_max=0                                     
178                                                   
179 while getopts ah opt; do                          
180         case $opt in                              
181         a)                                        
182                 allcpus=1                         
183                 ;;                                
184         h)                                        
185                 echo "Usage $0 [ -a ]"            
186                 echo -e "\t default offline on    
187                 echo -e "\t run with -a option    
188                 exit                              
189                 ;;                                
190         esac                                      
191 done                                              
192                                                   
193 prerequisite                                      
194                                                   
195 #                                                 
196 # Safe test (default) - offline and online one    
197 #                                                 
198 if [ $allcpus -eq 0 ]; then                       
199         echo "Limited scope test: one hotplug     
200         echo -e "\t (leaves cpu in the origina    
201         echo -e "\t online to offline to onlin    
202         offline_cpu_expect_success $online_max    
203         online_cpu_expect_success $online_max     
204                                                   
205         if [[ $offline_cpus -gt 0 ]]; then        
206                 echo -e "\t online to offline     
207                 online_cpu_expect_success $pre    
208                 offline_cpu_expect_success $pr    
209                 online_cpu $present_max           
210         fi                                        
211         exit $retval                              
212 else                                              
213         echo "Full scope test: all hotplug cpu    
214         echo -e "\t online all offline cpus"      
215         echo -e "\t offline all online cpus"      
216         echo -e "\t online all offline cpus"      
217 fi                                                
218                                                   
219 online_all_hot_pluggable_cpus                     
220                                                   
221 offline_all_hot_pluggable_cpus                    
222                                                   
223 online_all_hot_pluggable_cpus                     
224                                                   
225 exit $retval                                      
                                                      

~ [ 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