tools/testing/selftests/damon/sysfs.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/damon/sysfs.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/damon/sysfs.py- Extension
.py- Size
- 14331 bytes
- Lines
- 361
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
import json
import os
import subprocess
import _damon_sysfs
def dump_damon_status_dict(pid):
try:
subprocess.check_output(['which', 'drgn'], stderr=subprocess.DEVNULL)
except:
return None, 'drgn not found'
file_dir = os.path.dirname(os.path.abspath(__file__))
dump_script = os.path.join(file_dir, 'drgn_dump_damon_status.py')
rc = subprocess.call(['drgn', dump_script, pid, 'damon_dump_output'],
stderr=subprocess.DEVNULL)
if rc != 0:
return None, 'drgn fail'
try:
with open('damon_dump_output', 'r') as f:
return json.load(f), None
except Exception as e:
return None, 'json.load fail (%s)' % e
kdamonds = None
def fail(expectation, status):
print('unexpected %s' % expectation)
print(json.dumps(status, indent=4))
if kdamonds is not None:
kdamonds.stop()
exit(1)
def assert_true(condition, expectation, status):
if condition is not True:
fail(expectation, status)
def assert_watermarks_committed(watermarks, dump):
wmark_metric_val = {
'none': 0,
'free_mem_rate': 1,
}
assert_true(dump['metric'] == wmark_metric_val[watermarks.metric],
'metric', dump)
assert_true(dump['interval'] == watermarks.interval, 'interval', dump)
assert_true(dump['high'] == watermarks.high, 'high', dump)
assert_true(dump['mid'] == watermarks.mid, 'mid', dump)
assert_true(dump['low'] == watermarks.low, 'low', dump)
def assert_quota_goal_committed(qgoal, dump):
metric_val = {
'user_input': 0,
'some_mem_psi_us': 1,
'node_mem_used_bp': 2,
'node_mem_free_bp': 3,
}
assert_true(dump['metric'] == metric_val[qgoal.metric], 'metric', dump)
assert_true(dump['target_value'] == qgoal.target_value, 'target_value',
dump)
if qgoal.metric == 'user_input':
assert_true(dump['current_value'] == qgoal.current_value,
'current_value', dump)
assert_true(dump['nid'] == qgoal.nid, 'nid', dump)
def assert_quota_committed(quota, dump):
assert_true(dump['reset_interval'] == quota.reset_interval_ms,
'reset_interval', dump)
assert_true(dump['ms'] == quota.ms, 'ms', dump)
assert_true(dump['sz'] == quota.sz, 'sz', dump)
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.