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

cgroup: selftests: Move cgroup_util into its own library

KVM selftests will soon need to use some of the cgroup creation and
deletion functionality from cgroup_util.

Suggested-by: David Matlack <dmatlack@google.com>
Signed-off-by: James Houghton <jthoughton@google.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20250508184649.2576210-5-jthoughton@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

James Houghton and committed by
Sean Christopherson
2c754a84 3a7f9e51

+33 -13
+11 -10
tools/testing/selftests/cgroup/Makefile
··· 21 21 LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h 22 22 23 23 include ../lib.mk 24 + include lib/libcgroup.mk 24 25 25 - $(OUTPUT)/test_core: cgroup_util.c 26 - $(OUTPUT)/test_cpu: cgroup_util.c 27 - $(OUTPUT)/test_cpuset: cgroup_util.c 28 - $(OUTPUT)/test_freezer: cgroup_util.c 29 - $(OUTPUT)/test_hugetlb_memcg: cgroup_util.c 30 - $(OUTPUT)/test_kill: cgroup_util.c 31 - $(OUTPUT)/test_kmem: cgroup_util.c 32 - $(OUTPUT)/test_memcontrol: cgroup_util.c 33 - $(OUTPUT)/test_pids: cgroup_util.c 34 - $(OUTPUT)/test_zswap: cgroup_util.c 26 + $(OUTPUT)/test_core: $(LIBCGROUP_O) 27 + $(OUTPUT)/test_cpu: $(LIBCGROUP_O) 28 + $(OUTPUT)/test_cpuset: $(LIBCGROUP_O) 29 + $(OUTPUT)/test_freezer: $(LIBCGROUP_O) 30 + $(OUTPUT)/test_hugetlb_memcg: $(LIBCGROUP_O) 31 + $(OUTPUT)/test_kill: $(LIBCGROUP_O) 32 + $(OUTPUT)/test_kmem: $(LIBCGROUP_O) 33 + $(OUTPUT)/test_memcontrol: $(LIBCGROUP_O) 34 + $(OUTPUT)/test_pids: $(LIBCGROUP_O) 35 + $(OUTPUT)/test_zswap: $(LIBCGROUP_O)
+1 -1
tools/testing/selftests/cgroup/cgroup_util.c tools/testing/selftests/cgroup/lib/cgroup_util.c
··· 17 17 #include <unistd.h> 18 18 19 19 #include "cgroup_util.h" 20 - #include "../clone3/clone3_selftests.h" 20 + #include "../../clone3/clone3_selftests.h" 21 21 22 22 /* Returns read len on success, or -errno on failure. */ 23 23 ssize_t read_text(const char *path, char *buf, size_t max_len)
+2 -2
tools/testing/selftests/cgroup/cgroup_util.h tools/testing/selftests/cgroup/lib/include/cgroup_util.h
··· 2 2 #include <stdbool.h> 3 3 #include <stdlib.h> 4 4 5 - #include "../kselftest.h" 6 - 5 + #ifndef PAGE_SIZE 7 6 #define PAGE_SIZE 4096 7 + #endif 8 8 9 9 #define MB(x) (x << 20) 10 10
+19
tools/testing/selftests/cgroup/lib/libcgroup.mk
··· 1 + CGROUP_DIR := $(selfdir)/cgroup 2 + 3 + LIBCGROUP_C := lib/cgroup_util.c 4 + 5 + LIBCGROUP_O := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBCGROUP_C)) 6 + 7 + LIBCGROUP_O_DIRS := $(shell dirname $(LIBCGROUP_O) | uniq) 8 + 9 + CFLAGS += -I$(CGROUP_DIR)/lib/include 10 + 11 + EXTRA_HDRS := $(selfdir)/clone3/clone3_selftests.h 12 + 13 + $(LIBCGROUP_O_DIRS): 14 + mkdir -p $@ 15 + 16 + $(LIBCGROUP_O): $(OUTPUT)/%.o : $(CGROUP_DIR)/%.c $(EXTRA_HDRS) $(LIBCGROUP_O_DIRS) 17 + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ 18 + 19 + EXTRA_CLEAN += $(LIBCGROUP_O)