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

selftests: introduce gen_tar Makefile target

The gen_kselftest_tar.sh always packages *all* selftests and doesn't
pass along any variables to `make install` to influence what should be
built. This can result in an early error on the command line ("Unknown
tarball format TARGETS=XXX"), or unexpected test failures as the
tarball contains tests people wanted to skip on purpose.

Since the makefile already contains all the logic, we can add a target
for packaging. Keep the default .gz target the script uses, and actually
extend the supported formats by using tar's autodetection.

To not break current workflows, keep the gen_kselftest_tar.sh script as
it is, with an added suggestion to use the makefile target instead.

Signed-off-by: Veronika Kabatova <vkabatov@redhat.com>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Veronika Kabatova and committed by
Shuah Khan
a5f30467 2ef96a5b

+36 -1
+23
Documentation/dev-tools/kselftest.rst
··· 151 151 $ cd kselftest 152 152 $ ./run_kselftest.sh 153 153 154 + Packaging selftests 155 + =================== 156 + 157 + In some cases packaging is desired, such as when tests need to run on a 158 + different system. To package selftests, run:: 159 + 160 + $ make -C tools/testing/selftests gen_tar 161 + 162 + This generates a tarball in the `INSTALL_PATH/kselftest-packages` directory. By 163 + default, `.gz` format is used. The tar format can be overridden by specifying 164 + a `FORMAT` make variable. Any value recognized by `tar's auto-compress`_ option 165 + is supported, such as:: 166 + 167 + $ make -C tools/testing/selftests gen_tar FORMAT=.xz 168 + 169 + `make gen_tar` invokes `make install` so you can use it to package a subset of 170 + tests by using variables specified in `Running a subset of selftests`_ 171 + section:: 172 + 173 + $ make -C tools/testing/selftests gen_tar TARGETS="bpf" FORMAT=.xz 174 + 175 + .. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress 176 + 154 177 Contributing new tests 155 178 ====================== 156 179
+8 -1
tools/testing/selftests/Makefile
··· 249 249 $(error Error: set INSTALL_PATH to use install) 250 250 endif 251 251 252 + FORMAT ?= .gz 253 + TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 254 + gen_tar: install 255 + @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 256 + @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 257 + @echo "Created ${TAR_PATH}" 258 + 252 259 clean: 253 260 @for TARGET in $(TARGETS); do \ 254 261 BUILD_TARGET=$$BUILD/$$TARGET; \ 255 262 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 256 263 done; 257 264 258 - .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean 265 + .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
+5
tools/testing/selftests/gen_kselftest_tar.sh
··· 49 49 # directory 50 50 ./kselftest_install.sh "$install_dir" 51 51 (cd "$install_work"; tar $copts "$dest"/kselftest${ext} $install_name) 52 + 53 + # Don't put the message at the actual end as people may be parsing the 54 + # "archive created" line in their scripts. 55 + echo -e "\nConsider using 'make gen_tar' instead of this script\n" 56 + 52 57 echo "Kselftest archive kselftest${ext} created!" 53 58 54 59 # clean up top-level install work directory