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 tst_virt_hyperv; then 58 tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug" 59fi 60 61if [ $(get_present_cpus_num) -lt 2 ]; then 62 tst_brkm TCONF "system doesn't have required CPU hotplug support" 63fi 64 65if [ -z "${CPU_TO_TEST}" ]; then 66 tst_brkm TBROK "usage: ${0##*/} <CPU to online>" 67fi 68 69# Validate the specified CPU is available 70if ! cpu_is_valid "${CPU_TO_TEST}" ; then 71 tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 72fi 73 74# Validate the specified CPU is online; if not, online it 75if ! cpu_is_online "${CPU_TO_TEST}" ; then 76 if ! online_cpu ${CPU_TO_TEST}; then 77 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 78 fi 79fi 80 81TST_CLEANUP=do_clean 82 83# Start up a process that just uses CPU cycles 84cpuhotplug_do_spin_loop > /dev/null& 85SPIN_LOOP_PID=$! 86 87sleep 5 88until [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do 89 # Move spin_loop.sh to the CPU to offline. 90 set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST} 91 92 # Verify the process migrated to the CPU we intended it to go to 93 if ! offline_cpu ${CPU_TO_TEST}; then 94 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined" 95 fi 96 97 NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers` 98 if [ -z "${NEW_CPU}" ]; then 99 tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running" 100 fi 101 if [ ${CPU_TO_TEST} = ${NEW_CPU} ]; then 102 tst_resm TFAIL "process did not change from CPU ${NEW_CPU}" 103 tst_exit 104 fi 105 106 # Turn the CPU back online just to see what happens. 107 if ! online_cpu ${CPU_TO_TEST}; then 108 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 109 fi 110 111 LOOP_COUNT=$((LOOP_COUNT+1)) 112done 113 114tst_resm TPASS "turned off CPU ${CPU_TO_TEST}, process migrated to \ 115 CPU ${NEW_CPU}" 116 117sleep 2 118 119tst_exit 120