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