• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 memory.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" $PAGESIZES $PAGESIZES "cache" $PAGESIZES false
38}
39
40# Test mapped_file
41testcase_2()
42{
43	test_mem_stat "--mmap-file" $PAGESIZES $PAGESIZES \
44		"mapped_file" $PAGESIZES false
45}
46
47# Test unevictable with MAP_LOCKED
48testcase_3()
49{
50	test_mem_stat "--mmap-lock1" $PAGESIZE $PAGESIZE \
51		"unevictable" $PAGESIZE false
52}
53
54# Test unevictable with mlock
55testcase_4()
56{
57	test_mem_stat "--mmap-lock2" $PAGESIZE $PAGESIZE \
58		"unevictable" $PAGESIZE false
59}
60
61# Test hierarchical_memory_limit with enabling hierarchical accounting
62testcase_5()
63{
64	echo 1 > memory.use_hierarchy
65
66	mkdir subgroup
67	echo $PAGESIZE > memory.limit_in_bytes
68	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
69
70	cd subgroup
71	check_mem_stat "hierarchical_memory_limit" $PAGESIZE
72
73	cd ..
74	rmdir subgroup
75}
76
77# Test hierarchical_memory_limit with disabling hierarchical accounting
78testcase_6()
79{
80	echo 0 > memory.use_hierarchy
81
82	mkdir subgroup
83	echo $PAGESIZE > memory.limit_in_bytes
84	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
85
86	cd subgroup
87	check_mem_stat "hierarchical_memory_limit" $((PAGESIZE*2))
88
89	cd ..
90	rmdir subgroup
91}
92
93# Test hierarchical_memsw_limit with enabling hierarchical accounting
94testcase_7()
95{
96	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
97		tst_resm TCONF "mem+swap is not enabled"
98		return
99	fi
100
101	echo 1 > memory.use_hierarchy
102
103	mkdir subgroup
104	echo $PAGESIZE > memory.limit_in_bytes
105	echo $PAGESIZE > memory.memsw.limit_in_bytes
106	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
107	echo $((PAGESIZE*2)) > subgroup/memory.memsw.limit_in_bytes
108
109	cd subgroup
110	check_mem_stat "hierarchical_memsw_limit" $PAGESIZE
111
112	cd ..
113	rmdir subgroup
114}
115
116# Test hierarchical_memsw_limit with disabling hierarchical accounting
117testcase_8()
118{
119	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
120		tst_resm TCONF "mem+swap is not enabled"
121		return
122	fi
123
124	echo 0 > memory.use_hierarchy
125
126	mkdir subgroup
127	echo $PAGESIZE > memory.limit_in_bytes
128	echo $PAGESIZE > memory.memsw.limit_in_bytes
129	echo $((PAGESIZE*2)) > subgroup/memory.limit_in_bytes
130	echo $((PAGESIZE*2)) > subgroup/memory.memsw.limit_in_bytes
131
132	cd subgroup
133	check_mem_stat "hierarchical_memsw_limit" $((PAGESIZE*2))
134
135	cd ..
136	rmdir subgroup
137}
138
139run_tests
140
141tst_exit
142
143