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_rtg06.sh 15# 16# Description: sched RTG Stability 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 dmesg -c 29 PPID=$(ps -ef | grep "/sched_rtg06.sh" | grep -v grep | awk '{print $3}') 30} 31 32do_test() 33{ 34 stability_test randmom 35 36 stability_test ordered 37 38 stability_test all 39} 40 41stability_test() 42{ 43 sh create_process.sh 40 44 if [ "$1" == "randmom" ]; then 45 tst_res TINFO "All 40 porcesss join random rtg from 2 to 20" 46 random_rtg 47 fi 48 49 if [ "$1" == "ordered" ]; then 50 tst_res TINFO "All 40 processes join rtg from 2 to 20 one by one" 51 ordered_rtg 52 fi 53 54 if [ "$1" == "all" ]; then 55 tst_res TINFO "All 40 processes join rtg 2" 56 all_in_one_rtg 57 fi 58 sleep 60 59 tst_res TINFO "kill 40 loop processes...." 60 ps -ef | grep "sched_rtg06.sh" | grep -v "grep" | grep -v ${PPID} | cut -c 9-18 | xargs kill -9 61 tst_res TINFO "kill 40 task processes...." 62 ps -ef | grep "create_process" | grep -v "grep" | grep -v ${PPID} | cut -c 9-18 | xargs kill -9 63 sleep 5 64 tst_res TINFO "kill process successed." 65 aa start -b ohos.samples.ecg -a ohos.samples.ecg.MainAbility && 66 sleep 1 && 67 PID=$(ps -ef | grep ohos.samples.ecg | grep -v grep | awk '{print $2}') 68 if [ $? -eq 0 ]; then 69 dmesg | grep "BUG" || 70 dmesg | grep "panic" || 71 dmesg | grep "Unable to handle kernel" || 72 dmesg | grep "WARNING:" 73 if [ $? -eq 0 ]; then 74 tst_res TFAIL "$1 test error messages found!" 75 else 76 tst_res TPASS "sched RTG Stability $1 test success." 77 fi 78 else 79 tst_res TFAIL "sched RTG Stability $1 test failed!" 80 fi 81 aa force-stop ohos.samples.ecg 82} 83 84 85 86random_rtg() 87{ 88 for i in $(seq 1 40); do 89 { 90 while true; do 91 echo $((RANDOM % 19 + 2)) > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 92 sleep 0.1 93 echo 0 > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 94 sleep 0.2 95 done 96 }& 97 done 98} 99 100ordered_rtg() 101{ 102 for i in $(seq 1 40); do 103 { 104 if [ ${i} -le 20 ]; then 105 while true; do 106 echo ${i} > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 107 sleep 0.1 108 echo 0 > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 109 sleep 0.2 110 done & 111 else 112 while true; do 113 echo 2 > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 114 sleep 0.1 115 echo 0 > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 116 sleep 0.2 117 done 118 fi 119 }& 120 done 121} 122 123all_in_one_rtg() 124{ 125 local _rtg_id=$((RANDOM % 19 + 2)) 126 for i in $(seq 1 40); do 127 { 128 while true; do 129 echo $_rtg_id > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 130 sleep 0.1 131 echo 0 > /proc/$(sed -n ${i}p taskpid.txt)/sched_group_id 132 sleep 0.2 133 done 134 }& 135 done 136} 137 138do_clean() 139{ 140 rm -rf taskpid.txt 141} 142 143do_setup 144do_test 145do_clean 146tst_exit