• 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: sched_rtg01.sh
15#
16# Description: sched RTG /proc/$PID/sched_group_id basic function test
17#
18# Authors:     Ma Feng - mafeng.ma@huawei.com
19#
20# History:     April 6 2022 - init scripts
21#
22################################################################################
23
24source tst_oh.sh
25
26do_setup()
27{
28    sh create_process.sh 1
29    sleep 1
30    PID=$(ps -ef | grep "create_process" | grep -v grep | awk '{print $2}')
31}
32
33do_test()
34{
35    local res=0
36    local sched_group_id=/proc/$PID/sched_group_id
37
38    tst_res TINFO "Start process $PID join rtgid 2 test ..."
39    cur_rtgid=$(cat $sched_group_id)
40    if [ cur_rtgid -eq 2 ]; then
41        tst_res TINFO "process $PID already in rtgid 2, remove it firstly..."
42        echo 0 > $sched_group_id
43    fi
44
45    echo 2 > $sched_group_id
46    if [ $? -ne 0 ]; then
47        tst_res TFAIL "echo 2 > $sched_group_id failed!"
48        res=$(($res + 1))
49    fi
50    local rtgid2=$(cat $sched_group_id)
51    if [ $rtgid2 -ne 2 ]; then
52        tst_res TFAIL "process $PID join rtgid 2 failed!"
53        res=$(($res + 1))
54    fi
55
56    tst_res TINFO "Start process $PID switch rtgid 2 to 3 test ..."
57    echo 3 > $sched_group_id
58    if [ $? -eq 0 ]; then
59        tst_res TFAIL "echo 3 > $sched_group_id success unexpected."
60        res=$(($res + 1))
61    fi
62    local rtgid3=$(cat $sched_group_id)
63    if [ $rtgid3 -eq 3 ]; then
64        tst_res TFAIL "process $PID switch rtgid 2 to 3 sucess unexpected!"
65        res=$(($res + 1))
66    fi
67
68    tst_res TINFO "Start process $PID remove rtgid 2 test ..."
69    echo 0 > $sched_group_id
70    if [ $? -ne 0 ]; then
71        tst_res TFAIL "process $PID remove rtgid 2 failed!"
72        res=$(($res + 1))
73    fi
74    local rtgid0=$(cat $sched_group_id)
75    if [ $rtgid0 -ne 0 ]; then
76        tst_res TINFO "process $PID remove rtgid 2 failed!"
77        res=$(($res + 1))
78    fi
79
80    if [ $res -eq 0 ]; then
81        tst_res TPASS "sched RTG /proc/$PID/sched_group_id basic function pass."
82    else
83        tst_res TFAIL "sched RTG /proc/$PID/sched_group_id basic function failed!"
84    fi
85}
86
87do_clean()
88{
89    ps -ef | grep "create_process" | grep -v "grep" | cut -c 9-18  \
90    | xargs kill -9
91}
92
93do_setup
94do_test
95do_clean
96tst_exit