• 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: sched_rtg03.sh
18#
19# Description: sched RTG /proc/sched_rtg_debug interface test
20#
21# Authors:     liudanning - liudanning@h-partners.com
22#
23# History:     April 6 2022 - init scripts
24#
25################################################################################
26
27source tst_oh.sh
28
29do_setup()
30{
31    sh create_process.sh 1
32    sleep 1
33    PID=$(ps -ef | grep "create_process" | grep -v grep | awk '{print $2}')
34}
35
36do_test()
37{
38    local res=0
39    local sched_group_id=/proc/$PID/sched_group_id
40
41    tst_res TINFO "Start sched RTG /proc/sched_rtg_debug interface test ..."
42    cur_rtgid=$(cat $sched_group_id)
43    tst_res TINFO "process $PID already in rtgid $sched_group_id, remove it firstly..."
44    echo 0 > $sched_group_id
45
46    set_check_rtgid_debug 2 $PID 0 2
47
48    set_check_rtgid_debug 0 $PID 0 0
49}
50
51set_check_rtgid_debug()
52{
53    local _set_rtgid=$1
54    local _pid=$2
55    local _expect_ret=$3
56    local _expect_rtgid=$4
57
58    local _sched_group_id=/proc/$_pid/sched_group_id
59    local _sched_rtg_debug=/proc/sched_rtg_debug
60
61    echo $_set_rtgid > $_sched_group_id
62    if [ $? -eq $_expect_ret ]; then
63        tst_res TPASS "process $_pid rtgid set to $_set_rtgid expected."
64        if [ $(cat /proc/$_pid/sched_group_id) -eq $_expect_rtgid ]; then
65            tst_res TPASS "process $_pid rtgid equal to expected value."
66        else
67            tst_res TFAIL "process $_pid rtgid not equal to expected value!"
68        fi
69    else
70        tst_res TFAIL "process $_pid rtgid set to $_set_rtgid unexpected!"
71    fi
72
73    local _rtg_id=$(cat /proc/sched_rtg_debug | grep RTG_ID | grep -v grep | awk '{print $3}' | head -n 1)
74    local _rtg_pid=$(cat /proc/sched_rtg_debug | grep $PID | grep -v grep | awk '{print $3}')
75    if [ $_set_rtgid -ne 0 ]; then
76        if [ $_rtg_id -eq $_expect_rtgid ]; then
77            tst_res TPASS "RTG_ID $_rtg_id exists in $_sched_rtg_debug expected."
78            if [ $_rtg_pid -eq $PID ]; then
79                tst_res TPASS "PID $_pid exists in $_sched_rtg_debug expected."
80            else
81                tst_res TFAIL "PID $_pid not exists in $_sched_rtg_debug unexpected!"
82            fi
83        else
84            tst_res TFAIL "RTG_ID $_rtg_id not exists in $_sched_rtg_debug unexpected!"
85        fi
86    else
87        cat $_sched_rtg_debug | grep $PID
88        if [ $? -ne 0 ]; then
89            tst_res TPASS "process $_pid rtgid set to 0 expected."
90        else
91            tst_res TFAIL "process $_pid rtgid set to 0 unexpected!"
92        fi
93    fi
94}
95
96do_clean()
97{
98    ps -ef | grep "create_process" | grep -v "grep" | cut -c 9-18  \
99    | xargs kill -9
100}
101
102do_setup
103do_test
104do_clean
105tst_exit