Home | History | Annotate | Download | only in functional
      1 #!/bin/sh
      2 #
      3 # Test Case 4
      4 #
      5 
      6 export TCID="cpuhotplug04"
      7 export TST_TOTAL=1
      8 
      9 # Includes:
     10 . test.sh
     11 . cpuhotplug_testsuite.sh
     12 . cpuhotplug_hotplug.sh
     13 
     14 cat <<EOF
     15 Name:   $TCID
     16 Date:   `date`
     17 Desc:   Does it prevent us from offlining the last CPU?
     18 
     19 EOF
     20 
     21 usage()
     22 {
     23 	cat << EOF
     24 	usage: $0 -l loop
     25 
     26 	OPTIONS
     27 		-l  number of cycle test
     28 
     29 EOF
     30 	exit 1
     31 }
     32 
     33 do_clean()
     34 {
     35 	# Online the ones that were on initially
     36 	# Restore CPU states
     37 	set_all_cpu_states "$cpu_states"
     38 }
     39 
     40 while getopts l: OPTION; do
     41 	case $OPTION in
     42 	l)
     43 		HOTPLUG04_LOOPS=$OPTARG;;
     44 	?)
     45 		usage;;
     46 	esac
     47 done
     48 
     49 LOOP_COUNT=1
     50 
     51 cpus_num=$(get_present_cpus_num)
     52 if [ $cpus_num -lt 2 ]; then
     53 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
     54 fi
     55 
     56 if [ $(get_hotplug_cpus_num) -lt 1 ]; then
     57 	tst_brkm TCONF "system doesn't have at least one hotpluggable CPU"
     58 fi
     59 
     60 TST_CLEANUP=do_clean
     61 
     62 cpu_states=$(get_all_cpu_states)
     63 
     64 until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
     65 
     66 	# Online all the hotpluggable CPUs
     67 	for i in $(get_hotplug_cpus); do
     68 		if ! cpu_is_online $i; then
     69 			if ! online_cpu $i; then
     70 				tst_brkm TBROK "$i can not be onlined"
     71 			fi
     72 		fi
     73 	done
     74 
     75 	# Now offline them
     76 	cpu=0
     77 	for i in $(get_hotplug_cpus); do
     78 		cpu=$((cpu + 1))
     79 
     80 		# If all the CPUs are hotpluggable, we expect
     81 		# that the kernel will refuse to offline the last CPU.
     82 		# If only some of the CPUs are hotpluggable,
     83 		# they all can be offlined.
     84 		if [ $cpu -eq $cpus_num ]; then
     85 			if offline_cpu $i 2> /dev/null; then
     86 				tst_brkm TFAIL "Have we just offlined the last CPU?"
     87 			else
     88 				tst_resm TPASS "System prevented us from offlining the last CPU - $i"
     89 			fi
     90 		else
     91 			if ! offline_cpu $i; then
     92 				tst_brkm TFAIL "Could not offline $i"
     93 			fi
     94 		fi
     95 	done
     96 
     97 	LOOP_COUNT=$((LOOP_COUNT+1))
     98 
     99 done
    100 
    101 tst_resm TPASS "Success"
    102 
    103 tst_exit
    104