Re: [PATCH] selftests/vm: fix inability to build any vm tests

From: John Hubbard
Date: Thu Aug 18 2022 - 14:55:51 EST


On 8/18/22 10:58, Axel Rasmussen wrote:
1) I recalled that hmm-tests.c in the same directory also needs
gup_test.h, and wondered if that was covered. And it turns out the the
relative "up and over" include path is done in hmm-tests.c itself,
instead of in the Makefile, like this:

/*
* This is a private UAPI to the kernel test module so it isn't exported
* in the usual include/uapi/... directory.
*/
#include "../../../../lib/test_hmm_uapi.h"
#include "../../../../mm/gup_test.h"

It would be nice (maybe follow-up polishing for someone) if this were
done once, instead of twice (or more?) via different (source code vs.
Makefile) mechanisms.

Hmm, I suppose the way to clean this up would be to have the Makefile
compute this once, and pass in "-I $(selfdir)/../../.." to the
compiler so we could just "#include <mm/gup_test.h>" directly?

Yes, it's better to have the Makefile know where the include paths are,
rather than each source file, so that looks better.

But hold on, now I see that selftests/vm/Makefile already uses what is
effectively a src_topdir, anyway! Here:

CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES)

...which makes me think that real fix for the original problem should be
simply this:

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 947fc72413e9..d44c72b3abe3 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -40,6 +40,7 @@ ifeq (0,$(MAKELEVEL))
endif
endif
selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
+top_srcdir = $(selfdir)/../../..

# The following are built by lib.mk common compile rules.
# TEST_CUSTOM_PROGS should be used by tests that require


...and then the follow up cleanup can use top_srcdir to cleanup CFLAGS and
also pull the relative paths out of the source files and into the Makefile.


thanks,
--
John Hubbard
NVIDIA