forked from mirrors/linux
		
	selftests: cgroup: add test_zswap program
Patch series "selftests: cgroup: add zswap test program". This series adds 2 zswap related selftests that verify known and fixed issues. A new dedicated test program (test_zswap) is proposed since the test cases are specific to zswap and hosts specific helpers. The first patch adds the (empty) test program, while the other 2 add an actual test function each. This patch (of 3): Add empty cgroup-zswap self test scaffold program, test functions to be added in the next commits. Link: https://lkml.kernel.org/r/20230621153548.428093-1-cerasuolodomenico@gmail.com Link: https://lkml.kernel.org/r/20230621153548.428093-2-cerasuolodomenico@gmail.com Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com> Cc: Dan Streetman <ddstreet@ieee.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Rik van Riel <riel@surriel.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Seth Jennings <sjenning@redhat.com> Cc: Shakeel Butt <shakeelb@google.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Tejun Heo <tj@kernel.org> Cc: Vitaly Wool <vitaly.wool@konsulko.com> Cc: Zefan Li <lizefan.x@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									a2ebb51575
								
							
						
					
					
						commit
						fe3b1bf19b
					
				
					 3 changed files with 65 additions and 0 deletions
				
			
		
							
								
								
									
										1
									
								
								tools/testing/selftests/cgroup/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								tools/testing/selftests/cgroup/.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -5,4 +5,5 @@ test_freezer
 | 
				
			||||||
test_kmem
 | 
					test_kmem
 | 
				
			||||||
test_kill
 | 
					test_kill
 | 
				
			||||||
test_cpu
 | 
					test_cpu
 | 
				
			||||||
 | 
					test_zswap
 | 
				
			||||||
wait_inotify
 | 
					wait_inotify
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@ TEST_GEN_PROGS += test_core
 | 
				
			||||||
TEST_GEN_PROGS += test_freezer
 | 
					TEST_GEN_PROGS += test_freezer
 | 
				
			||||||
TEST_GEN_PROGS += test_kill
 | 
					TEST_GEN_PROGS += test_kill
 | 
				
			||||||
TEST_GEN_PROGS += test_cpu
 | 
					TEST_GEN_PROGS += test_cpu
 | 
				
			||||||
 | 
					TEST_GEN_PROGS += test_zswap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
 | 
					LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,3 +24,4 @@ $(OUTPUT)/test_core: cgroup_util.c
 | 
				
			||||||
$(OUTPUT)/test_freezer: cgroup_util.c
 | 
					$(OUTPUT)/test_freezer: cgroup_util.c
 | 
				
			||||||
$(OUTPUT)/test_kill: cgroup_util.c
 | 
					$(OUTPUT)/test_kill: cgroup_util.c
 | 
				
			||||||
$(OUTPUT)/test_cpu: cgroup_util.c
 | 
					$(OUTPUT)/test_cpu: cgroup_util.c
 | 
				
			||||||
 | 
					$(OUTPUT)/test_zswap: cgroup_util.c
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										62
									
								
								tools/testing/selftests/cgroup/test_zswap.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								tools/testing/selftests/cgroup/test_zswap.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,62 @@
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: GPL-2.0
 | 
				
			||||||
 | 
					#define _GNU_SOURCE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/limits.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "../kselftest.h"
 | 
				
			||||||
 | 
					#include "cgroup_util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define T(x) { x, #x }
 | 
				
			||||||
 | 
					struct zswap_test {
 | 
				
			||||||
 | 
						int (*fn)(const char *root);
 | 
				
			||||||
 | 
						const char *name;
 | 
				
			||||||
 | 
					} tests[] = {
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					#undef T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool zswap_configured(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return access("/sys/module/zswap", F_OK) == 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char root[PATH_MAX];
 | 
				
			||||||
 | 
						int i, ret = EXIT_SUCCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (cg_find_unified_root(root, sizeof(root)))
 | 
				
			||||||
 | 
							ksft_exit_skip("cgroup v2 isn't mounted\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!zswap_configured())
 | 
				
			||||||
 | 
							ksft_exit_skip("zswap isn't configured\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Check that memory controller is available:
 | 
				
			||||||
 | 
						 * memory is listed in cgroup.controllers
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (cg_read_strstr(root, "cgroup.controllers", "memory"))
 | 
				
			||||||
 | 
							ksft_exit_skip("memory controller isn't available\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (cg_read_strstr(root, "cgroup.subtree_control", "memory"))
 | 
				
			||||||
 | 
							if (cg_write(root, "cgroup.subtree_control", "+memory"))
 | 
				
			||||||
 | 
								ksft_exit_skip("Failed to set memory controller\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(tests); i++) {
 | 
				
			||||||
 | 
							switch (tests[i].fn(root)) {
 | 
				
			||||||
 | 
							case KSFT_PASS:
 | 
				
			||||||
 | 
								ksft_test_result_pass("%s\n", tests[i].name);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case KSFT_SKIP:
 | 
				
			||||||
 | 
								ksft_test_result_skip("%s\n", tests[i].name);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								ret = EXIT_FAILURE;
 | 
				
			||||||
 | 
								ksft_test_result_fail("%s\n", tests[i].name);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in a new issue