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