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: equilibrium_init.sh 18# 19# Description: enhancedf2fs03 and enhancedf2fs04 testsuite init script 20# 21# Authors: Li Zhanming - lizhanming3@h-partners.com 22# 23# History: Mar 15 2022 - init scripts 24# 25################################################################################ 26 27source tst_oh.sh 28 29state_init() 30{ 31 mkfs.f2fs -d1 -t1 -O quota $IMG_FILE 32 losetup /dev/block/loop1 $IMG_FILE 33 mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/ 34} 35 36equilibrium_init() 37{ 38 local ret=0 39 local segs_path=/sys/kernel/debug/f2fs/status 40 41 tst_res TINFO "Start equilibrium_init.sh." 42 local a=$(cat $segs_path | grep segs | awk -F ' ' '{print$3}') 43 44 local i=0 45 while [ $i -lt 32 ] 46 do 47 dd if=/dev/zero of=/mnt/f2fs_mount/image$i bs=512M count=1 48 i=$(( $i + 1 )) 49 done 50 51 local b=$(cat $segs_path | grep "valid blocks" | awk -F ' ' '{print$3}' | tr -cd "[0-9]") 52 local result_left=$(echo | awk "{peint $a*512*0.2}") 53 local result_might=$(echo | awk "{print $a*512-$b}") 54 local result_right=$(echo | awk "{print $a*512*0.1}") 55 local result1=$(echo "$result_left $result_might" \ 56 | awk '{if ($result_left -gt $result_might) print 1; else print 0}') 57 local result2=$(echo "$result_might $result_right" \ 58 | awk '{if ($result_might -gt $result_right) print 1; else print 0}') 59 if [ $result1 -gt 0 ] && [ $result2 -gt 0 ]; then 60 tst_res TPASS "Inequality holds." 61 else 62 tst_res TFAIL "Inequality does not hold." 63 ret=$(( $ret + 1 )) 64 fi 65 66 sleep 60 67 if [ $(cat /sys/fs/f2fs/loop1/discard_type) == '1' ];then 68 tst_res TPASS "equilibrium model successfully." 69 else 70 tst_res TFAIL "equilibrium model failed." 71 ret=$(( $ret + 1 )) 72 fi 73 74 echo 1 > /sys/kernel/debug/tracing/tracing_on 75 echo 1 > /sys/kernel/debug/tracing/events/f2fs/f2fs_issue_discard/enable 76 if [ $? -eq 0 ]; then 77 tst_res TPASS "Trace opened successfully." 78 else 79 tst_res TFAIL "Trace start failed." 80 ret=$(( $ret + 1 )) 81 fi 82 83 if [ $ret -eq 0 ];then 84 tst_res TPASS "equilibrium_init successfully." 85 else 86 tst_res TFAIL "equilibrium_init failed!" 87 fi 88} 89 90state_init 91equilibrium_init 92