1#!/bin/sh 2# 3# Test Case 4 4# 5 6export TCID="cpuhotplug04" 7export TST_TOTAL=1 8 9# Includes: 10. test.sh 11. cpuhotplug_testsuite.sh 12. cpuhotplug_hotplug.sh 13 14cat <<EOF 15Name: $TCID 16Date: `date` 17Desc: Does it prevent us from offlining the last CPU? 18 19EOF 20 21usage() 22{ 23 cat << EOF 24 usage: $0 -l loop 25 26 OPTIONS 27 -l number of cycle test 28 29EOF 30 exit 1 31} 32 33do_clean() 34{ 35 # Online the ones that were on initially 36 # Restore CPU states 37 set_all_cpu_states "$cpu_states" 38} 39 40while getopts l: OPTION; do 41 case $OPTION in 42 l) 43 HOTPLUG04_LOOPS=$OPTARG;; 44 ?) 45 usage;; 46 esac 47done 48 49LOOP_COUNT=1 50 51cpus_num=$(get_present_cpus_num) 52if [ $cpus_num -lt 2 ]; then 53 tst_brkm TCONF "system doesn't have required CPU hotplug support" 54fi 55 56if [ $(get_hotplug_cpus_num) -lt 1 ]; then 57 tst_brkm TCONF "system doesn't have at least one hotpluggable CPU" 58fi 59 60TST_CLEANUP=do_clean 61 62cpu_states=$(get_all_cpu_states) 63 64until [ $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 99done 100 101tst_resm TPASS "Success" 102 103tst_exit 104