1#!/bin/sh 2################################################################################ 3# 4# Copyright (C) 2022 Huawei Device Co., Ltd. 5# SPDX-License-Identifier: GPL-2.0 6# 7# Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT. 8# Do not use in new code. 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17# File: cpuisolation01.sh 18# 19# Description: check rw nodes test about CPU lightweight isolation 20# 21# Authors: liudanning - liudanning@h-partners.com 22# 23# History: Mar 24 2022 - init scripts 24# 25################################################################################ 26 27source tst_oh.sh 28 29do_setup() 30{ 31 echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus 32 echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus 33} 34 35write_invalid() 36{ 37 local max_value=$1 38 local min_value=$2 39 local mode=$3 40 41 min_cpus_value=$(cat $min_cpus) 42 max_cpus_value=$(cat $max_cpus) 43 min_cpus_value_backup=$(cat $min_cpus) 44 max_cpus_value_backup=$(cat $max_cpus) 45 46 echo $max_value > $max_cpus 47 ret_max=$? 48 echo $min_value > $min_cpus 49 ret_min=$? 50 min_cpus_value=$(cat $min_cpus) 51 max_cpus_value=$(cat $max_cpus) 52 53 # mode 1 is to inject a single invalid value 54 if [ $mode -eq 1 ]; then 55 if [ $ret_min -eq 1 ]; then 56 check_value 57 elif [ $min_cpus_value -eq 4 ]; then 58 check_value 59 elif [ $ret_max -eq 1 ]; then 60 check_value 61 elif [[ $min_cpus_value -eq 0 ]] && [[ $max_cpus_value -eq 4 ]]; then 62 check_value 63 else 64 tst_res TFAIL "writing single MAX VALUE $max_value or \ 65 MIN VALUE $min_value failed." 66 ((ret++)) 67 fi 68 fi 69 70 # mode 2 is to inject both invalid values 71 if [ $mode -eq 2 ]; then 72 if [[ $ret_min -eq 1 ]] && [[ $ret_max -eq 1 ]]; then 73 check_value 74 elif [[ $ret_min -eq 1 ]] && [[ $max_cpus_value -eq 4 ]]; then 75 check_value 76 elif [[ $ret_max -eq 1 ]] && [[ $min_cpus_value -eq 4 ]]; then 77 check_value 78 elif [[ $ret_max -ne 1 ]] && [[ $max_cpus_value -eq 4 ]] && \ 79 [[ $min_cpus_value -eq 4 ]]; then 80 check_value 81 else 82 tst_res TFAIL "writing both MAX VALUE $max_value and \ 83 MIN VALUE $min_value failed." 84 ((ret++)) 85 fi 86 fi 87 88 echo ${min_cpus_value_backup} > $min_cpus 89 echo ${max_cpus_value_backup} > $max_cpus 90} 91 92check_value() 93{ 94 if [ $min_cpus_value -ge 0 ] && [ $min_cpus_value -le $max_cpus_value ]\ 95 && [ $max_cpus_value -le 4 ]; then 96 tst_res TPASS "writing MAX VALUE $max_value and MIN VALUE $min_value , \ 97 value is normal." 98 else 99 tst_res TFAIL "writing MAX VALUE $max_value and MIN VALUE $min_value , \ 100 value is abnormal." 101 ((ret++)) 102 fi 103} 104 105do_test() 106{ 107 local ret=0 108 local dir_name=/sys/devices/system/cpu/cpu0/core_ctl 109 local min_cpus=${dir_name}/min_cpus 110 local max_cpus=${dir_name}/max_cpus 111 112 active_cpus=${dir_name}/active_cpus 113 enable=${dir_name}/enable 114 global_state=${dir_name}/global_state 115 need_cpus=${dir_name}/need_cpus 116 117 tst_res TINFO "Start to check rw nodes test about CPU lightweight isolation." 118 if [[ -e "${active_cpus}" && -e "${enable}" && -e "${global_state}" \ 119 && -e "${max_cpus}" && -e "${min_cpus}" && -e "${need_cpus}" ]]; then 120 tst_res TPASS "/sys/devices/system/cpu/cpu0/core_ctl/ node normal." 121 else 122 tst_res TFAIL "/sys/devices/system/cpu/cpu0/core_ctl/ node abnormal." 123 ((ret++)) 124 fi 125 126 write_invalid 4 -3 1 127 write_invalid 4 999 1 128 write_invalid -3 0 1 129 write_invalid 999 0 1 130 write_invalid -3 -3 2 131 write_invalid 999 -3 2 132 write_invalid -3 999 2 133 write_invalid 999 999 2 134 135 cpu_total=$(cat /proc/cpuinfo | grep "processor"| wc -l) 136 cpu_total=$(( $cpu_total - 1 )) 137 for i in $(seq 0 $cpu_total); do 138 cpu_name=$(cat $global_state | grep "CPU${i}") 139 echo $cpu_name 140 if [ "$cpu_name"x = "CPU${i}"x ]; then 141 tst_res TPASS "cpu$i name correct." 142 else 143 tst_res TFAIL "cpu$i name incorrect." 144 ((ret++)) 145 fi 146 147 line=$(( $i + 1)) 148 cpu_online_state=$(cat $global_state | grep 'Online:' | \ 149 sed -n "${line}p" | awk -F ':' '{print$2}') 150 if [ $cpu_online_state -eq 1 ]; then 151 tst_res TPASS "cpu$i online." 152 else 153 tst_res TFAIL"cpu$i offline." 154 ((ret++)) 155 fi 156 157 cpu_isolated_state=$(cat $global_state | grep 'Isolated:' | \ 158 sed -n "${line}p" | awk -F ':' '{print$2}') 159 if [ $cpu_isolated_state -eq 0 ]; then 160 tst_res TPASS "cpu$i isolated : 0." 161 else 162 tst_res TFAIL "cpu$i isolated : 1." 163 ((ret++)) 164 fi 165 166 cpu_is_busy_state=$(cat $global_state | grep 'Is busy:' | \ 167 sed -n "${line}p" | awk -F ':' '{print$2}') 168 if [ $cpu_is_busy_state -eq 1 ]; then 169 tst_res TPASS "cpu$i is_busy : 1." 170 else 171 tst_res TFAIL "cpu$i is_busy : 0." 172 ((ret++)) 173 fi 174 done 175 176 if [ $ret -eq 0 ];then 177 tst_res TPASS "check rw nodes test about CPU isolation successfully." 178 exit 0 179 else 180 tst_res TFAIL "check rw nodes test about CPU isolation failed!" 181 exit 1 182 fi 183} 184 185do_clean() 186{ 187 188} 189 190do_setup 191do_test 192do_clean 193tst_exit