1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# 3f08c3bdfSopenharmony_ci# Test Case 2 4f08c3bdfSopenharmony_ci# 5f08c3bdfSopenharmony_ci 6f08c3bdfSopenharmony_ciexport TCID="cpuhotplug02" 7f08c3bdfSopenharmony_ciexport TST_TOTAL=1 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci# Includes: 10f08c3bdfSopenharmony_ci. test.sh 11f08c3bdfSopenharmony_ci. cpuhotplug_testsuite.sh 12f08c3bdfSopenharmony_ci. cpuhotplug_hotplug.sh 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_cicat <<EOF 15f08c3bdfSopenharmony_ciName: $TCID 16f08c3bdfSopenharmony_ciDate: `date` 17f08c3bdfSopenharmony_ciDesc: What happens to a process when its CPU is offlined? 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ciEOF 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ciusage() 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci cat << EOF 24f08c3bdfSopenharmony_ci usage: $0 -c cpu -l loop 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci OPTIONS 27f08c3bdfSopenharmony_ci -c cpu which is specified for testing 28f08c3bdfSopenharmony_ci -l number of cycle test 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ciEOF 31f08c3bdfSopenharmony_ci exit 1 32f08c3bdfSopenharmony_ci} 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci# do_clean() 35f08c3bdfSopenharmony_ci# 36f08c3bdfSopenharmony_ci# Callback to be executed when script exits from a user interrupt 37f08c3bdfSopenharmony_ci# or regular program termination. 38f08c3bdfSopenharmony_ci# 39f08c3bdfSopenharmony_cido_clean() 40f08c3bdfSopenharmony_ci{ 41f08c3bdfSopenharmony_ci kill_pid ${SPIN_LOOP_PID} 42f08c3bdfSopenharmony_ci} 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ciwhile getopts c:l: OPTION; do 45f08c3bdfSopenharmony_ci case $OPTION in 46f08c3bdfSopenharmony_ci c) 47f08c3bdfSopenharmony_ci CPU_TO_TEST=$OPTARG;; 48f08c3bdfSopenharmony_ci l) 49f08c3bdfSopenharmony_ci HOTPLUG02_LOOPS=$OPTARG;; 50f08c3bdfSopenharmony_ci ?) 51f08c3bdfSopenharmony_ci usage;; 52f08c3bdfSopenharmony_ci esac 53f08c3bdfSopenharmony_cidone 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ciLOOP_COUNT=1 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_ciif tst_virt_hyperv; then 58f08c3bdfSopenharmony_ci tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug" 59f08c3bdfSopenharmony_cifi 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ciif [ $(get_present_cpus_num) -lt 2 ]; then 62f08c3bdfSopenharmony_ci tst_brkm TCONF "system doesn't have required CPU hotplug support" 63f08c3bdfSopenharmony_cifi 64f08c3bdfSopenharmony_ci 65f08c3bdfSopenharmony_ciif [ -z "${CPU_TO_TEST}" ]; then 66f08c3bdfSopenharmony_ci tst_brkm TBROK "usage: ${0##*/} <CPU to online>" 67f08c3bdfSopenharmony_cifi 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ci# Validate the specified CPU is available 70f08c3bdfSopenharmony_ciif ! cpu_is_valid "${CPU_TO_TEST}" ; then 71f08c3bdfSopenharmony_ci tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 72f08c3bdfSopenharmony_cifi 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci# Validate the specified CPU is online; if not, online it 75f08c3bdfSopenharmony_ciif ! cpu_is_online "${CPU_TO_TEST}" ; then 76f08c3bdfSopenharmony_ci if ! online_cpu ${CPU_TO_TEST}; then 77f08c3bdfSopenharmony_ci tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 78f08c3bdfSopenharmony_ci fi 79f08c3bdfSopenharmony_cifi 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ciTST_CLEANUP=do_clean 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_ci# Start up a process that just uses CPU cycles 84f08c3bdfSopenharmony_cicpuhotplug_do_spin_loop > /dev/null& 85f08c3bdfSopenharmony_ciSPIN_LOOP_PID=$! 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_cisleep 5 88f08c3bdfSopenharmony_ciuntil [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do 89f08c3bdfSopenharmony_ci # Move spin_loop.sh to the CPU to offline. 90f08c3bdfSopenharmony_ci set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST} 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci # Verify the process migrated to the CPU we intended it to go to 93f08c3bdfSopenharmony_ci if ! offline_cpu ${CPU_TO_TEST}; then 94f08c3bdfSopenharmony_ci tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined" 95f08c3bdfSopenharmony_ci fi 96f08c3bdfSopenharmony_ci 97f08c3bdfSopenharmony_ci NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers` 98f08c3bdfSopenharmony_ci if [ -z "${NEW_CPU}" ]; then 99f08c3bdfSopenharmony_ci tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running" 100f08c3bdfSopenharmony_ci fi 101f08c3bdfSopenharmony_ci if [ ${CPU_TO_TEST} = ${NEW_CPU} ]; then 102f08c3bdfSopenharmony_ci tst_resm TFAIL "process did not change from CPU ${NEW_CPU}" 103f08c3bdfSopenharmony_ci tst_exit 104f08c3bdfSopenharmony_ci fi 105f08c3bdfSopenharmony_ci 106f08c3bdfSopenharmony_ci # Turn the CPU back online just to see what happens. 107f08c3bdfSopenharmony_ci if ! online_cpu ${CPU_TO_TEST}; then 108f08c3bdfSopenharmony_ci tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 109f08c3bdfSopenharmony_ci fi 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_ci LOOP_COUNT=$((LOOP_COUNT+1)) 112f08c3bdfSopenharmony_cidone 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_citst_resm TPASS "turned off CPU ${CPU_TO_TEST}, process migrated to \ 115f08c3bdfSopenharmony_ci CPU ${NEW_CPU}" 116f08c3bdfSopenharmony_ci 117f08c3bdfSopenharmony_cisleep 2 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_citst_exit 120