selftests/damon/sysfs: test filters directory
authorSeongJae Park <sj@kernel.org>
Mon, 5 Dec 2022 23:08:28 +0000 (23:08 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 19 Jan 2023 01:12:44 +0000 (17:12 -0800)
Add simple test cases for scheme filters of DAMON sysfs interface.  The
test cases check if the files are populated as expected, receives some
valid inputs, and refuses some invalid inputs.

Link: https://lkml.kernel.org/r/20221205230830.144349-10-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/damon/sysfs.sh

index db4942383a50f523ca8bb1cb1a682a13be521899..a00336ffdcad4861e228935d05ee52ded94b462b 100644 (file)
@@ -96,6 +96,34 @@ test_stats()
        done
 }
 
+test_filter()
+{
+       filter_dir=$1
+       ensure_file "$filter_dir/type" "exist" "600"
+       ensure_write_succ "$filter_dir/type" "anon" "valid input"
+       ensure_write_succ "$filter_dir/type" "memcg" "valid input"
+       ensure_write_fail "$filter_dir/type" "foo" "invalid input"
+       ensure_file "$filter_dir/matching" "exist" "600"
+       ensure_file "$filter_dir/memcg_path" "exist" "600"
+}
+
+test_filters()
+{
+       filters_dir=$1
+       ensure_dir "$filters_dir" "exist"
+       ensure_file "$filters_dir/nr_filters" "exist" "600"
+       ensure_write_succ  "$filters_dir/nr_filters" "1" "valid input"
+       test_filter "$filters_dir/0"
+
+       ensure_write_succ  "$filters_dir/nr_filters" "2" "valid input"
+       test_filter "$filters_dir/0"
+       test_filter "$filters_dir/1"
+
+       ensure_write_succ "$filters_dir/nr_filters" "0" "valid input"
+       ensure_dir "$filters_dir/0" "not_exist"
+       ensure_dir "$filters_dir/1" "not_exist"
+}
+
 test_watermarks()
 {
        watermarks_dir=$1
@@ -143,6 +171,7 @@ test_scheme()
        test_access_pattern "$scheme_dir/access_pattern"
        test_quotas "$scheme_dir/quotas"
        test_watermarks "$scheme_dir/watermarks"
+       test_filters "$scheme_dir/filters"
        test_stats "$scheme_dir/stats"
        test_tried_regions "$scheme_dir/tried_regions"
 }