1*4882a593Smuzhiyun#!/bin/bash 2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-or-later 3*4882a593Smuzhiyun# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# Test creates several zram devices with different filesystems on them. 6*4882a593Smuzhiyun# It fills each device with zeros and checks that compression works. 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 9*4882a593Smuzhiyun# Modified: Naresh Kamboju <naresh.kamboju@linaro.org> 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunTCID="zram01" 12*4882a593SmuzhiyunERR_CODE=0 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun. ./zram_lib.sh 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun# Test will create the following number of zram devices: 17*4882a593Smuzhiyundev_num=1 18*4882a593Smuzhiyun# This is a list of parameters for zram devices. 19*4882a593Smuzhiyun# Number of items must be equal to 'dev_num' parameter. 20*4882a593Smuzhiyunzram_max_streams="2" 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun# The zram sysfs node 'disksize' value can be either in bytes, 23*4882a593Smuzhiyun# or you can use mem suffixes. But in some old kernels, mem 24*4882a593Smuzhiyun# suffixes are not supported, for example, in RHEL6.6GA's kernel 25*4882a593Smuzhiyun# layer, it uses strict_strtoull() to parse disksize which does 26*4882a593Smuzhiyun# not support mem suffixes, in some newer kernels, they use 27*4882a593Smuzhiyun# memparse() which supports mem suffixes. So here we just use 28*4882a593Smuzhiyun# bytes to make sure everything works correctly. 29*4882a593Smuzhiyunzram_sizes="2097152" # 2MB 30*4882a593Smuzhiyunzram_mem_limits="2M" 31*4882a593Smuzhiyunzram_filesystems="ext4" 32*4882a593Smuzhiyunzram_algs="lzo" 33*4882a593Smuzhiyun 34*4882a593Smuzhiyunzram_fill_fs() 35*4882a593Smuzhiyun{ 36*4882a593Smuzhiyun for i in $(seq $dev_start $dev_end); do 37*4882a593Smuzhiyun echo "fill zram$i..." 38*4882a593Smuzhiyun local b=0 39*4882a593Smuzhiyun while [ true ]; do 40*4882a593Smuzhiyun dd conv=notrunc if=/dev/zero of=zram${i}/file \ 41*4882a593Smuzhiyun oflag=append count=1 bs=1024 status=none \ 42*4882a593Smuzhiyun > /dev/null 2>&1 || break 43*4882a593Smuzhiyun b=$(($b + 1)) 44*4882a593Smuzhiyun done 45*4882a593Smuzhiyun echo "zram$i can be filled with '$b' KB" 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"` 48*4882a593Smuzhiyun local v=$((100 * 1024 * $b / $mem_used_total)) 49*4882a593Smuzhiyun if [ "$v" -lt 100 ]; then 50*4882a593Smuzhiyun echo "FAIL compression ratio: 0.$v:1" 51*4882a593Smuzhiyun ERR_CODE=-1 52*4882a593Smuzhiyun return 53*4882a593Smuzhiyun fi 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK" 56*4882a593Smuzhiyun done 57*4882a593Smuzhiyun} 58*4882a593Smuzhiyun 59*4882a593Smuzhiyuncheck_prereqs 60*4882a593Smuzhiyunzram_load 61*4882a593Smuzhiyunzram_max_streams 62*4882a593Smuzhiyunzram_compress_alg 63*4882a593Smuzhiyunzram_set_disksizes 64*4882a593Smuzhiyunzram_set_memlimit 65*4882a593Smuzhiyunzram_makefs 66*4882a593Smuzhiyunzram_mount 67*4882a593Smuzhiyun 68*4882a593Smuzhiyunzram_fill_fs 69*4882a593Smuzhiyunzram_cleanup 70*4882a593Smuzhiyun 71*4882a593Smuzhiyunif [ $ERR_CODE -ne 0 ]; then 72*4882a593Smuzhiyun echo "$TCID : [FAIL]" 73*4882a593Smuzhiyunelse 74*4882a593Smuzhiyun echo "$TCID : [PASS]" 75*4882a593Smuzhiyunfi 76