Skip to content

Commit 2c754a8

Browse files
48casean-jc
authored andcommitted
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 <[email protected]> Signed-off-by: James Houghton <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 3a7f9e5 commit 2c754a8

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

tools/testing/selftests/cgroup/Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ TEST_GEN_PROGS += test_zswap
2121
LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
2222

2323
include ../lib.mk
24+
include lib/libcgroup.mk
2425

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)

tools/testing/selftests/cgroup/cgroup_util.c renamed to tools/testing/selftests/cgroup/lib/cgroup_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <unistd.h>
1818

1919
#include "cgroup_util.h"
20-
#include "../clone3/clone3_selftests.h"
20+
#include "../../clone3/clone3_selftests.h"
2121

2222
/* Returns read len on success, or -errno on failure. */
2323
ssize_t read_text(const char *path, char *buf, size_t max_len)

tools/testing/selftests/cgroup/cgroup_util.h renamed to tools/testing/selftests/cgroup/lib/include/cgroup_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <stdbool.h>
33
#include <stdlib.h>
44

5-
#include "../kselftest.h"
6-
5+
#ifndef PAGE_SIZE
76
#define PAGE_SIZE 4096
7+
#endif
88

99
#define MB(x) (x << 20)
1010

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)

0 commit comments

Comments
 (0)