1#!/bin/sh 2# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 3# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz> 4# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 5# 6# Test creates several zram devices with different filesystems on them. 7# It fills each device with zeros and checks that compression works. 8 9TST_CNT=7 10TST_TESTFUNC="do_test" 11TST_NEEDS_CMDS="awk bc dd" 12. zram_lib.sh 13 14# Test will create the following number of zram devices: 15dev_num=4 16# This is a list of parameters for zram devices. 17# Number of items must be equal to 'dev_num' parameter. 18zram_max_streams="2 3 5 8" 19 20FS_SIZE="402653184" 21FS_TYPE="btrfs" 22 23RAM_SIZE=$(awk '/MemTotal:/ {print $2}' /proc/meminfo) 24if [ "$RAM_SIZE" -lt 1048576 ]; then 25 tst_res TINFO "not enough space for Btrfs" 26 FS_SIZE="26214400" 27 FS_TYPE="ext2" 28fi 29 30# The zram sysfs node 'disksize' value can be either in bytes, 31# or you can use mem suffixes. But in some old kernels, mem 32# suffixes are not supported, for example, in RHEL6.6GA's kernel 33# layer, it uses strict_strtoull() to parse disksize which does 34# not support mem suffixes, in some newer kernels, they use 35# memparse() which supports mem suffixes. So here we just use 36# bytes to make sure everything works correctly. 37zram_sizes="26214400 26214400 26214400 $FS_SIZE" 38zram_mem_limits="25M 25M 25M $((FS_SIZE/1024/1024))M" 39zram_filesystems="ext3 ext4 xfs $FS_TYPE" 40 41zram_fill_fs() 42{ 43 for i in $(seq 0 $(($dev_num - 1))); do 44 tst_res TINFO "filling zram$i (it can take long time)" 45 local b=0 46 while true; do 47 dd conv=notrunc if=/dev/zero of=zram${i}/file \ 48 oflag=append count=1 bs=1024 status=none \ 49 >/dev/null 2>err.txt || break 50 b=$(($b + 1)) 51 done 52 if [ $b -eq 0 ]; then 53 [ -s err.txt ] && tst_res TWARN "dd error: $(cat err.txt)" 54 tst_brk TBROK "cannot fill zram $i" 55 fi 56 tst_res TPASS "zram$i was filled with '$b' KB" 57 58 if [ ! -f "/sys/block/zram$i/mm_stat" ]; then 59 if [ $i -eq 0 ]; then 60 tst_res TCONF "zram compression ratio test requires zram mm_stat sysfs file" 61 fi 62 63 continue 64 fi 65 66 local compr_size=`awk '{print $2}' "/sys/block/zram$i/mm_stat"` 67 local v=$((100 * 1024 * $b / $compr_size)) 68 local r=`echo "scale=2; $v / 100 " | bc` 69 70 if [ "$v" -lt 100 ]; then 71 tst_res TFAIL "compression ratio: $r:1" 72 break 73 fi 74 75 tst_res TPASS "compression ratio: $r:1" 76 done 77} 78 79do_test() 80{ 81 case $1 in 82 1) zram_max_streams;; 83 2) zram_compress_alg;; 84 3) zram_set_disksizes;; 85 4) zram_set_memlimit;; 86 5) zram_makefs;; 87 6) zram_mount;; 88 7) zram_fill_fs;; 89 esac 90} 91 92tst_run 93