1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# 3f08c3bdfSopenharmony_ci# Test Case 4 4f08c3bdfSopenharmony_ci# 5f08c3bdfSopenharmony_ci 6f08c3bdfSopenharmony_ciexport TCID="cpuhotplug04" 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: Does it prevent us from offlining the last CPU? 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ciEOF 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ciusage() 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci cat << EOF 24f08c3bdfSopenharmony_ci usage: $0 -l loop 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci OPTIONS 27f08c3bdfSopenharmony_ci -l number of cycle test 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ciEOF 30f08c3bdfSopenharmony_ci exit 1 31f08c3bdfSopenharmony_ci} 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_cido_clean() 34f08c3bdfSopenharmony_ci{ 35f08c3bdfSopenharmony_ci # Online the ones that were on initially 36f08c3bdfSopenharmony_ci # Restore CPU states 37f08c3bdfSopenharmony_ci set_all_cpu_states "$cpu_states" 38f08c3bdfSopenharmony_ci} 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ciwhile getopts l: OPTION; do 41f08c3bdfSopenharmony_ci case $OPTION in 42f08c3bdfSopenharmony_ci l) 43f08c3bdfSopenharmony_ci HOTPLUG04_LOOPS=$OPTARG;; 44f08c3bdfSopenharmony_ci ?) 45f08c3bdfSopenharmony_ci usage;; 46f08c3bdfSopenharmony_ci esac 47f08c3bdfSopenharmony_cidone 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ciLOOP_COUNT=1 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_ciif tst_virt_hyperv; then 52f08c3bdfSopenharmony_ci tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug" 53f08c3bdfSopenharmony_cifi 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_cicpus_num=$(get_present_cpus_num) 56f08c3bdfSopenharmony_ciif [ $cpus_num -lt 2 ]; then 57f08c3bdfSopenharmony_ci tst_brkm TCONF "system doesn't have required CPU hotplug support" 58f08c3bdfSopenharmony_cifi 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ciif [ $(get_hotplug_cpus_num) -lt 1 ]; then 61f08c3bdfSopenharmony_ci tst_brkm TCONF "system doesn't have at least one hotpluggable CPU" 62f08c3bdfSopenharmony_cifi 63f08c3bdfSopenharmony_ci 64f08c3bdfSopenharmony_ciTST_CLEANUP=do_clean 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_cicpu_states=$(get_all_cpu_states) 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_ciuntil [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do 69f08c3bdfSopenharmony_ci 70f08c3bdfSopenharmony_ci # Online all the hotpluggable CPUs 71f08c3bdfSopenharmony_ci for i in $(get_hotplug_cpus); do 72f08c3bdfSopenharmony_ci if ! cpu_is_online $i; then 73f08c3bdfSopenharmony_ci if ! online_cpu $i; then 74f08c3bdfSopenharmony_ci tst_brkm TBROK "$i can not be onlined" 75f08c3bdfSopenharmony_ci fi 76f08c3bdfSopenharmony_ci fi 77f08c3bdfSopenharmony_ci done 78f08c3bdfSopenharmony_ci 79f08c3bdfSopenharmony_ci # Now offline them 80f08c3bdfSopenharmony_ci cpu=0 81f08c3bdfSopenharmony_ci for i in $(get_hotplug_cpus); do 82f08c3bdfSopenharmony_ci cpu=$((cpu + 1)) 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ci # If all the CPUs are hotpluggable, we expect 85f08c3bdfSopenharmony_ci # that the kernel will refuse to offline the last CPU. 86f08c3bdfSopenharmony_ci # If only some of the CPUs are hotpluggable, 87f08c3bdfSopenharmony_ci # they all can be offlined. 88f08c3bdfSopenharmony_ci if [ $cpu -eq $cpus_num ]; then 89f08c3bdfSopenharmony_ci if offline_cpu $i 2> /dev/null; then 90f08c3bdfSopenharmony_ci tst_brkm TFAIL "Have we just offlined the last CPU?" 91f08c3bdfSopenharmony_ci else 92f08c3bdfSopenharmony_ci tst_resm TPASS "System prevented us from offlining the last CPU - $i" 93f08c3bdfSopenharmony_ci fi 94f08c3bdfSopenharmony_ci else 95f08c3bdfSopenharmony_ci if ! offline_cpu $i; then 96f08c3bdfSopenharmony_ci tst_brkm TFAIL "Could not offline $i" 97f08c3bdfSopenharmony_ci fi 98f08c3bdfSopenharmony_ci fi 99f08c3bdfSopenharmony_ci done 100f08c3bdfSopenharmony_ci 101f08c3bdfSopenharmony_ci LOOP_COUNT=$((LOOP_COUNT+1)) 102f08c3bdfSopenharmony_ci 103f08c3bdfSopenharmony_cidone 104f08c3bdfSopenharmony_ci 105f08c3bdfSopenharmony_citst_resm TPASS "Success" 106f08c3bdfSopenharmony_ci 107f08c3bdfSopenharmony_citst_exit 108