1*f21fb798SNaresh Kamboju#!/bin/bash 2*f21fb798SNaresh Kamboju# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 3*f21fb798SNaresh Kamboju# 4*f21fb798SNaresh Kamboju# This program is free software; you can redistribute it and/or 5*f21fb798SNaresh Kamboju# modify it under the terms of the GNU General Public License as 6*f21fb798SNaresh Kamboju# published by the Free Software Foundation; either version 2 of 7*f21fb798SNaresh Kamboju# the License, or (at your option) any later version. 8*f21fb798SNaresh Kamboju# 9*f21fb798SNaresh Kamboju# This program is distributed in the hope that it would be useful, 10*f21fb798SNaresh Kamboju# but WITHOUT ANY WARRANTY; without even the implied warranty of 11*f21fb798SNaresh Kamboju# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*f21fb798SNaresh Kamboju# GNU General Public License for more details. 13*f21fb798SNaresh Kamboju# 14*f21fb798SNaresh Kamboju# Test creates several zram devices with different filesystems on them. 15*f21fb798SNaresh Kamboju# It fills each device with zeros and checks that compression works. 16*f21fb798SNaresh Kamboju# 17*f21fb798SNaresh Kamboju# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 18*f21fb798SNaresh Kamboju# Modified: Naresh Kamboju <naresh.kamboju@linaro.org> 19*f21fb798SNaresh Kamboju 20*f21fb798SNaresh KambojuTCID="zram01" 21*f21fb798SNaresh KambojuERR_CODE=0 22*f21fb798SNaresh Kamboju 23*f21fb798SNaresh Kamboju. ./zram_lib.sh 24*f21fb798SNaresh Kamboju 25*f21fb798SNaresh Kamboju# Test will create the following number of zram devices: 26*f21fb798SNaresh Kambojudev_num=1 27*f21fb798SNaresh Kamboju# This is a list of parameters for zram devices. 28*f21fb798SNaresh Kamboju# Number of items must be equal to 'dev_num' parameter. 29*f21fb798SNaresh Kambojuzram_max_streams="2" 30*f21fb798SNaresh Kamboju 31*f21fb798SNaresh Kamboju# The zram sysfs node 'disksize' value can be either in bytes, 32*f21fb798SNaresh Kamboju# or you can use mem suffixes. But in some old kernels, mem 33*f21fb798SNaresh Kamboju# suffixes are not supported, for example, in RHEL6.6GA's kernel 34*f21fb798SNaresh Kamboju# layer, it uses strict_strtoull() to parse disksize which does 35*f21fb798SNaresh Kamboju# not support mem suffixes, in some newer kernels, they use 36*f21fb798SNaresh Kamboju# memparse() which supports mem suffixes. So here we just use 37*f21fb798SNaresh Kamboju# bytes to make sure everything works correctly. 38*f21fb798SNaresh Kambojuzram_sizes="2097152" # 2MB 39*f21fb798SNaresh Kambojuzram_mem_limits="2M" 40*f21fb798SNaresh Kambojuzram_filesystems="ext4" 41*f21fb798SNaresh Kambojuzram_algs="lzo" 42*f21fb798SNaresh Kamboju 43*f21fb798SNaresh Kambojuzram_fill_fs() 44*f21fb798SNaresh Kamboju{ 45*f21fb798SNaresh Kamboju local mem_free0=$(free -m | awk 'NR==2 {print $4}') 46*f21fb798SNaresh Kamboju 47*f21fb798SNaresh Kamboju for i in $(seq 0 $(($dev_num - 1))); do 48*f21fb798SNaresh Kamboju echo "fill zram$i..." 49*f21fb798SNaresh Kamboju local b=0 50*f21fb798SNaresh Kamboju while [ true ]; do 51*f21fb798SNaresh Kamboju dd conv=notrunc if=/dev/zero of=zram${i}/file \ 52*f21fb798SNaresh Kamboju oflag=append count=1 bs=1024 status=none \ 53*f21fb798SNaresh Kamboju > /dev/null 2>&1 || break 54*f21fb798SNaresh Kamboju b=$(($b + 1)) 55*f21fb798SNaresh Kamboju done 56*f21fb798SNaresh Kamboju echo "zram$i can be filled with '$b' KB" 57*f21fb798SNaresh Kamboju done 58*f21fb798SNaresh Kamboju 59*f21fb798SNaresh Kamboju local mem_free1=$(free -m | awk 'NR==2 {print $4}') 60*f21fb798SNaresh Kamboju local used_mem=$(($mem_free0 - $mem_free1)) 61*f21fb798SNaresh Kamboju 62*f21fb798SNaresh Kamboju local total_size=0 63*f21fb798SNaresh Kamboju for sm in $zram_sizes; do 64*f21fb798SNaresh Kamboju local s=$(echo $sm | sed 's/M//') 65*f21fb798SNaresh Kamboju total_size=$(($total_size + $s)) 66*f21fb798SNaresh Kamboju done 67*f21fb798SNaresh Kamboju 68*f21fb798SNaresh Kamboju echo "zram used ${used_mem}M, zram disk sizes ${total_size}M" 69*f21fb798SNaresh Kamboju 70*f21fb798SNaresh Kamboju local v=$((100 * $total_size / $used_mem)) 71*f21fb798SNaresh Kamboju 72*f21fb798SNaresh Kamboju if [ "$v" -lt 100 ]; then 73*f21fb798SNaresh Kamboju echo "FAIL compression ratio: 0.$v:1" 74*f21fb798SNaresh Kamboju ERR_CODE=-1 75*f21fb798SNaresh Kamboju zram_cleanup 76*f21fb798SNaresh Kamboju return 77*f21fb798SNaresh Kamboju fi 78*f21fb798SNaresh Kamboju 79*f21fb798SNaresh Kamboju echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK" 80*f21fb798SNaresh Kamboju} 81*f21fb798SNaresh Kamboju 82*f21fb798SNaresh Kambojuzram_load 83*f21fb798SNaresh Kambojuzram_max_streams 84*f21fb798SNaresh Kambojuzram_compress_alg 85*f21fb798SNaresh Kambojuzram_set_disksizes 86*f21fb798SNaresh Kambojuzram_set_memlimit 87*f21fb798SNaresh Kambojuzram_makefs 88*f21fb798SNaresh Kambojuzram_mount 89*f21fb798SNaresh Kamboju 90*f21fb798SNaresh Kambojuzram_fill_fs 91*f21fb798SNaresh Kambojuzram_cleanup 92*f21fb798SNaresh Kambojuzram_unload 93*f21fb798SNaresh Kamboju 94*f21fb798SNaresh Kambojuif [ $ERR_CODE -ne 0 ]; then 95*f21fb798SNaresh Kamboju echo "$TCID : [FAIL]" 96*f21fb798SNaresh Kambojuelse 97*f21fb798SNaresh Kamboju echo "$TCID : [PASS]" 98*f21fb798SNaresh Kambojufi 99