aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaresh Kamboju <naresh.kamboju@linaro.org>2015-06-04 21:51:56 +0530
committerNaresh Kamboju <naresh.kamboju@linaro.org>2015-06-04 21:51:56 +0530
commit6244615daf701df5e7a0e065adb84b1a5491c15f (patch)
tree0fe4cb5c0f56d397d2227eb415e733ad8a9c00ca
ZRAM : Adding ZRAM test cases
Adding ZRAM test cases. This feature is been added into LSK. ZRAM Kconfig as below: - CONFIG_ZPOOL=y - CONFIG_ZSMALLOC=y - CONFIG_ZRAM=y - CONFIG_ZRAM_LZ4_COMPRESS=y Signed-off-by: Naresh Kamboju <naresh.kamboju@linaro.org>
-rwxr-xr-xzram01.sh91
-rwxr-xr-xzram02.sh46
-rwxr-xr-xzram_lib.sh190
3 files changed, 327 insertions, 0 deletions
diff --git a/zram01.sh b/zram01.sh
new file mode 100755
index 0000000..8d98e2d
--- /dev/null
+++ b/zram01.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Test creates several zram devices with different filesystems on them.
+# It fills each device with zeros and checks that compression works.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+# Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
+
+. ./zram_lib.sh
+
+# Test will create the following number of zram devices:
+dev_num=1
+# This is a list of parameters for zram devices.
+# Number of items must be equal to 'dev_num' parameter.
+zram_max_streams="2"
+
+# The zram sysfs node 'disksize' value can be either in bytes,
+# or you can use mem suffixes. But in some old kernels, mem
+# suffixes are not supported, for example, in RHEL6.6GA's kernel
+# layer, it uses strict_strtoull() to parse disksize which does
+# not support mem suffixes, in some newer kernels, they use
+# memparse() which supports mem suffixes. So here we just use
+# bytes to make sure everything works correctly.
+zram_sizes="2097152" # 2MB
+zram_mem_limits="2M"
+zram_filesystems="ext4"
+zram_algs="lzo"
+
+zram_fill_fs()
+{
+ which dd free awk
+ local mem_free0=$(free -m | awk 'NR==2 {print $4}')
+
+ for i in $(seq 0 $(($dev_num - 1))); do
+ echo "fill zram$i..."
+ local b=0
+ while [ true ]; do
+ dd conv=notrunc if=/dev/zero of=zram${i}/file \
+ oflag=append count=1 bs=1024 status=none \
+ > /dev/null 2>&1 || break
+ b=$(($b + 1))
+ done
+ echo "zram$i can be filled with '$b' KB"
+ done
+
+ local mem_free1=$(free -m | awk 'NR==2 {print $4}')
+ local used_mem=$(($mem_free0 - $mem_free1))
+
+ local total_size=0
+ for sm in $zram_sizes; do
+ local s=$(echo $sm | sed 's/M//')
+ total_size=$(($total_size + $s))
+ done
+
+ echo "zram used ${used_mem}M, zram disk sizes ${total_size}M"
+
+ local v=$((100 * $total_size / $used_mem))
+
+ if [ "$v" -lt 100 ]; then
+ echo "FAIL compression ratio: 0.$v:1"
+ zram_cleanup
+ return
+ fi
+
+ echo "ZRAM compression ratio: $(echo "scale=2; $v / 100 " | bc):1 : PASS"
+}
+
+zram_max_streams
+zram_compress_alg
+zram_set_disksizes
+zram_set_memlimit
+zram_makefs
+zram_mount
+
+zram_fill_fs
+zram_cleanup
diff --git a/zram02.sh b/zram02.sh
new file mode 100755
index 0000000..dbb7e51
--- /dev/null
+++ b/zram02.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Test checks that we can create swap zram device.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+# Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
+
+. ./zram_lib.sh
+
+# Test will create the following number of zram devices:
+dev_num=1
+# This is a list of parameters for zram devices.
+# Number of items must be equal to 'dev_num' parameter.
+zram_max_streams="2"
+
+# The zram sysfs node 'disksize' value can be either in bytes,
+# or you can use mem suffixes. But in some old kernels, mem
+# suffixes are not supported, for example, in RHEL6.6GA's kernel
+# layer, it uses strict_strtoull() to parse disksize which does
+# not support mem suffixes, in some newer kernels, they use
+# memparse() which supports mem suffixes. So here we just use
+# bytes to make sure everything works correctly.
+zram_sizes="1048576" # 1M
+zram_mem_limits="1M"
+
+zram_max_streams
+zram_set_disksizes
+zram_set_memlimit
+zram_makeswap
+zram_swapoff
+zram_cleanup
diff --git a/zram_lib.sh b/zram_lib.sh
new file mode 100755
index 0000000..4f4ea89
--- /dev/null
+++ b/zram_lib.sh
@@ -0,0 +1,190 @@
+#!/bin/sh
+# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+# Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
+
+dev_makeswap=-1
+dev_mounted=-1
+
+trap INT
+
+zram_cleanup()
+{
+ echo "zram cleanup"
+ local i=
+ for i in $(seq 0 $dev_makeswap); do
+ swapoff /dev/zram$i
+ done
+
+ for i in $(seq 0 $dev_mounted); do
+ umount /dev/zram$i
+ done
+
+ for i in $(seq 0 $(($dev_num - 1))); do
+ echo 1 > /sys/block/zram${i}/reset
+ rm -rf zram$i
+ done
+
+}
+
+zram_max_streams()
+{
+ echo "set max_comp_streams to zram device(s)"
+
+ local i=0
+ for max_s in $zram_max_streams; do
+ local sys_path="/sys/block/zram${i}/max_comp_streams"
+ echo $max_s > $sys_path || \
+ echo "FAIL failed to set '$max_s' to $sys_path"
+ sleep 1
+ local max_streams=$(cat $sys_path)
+
+ [ "$max_s" -ne "$max_streams" ] && \
+ echo "FAIL can't set max_streams '$max_s', get $max_stream"
+
+ i=$(($i + 1))
+ echo "$sys_path = '$max_streams' ($i/$dev_num)"
+ done
+
+ echo "ZRAM max streams : PASS"
+}
+
+zram_compress_alg()
+{
+ echo "test that we can set compression algorithm"
+
+ local algs=$(cat /sys/block/zram0/comp_algorithm)
+ echo "supported algs: $algs"
+ local i=0
+ for alg in $zram_algs; do
+ local sys_path="/sys/block/zram${i}/comp_algorithm"
+ echo "$alg" > $sys_path || \
+ echo "FAIL can't set '$alg' to $sys_path"
+ i=$(($i + 1))
+ echo "$sys_path = '$alg' ($i/$dev_num)"
+ done
+
+ echo "ZRAM set compression algorithm : PASS"
+}
+
+zram_set_disksizes()
+{
+ echo "set disk size to zram device(s)"
+ local i=0
+ for ds in $zram_sizes; do
+ local sys_path="/sys/block/zram${i}/disksize"
+ echo "$ds" > $sys_path || \
+ echo "FAIL can't set '$ds' to $sys_path"
+
+ i=$(($i + 1))
+ echo "$sys_path = '$ds' ($i/$dev_num)"
+ done
+
+ echo "ZRAM set disksizes : PASS"
+}
+
+zram_set_memlimit()
+{
+ echo "set memory limit to zram device(s)"
+
+ local i=0
+ for ds in $zram_mem_limits; do
+ local sys_path="/sys/block/zram${i}/mem_limit"
+ echo "$ds" > $sys_path || \
+ echo "FAIL can't set '$ds' to $sys_path"
+
+ i=$(($i + 1))
+ echo "$sys_path = '$ds' ($i/$dev_num)"
+ done
+
+ echo "ZRAM set memory limit : PASS"
+}
+
+zram_makeswap()
+{
+ echo "make swap with zram device(s)"
+ which mkswap swapon swapoff
+ local i=0
+ for i in $(seq 0 $(($dev_num - 1))); do
+ mkswap /dev/zram$i > err.log 2>&1
+ if [ $? -ne 0 ]; then
+ cat err.log
+ echo "FAIL mkswap /dev/zram$1 failed"
+ fi
+
+ swapon /dev/zram$i > err.log 2>&1
+ if [ $? -ne 0 ]; then
+ cat err.log
+ echo "FAIL swapon /dev/zram$1 failed"
+ fi
+
+ echo "done with /dev/zram$i"
+ dev_makeswap=$i
+ done
+
+ echo "ZRAM making zram mkswap and swapon : PASS"
+}
+
+zram_swapoff()
+{
+ which swapoff
+ local i=
+ for i in $(seq 0 $dev_makeswap); do
+ swapoff /dev/zram$i > err.log 2>&1
+ if [ $? -ne 0 ]; then
+ cat err.log
+ echo "FAIL swapoff /dev/zram$i failed"
+ fi
+ done
+ dev_makeswap=-1
+
+ echo "ZRAM swapoff : PASS"
+}
+
+zram_makefs()
+{
+ which mkfs
+ local i=0
+ for fs in $zram_filesystems; do
+ # if requested fs not supported default it to ext2
+ which mkfs.$fs > /dev/null 2>&1 || fs=ext2
+
+ echo "make $fs filesystem on /dev/zram$i"
+ mkfs.$fs /dev/zram$i > err.log 2>&1
+ if [ $? -ne 0 ]; then
+ cat err.log
+ echo "FAIL failed to make $fs on /dev/zram$i"
+ fi
+ i=$(($i + 1))
+ echo "ZRAM mkfs.$fs : PASS"
+ done
+}
+
+zram_mount()
+{
+ local i=0
+ for i in $(seq 0 $(($dev_num - 1))); do
+ echo "mount /dev/zram$i"
+ mkdir zram$i
+ mount /dev/zram$i zram$i > /dev/null || \
+ echo "FAIL mount /dev/zram$i failed"
+ dev_mounted=$i
+ done
+
+ echo "ZRAM mount of zram device(s) : PASS"
+}