Message ID | 20240124170222.261664-2-bpoirier@nvidia.com |
---|---|
State | Superseded |
Headers | show |
Series | selftests: Add TEST_INCLUDES directive and adjust tests to use it | expand |
On Wed, 24 Jan 2024 12:02:17 -0500 Benjamin Poirier wrote: > --- a/Documentation/dev-tools/kselftest.rst > +++ b/Documentation/dev-tools/kselftest.rst > @@ -255,9 +255,19 @@ Contributing new tests (details) > > TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the > executable which is not tested by default. > + > TEST_FILES, TEST_GEN_FILES mean it is the file which is used by > test. > > + TEST_INCLUDES is similar to TEST_FILES, it lists files which should be > + included when exporting or installing the tests, with the following > + differences: > + * symlinks to files in other directories are preserved > + * the part of paths below tools/testing/selftests/ is preserved when copying > + the files to the output directory > + TEST_INCLUDES is meant to list dependencies located in other directories of > + the selftests hierarchy. > + I think that this chunk causes a warning when doing make htmldocs: Documentation/dev-tools/kselftest.rst:267: WARNING: Unexpected indentation. Documentation/dev-tools/kselftest.rst:268: WARNING: Block quote ends without a blank line; unexpected unindent. Could you double-check?
On 2024-01-24 20:46 -0800, Jakub Kicinski wrote: > On Wed, 24 Jan 2024 12:02:17 -0500 Benjamin Poirier wrote: > > --- a/Documentation/dev-tools/kselftest.rst > > +++ b/Documentation/dev-tools/kselftest.rst > > @@ -255,9 +255,19 @@ Contributing new tests (details) > > > > TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the > > executable which is not tested by default. > > + > > TEST_FILES, TEST_GEN_FILES mean it is the file which is used by > > test. > > > > + TEST_INCLUDES is similar to TEST_FILES, it lists files which should be > > + included when exporting or installing the tests, with the following > > + differences: > > + * symlinks to files in other directories are preserved > > + * the part of paths below tools/testing/selftests/ is preserved when copying > > + the files to the output directory > > + TEST_INCLUDES is meant to list dependencies located in other directories of > > + the selftests hierarchy. > > + > > I think that this chunk causes a warning when doing make htmldocs: > > Documentation/dev-tools/kselftest.rst:267: WARNING: Unexpected indentation. > Documentation/dev-tools/kselftest.rst:268: WARNING: Block quote ends without a blank line; unexpected unindent. > > Could you double-check? You're right, thanks for pointing it out. I'll send a v2.
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index ab376b316c36..470cc7913647 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -255,9 +255,19 @@ Contributing new tests (details) TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the executable which is not tested by default. + TEST_FILES, TEST_GEN_FILES mean it is the file which is used by test. + TEST_INCLUDES is similar to TEST_FILES, it lists files which should be + included when exporting or installing the tests, with the following + differences: + * symlinks to files in other directories are preserved + * the part of paths below tools/testing/selftests/ is preserved when copying + the files to the output directory + TEST_INCLUDES is meant to list dependencies located in other directories of + the selftests hierarchy. + * First use the headers inside the kernel source and/or git repo, and then the system headers. Headers for the kernel release as opposed to headers installed by the distro on the system should be the primary focus to be able diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 15b6a111c3be..082db6b68060 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -191,6 +191,8 @@ run_tests: all @for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \ + SRC_PATH=$(shell readlink -e $$(pwd)) \ + OBJ_PATH=$(BUILD) \ O=$(abs_objtree); \ done; @@ -241,7 +243,10 @@ ifdef INSTALL_PATH @ret=1; \ for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ - $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \ + INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \ + SRC_PATH=$(shell readlink -e $$(pwd)) \ + OBJ_PATH=$(INSTALL_PATH) \ O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ ret=$$((ret * $$?)); \ diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index aa646e0661f3..087fee22dd53 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -69,11 +69,29 @@ define RUN_TESTS run_many $(1) endef +define INSTALL_INCLUDES + $(if $(TEST_INCLUDES), \ + relative_files=""; \ + for entry in $(TEST_INCLUDES); do \ + entry_dir=$$(readlink -e "$$(dirname "$$entry")"); \ + entry_name=$$(basename "$$entry"); \ + relative_dir=$${entry_dir#"$$SRC_PATH"/}; \ + if [ "$$relative_dir" = "$$entry_dir" ]; then \ + echo "Error: TEST_INCLUDES entry \"$$entry\" not located inside selftests directory ($$SRC_PATH)" >&2; \ + exit 1; \ + fi; \ + relative_files="$$relative_files $$relative_dir/$$entry_name"; \ + done; \ + cd $(SRC_PATH) && rsync -aR $$relative_files $(OBJ_PATH)/ \ + ) +endef + run_tests: all ifdef building_out_of_srctree @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ fi + @$(INSTALL_INCLUDES) @if [ "X$(TEST_PROGS)" != "X" ]; then \ $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ @@ -103,6 +121,7 @@ endef install: all ifdef INSTALL_PATH $(INSTALL_RULE) + $(INSTALL_INCLUDES) else $(error Error: set INSTALL_PATH to use install) endif