Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20250720171652.92309-21-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
16797a55 a4027b5f

+16 -12
+16 -12
tools/testing/selftests/damon/sysfs.py
··· 164 164 assert_true(dump['max_nr_regions'] == attrs.max_nr_regions, 165 165 'max_nr_regions', dump) 166 166 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 + 167 182 def main(): 168 183 kdamonds = _damon_sysfs.Kdamonds( 169 184 [_damon_sysfs.Kdamond( ··· 197 182 kdamonds.stop() 198 183 exit(1) 199 184 200 - if len(status['contexts']) != 1: 201 - fail('number of contexts', status) 202 - 203 - ctx = status['contexts'][0] 204 - 205 - assert_monitoring_attrs_committed(_damon_sysfs.DamonAttrs(), ctx['attrs']) 206 - 207 - if ctx['adaptive_targets'] != [ 208 - { 'pid': 0, 'nr_regions': 0, 'regions_list': []}]: 209 - fail('adaptive targets', status) 210 - 211 - assert_schemes_committed([_damon_sysfs.Damos()], ctx['schemes']) 185 + assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts']) 212 186 213 187 kdamonds.stop() 214 188