Message ID | 20241004094247.795385-1-bjorn@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | selftests: sched_ext: Add sched_ext as proper selftest target | expand |
On 10/4/24 03:42, Björn Töpel wrote: > From: Björn Töpel <bjorn@rivosinc.com> > > The sched_ext selftests is missing proper cross-compilation support, a > proper target entry, and out-of-tree build support. > > When building the kselftest suite, e.g.: > > make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \ > SKIP_TARGETS="" O=/output/foo -C tools/testing/selftests install > > The expectation is that the sched_ext is included, cross-built, and > placed into /output/foo. > > Add CROSS_COMPILE, OUTPUT, and TARGETS support to the sched_ext > selftest. > > Signed-off-by: Björn Töpel <bjorn@rivosinc.com> > --- > tools/testing/selftests/Makefile | 1 + > tools/testing/selftests/sched_ext/Makefile | 59 +++++++++++++++------- > 2 files changed, 41 insertions(+), 19 deletions(-) > Thank you for the find. It appears *sched* is also missing from the default TARGETS in selftests/Makefile This change looks good to me. Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Tejun, Do let me know if you like me to take this through kselftest tree. thanks, -- Shuah thanks, -- Shuah
On 10/4/24 11:46, Shuah Khan wrote: > On 10/4/24 03:42, Björn Töpel wrote: >> From: Björn Töpel <bjorn@rivosinc.com> >> >> The sched_ext selftests is missing proper cross-compilation support, a >> proper target entry, and out-of-tree build support. >> >> When building the kselftest suite, e.g.: >> >> make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \ >> SKIP_TARGETS="" O=/output/foo -C tools/testing/selftests install >> >> The expectation is that the sched_ext is included, cross-built, and >> placed into /output/foo. >> >> Add CROSS_COMPILE, OUTPUT, and TARGETS support to the sched_ext >> selftest. >> >> Signed-off-by: Björn Töpel <bjorn@rivosinc.com> >> --- >> tools/testing/selftests/Makefile | 1 + >> tools/testing/selftests/sched_ext/Makefile | 59 +++++++++++++++------- >> 2 files changed, 41 insertions(+), 19 deletions(-) >> > > Thank you for the find. It appears *sched* is also missing > from the default TARGETS in selftests/Makefile > > This change looks good to me. > > Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> > > Tejun, Do let me know if you like me to take this through kselftest tree. > Please don't take this patch at the moment. Adding Mark. After catching up with my Inbox - this is a no for me. This test depends on bpf and will fail in CIs that don't have the support. We are discussing the issue here in this thread. https://patchwork.kernel.org/project/linux-kselftest/patch/20241004095348.797020-1-bjorn@kernel.org/ thanks, -- Shuah
On Fri, Oct 04, 2024 at 11:42:46AM +0200, Björn Töpel wrote: > From: Björn Töpel <bjorn@rivosinc.com> Thanks a lot Björn for working on this. > The sched_ext selftests is missing proper cross-compilation support, a > proper target entry, and out-of-tree build support. > > When building the kselftest suite, e.g.: > > make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \ > SKIP_TARGETS="" O=/output/foo -C tools/testing/selftests install > > The expectation is that the sched_ext is included, cross-built, and > placed into /output/foo. > > Add CROSS_COMPILE, OUTPUT, and TARGETS support to the sched_ext > selftest. > > Signed-off-by: Björn Töpel <bjorn@rivosinc.com> > --- > tools/testing/selftests/Makefile | 1 + > tools/testing/selftests/sched_ext/Makefile | 59 +++++++++++++++------- > 2 files changed, 41 insertions(+), 19 deletions(-) > > diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile > index b38199965f99..20ee8a0b795c 100644 > --- a/tools/testing/selftests/Makefile > +++ b/tools/testing/selftests/Makefile > @@ -88,6 +88,7 @@ TARGETS += rlimits > TARGETS += rseq > TARGETS += rtc > TARGETS += rust > +TARGETS += sched_ext > TARGETS += seccomp > TARGETS += sgx > TARGETS += sigaltstack > diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/selftests/sched_ext/Makefile > index 0754a2c110a1..66467a99184d 100644 > --- a/tools/testing/selftests/sched_ext/Makefile > +++ b/tools/testing/selftests/sched_ext/Makefile > @@ -13,14 +13,8 @@ LLVM_SUFFIX := $(LLVM) > endif > > CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as > -else > -CC := gcc Given that we're including ../lib.mk, can we just get rid of this whole block? > endif # LLVM > > -ifneq ($(CROSS_COMPILE),) > -$(error CROSS_COMPILE not supported for scx selftests) > -endif # CROSS_COMPILE > - > CURDIR := $(abspath .) > REPOROOT := $(abspath ../../../..) > TOOLSDIR := $(REPOROOT)/tools > @@ -34,18 +28,39 @@ GENHDR := $(GENDIR)/autoconf.h > SCXTOOLSDIR := $(TOOLSDIR)/sched_ext > SCXTOOLSINCDIR := $(TOOLSDIR)/sched_ext/include > > -OUTPUT_DIR := $(CURDIR)/build > +ifeq (,$(OUTPUT)) > +OUTPUT := $(CURDIR)/build > +RUNNER_DIR := $(CURDIR) > +else > +OUTPUT_DIR := $(OUTPUT) This breaks if you use make from the selftests/sched_ext directory. AFAICT it looks like OUTPUT is always set in ../lib.mk, so we always go to the OUTPUT_DIR := $(CURDIR) branch. Because of that, running `make clean` will delete the whole sched_ext selftests directory. Also, did you mean for the first branch to be: +OUTPUT_DIR := $(CURDIR)/build as opposed to: > +OUTPUT := $(CURDIR)/build [...] Thanks, David
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index b38199965f99..20ee8a0b795c 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -88,6 +88,7 @@ TARGETS += rlimits TARGETS += rseq TARGETS += rtc TARGETS += rust +TARGETS += sched_ext TARGETS += seccomp TARGETS += sgx TARGETS += sigaltstack diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/selftests/sched_ext/Makefile index 0754a2c110a1..66467a99184d 100644 --- a/tools/testing/selftests/sched_ext/Makefile +++ b/tools/testing/selftests/sched_ext/Makefile @@ -13,14 +13,8 @@ LLVM_SUFFIX := $(LLVM) endif CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as -else -CC := gcc endif # LLVM -ifneq ($(CROSS_COMPILE),) -$(error CROSS_COMPILE not supported for scx selftests) -endif # CROSS_COMPILE - CURDIR := $(abspath .) REPOROOT := $(abspath ../../../..) TOOLSDIR := $(REPOROOT)/tools @@ -34,18 +28,39 @@ GENHDR := $(GENDIR)/autoconf.h SCXTOOLSDIR := $(TOOLSDIR)/sched_ext SCXTOOLSINCDIR := $(TOOLSDIR)/sched_ext/include -OUTPUT_DIR := $(CURDIR)/build +ifeq (,$(OUTPUT)) +OUTPUT := $(CURDIR)/build +RUNNER_DIR := $(CURDIR) +else +OUTPUT_DIR := $(OUTPUT) +RUNNER_DIR := $(OUTPUT) +endif OBJ_DIR := $(OUTPUT_DIR)/obj INCLUDE_DIR := $(OUTPUT_DIR)/include BPFOBJ_DIR := $(OBJ_DIR)/libbpf SCXOBJ_DIR := $(OBJ_DIR)/sched_ext BPFOBJ := $(BPFOBJ_DIR)/libbpf.a LIBBPF_OUTPUT := $(OBJ_DIR)/libbpf/libbpf.a -DEFAULT_BPFTOOL := $(OUTPUT_DIR)/sbin/bpftool HOST_BUILD_DIR := $(OBJ_DIR) HOST_OUTPUT_DIR := $(OUTPUT_DIR) -VMLINUX_BTF_PATHS ?= ../../../../vmlinux \ +ifneq ($(CROSS_COMPILE),) +DEFAULT_BPFTOOL := $(OUTPUT_DIR)/host/sbin/bpftool +HOST_OBJ_DIR := $(OBJ_DIR)/host/bpftool +HOST_LIBBPF_OUTPUT := $(OBJ_DIR)/host/libbpf/ +HOST_LIBBPF_DESTDIR := $(OUTPUT_DIR)/host/ +HOST_DESTDIR := $(OUTPUT_DIR)/host/ +else +DEFAULT_BPFTOOL := $(OUTPUT_DIR)/sbin/bpftool +HOST_OBJ_DIR := $(OBJ_DIR)/bpftool +HOST_LIBBPF_OUTPUT := $(OBJ_DIR)/libbpf/ +HOST_LIBBPF_DESTDIR := $(OUTPUT_DIR)/ +HOST_DESTDIR := $(OUTPUT_DIR)/ +endif + +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux \ /sys/kernel/btf/vmlinux \ /boot/vmlinux-$(shell uname -r) VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) @@ -80,17 +95,23 @@ IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \ # Use '-idirafter': Don't interfere with include mechanics except where the # build would have failed anyways. define get_sys_includes -$(shell $(1) -v -E - </dev/null 2>&1 \ +$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') endef +ifneq ($(CROSS_COMPILE),) +CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +endif + +CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) + BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) \ $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) \ -I$(CURDIR)/include -I$(CURDIR)/include/bpf-compat \ -I$(INCLUDE_DIR) -I$(APIDIR) -I$(SCXTOOLSINCDIR) \ -I$(REPOROOT)/include \ - $(call get_sys_includes,$(CLANG)) \ + $(CLANG_SYS_INCLUDES) \ -Wall -Wno-compare-distinct-pointer-types \ -Wno-incompatible-function-pointer-types \ -O2 -mcpu=v3 @@ -98,7 +119,7 @@ BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) \ # sort removes libbpf duplicates when not cross-building MAKE_DIRS := $(sort $(OBJ_DIR)/libbpf $(OBJ_DIR)/libbpf \ $(OBJ_DIR)/bpftool $(OBJ_DIR)/resolve_btfids \ - $(INCLUDE_DIR) $(SCXOBJ_DIR)) + $(HOST_OBJ_DIR) $(INCLUDE_DIR) $(SCXOBJ_DIR)) $(MAKE_DIRS): $(call msg,MKDIR,,$@) @@ -112,14 +133,14 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ DESTDIR=$(OUTPUT_DIR) prefix= all install_headers $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ - $(LIBBPF_OUTPUT) | $(OBJ_DIR)/bpftool + $(LIBBPF_OUTPUT) | $(HOST_OBJ_DIR) $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \ EXTRA_CFLAGS='-g -O0' \ - OUTPUT=$(OBJ_DIR)/bpftool/ \ - LIBBPF_OUTPUT=$(OBJ_DIR)/libbpf/ \ - LIBBPF_DESTDIR=$(OUTPUT_DIR)/ \ - prefix= DESTDIR=$(OUTPUT_DIR)/ install-bin + OUTPUT=$(HOST_OBJ_DIR)/ \ + LIBBPF_OUTPUT=$(HOST_LIBBPF_OUTPUT) \ + LIBBPF_DESTDIR=$(HOST_LIBBPF_DESTDIR) \ + prefix= DESTDIR=$(HOST_DESTDIR) install-bin $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR) ifeq ($(VMLINUX_H),) @@ -203,7 +224,7 @@ $(SCXOBJ_DIR)/util.o: util.c | $(SCXOBJ_DIR) runner: $(SCXOBJ_DIR)/runner.o $(SCXOBJ_DIR)/util.o $(BPFOBJ) $(testcase-targets) @echo "$(testcase-targets)" - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + $(CC) $(CFLAGS) -o $(RUNNER_DIR)/$@ $^ $(LDFLAGS) TEST_GEN_PROGS := runner