staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / zram / zram_lib.sh
blob6f872f266fd1151b6771f55147d265468a3ad74d
1 #!/bin/sh
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>
8 MODULE=0
9 dev_makeswap=-1
10 dev_mounted=-1
12 # Kselftest framework requirement - SKIP code is 4.
13 ksft_skip=4
15 trap INT
17 check_prereqs()
19 local msg="skip all tests:"
20 local uid=$(id -u)
22 if [ $uid -ne 0 ]; then
23 echo $msg must be run as root >&2
24 exit $ksft_skip
28 zram_cleanup()
30 echo "zram cleanup"
31 local i=
32 for i in $(seq 0 $dev_makeswap); do
33 swapoff /dev/zram$i
34 done
36 for i in $(seq 0 $dev_mounted); do
37 umount /dev/zram$i
38 done
40 for i in $(seq 0 $(($dev_num - 1))); do
41 echo 1 > /sys/block/zram${i}/reset
42 rm -rf zram$i
43 done
47 zram_unload()
49 if [ $MODULE -ne 0 ] ; then
50 echo "zram rmmod zram"
51 rmmod zram > /dev/null 2>&1
55 zram_load()
57 # check zram module exists
58 MODULE_PATH=/lib/modules/`uname -r`/kernel/drivers/block/zram/zram.ko
59 if [ -f $MODULE_PATH ]; then
60 MODULE=1
61 echo "create '$dev_num' zram device(s)"
62 modprobe zram num_devices=$dev_num
63 if [ $? -ne 0 ]; then
64 echo "failed to insert zram module"
65 exit 1
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"
72 ERR_CODE=-1
73 else
74 echo "zram load module successful"
76 elif [ -b /dev/zram0 ]; then
77 echo "/dev/zram0 device file found: OK"
78 else
79 echo "ERROR: No zram.ko module or no /dev/zram0 device found"
80 echo "$TCID : CONFIG_ZRAM is not set"
81 exit 1
85 zram_max_streams()
87 echo "set max_comp_streams to zram device(s)"
89 local i=0
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"
94 sleep 1
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"
100 i=$(($i + 1))
101 echo "$sys_path = '$max_streams' ($i/$dev_num)"
102 done
104 echo "zram max streams: OK"
107 zram_compress_alg()
109 echo "test that we can set compression algorithm"
111 local algs=$(cat /sys/block/zram0/comp_algorithm)
112 echo "supported algs: $algs"
113 local i=0
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"
118 i=$(($i + 1))
119 echo "$sys_path = '$alg' ($i/$dev_num)"
120 done
122 echo "zram set compression algorithm: OK"
125 zram_set_disksizes()
127 echo "set disk size to zram device(s)"
128 local i=0
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"
134 i=$(($i + 1))
135 echo "$sys_path = '$ds' ($i/$dev_num)"
136 done
138 echo "zram set disksizes: OK"
141 zram_set_memlimit()
143 echo "set memory limit to zram device(s)"
145 local i=0
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"
151 i=$(($i + 1))
152 echo "$sys_path = '$ds' ($i/$dev_num)"
153 done
155 echo "zram set memory limit: OK"
158 zram_makeswap()
160 echo "make swap with zram device(s)"
161 local i=0
162 for i in $(seq 0 $(($dev_num - 1))); do
163 mkswap /dev/zram$i > err.log 2>&1
164 if [ $? -ne 0 ]; then
165 cat err.log
166 echo "FAIL mkswap /dev/zram$1 failed"
169 swapon /dev/zram$i > err.log 2>&1
170 if [ $? -ne 0 ]; then
171 cat err.log
172 echo "FAIL swapon /dev/zram$1 failed"
175 echo "done with /dev/zram$i"
176 dev_makeswap=$i
177 done
179 echo "zram making zram mkswap and swapon: OK"
182 zram_swapoff()
184 local i=
185 for i in $(seq 0 $dev_makeswap); do
186 swapoff /dev/zram$i > err.log 2>&1
187 if [ $? -ne 0 ]; then
188 cat err.log
189 echo "FAIL swapoff /dev/zram$i failed"
191 done
192 dev_makeswap=-1
194 echo "zram swapoff: OK"
197 zram_makefs()
199 local i=0
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
207 cat err.log
208 echo "FAIL failed to make $fs on /dev/zram$i"
210 i=$(($i + 1))
211 echo "zram mkfs.$fs: OK"
212 done
215 zram_mount()
217 local i=0
218 for i in $(seq 0 $(($dev_num - 1))); do
219 echo "mount /dev/zram$i"
220 mkdir zram$i
221 mount /dev/zram$i zram$i > /dev/null || \
222 echo "FAIL mount /dev/zram$i failed"
223 dev_mounted=$i
224 done
226 echo "zram mount of zram device(s): OK"