xref: /aosp_15_r20/external/ltp/testcases/kernel/device-drivers/zram/zram02.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
3# Copyright (c) 2019-2021 Petr Vorel <[email protected]>
4# Author: Alexey Kodanev <[email protected]>
5#
6# Test checks that we can create swap zram device.
7
8TST_CNT=6
9TST_TESTFUNC="do_test"
10
11# List of parameters for zram devices.
12# For each number the test creates own zram device.
13zram_max_streams="2"
14
15# The zram sysfs node 'disksize' value can be either in bytes,
16# or you can use mem suffixes. But in some old kernels, mem
17# suffixes are not supported, for example, in RHEL6.6GA's kernel
18# layer, it uses strict_strtoull() to parse disksize which does
19# not support mem suffixes, in some newer kernels, they use
20# memparse() which supports mem suffixes. So here we just use
21# bytes to make sure everything works correctly.
22zram_sizes="107374182400" # 100GB
23zram_mem_limits="1M"
24
25zram_makeswap()
26{
27	tst_res TINFO "make swap with zram device(s)"
28	tst_require_cmds mkswap swapon swapoff
29	local i=0
30
31	for i in $(seq $dev_start $dev_end); do
32		ROD mkswap /dev/zram$i
33		ROD swapon /dev/zram$i
34		tst_res TINFO "done with /dev/zram$i"
35		dev_makeswap=$i
36	done
37
38	tst_res TPASS "making zram swap succeeded"
39}
40
41zram_swapoff()
42{
43	tst_require_cmds swapoff
44	local i
45
46	for i in $(seq $dev_start $dev_end); do
47		ROD swapoff /dev/zram$i
48	done
49	dev_makeswap=-1
50
51	tst_res TPASS "swapoff completed"
52}
53
54do_test()
55{
56	case $1 in
57	 1) zram_max_streams;;
58	 2) zram_compress_alg;;
59	 3) zram_set_disksizes;;
60	 4) zram_set_memlimit;;
61	 5) zram_makeswap;;
62	 6) zram_swapoff;;
63	esac
64}
65
66. zram_lib.sh
67tst_run
68