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_memsw_limit_in_bytes_test.sh
24# Description:  Tests memory.memsw.limit_in_bytes.
25# Author:       Peng Haitao <penght@cn.fujitsu.com>
26# History:      2012/01/3 - Created.
27#
28
29TCID="memcg_memsw_limit_in_bytes_test"
30TST_TOTAL=12
31
32. memcg_lib.sh
33
34testcase_1()
35{
36	test_proc_kill $PAGESIZE "--mmap-lock1" $((PAGESIZE*2)) 1
37}
38
39testcase_2()
40{
41	test_proc_kill $PAGESIZE "--mmap-lock2" $((PAGESIZE*2)) 1
42}
43
44testcase_3()
45{
46	test_proc_kill 0 "--mmap-anon" $PAGESIZE 1
47}
48
49testcase_4()
50{
51	test_proc_kill 0 "--mmap-file" $PAGESIZE 1
52}
53
54testcase_5()
55{
56	test_proc_kill 0 "--shm -k 21" $PAGESIZE 1
57}
58
59testcase_6()
60{
61	test_limit_in_bytes $((PAGESIZE-1)) 1
62}
63
64testcase_7()
65{
66	test_limit_in_bytes $((PAGESIZE+1)) 1
67}
68
69testcase_8()
70{
71	test_limit_in_bytes 1 1
72}
73
74testcase_9()
75{
76	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
77		tst_resm TCONF "mem+swap is not enabled"
78		return
79	fi
80
81	echo 10M > memory.limit_in_bytes
82
83	if tst_kvcmp -lt "2.6.31"; then
84		EXPECT_FAIL echo -1 \> memory.memsw.limit_in_bytes
85	else
86		EXPECT_PASS echo -1 \> memory.memsw.limit_in_bytes
87	fi
88}
89
90testcase_10()
91{
92	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
93		tst_resm TCONF "mem+swap is not enabled"
94		return
95	fi
96
97	echo 10M > memory.limit_in_bytes
98	EXPECT_FAIL echo 1.0 \> memory.memsw.limit_in_bytes
99}
100
101testcase_11()
102{
103	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
104		tst_resm TCONF "mem+swap is not enabled"
105		return
106	fi
107
108	echo 10M > memory.limit_in_bytes
109	EXPECT_FAIL echo 1xx \> memory.memsw.limit_in_bytes
110}
111
112testcase_12()
113{
114	if [ "$MEMSW_LIMIT_FLAG" -eq 0 ]; then
115		tst_resm TCONF "mem+swap is not enabled"
116		return
117	fi
118
119	echo 10M > memory.limit_in_bytes
120	EXPECT_FAIL echo xx \> memory.memsw.limit_in_bytes
121}
122
123run_tests
124
125tst_exit
126