• 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# 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: life_init.sh
18#
19# Description: enhancedf2fs01 and enhancedf2fs02 testsuite init script
20#
21# Authors:     Li Zhanming - lizhanming3@h-partners.com
22#
23# History:     April 8 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
36life_init()
37{
38    local ret=0
39    local _segs_path=/sys/kernel/debug/f2fs/status
40    local _sys_path=/sys/kernel/debug/tracing
41
42    tst_res TINFO "Start life_init.sh."
43
44    local a=$(cat $_segs_path | grep segs | awk -F ' ' '{print$3}')
45    local b=$(cat $_segs_path| grep "valid blocks" | awk -F ' ' '{print$3}' | tr -cd "[0-9]")
46    local result_left=$(echo | awk "{print $a*512-$b}")
47    local result_right=$(echo | awk "{print $a*512*0.2}")
48    local result=$(echo "$result_left $result_right"  \
49    | awk '{if ($result_left -gt $result_right) print 1; else print 0}')
50    if [ $result -gt 0 ]; then
51        tst_res TPASS "Inequality holds."
52    else
53        tst_res TFAIL "Inequality does not hold."
54        ret=$(( $ret + 1 ))
55    fi
56
57    if [ $(cat /sys/fs/f2fs/loop1/discard_type) == '0' ];then
58        tst_res TPASS "life model successfully."
59    else
60        tst_res TFAIL "life model failed."
61        ret=$(( $ret + 1 ))
62    fi
63
64    echo 1 > $_sys_path/tracing_on
65    echo 1 > $_sys_path/events/f2fs/f2fs_issue_discard/enable
66    if [ $? -eq 0 ];then
67        tst_res TPASS "Trace opened successfully."
68    else
69        tst_res TFAIL "Trace start failed."
70        ret=$(( $ret + 1 ))
71    fi
72    if [ $ret -eq 0 ];then
73        tst_res TPASS "life_init pass."
74    else
75        tst_res TFAIL "life_init failed!"
76    fi
77}
78
79state_init
80life_init
81