2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
5 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
6 # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
12 # Kselftest framework requirement - SKIP code is 4.
19 local msg
="skip all tests:"
22 if [ $uid -ne 0 ]; then
23 echo $msg must be run as root
>&2
32 for i
in $
(seq 0 $dev_makeswap); do
36 for i
in $
(seq 0 $dev_mounted); do
40 for i
in $
(seq 0 $
(($dev_num - 1))); do
41 echo 1 > /sys
/block
/zram
${i}/reset
49 if [ $MODULE -ne 0 ] ; then
50 echo "zram rmmod zram"
51 rmmod zram
> /dev
/null
2>&1
57 # check zram module exists
58 MODULE_PATH
=/lib
/modules
/`uname -r`/kernel
/drivers
/block
/zram
/zram.ko
59 if [ -f $MODULE_PATH ]; then
61 echo "create '$dev_num' zram device(s)"
62 modprobe zram num_devices
=$dev_num
64 echo "failed to insert zram module"
68 dev_num_created
=$
(ls /dev
/zram
* |
wc -w)
70 if [ "$dev_num_created" -ne "$dev_num" ]; then
71 echo "unexpected num of devices: $dev_num_created"
74 echo "zram load module successful"
76 elif [ -b /dev
/zram0
]; then
77 echo "/dev/zram0 device file found: OK"
79 echo "ERROR: No zram.ko module or no /dev/zram0 device found"
80 echo "$TCID : CONFIG_ZRAM is not set"
87 echo "set max_comp_streams to zram device(s)"
90 for max_s
in $zram_max_streams; do
91 local sys_path
="/sys/block/zram${i}/max_comp_streams"
92 echo $max_s > $sys_path || \
93 echo "FAIL failed to set '$max_s' to $sys_path"
95 local max_streams
=$
(cat $sys_path)
97 [ "$max_s" -ne "$max_streams" ] && \
98 echo "FAIL can't set max_streams '$max_s', get $max_stream"
101 echo "$sys_path = '$max_streams' ($i/$dev_num)"
104 echo "zram max streams: OK"
109 echo "test that we can set compression algorithm"
111 local algs
=$
(cat /sys
/block
/zram
0/comp_algorithm
)
112 echo "supported algs: $algs"
114 for alg
in $zram_algs; do
115 local sys_path
="/sys/block/zram${i}/comp_algorithm"
116 echo "$alg" > $sys_path || \
117 echo "FAIL can't set '$alg' to $sys_path"
119 echo "$sys_path = '$alg' ($i/$dev_num)"
122 echo "zram set compression algorithm: OK"
127 echo "set disk size to zram device(s)"
129 for ds
in $zram_sizes; do
130 local sys_path
="/sys/block/zram${i}/disksize"
131 echo "$ds" > $sys_path || \
132 echo "FAIL can't set '$ds' to $sys_path"
135 echo "$sys_path = '$ds' ($i/$dev_num)"
138 echo "zram set disksizes: OK"
143 echo "set memory limit to zram device(s)"
146 for ds
in $zram_mem_limits; do
147 local sys_path
="/sys/block/zram${i}/mem_limit"
148 echo "$ds" > $sys_path || \
149 echo "FAIL can't set '$ds' to $sys_path"
152 echo "$sys_path = '$ds' ($i/$dev_num)"
155 echo "zram set memory limit: OK"
160 echo "make swap with zram device(s)"
162 for i
in $
(seq 0 $
(($dev_num - 1))); do
163 mkswap
/dev
/zram
$i > err.log
2>&1
164 if [ $?
-ne 0 ]; then
166 echo "FAIL mkswap /dev/zram$1 failed"
169 swapon
/dev
/zram
$i > err.log
2>&1
170 if [ $?
-ne 0 ]; then
172 echo "FAIL swapon /dev/zram$1 failed"
175 echo "done with /dev/zram$i"
179 echo "zram making zram mkswap and swapon: OK"
185 for i
in $
(seq 0 $dev_makeswap); do
186 swapoff
/dev
/zram
$i > err.log
2>&1
187 if [ $?
-ne 0 ]; then
189 echo "FAIL swapoff /dev/zram$i failed"
194 echo "zram swapoff: OK"
200 for fs
in $zram_filesystems; do
201 # if requested fs not supported default it to ext2
202 which mkfs.
$fs > /dev
/null
2>&1 || fs
=ext2
204 echo "make $fs filesystem on /dev/zram$i"
205 mkfs.
$fs /dev
/zram
$i > err.log
2>&1
206 if [ $?
-ne 0 ]; then
208 echo "FAIL failed to make $fs on /dev/zram$i"
211 echo "zram mkfs.$fs: OK"
218 for i
in $
(seq 0 $
(($dev_num - 1))); do
219 echo "mount /dev/zram$i"
221 mount
/dev
/zram
$i zram
$i > /dev
/null || \
222 echo "FAIL mount /dev/zram$i failed"
226 echo "zram mount of zram device(s): OK"