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>
14 # Kselftest framework requirement - SKIP code is 4.
16 kernel_version
=`uname -r | cut -d'.' -f1,2`
17 kernel_major
=${kernel_version%.*}
18 kernel_minor
=${kernel_version#*.}
24 local msg
="skip all tests:"
27 if [ $uid -ne 0 ]; then
28 echo $msg must be run as root
>&2
38 if [ $kernel_major -gt $major ]; then
40 elif [[ $kernel_major -eq $major && $kernel_minor -ge $minor ]]; then
51 for i
in $
(seq $dev_start $dev_makeswap); do
55 for i
in $
(seq $dev_start $dev_mounted); do
59 for i
in $
(seq $dev_start $dev_end); do
60 echo 1 > /sys
/block
/zram
${i}/reset
64 if [ $sys_control -eq 1 ]; then
65 for i
in $
(seq $dev_start $dev_end); do
66 echo $i > /sys
/class
/zram-control
/hot_remove
70 if [ $module_load -eq 1 ]; then
71 rmmod zram
> /dev
/null
2>&1
77 echo "create '$dev_num' zram device(s)"
79 # zram module loaded, new kernel
80 if [ -d "/sys/class/zram-control" ]; then
81 echo "zram modules already loaded, kernel supports" \
82 "zram-control interface"
83 dev_start
=$
(ls /dev
/zram
* |
wc -w)
84 dev_end
=$
(($dev_start + $dev_num - 1))
87 for i
in $
(seq $dev_start $dev_end); do
88 cat /sys
/class
/zram-control
/hot_add
> /dev
/null
91 echo "all zram devices (/dev/zram$dev_start~$dev_end" \
92 "successfully created"
96 # detect old kernel or built-in
97 modprobe zram num_devices
=$dev_num
98 if [ ! -d "/sys/class/zram-control" ]; then
99 if grep -q '^zram' /proc
/modules
; then
100 rmmod zram
> /dev
/null
2>&1
101 if [ $?
-ne 0 ]; then
102 echo "zram module is being used on old kernel" \
103 "without zram-control interface"
107 echo "test needs CONFIG_ZRAM=m on old kernel without" \
108 "zram-control interface"
111 modprobe zram num_devices
=$dev_num
115 dev_end
=$
(($dev_num - 1))
116 echo "all zram devices (/dev/zram0~$dev_end) successfully created"
121 echo "set max_comp_streams to zram device(s)"
124 if [ $?
-eq 0 ]; then
125 echo "The device attribute max_comp_streams was"\
131 for max_s
in $zram_max_streams; do
132 local sys_path
="/sys/block/zram${i}/max_comp_streams"
133 echo $max_s > $sys_path || \
134 echo "FAIL failed to set '$max_s' to $sys_path"
136 local max_streams
=$
(cat $sys_path)
138 [ "$max_s" -ne "$max_streams" ] && \
139 echo "FAIL can't set max_streams '$max_s', get $max_stream"
142 echo "$sys_path = '$max_streams'"
145 echo "zram max streams: OK"
150 echo "test that we can set compression algorithm"
153 local algs
=$
(cat /sys
/block
/zram
${i}/comp_algorithm
)
154 echo "supported algs: $algs"
156 for alg
in $zram_algs; do
157 local sys_path
="/sys/block/zram${i}/comp_algorithm"
158 echo "$alg" > $sys_path || \
159 echo "FAIL can't set '$alg' to $sys_path"
161 echo "$sys_path = '$alg'"
164 echo "zram set compression algorithm: OK"
169 echo "set disk size to zram device(s)"
171 for ds
in $zram_sizes; do
172 local sys_path
="/sys/block/zram${i}/disksize"
173 echo "$ds" > $sys_path || \
174 echo "FAIL can't set '$ds' to $sys_path"
177 echo "$sys_path = '$ds'"
180 echo "zram set disksizes: OK"
185 echo "set memory limit to zram device(s)"
188 for ds
in $zram_mem_limits; do
189 local sys_path
="/sys/block/zram${i}/mem_limit"
190 echo "$ds" > $sys_path || \
191 echo "FAIL can't set '$ds' to $sys_path"
194 echo "$sys_path = '$ds'"
197 echo "zram set memory limit: OK"
202 echo "make swap with zram device(s)"
204 for i
in $
(seq $dev_start $dev_end); do
205 mkswap
/dev
/zram
$i > err.log
2>&1
206 if [ $?
-ne 0 ]; then
208 echo "FAIL mkswap /dev/zram$1 failed"
211 swapon
/dev
/zram
$i > err.log
2>&1
212 if [ $?
-ne 0 ]; then
214 echo "FAIL swapon /dev/zram$1 failed"
217 echo "done with /dev/zram$i"
221 echo "zram making zram mkswap and swapon: OK"
227 for i
in $
(seq $dev_start $dev_end); do
228 swapoff
/dev
/zram
$i > err.log
2>&1
229 if [ $?
-ne 0 ]; then
231 echo "FAIL swapoff /dev/zram$i failed"
236 echo "zram swapoff: OK"
242 for fs
in $zram_filesystems; do
243 # if requested fs not supported default it to ext2
244 which mkfs.
$fs > /dev
/null
2>&1 || fs
=ext2
246 echo "make $fs filesystem on /dev/zram$i"
247 mkfs.
$fs /dev
/zram
$i > err.log
2>&1
248 if [ $?
-ne 0 ]; then
250 echo "FAIL failed to make $fs on /dev/zram$i"
253 echo "zram mkfs.$fs: OK"
260 for i
in $
(seq $dev_start $dev_end); do
261 echo "mount /dev/zram$i"
263 mount
/dev
/zram
$i zram
$i > /dev
/null || \
264 echo "FAIL mount /dev/zram$i failed"
268 echo "zram mount of zram device(s): OK"