Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kselftests: lib.mk: Add TEST_GEN_MODS_DIR variable

Add TEST_GEN_MODS_DIR variable for kselftests. It can point to
a directory containing kernel modules that will be used by
selftest scripts.

The modules are built as external modules for the running kernel.
As a result they are always binary compatible and the same tests
can be used for older or newer kernels.

The build requires "kernel-devel" package to be installed.
For example, in the upstream sources, the rpm devel package
is produced by "make rpm-pkg"

The modules can be built independently by

make -C tools/testing/selftests/livepatch/

or they will be automatically built before running the tests via

make -C tools/testing/selftests/livepatch/ run_tests

Note that they are _not_ built when running the standalone
tests by calling, for example, ./test-state.sh.

Along with TEST_GEN_MODS_DIR, it was necessary to create a new install
rule. INSTALL_MODS_RULE is needed because INSTALL_SINGLE_RULE would
copy the entire TEST_GEN_MODS_DIR directory to the destination, even
the files created by Kbuild to compile the modules. The new install
rule copies only the .ko files, as we would expect the gen_tar to work.

Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Marcos Paulo de Souza and committed by
Shuah Khan
6727980b 6613476e

+25 -5
+4
Documentation/dev-tools/kselftest.rst
··· 245 245 TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested by 246 246 default. 247 247 248 + TEST_GEN_MODS_DIR should be used by tests that require modules to be built 249 + before the test starts. The variable will contain the name of the directory 250 + containing the modules. 251 + 248 252 TEST_CUSTOM_PROGS should be used by tests that require custom build 249 253 rules and prevent common build rule use. 250 254
+21 -5
tools/testing/selftests/lib.mk
··· 54 54 # TEST_PROGS are for test shell scripts. 55 55 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests 56 56 # and install targets. Common clean doesn't touch them. 57 + # TEST_GEN_MODS_DIR is used to specify a directory with modules to be built 58 + # before the test executes. These modules are cleaned on the clean target as well. 57 59 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 58 60 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 59 61 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 62 + TEST_GEN_MODS_DIR := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_MODS_DIR)) 60 63 61 - all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 64 + all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) \ 65 + $(if $(TEST_GEN_MODS_DIR),gen_mods_dir) 62 66 63 67 define RUN_TESTS 64 68 BASE_DIR="$(selfdir)"; \ ··· 75 71 76 72 run_tests: all 77 73 ifdef building_out_of_srctree 78 - @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 79 - rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 74 + @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)$(TEST_GEN_MODS_DIR)" != "X" ]; then \ 75 + rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(TEST_GEN_MODS_DIR) $(OUTPUT); \ 80 76 fi 81 77 @if [ "X$(TEST_PROGS)" != "X" ]; then \ 82 78 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ ··· 88 84 @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 89 85 endif 90 86 87 + gen_mods_dir: 88 + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) 89 + 90 + clean_mods_dir: 91 + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) clean 92 + 91 93 define INSTALL_SINGLE_RULE 92 94 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 93 95 $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/) 96 + endef 97 + 98 + define INSTALL_MODS_RULE 99 + $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)/$(INSTALL_LIST)) 100 + $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST)/*.ko $(INSTALL_PATH)/$(INSTALL_LIST)) 94 101 endef 95 102 96 103 define INSTALL_RULE ··· 112 97 $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) 113 98 $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 114 99 $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) 100 + $(eval INSTALL_LIST = $(notdir $(TEST_GEN_MODS_DIR))) $(INSTALL_MODS_RULE) 115 101 $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) 116 102 endef 117 103 ··· 138 122 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 139 123 endef 140 124 141 - clean: 125 + clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir) 142 126 $(CLEAN) 143 127 144 128 # Enables to extend CFLAGS and LDFLAGS from command line, e.g. ··· 169 153 $(LINK.S) $^ $(LDLIBS) -o $@ 170 154 endif 171 155 172 - .PHONY: run_tests all clean install emit_tests 156 + .PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir