1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2009 FUJITSU LIMITED 4# Copyright (c) 2016 Cyril Hrubis <[email protected]> 5# Copyright (c) 2021 Joerg Vehlow <[email protected]> 6# 7# Author: Li Zefan <[email protected]> 8# Restructure for LTP: Shi Weihua <[email protected]> 9# Added memcg enable/disable functionality: Rishikesh K Rajak <[email protected]> 10 11MEMCG_TESTFUNC=test 12MEMCG_SHMMAX=1 13TST_CNT=15 14 15TST_CLEANUP=cleanup 16 17cleanup() 18{ 19 memcg_cleanup 20 swapon -a 21} 22 23test1() 24{ 25 tst_res TINFO "Test mmap(locked) + alloc_mem > limit_in_bytes" 26 test_proc_kill $PAGESIZE "--mmap-lock1" $((PAGESIZE * 2)) 0 27} 28 29test2() 30{ 31 test_proc_kill $PAGESIZE "--mmap-lock2" $((PAGESIZE * 2)) 0 32} 33 34test3() 35{ 36 tst_res TINFO "Test swapoff + alloc_mem > limit_in_bytes" 37 swapoff -a 38 test_proc_kill $PAGESIZE "--mmap-anon" $((PAGESIZE * 2)) 0 39 swapon -a 40} 41 42test4() 43{ 44 swapoff -a 45 test_proc_kill $PAGESIZE "--mmap-file" $((PAGESIZE * 2)) 0 46 swapon -a 47} 48 49test5() 50{ 51 swapoff -a 52 test_proc_kill $PAGESIZE "--shm -k 18" $((PAGESIZE * 2)) 0 53 swapon -a 54} 55 56test6() 57{ 58 tst_res TINFO "Test limit_in_bytes == 0" 59 test_proc_kill 0 "--mmap-anon" $PAGESIZE 0 60} 61 62test7() 63{ 64 test_proc_kill 0 "--mmap-file" $PAGESIZE 0 65} 66 67test8() 68{ 69 test_proc_kill 0 "--shm -k 21" $PAGESIZE 0 70} 71 72test9() 73{ 74 tst_res TINFO "Test limit_in_bytes will be aligned to PAGESIZE" 75 test_limit_in_bytes $((PAGESIZE - 1)) 0 76} 77 78test10() 79{ 80 test_limit_in_bytes $((PAGESIZE + 1)) 0 81} 82 83test11() 84{ 85 test_limit_in_bytes 1 0 86} 87 88test12() 89{ 90 tst_res TINFO "Test invalid memory.limit_in_bytes" 91 EXPECT_PASS echo -1 \> memory.limit_in_bytes 92} 93 94test13() 95{ 96 EXPECT_FAIL echo 1.0 \> memory.limit_in_bytes 97} 98 99test14() 100{ 101 EXPECT_FAIL echo 1xx \> memory.limit_in_bytes 102} 103 104test15() 105{ 106 EXPECT_FAIL echo xx \> memory.limit_in_bytes 107} 108 109. memcg_lib.sh 110tst_run 111