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