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