• 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# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10# See the License for the specific language governing permissions and
11# limitations under the License.
12#
13################################################################################
14# File: cpuisolation04.sh
15#
16# Description: check CPU lightweight isolation stress test
17#
18# Authors:     liudanning - liudanning@h-partners.com
19#
20# History:     Mar 24 2022 - init scripts
21#
22################################################################################
23
24source tst_oh.sh
25
26do_setup()
27{
28    PPID=$(ps -ef | grep "/cpuisolation04.sh"  | grep -v grep | awk '{print $3}')
29}
30
31do_test()
32{
33    ret=0
34    dir_name=/sys/devices/system/cpu/cpu0/core_ctl
35    global_state=${dir_name}/global_state
36    tst_res TINFO "Start to check CPU lightweight isolation stress test"
37    active_num1=0
38    isolated_num1=0
39    proc_sd=/proc/sched_debug
40
41    sh create_process.sh 40
42    sleep 5
43    for i in $(seq 0 5); do
44        randmom=$((RANDOM %4 + 1))
45        echo $randmom > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus
46        do_isolate
47        if [ $randmom -ne 4 ]; then
48            do_num
49        fi
50        sleep 2
51    done
52    tst_res TINFO "kill 40 task processes...."
53    ps -ef | grep "create_process" | grep -v "grep"  \
54    | grep -v ${PPID} | cut -c 9-18 | xargs kill -9
55    echo "check stress test"
56    echo "ret=$ret"
57    if [ $ret -eq 0 ]; then
58        tst_res TPASS "CPU lightweight isolation stress test success."
59    else
60        tst_res TFAIL "CPU lightweight isolation stress test failed!"
61    fi
62
63    echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus
64}
65
66do_isolate()
67{
68    touch isolated_cpu1.txt
69    touch active_cpu1.txt
70    for i in $(seq 0 3); do
71        line=$(( $i + 1))
72        cpu_isolated_state=$(cat $global_state | grep 'Isolated:'  \
73        | sed -n "${line}p" | awk -F ':' '{print$2}')
74        if [ $cpu_isolated_state -eq 0 ]; then
75            tst_res TINFO "cpu$i is active."
76            active_num=$(( $active_num + 1 ))
77            echo $i >> active_cpu1.txt
78        else
79            tst_res TINFO "cpu$i is isolated."
80            isolated_num=$(( $isolated_num + 1 ))
81            echo $i >> isolated_cpu1.txt
82        fi
83    done
84
85    if [ $active_num -eq $randmom ];then
86        tst_res TPASS "isolation is right."
87    else
88        tst_res TFAIL "the cpus state error."
89        ((ret++))
90    fi
91    active_num=0
92    isolated_num=0
93}
94
95do_num()
96{
97    cpu_pid0=0
98    cpu_pid1=0
99    cpu_pid2=0
100    cpu_pid3=0
101    echo "y" | rm cpu_log.txt
102    cat $proc_sd > cpu_log.txt
103    for i in $(cat isolated_cpu1.txt); do
104        for pid in $(cat taskpid.txt); do
105        if [ $(sed -n '/^cpu#0/,/cpu#1$/p' cpu_log.txt  \
106        | awk -F " " '{print $3}' | grep -w "$pid") ];then
107            cpu_pid0=$(($cpu_pid0 + 1))
108        elif [ $(sed -n '/^cpu#1/,/cpu#2$/p' cpu_log.txt  \
109        | awk -F " " '{print $3}' | grep -w "$pid") ];then
110            cpu_pid1=$(($cpu_pid1 + 1))
111        elif [ $(sed -n '/^cpu#2/,/cpu#3$/p' cpu_log.txt  \
112        | awk -F " " '{print $3}' | grep -w "$pid") ];then
113            cpu_pid2=$(($cpu_pid2 + 1))
114        elif [ $(sed -n '/^cpu#3/,$p' cpu_log.txt  \
115        | awk -F " " '{print $3}' | grep -w "$pid") ];then
116            cpu_pid3=$(($cpu_pid3 + 1))
117        fi
118        done
119        if [ $(eval echo '$'cpu_pid"$i") -eq 0 ]; then
120            tst_res TPASS "cpu${i} process migrated."
121        else
122            tst_res TFAIL "cpu${i} process is not migrated."
123            ((ret++))
124        fi
125    done
126
127    echo "y" | rm isolated_cpu1.txt
128    echo "y" | rm active_cpu1.txt
129}
130
131do_clean()
132{
133    echo "y" | rm cpu_log.txt
134    echo "y" | rm isolated_cpu1.txt
135    echo "y" | rm active_cpu1.txt
136}
137
138do_setup
139do_test
140do_clean
141tst_exit