• 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_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/16 - Created.
27#
28
29export TCID="memcg_usage_in_bytes_test"
30export TST_TOTAL=2
31export TST_COUNT=0
32
33. memcg_lib.sh || exit 1
34
35MEM_SWAP_FLAG=0
36
37# Test memory.usage_in_bytes
38testcase_1()
39{
40	test_mem_stat "--mmap-anon" $((PAGESIZE*1024)) \
41		"memory.usage_in_bytes" $((PAGESIZE*1024)) 0
42}
43
44# Test memory.memsw.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_mem_stat "--mmap-anon" $((PAGESIZE*1024)) \
55		"memory.memsw.usage_in_bytes" $((PAGESIZE*1024)) 0
56}
57
58# Run all the test cases
59for i in $(seq 1 $TST_TOTAL)
60do
61	export TST_COUNT=$(( $TST_COUNT + 1 ))
62	cur_id=$i
63
64	do_mount
65	if [ $? -ne 0 ]; then
66		echo "Cannot create memcg"
67		exit 1
68	fi
69
70	# prepare
71	mkdir /dev/memcg/$i 2> /dev/null
72	cd /dev/memcg/$i
73
74	if [ -e memory.memsw.usage_in_bytes ]; then
75		MEM_SWAP_FLAG=1
76	fi
77
78	# run the case
79	testcase_$i
80
81	# clean up
82	sleep 1
83	cd $TEST_PATH
84	rmdir /dev/memcg/$i
85
86	cleanup
87done
88
89if [ $failed -ne 0 ]; then
90	exit $failed
91else
92	exit 0
93fi
94