1#!/bin/sh 2# 3# Test Case 6 - top 4# 5 6export TCID="cpuhotplug06" 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 top work properly when CPU hotplug events occur? 18 19EOF 20 21usage() 22{ 23 cat << EOF 24 usage: $0 -c cpu -l loop 25 26 OPTIONS 27 -c cpu which is specified for testing 28 -l number of cycle test 29 30EOF 31 exit 1 32} 33 34do_clean() 35{ 36 pid_is_valid ${TOP_PID} && kill_pid ${TOP_PID} 37} 38 39while getopts c:l: OPTION; do 40 case $OPTION in 41 c) 42 CPU_TO_TEST=$OPTARG;; 43 l) 44 HOTPLUG06_LOOPS=$OPTARG;; 45 ?) 46 usage;; 47 esac 48done 49 50LOOP_COUNT=1 51 52if tst_virt_hyperv; then 53 tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug" 54fi 55 56if top -v | grep -q htop; then 57 tst_brkm TCONF "htop is used instead of top (workaround: alias top='/path/to/real/top')" 58fi 59 60if [ $(get_present_cpus_num) -lt 2 ]; then 61 tst_brkm TCONF "system doesn't have required CPU hotplug support" 62fi 63 64if [ -z "$CPU_TO_TEST" ]; then 65 tst_brkm TBROK "Usage: ${0##*/} <CPU to offline>" 66fi 67 68# Verify that the specified CPU is available 69if ! cpu_is_valid "${CPU_TO_TEST}" ; then 70 tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 71fi 72 73# Check that the specified CPU is online; if not, online it 74if ! cpu_is_online "${CPU_TO_TEST}" ; then 75 if ! online_cpu ${CPU_TO_TEST}; then 76 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 77 fi 78fi 79 80TST_CLEANUP=do_clean 81 82until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do 83 # Start up top and give it a little time to run 84 top -b -d 00.10 > /dev/null 2>&1 & 85 TOP_PID=$! 86 sleep 1 87 88 # Now offline the CPU 89 if ! offline_cpu ${CPU_TO_TEST} ; then 90 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined" 91 fi 92 93 # Wait a little time for top to notice the CPU is gone 94 sleep 1 95 96 # Check that top hasn't crashed 97 if ! pid_is_valid ${TOP_PID} ; then 98 tst_resm TFAIL "PID ${TOP_PID} no longer running" 99 tst_exit 100 fi 101 102 if ! online_cpu ${CPU_TO_TEST}; then 103 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 104 fi 105 106 kill_pid ${TOP_PID} 107 108 LOOP_COUNT=$((LOOP_COUNT+1)) 109 110done 111 112tst_resm TPASS "PID ${TOP_PID} still running." 113 114tst_exit 115