Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0-or-later
0003 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
0004 #
0005 # Test creates several zram devices with different filesystems on them.
0006 # It fills each device with zeros and checks that compression works.
0007 #
0008 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
0009 # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
0010 
0011 TCID="zram01"
0012 ERR_CODE=0
0013 
0014 . ./zram_lib.sh
0015 
0016 # Test will create the following number of zram devices:
0017 dev_num=1
0018 # This is a list of parameters for zram devices.
0019 # Number of items must be equal to 'dev_num' parameter.
0020 zram_max_streams="2"
0021 
0022 # The zram sysfs node 'disksize' value can be either in bytes,
0023 # or you can use mem suffixes. But in some old kernels, mem
0024 # suffixes are not supported, for example, in RHEL6.6GA's kernel
0025 # layer, it uses strict_strtoull() to parse disksize which does
0026 # not support mem suffixes, in some newer kernels, they use
0027 # memparse() which supports mem suffixes. So here we just use
0028 # bytes to make sure everything works correctly.
0029 zram_sizes="2097152" # 2MB
0030 zram_mem_limits="2M"
0031 zram_filesystems="ext4"
0032 zram_algs="lzo"
0033 
0034 zram_fill_fs()
0035 {
0036         for i in $(seq $dev_start $dev_end); do
0037                 echo "fill zram$i..."
0038                 local b=0
0039                 while [ true ]; do
0040                         dd conv=notrunc if=/dev/zero of=zram${i}/file \
0041                                 oflag=append count=1 bs=1024 status=none \
0042                                 > /dev/null 2>&1 || break
0043                         b=$(($b + 1))
0044                 done
0045                 echo "zram$i can be filled with '$b' KB"
0046 
0047                 local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
0048                 local v=$((100 * 1024 * $b / $mem_used_total))
0049                 if [ "$v" -lt 100 ]; then
0050                          echo "FAIL compression ratio: 0.$v:1"
0051                          ERR_CODE=-1
0052                          return
0053                 fi
0054 
0055                 echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
0056         done
0057 }
0058 
0059 check_prereqs
0060 zram_load
0061 zram_max_streams
0062 zram_compress_alg
0063 zram_set_disksizes
0064 zram_set_memlimit
0065 zram_makefs
0066 zram_mount
0067 
0068 zram_fill_fs
0069 zram_cleanup
0070 
0071 if [ $ERR_CODE -ne 0 ]; then
0072         echo "$TCID : [FAIL]"
0073 else
0074         echo "$TCID : [PASS]"
0075 fi