2 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of
7 # the License, or (at your option) any later version.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
15 # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
21 # Kselftest framework requirement - SKIP code is 4.
28 local msg
="skip all tests:"
31 if [ $uid -ne 0 ]; then
32 echo $msg must be run as root
>&2
41 for i
in $
(seq 0 $dev_makeswap); do
45 for i
in $
(seq 0 $dev_mounted); do
49 for i
in $
(seq 0 $
(($dev_num - 1))); do
50 echo 1 > /sys
/block
/zram
${i}/reset
58 if [ $MODULE -ne 0 ] ; then
59 echo "zram rmmod zram"
60 rmmod zram
> /dev
/null
2>&1
66 # check zram module exists
67 MODULE_PATH
=/lib
/modules
/`uname -r`/kernel
/drivers
/block
/zram
/zram.ko
68 if [ -f $MODULE_PATH ]; then
70 echo "create '$dev_num' zram device(s)"
71 modprobe zram num_devices
=$dev_num
73 echo "failed to insert zram module"
77 dev_num_created
=$
(ls /dev
/zram
* |
wc -w)
79 if [ "$dev_num_created" -ne "$dev_num" ]; then
80 echo "unexpected num of devices: $dev_num_created"
83 echo "zram load module successful"
85 elif [ -b /dev
/zram0
]; then
86 echo "/dev/zram0 device file found: OK"
88 echo "ERROR: No zram.ko module or no /dev/zram0 device found"
89 echo "$TCID : CONFIG_ZRAM is not set"
96 echo "set max_comp_streams to zram device(s)"
99 for max_s
in $zram_max_streams; do
100 local sys_path
="/sys/block/zram${i}/max_comp_streams"
101 echo $max_s > $sys_path || \
102 echo "FAIL failed to set '$max_s' to $sys_path"
104 local max_streams
=$
(cat $sys_path)
106 [ "$max_s" -ne "$max_streams" ] && \
107 echo "FAIL can't set max_streams '$max_s', get $max_stream"
110 echo "$sys_path = '$max_streams' ($i/$dev_num)"
113 echo "zram max streams: OK"
118 echo "test that we can set compression algorithm"
120 local algs
=$
(cat /sys
/block
/zram
0/comp_algorithm
)
121 echo "supported algs: $algs"
123 for alg
in $zram_algs; do
124 local sys_path
="/sys/block/zram${i}/comp_algorithm"
125 echo "$alg" > $sys_path || \
126 echo "FAIL can't set '$alg' to $sys_path"
128 echo "$sys_path = '$alg' ($i/$dev_num)"
131 echo "zram set compression algorithm: OK"
136 echo "set disk size to zram device(s)"
138 for ds
in $zram_sizes; do
139 local sys_path
="/sys/block/zram${i}/disksize"
140 echo "$ds" > $sys_path || \
141 echo "FAIL can't set '$ds' to $sys_path"
144 echo "$sys_path = '$ds' ($i/$dev_num)"
147 echo "zram set disksizes: OK"
152 echo "set memory limit to zram device(s)"
155 for ds
in $zram_mem_limits; do
156 local sys_path
="/sys/block/zram${i}/mem_limit"
157 echo "$ds" > $sys_path || \
158 echo "FAIL can't set '$ds' to $sys_path"
161 echo "$sys_path = '$ds' ($i/$dev_num)"
164 echo "zram set memory limit: OK"
169 echo "make swap with zram device(s)"
171 for i
in $
(seq 0 $
(($dev_num - 1))); do
172 mkswap
/dev
/zram
$i > err.log
2>&1
173 if [ $?
-ne 0 ]; then
175 echo "FAIL mkswap /dev/zram$1 failed"
178 swapon
/dev
/zram
$i > err.log
2>&1
179 if [ $?
-ne 0 ]; then
181 echo "FAIL swapon /dev/zram$1 failed"
184 echo "done with /dev/zram$i"
188 echo "zram making zram mkswap and swapon: OK"
194 for i
in $
(seq 0 $dev_makeswap); do
195 swapoff
/dev
/zram
$i > err.log
2>&1
196 if [ $?
-ne 0 ]; then
198 echo "FAIL swapoff /dev/zram$i failed"
203 echo "zram swapoff: OK"
209 for fs
in $zram_filesystems; do
210 # if requested fs not supported default it to ext2
211 which mkfs.
$fs > /dev
/null
2>&1 || fs
=ext2
213 echo "make $fs filesystem on /dev/zram$i"
214 mkfs.
$fs /dev
/zram
$i > err.log
2>&1
215 if [ $?
-ne 0 ]; then
217 echo "FAIL failed to make $fs on /dev/zram$i"
220 echo "zram mkfs.$fs: OK"
227 for i
in $
(seq 0 $
(($dev_num - 1))); do
228 echo "mount /dev/zram$i"
230 mount
/dev
/zram
$i zram
$i > /dev
/null || \
231 echo "FAIL mount /dev/zram$i failed"
235 echo "zram mount of zram device(s): OK"