Skip to content

Commit 16797a5

Browse files
sjp38akpm00
authored andcommitted
selftests/damon/sysfs.py: generalize DAMON context commit assertion
DAMON context commitment assertion is hard-coded for a specific test case. Split it out into a general version that can be reused for different test cases. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a4027b5 commit 16797a5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tools/testing/selftests/damon/sysfs.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ def assert_monitoring_attrs_committed(attrs, dump):
164164
assert_true(dump['max_nr_regions'] == attrs.max_nr_regions,
165165
'max_nr_regions', dump)
166166

167+
def assert_ctx_committed(ctx, dump):
168+
ops_val = {
169+
'vaddr': 0,
170+
'fvaddr': 1,
171+
'paddr': 2,
172+
}
173+
assert_true(dump['ops']['id'] == ops_val[ctx.ops], 'ops_id', dump)
174+
assert_monitoring_attrs_committed(ctx.monitoring_attrs, dump['attrs'])
175+
assert_schemes_committed(ctx.schemes, dump['schemes'])
176+
177+
def assert_ctxs_committed(ctxs, dump):
178+
assert_true(len(ctxs) == len(dump), 'ctxs length', dump)
179+
for idx, ctx in enumerate(ctxs):
180+
assert_ctx_committed(ctx, dump[idx])
181+
167182
def main():
168183
kdamonds = _damon_sysfs.Kdamonds(
169184
[_damon_sysfs.Kdamond(
@@ -182,18 +197,7 @@ def main():
182197
kdamonds.stop()
183198
exit(1)
184199

185-
if len(status['contexts']) != 1:
186-
fail('number of contexts', status)
187-
188-
ctx = status['contexts'][0]
189-
190-
assert_monitoring_attrs_committed(_damon_sysfs.DamonAttrs(), ctx['attrs'])
191-
192-
if ctx['adaptive_targets'] != [
193-
{ 'pid': 0, 'nr_regions': 0, 'regions_list': []}]:
194-
fail('adaptive targets', status)
195-
196-
assert_schemes_committed([_damon_sysfs.Damos()], ctx['schemes'])
200+
assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts'])
197201

198202
kdamonds.stop()
199203

0 commit comments

Comments
 (0)