diff mbox series

[RFC,3/5] selftests/damon/_damon: implement sysfs updat_schemes_tried_bytes command

Message ID 20231202000806.46210-4-sj@kernel.org
State Superseded
Headers show
Series selftests/damon: add Python modules for DAMON control and functionality tests | expand

Commit Message

SeongJae Park Dec. 2, 2023, 12:08 a.m. UTC
Implement update_schemes_tried_bytes command in the test-writing-purpose
DAMON sysfs interface wrapper Python module.  It is not only making the
update, but also read the updated value from the sysfs interface and
store on the Kdamond python objects so that user of the module can get
it by reading the field of the object.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/_damon.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/damon/_damon.py b/tools/testing/selftests/damon/_damon.py
index 6b99f87a5f1e..e98cf4b6a4b7 100644
--- a/tools/testing/selftests/damon/_damon.py
+++ b/tools/testing/selftests/damon/_damon.py
@@ -76,6 +76,7 @@  class Damos:
     # todo: Support quotas, watermarks, stats, tried_regions
     idx = None
     context = None
+    tried_bytes = None
 
     def __init__(self, action='stat', access_pattern=DamosAccessPattern()):
         self.action = action
@@ -284,6 +285,19 @@  class Kdamond:
         err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on')
         return err
 
+    def update_schemes_tried_bytes(self):
+        err = write_file(os.path.join(self.sysfs_dir(), 'state'),
+                'update_schemes_tried_bytes')
+        if err != None:
+            return err
+        for context in self.contexts:
+            for scheme in context.schemes:
+                content, err = read_file(os.path.join(scheme.sysfs_dir(),
+                    'tried_regions', 'total_bytes'))
+                if err != None:
+                    return err
+                scheme.tried_bytes = int(content)
+
 class Kdamonds:
     kdamonds = []