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