mbox series

[00/10] selftests: Fix separate output directory builds

Message ID 20220118112909.1885705-1-usama.anjum@collabora.com
Headers show
Series selftests: Fix separate output directory builds | expand

Message

Muhammad Usama Anjum Jan. 18, 2022, 11:28 a.m. UTC
Build of several selftests fail if separate output directory is
specified by the following methods:
1) make -C tools/testing/selftests O=<build_dir>
2) export KBUILD_OUTPUT="build_dir"; make -C tools/testing/selftests

Build fails because of several reasons:
1) The kernel headers aren't found.
2) The path of output objects is wrong and hence unaccessible.

These problems can be solved by:
1) Including the correct path of uapi header files
2) By setting the BUILD variable correctly inside Makefile

Following different build scnerios have been tested after making these
changes:
make -C tools/testing/selftests
make -C tools/testing/selftests O=build
make -C tools/testing/selftests o=/opt/build
export KBUILD_OUTPUT="/opt/build"; make -C tools/testing/selftests
export KBUILD_OUTPUT="build"; make -C tools/testing/selftests
cd <any_dir>; make -C <src_path>/tools/testing/selftests
cd <any_dir>; make -C <src_path>/tools/testing/selftests O=build

Muhammad Usama Anjum (10):
  selftests: set the BUILD variable to absolute path
  selftests: Add and export a kernel uapi headers path
  selftests: Correct the headers install path
  selftests: futex: Add the uapi headers include variable
  selftests: kvm: Add the uapi headers include variable
  selftests: landlock: Add the uapi headers include variable
  selftests: net: Add the uapi headers include variable
  selftests: mptcp: Add the uapi headers include variable
  selftests: vm: Add the uapi headers include variable
  selftests: vm: remove dependecy from internal kernel macros

 tools/testing/selftests/Makefile              | 32 +++++++++++++------
 .../selftests/futex/functional/Makefile       |  5 ++-
 tools/testing/selftests/kvm/Makefile          |  6 ++--
 tools/testing/selftests/landlock/Makefile     | 11 ++-----
 tools/testing/selftests/net/Makefile          |  2 +-
 tools/testing/selftests/net/mptcp/Makefile    |  3 +-
 tools/testing/selftests/vm/Makefile           |  2 +-
 tools/testing/selftests/vm/userfaultfd.c      |  3 ++
 8 files changed, 35 insertions(+), 29 deletions(-)

Comments

Mickaël Salaün Jan. 18, 2022, 12:35 p.m. UTC | #1
On 18/01/2022 12:29, Muhammad Usama Anjum wrote:
> Out of tree build of this test fails if relative path of the output
> directory is specified. Remove the un-needed include paths and use
> KHDR_INCLUDES to correctly reach the headers.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>   tools/testing/selftests/landlock/Makefile | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/landlock/Makefile b/tools/testing/selftests/landlock/Makefile
> index a99596ca9882..44c724b38a37 100644
> --- a/tools/testing/selftests/landlock/Makefile
> +++ b/tools/testing/selftests/landlock/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0
>   
> -CFLAGS += -Wall -O2
> +CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
>   
>   src_test := $(wildcard *_test.c)
>   
> @@ -12,13 +12,8 @@ KSFT_KHDR_INSTALL := 1
>   OVERRIDE_TARGETS := 1
>   include ../lib.mk
>   
> -khdr_dir = $(top_srcdir)/usr/include

This should be updated to:
khdr_dir = ${abs_srctree}/usr/include

Using a global KHDR_DIR instead of khdr_dir could be useful for others too.

> -
> -$(khdr_dir)/linux/landlock.h: khdr
> -	@:

This should be kept as is, otherwise we loose this check to rebuild the 
headers if linux/landlock.h is updated, which is handy for development.
KVM lost a similar behavior with this patch series.

> -
>   $(OUTPUT)/true: true.c
>   	$(LINK.c) $< $(LDLIBS) -o $@ -static
>   
> -$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h

This should not be changed.

> -	$(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
> +$(OUTPUT)/%_test: %_test.c ../kselftest_harness.h common.h
> +	$(LINK.c) $< $(LDLIBS) -o $@ -lcap

This doesn't work when building in the local directory because 
$abs_srctree and $KHDR_INCLUDES are empty:
cd tools/testing/selftests/landlock && make