memcg_stat_test.sh revision 5e65d837ee4e3390c885db1d2eb340c80c2b6c36
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_stat_test.sh
24# Description:  Tests memroy.stat.
25# Author:       Peng Haitao <penght@cn.fujitsu.com>
26# History:      2012/01/16 - Created.
27#
28
29TCID="memcg_stat_test"
30TST_TOTAL=8
31
32. memcg_lib.sh
33
34# Test cache
35testcase_1()
36{
37	test_mem_stat "--shm -k 3" $PAGESIZE "cache" $PAGESIZE 0
38}
39
40# Test mapped_file
41testcase_2()
42{
43	test_mem_stat "--mmap-file" $PAGESIZE "mapped_file" $PAGESIZE 0
44}
45
46# Test unevictable with MAP_LOCKED
47testcase_3()
48{
49	test_mem_stat "--mmap-lock1" $PAGESIZE "unevictable" $PAGESIZE 0
50}
51
52# Test unevictable with mlock
53testcase_4()
54{
55	test_mem_stat "--mmap-lock2" $PAGESIZE "unevictable" $PAGESIZE 0
56}
57
58# Test hierarchical_memory_limit with enabling hierarchical accounting
59testcase_5()
60{
61	echo 1 > memory.use_hierarchy
62
63	mkdir subgroup
64	echo $PAGESIZE > memory.limit_in_bytes
65	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
66
67	cd subgroup
68	check_mem_stat "hierarchical_memory_limit" $PAGESIZE
69
70	cd ..
71	rmdir subgroup
72}
73
74# Test hierarchical_memory_limit with disabling hierarchical accounting
75testcase_6()
76{
77	echo 0 > memory.use_hierarchy
78
79	mkdir subgroup
80	echo $PAGESIZE > memory.limit_in_bytes
81	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
82
83	cd subgroup
84	check_mem_stat "hierarchical_memory_limit" $((PAGESIZE*2))
85
86	cd ..
87	rmdir subgroup
88}
89
90# Test hierarchical_memsw_limit with enabling hierarchical accounting
91testcase_7()
92{
93	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
94		tst_resm TCONF "mem+swap is not enabled"
95		return
96	fi
97
98	echo 1 > memory.use_hierarchy
99
100	mkdir subgroup
101	echo $PAGESIZE > memory.limit_in_bytes
102	echo $PAGESIZE > memory.memsw.limit_in_bytes
103	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
104	echo $((PAGESIZE*2)) > subgroup/memory.memsw.limit_in_bytes
105
106	cd subgroup
107	check_mem_stat "hierarchical_memsw_limit" $PAGESIZE
108
109	cd ..
110	rmdir subgroup
111}
112
113# Test hierarchical_memsw_limit with disabling hierarchical accounting
114testcase_8()
115{
116	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
117		tst_resm TCONF "mem+swap is not enabled"
118		return
119	fi
120
121	echo 0 > memory.use_hierarchy
122
123	mkdir subgroup
124	echo $PAGESIZE > memory.limit_in_bytes
125	echo $PAGESIZE > memory.memsw.limit_in_bytes
126	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
127	echo $((PAGESIZE*2)) > subgroup/memory.memsw.limit_in_bytes
128
129	cd subgroup
130	check_mem_stat "hierarchical_memsw_limit" $((PAGESIZE*2))
131
132	cd ..
133	rmdir subgroup
134}
135
136run_tests
137
138tst_exit
139
140