xref: /aosp_15_r20/external/ltp/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2009 FUJITSU LIMITED
4# Copyright (c) 2016 Cyril Hrubis <[email protected]>
5# Copyright (c) 2021 Joerg Vehlow <[email protected]>
6#
7# Author: Li Zefan <[email protected]>
8# Restructure for LTP: Shi Weihua <[email protected]>
9# Added memcg enable/disable functionality: Rishikesh K Rajak <[email protected]>
10
11MEMCG_TESTFUNC=test
12TST_CNT=6
13
14
15# Test memory.force_empty
16test1()
17{
18	start_memcg_process --mmap-anon -s $PAGESIZE
19	echo $MEMCG_PROCESS_PID > tasks
20	signal_memcg_process $PAGESIZE
21	echo $MEMCG_PROCESS_PID > ../tasks
22
23	# This expects that there is swap configured
24	EXPECT_PASS echo 1 \> memory.force_empty
25
26	stop_memcg_process $pid
27}
28
29test2()
30{
31	EXPECT_PASS echo 0 \> memory.force_empty
32}
33
34test3()
35{
36	EXPECT_PASS echo 1.0 \> memory.force_empty
37}
38
39test4()
40{
41	EXPECT_PASS echo 1xx \> memory.force_empty
42}
43
44test5()
45{
46	EXPECT_PASS echo xx \> memory.force_empty
47}
48
49test6()
50{
51	# writing to non-empty top mem cgroup's force_empty
52	# should return failure
53	EXPECT_FAIL echo 1 \> "$mount_point/memory.force_empty"
54}
55
56. memcg_lib.sh
57tst_run
58