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>
25 local msg
="skip all tests:"
28 if [ $uid -ne 0 ]; then
29 echo $msg must be run as root
>&2
38 for i
in $
(seq 0 $dev_makeswap); do
42 for i
in $
(seq 0 $dev_mounted); do
46 for i
in $
(seq 0 $
(($dev_num - 1))); do
47 echo 1 > /sys
/block
/zram
${i}/reset
55 if [ $MODULE -ne 0 ] ; then
56 echo "zram rmmod zram"
57 rmmod zram
> /dev
/null
2>&1
63 # check zram module exists
64 MODULE_PATH
=/lib
/modules
/`uname -r`/kernel
/drivers
/block
/zram
/zram.ko
65 if [ -f $MODULE_PATH ]; then
67 echo "create '$dev_num' zram device(s)"
68 modprobe zram num_devices
=$dev_num
70 echo "failed to insert zram module"
74 dev_num_created
=$
(ls /dev
/zram
* |
wc -w)
76 if [ "$dev_num_created" -ne "$dev_num" ]; then
77 echo "unexpected num of devices: $dev_num_created"
80 echo "zram load module successful"
82 elif [ -b /dev
/zram0
]; then
83 echo "/dev/zram0 device file found: OK"
85 echo "ERROR: No zram.ko module or no /dev/zram0 device found"
86 echo "$TCID : CONFIG_ZRAM is not set"
93 echo "set max_comp_streams to zram device(s)"
96 for max_s
in $zram_max_streams; do
97 local sys_path
="/sys/block/zram${i}/max_comp_streams"
98 echo $max_s > $sys_path || \
99 echo "FAIL failed to set '$max_s' to $sys_path"
101 local max_streams
=$
(cat $sys_path)
103 [ "$max_s" -ne "$max_streams" ] && \
104 echo "FAIL can't set max_streams '$max_s', get $max_stream"
107 echo "$sys_path = '$max_streams' ($i/$dev_num)"
110 echo "zram max streams: OK"
115 echo "test that we can set compression algorithm"
117 local algs
=$
(cat /sys
/block
/zram
0/comp_algorithm
)
118 echo "supported algs: $algs"
120 for alg
in $zram_algs; do
121 local sys_path
="/sys/block/zram${i}/comp_algorithm"
122 echo "$alg" > $sys_path || \
123 echo "FAIL can't set '$alg' to $sys_path"
125 echo "$sys_path = '$alg' ($i/$dev_num)"
128 echo "zram set compression algorithm: OK"
133 echo "set disk size to zram device(s)"
135 for ds
in $zram_sizes; do
136 local sys_path
="/sys/block/zram${i}/disksize"
137 echo "$ds" > $sys_path || \
138 echo "FAIL can't set '$ds' to $sys_path"
141 echo "$sys_path = '$ds' ($i/$dev_num)"
144 echo "zram set disksizes: OK"
149 echo "set memory limit to zram device(s)"
152 for ds
in $zram_mem_limits; do
153 local sys_path
="/sys/block/zram${i}/mem_limit"
154 echo "$ds" > $sys_path || \
155 echo "FAIL can't set '$ds' to $sys_path"
158 echo "$sys_path = '$ds' ($i/$dev_num)"
161 echo "zram set memory limit: OK"
166 echo "make swap with zram device(s)"
168 for i
in $
(seq 0 $
(($dev_num - 1))); do
169 mkswap
/dev
/zram
$i > err.log
2>&1
170 if [ $?
-ne 0 ]; then
172 echo "FAIL mkswap /dev/zram$1 failed"
175 swapon
/dev
/zram
$i > err.log
2>&1
176 if [ $?
-ne 0 ]; then
178 echo "FAIL swapon /dev/zram$1 failed"
181 echo "done with /dev/zram$i"
185 echo "zram making zram mkswap and swapon: OK"
191 for i
in $
(seq 0 $dev_makeswap); do
192 swapoff
/dev
/zram
$i > err.log
2>&1
193 if [ $?
-ne 0 ]; then
195 echo "FAIL swapoff /dev/zram$i failed"
200 echo "zram swapoff: OK"
206 for fs
in $zram_filesystems; do
207 # if requested fs not supported default it to ext2
208 which mkfs.
$fs > /dev
/null
2>&1 || fs
=ext2
210 echo "make $fs filesystem on /dev/zram$i"
211 mkfs.
$fs /dev
/zram
$i > err.log
2>&1
212 if [ $?
-ne 0 ]; then
214 echo "FAIL failed to make $fs on /dev/zram$i"
217 echo "zram mkfs.$fs: OK"
224 for i
in $
(seq 0 $
(($dev_num - 1))); do
225 echo "mount /dev/zram$i"
227 mount
/dev
/zram
$i zram
$i > /dev
/null || \
228 echo "FAIL mount /dev/zram$i failed"
232 echo "zram mount of zram device(s): OK"