Skip to content

Commit 1ae7cf8

Browse files
drakenclimberkamalesh-babulal
authored andcommitted
ftests: Add a test for the memory abstraction layer
Add a test for the memory abstraction layer abstractions. Currently only supports: memory.max <-> memory.limit_in_bytes memory.high <-> memory.soft_limit_in_bytes ----------------------------------------------------------------- Test Results: Run Date: Apr 14 14:52:47 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) -------------------------------------------- setup 0.00 093-cgxget-memory_settings.py 3.34 teardown 0.00 -------------------------------------------- Total Run Time 3.34 [Kamalesh removed the unused exceptions variable (lint warnings)] Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
1 parent 9c8ce4d commit 1ae7cf8

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: LGPL-2.1-only
3+
#
4+
# cgxget functionality test - various cpuset settings
5+
#
6+
# Copyright (c) 2021-2025 Oracle and/or its affiliates.
7+
# Author: Tom Hromatka <tom.hromatka@oracle.com>
8+
#
9+
10+
from cgroup import Cgroup, CgroupVersion
11+
from run import RunError
12+
import consts
13+
import ftests
14+
import sys
15+
import os
16+
17+
CONTROLLER = 'memory'
18+
CGNAME = '093cgxget'
19+
20+
CGRP_VER_V1 = CgroupVersion.CGROUP_V1
21+
CGRP_VER_V2 = CgroupVersion.CGROUP_V2
22+
23+
TABLE = [
24+
# writesetting, writeval, writever, readsetting, readval, readver
25+
26+
# memory.limit_in_bytes -> memory.max
27+
['memory.limit_in_bytes', '0', CGRP_VER_V1,
28+
'memory.limit_in_bytes', '0', CGRP_VER_V1],
29+
['memory.limit_in_bytes', '0', CGRP_VER_V1,
30+
'memory.max', '0', CGRP_VER_V2],
31+
32+
['memory.limit_in_bytes', '4096000', CGRP_VER_V1,
33+
'memory.limit_in_bytes', '4096000', CGRP_VER_V1],
34+
['memory.limit_in_bytes', '8192000', CGRP_VER_V1,
35+
'memory.max', '8192000', CGRP_VER_V2],
36+
37+
['memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1,
38+
'memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
39+
['memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1,
40+
'memory.max', 'max', CGRP_VER_V2],
41+
42+
['memory.limit_in_bytes', '9223372036860000000', CGRP_VER_V1,
43+
'memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
44+
['memory.limit_in_bytes', '9223372036860000000', CGRP_VER_V1,
45+
'memory.max', 'max', CGRP_VER_V2],
46+
47+
['memory.limit_in_bytes', '-1', CGRP_VER_V1,
48+
'memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
49+
['memory.limit_in_bytes', '-1', CGRP_VER_V1,
50+
'memory.max', 'max', CGRP_VER_V2],
51+
52+
# memory.soft_limit_in_bytes -> memory.high
53+
['memory.soft_limit_in_bytes', '0', CGRP_VER_V1,
54+
'memory.soft_limit_in_bytes', '0', CGRP_VER_V1],
55+
['memory.soft_limit_in_bytes', '0', CGRP_VER_V1,
56+
'memory.high', '0', CGRP_VER_V2],
57+
58+
['memory.soft_limit_in_bytes', '409600', CGRP_VER_V1,
59+
'memory.soft_limit_in_bytes', '409600', CGRP_VER_V1],
60+
['memory.soft_limit_in_bytes', '819200', CGRP_VER_V1,
61+
'memory.high', '819200', CGRP_VER_V2],
62+
63+
['memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1,
64+
'memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
65+
['memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1,
66+
'memory.high', 'max', CGRP_VER_V2],
67+
68+
['memory.soft_limit_in_bytes', '9223372036860000000', CGRP_VER_V1,
69+
'memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
70+
['memory.soft_limit_in_bytes', '9223372036860000000', CGRP_VER_V1,
71+
'memory.high', 'max', CGRP_VER_V2],
72+
73+
['memory.soft_limit_in_bytes', '-1', CGRP_VER_V1,
74+
'memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
75+
['memory.soft_limit_in_bytes', '-1', CGRP_VER_V1,
76+
'memory.high', 'max', CGRP_VER_V2],
77+
78+
# memory.max -> memory.limit_in_bytes
79+
['memory.max', '0', CGRP_VER_V2,
80+
'memory.max', '0', CGRP_VER_V2],
81+
['memory.max', '0', CGRP_VER_V2,
82+
'memory.limit_in_bytes', '0', CGRP_VER_V1],
83+
84+
['memory.max', '40960', CGRP_VER_V2,
85+
'memory.max', '40960', CGRP_VER_V2],
86+
['memory.max', '81920', CGRP_VER_V2,
87+
'memory.limit_in_bytes', '81920', CGRP_VER_V1],
88+
89+
['memory.max', 'max', CGRP_VER_V2,
90+
'memory.max', 'max', CGRP_VER_V2],
91+
['memory.max', 'max', CGRP_VER_V2,
92+
'memory.limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
93+
94+
# memory.high -> memory.soft_limit_in_bytes
95+
['memory.high', '0', CGRP_VER_V2,
96+
'memory.high', '0', CGRP_VER_V2],
97+
['memory.high', '0', CGRP_VER_V2,
98+
'memory.soft_limit_in_bytes', '0', CGRP_VER_V1],
99+
100+
['memory.high', '4096', CGRP_VER_V2,
101+
'memory.high', '4096', CGRP_VER_V2],
102+
['memory.high', '8192', CGRP_VER_V2,
103+
'memory.soft_limit_in_bytes', '8192', CGRP_VER_V1],
104+
105+
['memory.high', 'max', CGRP_VER_V2,
106+
'memory.high', 'max', CGRP_VER_V2],
107+
['memory.high', 'max', CGRP_VER_V2,
108+
'memory.soft_limit_in_bytes', '9223372036854771712', CGRP_VER_V1],
109+
]
110+
111+
112+
def prereqs(config):
113+
result = consts.TEST_PASSED
114+
cause = None
115+
116+
return result, cause
117+
118+
119+
def setup(config):
120+
Cgroup.create(config, CONTROLLER, CGNAME)
121+
122+
123+
def invalid_values_test(config):
124+
result = consts.TEST_PASSED
125+
cause = None
126+
127+
try:
128+
Cgroup.xset(config, cgname=CGNAME, setting='memory.limit_in_bytes',
129+
value='-10', version=CGRP_VER_V1)
130+
except RunError:
131+
# we passed in an invalid value. this should fail
132+
pass
133+
else:
134+
result = consts.TEST_FAILED
135+
cause = 'cgxset unexpectedly succeeded'
136+
137+
try:
138+
Cgroup.xset(config, cgname=CGNAME, setting='memory.max',
139+
value='-10', version=CGRP_VER_V2)
140+
except RunError:
141+
# we passed in an invalid value. this should fail
142+
pass
143+
else:
144+
result = consts.TEST_FAILED
145+
cause = 'cgxset unexpectedly succeeded'
146+
147+
return result, cause
148+
149+
150+
def test(config):
151+
result = consts.TEST_PASSED
152+
cause = None
153+
154+
result, cause = invalid_values_test(config)
155+
if result != consts.TEST_PASSED:
156+
return result, cause
157+
158+
for entry in TABLE:
159+
Cgroup.xset(config, cgname=CGNAME, setting=entry[0],
160+
value=entry[1], version=entry[2])
161+
162+
out = Cgroup.xget(config, cgname=CGNAME, setting=entry[3],
163+
version=entry[5], values_only=True,
164+
print_headers=False)
165+
166+
if out != entry[4]:
167+
result = consts.TEST_FAILED
168+
cause = (
169+
'After setting {}={}, expected {}={}, but received '
170+
'{}={}'
171+
''.format(entry[0], entry[1], entry[3], entry[4],
172+
entry[3], out)
173+
)
174+
return result, cause
175+
176+
return result, cause
177+
178+
179+
def teardown(config):
180+
Cgroup.delete(config, CONTROLLER, CGNAME)
181+
182+
183+
def main(config):
184+
[result, cause] = prereqs(config)
185+
if result != consts.TEST_PASSED:
186+
return [result, cause]
187+
188+
setup(config)
189+
[result, cause] = test(config)
190+
teardown(config)
191+
192+
return [result, cause]
193+
194+
195+
if __name__ == '__main__':
196+
config = ftests.parse_args()
197+
# this test was invoked directly. run only it
198+
config.args.num = int(os.path.basename(__file__).split('-')[0])
199+
sys.exit(ftests.main(config))
200+
201+
# vim: set et ts=4 sw=4:

0 commit comments

Comments
 (0)