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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/damon/sysfs.py: merge DAMON status dumping into commitment assertion

For each test case, sysfs.py makes changes to DAMON, dumps DAMON internal
status and asserts the expectation is met. The dumping part should be the
same for all cases, so it is duplicated for each test case. Which means
it is easy to make mistakes. Actually a few of those duplicates are not
turning DAMON off in case of the dumping failure. It makes following
selftests that need to turn DAMON on fails with -EBUSY. Merge the status
dumping into commitment assertion with proper dumping failure handling, to
deduplicate and avoid the unnecessary following tests failures.

Link: https://lkml.kernel.org/r/20251112154114.66053-8-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Bill Wendling <morbo@google.com>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
675774ad 10e8c7ba

+13 -30
+13 -30
tools/testing/selftests/damon/sysfs.py
··· 185 185 assert_monitoring_targets_committed(ctx.targets, dump['adaptive_targets']) 186 186 assert_schemes_committed(ctx.schemes, dump['schemes']) 187 187 188 - def assert_ctxs_committed(ctxs, dump): 188 + def assert_ctxs_committed(kdamonds): 189 + status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid) 190 + if err is not None: 191 + print(err) 192 + kdamonds.stop() 193 + exit(1) 194 + 195 + ctxs = kdamonds.kdamonds[0].contexts 196 + dump = status['contexts'] 189 197 assert_true(len(ctxs) == len(dump), 'ctxs length', dump) 190 198 for idx, ctx in enumerate(ctxs): 191 199 assert_ctx_committed(ctx, dump[idx]) ··· 210 202 print('kdamond start failed: %s' % err) 211 203 exit(1) 212 204 213 - status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid) 214 - if err is not None: 215 - print(err) 216 - kdamonds.stop() 217 - exit(1) 218 - 219 - assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts']) 205 + assert_ctxs_committed(kdamonds) 220 206 221 207 context = _damon_sysfs.DamonCtx( 222 208 monitoring_attrs=_damon_sysfs.DamonAttrs( ··· 258 256 kdamonds.kdamonds[0].contexts = [context] 259 257 kdamonds.kdamonds[0].commit() 260 258 261 - status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid) 262 - if err is not None: 263 - print(err) 264 - exit(1) 265 - 266 - assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts']) 259 + assert_ctxs_committed(kdamonds) 267 260 268 261 # test online commitment of minimum context. 269 262 context = _damon_sysfs.DamonCtx() ··· 267 270 kdamonds.kdamonds[0].contexts = [context] 268 271 kdamonds.kdamonds[0].commit() 269 272 270 - status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid) 271 - if err is not None: 272 - print(err) 273 - exit(1) 274 - 275 - assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts']) 273 + assert_ctxs_committed(kdamonds) 276 274 277 275 kdamonds.stop() 278 276 ··· 295 303 exit(1) 296 304 kdamonds.kdamonds[0].contexts[0].targets[1].obsolete = True 297 305 kdamonds.kdamonds[0].commit() 298 - 299 - status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid) 300 - if err is not None: 301 - print(err) 302 - kdamonds.stop() 303 - exit(1) 304 - 305 306 del kdamonds.kdamonds[0].contexts[0].targets[1] 306 - 307 - assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts']) 308 - 307 + assert_ctxs_committed(kdamonds) 309 308 kdamonds.stop() 310 309 311 310 if __name__ == '__main__':