• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2009 FUJITSU LIMITED
4# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
6#
7# Author: Li Zefan <lizf@cn.fujitsu.com>
8# Restructure for LTP: Shi Weihua <shiwh@cn.fujitsu.com>
9# Added memcg enable/disable functionality: Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>
10
11MEMCG_TESTFUNC=test
12MEMCG_SHMMAX=1
13TST_CNT=15
14
15. memcg_lib.sh
16TST_CLEANUP=cleanup
17
18cleanup()
19{
20	memcg_cleanup
21	swapon -a
22}
23
24test1()
25{
26	tst_res TINFO "Test mmap(locked) + alloc_mem > limit_in_bytes"
27	test_proc_kill $PAGESIZE "--mmap-lock1" $((PAGESIZE * 2)) 0
28}
29
30test2()
31{
32	test_proc_kill $PAGESIZE "--mmap-lock2" $((PAGESIZE * 2)) 0
33}
34
35test3()
36{
37	tst_res TINFO "Test swapoff + alloc_mem > limit_in_bytes"
38	swapoff -a
39	test_proc_kill $PAGESIZE "--mmap-anon" $((PAGESIZE * 2)) 0
40	swapon -a
41}
42
43test4()
44{
45	swapoff -a
46	test_proc_kill $PAGESIZE "--mmap-file" $((PAGESIZE * 2)) 0
47	swapon -a
48}
49
50test5()
51{
52	swapoff -a
53	test_proc_kill $PAGESIZE "--shm -k 18" $((PAGESIZE * 2)) 0
54	swapon -a
55}
56
57test6()
58{
59	tst_res TINFO "Test limit_in_bytes == 0"
60	test_proc_kill 0 "--mmap-anon" $PAGESIZE 0
61}
62
63test7()
64{
65	test_proc_kill 0 "--mmap-file" $PAGESIZE 0
66}
67
68test8()
69{
70	test_proc_kill 0 "--shm -k 21" $PAGESIZE 0
71}
72
73test9()
74{
75	tst_res TINFO "Test limit_in_bytes will be aligned to PAGESIZE"
76	test_limit_in_bytes $((PAGESIZE - 1)) 0
77}
78
79test10()
80{
81	test_limit_in_bytes $((PAGESIZE + 1)) 0
82}
83
84test11()
85{
86	test_limit_in_bytes 1 0
87}
88
89test12()
90{
91	tst_res TINFO "Test invalid memory.limit_in_bytes"
92	if tst_kvcmp -lt "2.6.31"; then
93		EXPECT_FAIL echo -1 \> memory.limit_in_bytes
94	else
95		EXPECT_PASS echo -1 \> memory.limit_in_bytes
96	fi
97}
98
99test13()
100{
101	EXPECT_FAIL echo 1.0 \> memory.limit_in_bytes
102}
103
104test14()
105{
106	EXPECT_FAIL echo 1xx \> memory.limit_in_bytes
107}
108
109test15()
110{
111	EXPECT_FAIL echo xx \> memory.limit_in_bytes
112}
113
114tst_run
115