• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: cpuisolation04.sh
18#
19# Description: check CPU lightweight isolation stress test
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    PPID=$(ps -ef | grep "/cpuisolation04.sh"  | grep -v grep | awk '{print $3}')
32}
33
34do_test()
35{
36    ret=0
37    dir_name=/sys/devices/system/cpu/cpu0/core_ctl
38    global_state=${dir_name}/global_state
39    tst_res TINFO "Start to check CPU lightweight isolation stress test"
40    active_num1=0
41    isolated_num1=0
42    proc_sd=/proc/sched_debug
43
44    sh create_process.sh 40
45    sleep 5
46    for i in $(seq 0 5); do
47        randmom=$((RANDOM %4 + 1))
48        echo $randmom > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus
49        do_isolate
50        if [ $randmom -ne 4 ]; then
51            do_num
52        fi
53        sleep 2
54    done
55    tst_res TINFO "kill 40 task processes...."
56    ps -ef | grep "create_process" | grep -v "grep"  \
57    | grep -v ${PPID} | cut -c 9-18 | xargs kill -9
58    echo "check stress test"
59    echo "ret=$ret"
60    if [ $ret -eq 0 ]; then
61        tst_res TPASS "CPU lightweight isolation stress test success."
62    else
63        tst_res TFAIL "CPU lightweight isolation stress test failed!"
64    fi
65
66    echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus
67}
68
69do_isolate()
70{
71    touch isolated_cpu1.txt
72    touch active_cpu1.txt
73    for i in $(seq 0 3); do
74        line=$(( $i + 1))
75        cpu_isolated_state=$(cat $global_state | grep 'Isolated:'  \
76        | sed -n "${line}p" | awk -F ':' '{print$2}')
77        if [ $cpu_isolated_state -eq 0 ]; then
78            tst_res TINFO "cpu$i is active."
79            active_num=$(( $active_num + 1 ))
80            echo $i >> active_cpu1.txt
81        else
82            tst_res TINFO "cpu$i is isolated."
83            isolated_num=$(( $isolated_num + 1 ))
84            echo $i >> isolated_cpu1.txt
85        fi
86    done
87
88    if [ $active_num -eq $randmom ];then
89        tst_res TPASS "isolation is right."
90    else
91        tst_res TFAIL "the cpus state error."
92        ((ret++))
93    fi
94    active_num=0
95    isolated_num=0
96}
97
98do_num()
99{
100    cpu_pid0=0
101    cpu_pid1=0
102    cpu_pid2=0
103    cpu_pid3=0
104    echo "y" | rm cpu_log.txt
105    cat $proc_sd > cpu_log.txt
106    for i in $(cat isolated_cpu1.txt); do
107        for pid in $(cat taskpid.txt); do
108        if [ $(sed -n '/^cpu#0/,/cpu#1$/p' cpu_log.txt  \
109        | awk -F " " '{print $3}' | grep -w "$pid") ];then
110            cpu_pid0=$(($cpu_pid0 + 1))
111        elif [ $(sed -n '/^cpu#1/,/cpu#2$/p' cpu_log.txt  \
112        | awk -F " " '{print $3}' | grep -w "$pid") ];then
113            cpu_pid1=$(($cpu_pid1 + 1))
114        elif [ $(sed -n '/^cpu#2/,/cpu#3$/p' cpu_log.txt  \
115        | awk -F " " '{print $3}' | grep -w "$pid") ];then
116            cpu_pid2=$(($cpu_pid2 + 1))
117        elif [ $(sed -n '/^cpu#3/,$p' cpu_log.txt  \
118        | awk -F " " '{print $3}' | grep -w "$pid") ];then
119            cpu_pid3=$(($cpu_pid3 + 1))
120        fi
121        done
122        if [ $(eval echo '$'cpu_pid"$i") -eq 0 ]; then
123            tst_res TPASS "cpu${i} process migrated."
124        else
125            tst_res TFAIL "cpu${i} process is not migrated."
126            ((ret++))
127        fi
128    done
129
130    echo "y" | rm isolated_cpu1.txt
131    echo "y" | rm active_cpu1.txt
132}
133
134do_clean()
135{
136    echo "y" | rm cpu_log.txt
137    echo "y" | rm isolated_cpu1.txt
138    echo "y" | rm active_cpu1.txt
139}
140
141do_setup
142do_test
143do_clean
144tst_exit