memcg_max_usage_in_bytes_test.sh revision e549be72eaf0615547c22da101d6cf666e615419
1#! /bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) 2012 FUJITSU LIMITED                                         ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21################################################################################
22#
23# File :        memcg_max_usage_in_bytes_test.sh
24# Description:  Tests memory.max_usage_in_bytes.
25# Author:       Peng Haitao <penght@cn.fujitsu.com>
26# History:      2012/01/17 - Created.
27#
28
29export TCID="memcg_max_usage_in_bytes_test"
30export TST_TOTAL=4
31export TST_COUNT=0
32
33. memcg_lib.sh || exit 1
34
35MEM_SWAP_FLAG=0
36
37# Test memory.max_usage_in_bytes
38testcase_1()
39{
40	test_max_usage_in_bytes "--mmap-anon" $((PAGESIZE*1024)) \
41		"memory.max_usage_in_bytes" $((PAGESIZE*1024)) 0
42}
43
44# Test memory.memsw.max_usage_in_bytes
45testcase_2()
46{
47	if [ $MEM_SWAP_FLAG -eq 0 ]; then
48		tst_resm TCONF "mem+swap is not enabled"
49		return
50	fi
51
52	echo $((PAGESIZE*2048)) > memory.limit_in_bytes
53	echo $((PAGESIZE*2048)) > memory.memsw.limit_in_bytes
54	test_max_usage_in_bytes "--mmap-anon" $((PAGESIZE*1024)) \
55		"memory.memsw.max_usage_in_bytes" $((PAGESIZE*1024)) 0
56}
57
58# Test reset memory.max_usage_in_bytes
59testcase_3()
60{
61	test_max_usage_in_bytes "--mmap-anon" $((PAGESIZE*1024)) \
62		"memory.max_usage_in_bytes" $((PAGESIZE*1024)) 1
63}
64
65# Test reset memory.memsw.max_usage_in_bytes
66testcase_4()
67{
68	if [ $MEM_SWAP_FLAG -eq 0 ]; then
69		tst_resm TCONF "mem+swap is not enabled"
70		return
71	fi
72
73	echo $((PAGESIZE*2048)) > memory.limit_in_bytes
74	echo $((PAGESIZE*2048)) > memory.memsw.limit_in_bytes
75	test_max_usage_in_bytes "--mmap-anon" $((PAGESIZE*1024)) \
76		"memory.memsw.max_usage_in_bytes" $((PAGESIZE*1024)) 1
77}
78
79# Run all the test cases
80for i in $(seq 1 $TST_TOTAL)
81do
82	export TST_COUNT=$(( $TST_COUNT + 1 ))
83	cur_id=$i
84
85	do_mount
86	if [ $? -ne 0 ]; then
87		echo "Cannot create memcg"
88		exit 1
89	fi
90
91	# prepare
92	mkdir /dev/memcg/$i 2> /dev/null
93	cd /dev/memcg/$i
94
95	if [ -e memory.memsw.max_usage_in_bytes ]; then
96		MEM_SWAP_FLAG=1
97	fi
98
99	# run the case
100	testcase_$i
101
102	# clean up
103	sleep 1
104	cd $TEST_PATH
105	rmdir /dev/memcg/$i
106
107	cleanup
108done
109
110if [ $failed -ne 0 ]; then
111	exit $failed
112else
113	exit 0
114fi
115