1#!/bin/sh 2# 3# Test Case 2 4# 5 6export TCID="cpuhotplug02" 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: What happens to a process when its CPU is offlined? 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 34# do_clean() 35# 36# Callback to be executed when script exits from a user interrupt 37# or regular program termination. 38# 39do_clean() 40{ 41 kill_pid ${SPIN_LOOP_PID} 42} 43 44while getopts c:l: OPTION; do 45 case $OPTION in 46 c) 47 CPU_TO_TEST=$OPTARG;; 48 l) 49 HOTPLUG02_LOOPS=$OPTARG;; 50 ?) 51 usage;; 52 esac 53done 54 55LOOP_COUNT=1 56 57if [ $(get_present_cpus_num) -lt 2 ]; then 58 tst_brkm TCONF "system doesn't have required CPU hotplug support" 59fi 60 61if [ -z "${CPU_TO_TEST}" ]; then 62 tst_brkm TBROK "usage: ${0##*/} <CPU to online>" 63fi 64 65# Validate the specified CPU is available 66if ! cpu_is_valid "${CPU_TO_TEST}" ; then 67 tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 68fi 69 70# Validate the specified CPU is online; if not, online it 71if ! cpu_is_online "${CPU_TO_TEST}" ; then 72 if ! online_cpu ${CPU_TO_TEST}; then 73 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 74 fi 75fi 76 77TST_CLEANUP=do_clean 78 79# Start up a process that just uses CPU cycles 80cpuhotplug_do_spin_loop > /dev/null& 81SPIN_LOOP_PID=$! 82 83sleep 5 84until [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do 85 # Move spin_loop.sh to the CPU to offline. 86 set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST} 87 88 # Verify the process migrated to the CPU we intended it to go to 89 offline_cpu ${CPU_TO_TEST} 90 NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers` 91 if [ -z "${NEW_CPU}" ]; then 92 tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running" 93 fi 94 if [ ${CPU_TO_TEST} = ${NEW_CPU} ]; then 95 tst_resm TFAIL "process did not change from CPU ${NEW_CPU}" 96 tst_exit 97 fi 98 99 # Turn the CPU back online just to see what happens. 100 online_cpu ${CPU_TO_TEST} 101 LOOP_COUNT=$((LOOP_COUNT+1)) 102done 103 104tst_resm TPASS "turned off CPU ${CPU_TO_TEST}, process migrated to \ 105 CPU ${NEW_CPU}" 106 107sleep 2 108 109tst_exit 110