Home | History | Annotate | Download | only in functional
      1 #!/bin/sh
      2 #
      3 # Test Case 6 - top
      4 #
      5 
      6 export TCID="cpuhotplug06"
      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 top work properly when CPU hotplug events occur?
     18 
     19 EOF
     20 
     21 usage()
     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 
     30 EOF
     31 	exit 1
     32 }
     33 
     34 do_clean()
     35 {
     36 	pid_is_valid ${TOP_PID} && kill_pid ${TOP_PID}
     37 }
     38 
     39 while 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
     48 done
     49 
     50 LOOP_COUNT=1
     51 
     52 if [ $(get_present_cpus_num) -lt 2 ]; then
     53 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
     54 fi
     55 
     56 if [ -z "$CPU_TO_TEST" ]; then
     57 	tst_brkm TBROK "Usage: ${0##*/} <CPU to offline>"
     58 fi
     59 
     60 # Verify that the specified CPU is available
     61 if ! cpu_is_valid "${CPU_TO_TEST}" ; then
     62 	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
     63 fi
     64 
     65 # Check that the specified CPU is online; if not, online it
     66 if ! cpu_is_online "${CPU_TO_TEST}" ; then
     67 	if ! online_cpu ${CPU_TO_TEST}; then
     68 		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
     69 	fi
     70 fi
     71 
     72 TST_CLEANUP=do_clean
     73 
     74 until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do
     75 	# Start up top and give it a little time to run
     76 	top -b -d 00.10 > /dev/null 2>&1 &
     77 	TOP_PID=$!
     78 	sleep 1
     79 
     80 	# Now offline the CPU
     81 	if ! offline_cpu ${CPU_TO_TEST} ; then
     82 		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
     83 	fi
     84 
     85 	# Wait a little time for top to notice the CPU is gone
     86 	sleep 1
     87 
     88 	# Check that top hasn't crashed
     89 	if ! pid_is_valid ${TOP_PID} ; then
     90 		tst_resm TFAIL "PID ${TOP_PID} no longer running"
     91 		tst_exit
     92 	fi
     93 
     94 	online_cpu ${CPU_TO_TEST}
     95 	kill_pid ${TOP_PID}
     96 
     97 	LOOP_COUNT=$((LOOP_COUNT+1))
     98 
     99 done
    100 
    101 tst_resm TPASS "PID ${TOP_PID} still running."
    102 
    103 tst_exit
    104