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

Merge branch 'selftests-TEST_INCLUDES'

Benjamin Poirier says:

====================
selftests: Add TEST_INCLUDES directive and adjust tests to use it

After commit 25ae948b4478 ("selftests/net: add lib.sh") but before commit
2114e83381d3 ("selftests: forwarding: Avoid failures to source
net/lib.sh"), some net selftests encountered errors when they were being
exported and run. This was because the new net/lib.sh was not exported
along with the tests. The errors were crudely avoided by duplicating some
content between net/lib.sh and net/forwarding/lib.sh in 2114e83381d3.

In order to restore the sourcing of net/lib.sh from net/forwarding/lib.sh
and remove the duplicated content, this series introduces a new selftests
Makefile variable to list extra files to export from other directories and
makes use of it to avoid reintroducing the errors mentioned above.

v2:
* "selftests: Introduce Makefile variable to list shared bash scripts"
Fix rst syntax in Documentation/dev-tools/kselftest.rst (Jakub Kicinski)

v1:
* "selftests: Introduce Makefile variable to list shared bash scripts"
Changed TEST_INCLUDES to take relative paths, like other TEST_* variables.
Paths are adjusted accordingly in the subsequent patches. (Vladimir Oltean)

* selftests: bonding: Change script interpreter
selftests: forwarding: Remove executable bits from lib.sh
Removed from this series, submitted separately.

Since commit 2114e83381d3 ("selftests: forwarding: Avoid failures to source
net/lib.sh") resolved the test errors, this version of the series is
focused on removing the duplication that was added in that commit. Directly
rebasing the series would reintroduce the problems that 2114e83381d3
avoided before fixing them again. In order to prevent such breakage partway
through the series, patches are reordered and content changed slightly but
there is no diff at the end compared with the simple rebasing approach. I
have dropped most review tags on account of this reordering.

RFC:
https://lore.kernel.org/netdev/20231222135836.992841-1-bpoirier@nvidia.com/

Link: https://lore.kernel.org/netdev/ZXu7dGj7F9Ng8iIX@Laptop-X1/
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+89 -50
+12
Documentation/dev-tools/kselftest.rst
··· 255 255 256 256 TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the 257 257 executable which is not tested by default. 258 + 258 259 TEST_FILES, TEST_GEN_FILES mean it is the file which is used by 259 260 test. 261 + 262 + TEST_INCLUDES is similar to TEST_FILES, it lists files which should be 263 + included when exporting or installing the tests, with the following 264 + differences: 265 + 266 + * symlinks to files in other directories are preserved 267 + * the part of paths below tools/testing/selftests/ is preserved when 268 + copying the files to the output directory 269 + 270 + TEST_INCLUDES is meant to list dependencies located in other directories of 271 + the selftests hierarchy. 260 272 261 273 * First use the headers inside the kernel source and/or git repo, and then the 262 274 system headers. Headers for the kernel release as opposed to headers
+6 -1
tools/testing/selftests/Makefile
··· 191 191 @for TARGET in $(TARGETS); do \ 192 192 BUILD_TARGET=$$BUILD/$$TARGET; \ 193 193 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \ 194 + SRC_PATH=$(shell readlink -e $$(pwd)) \ 195 + OBJ_PATH=$(BUILD) \ 194 196 O=$(abs_objtree); \ 195 197 done; 196 198 ··· 243 241 @ret=1; \ 244 242 for TARGET in $(TARGETS); do \ 245 243 BUILD_TARGET=$$BUILD/$$TARGET; \ 246 - $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 244 + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \ 245 + INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \ 246 + SRC_PATH=$(shell readlink -e $$(pwd)) \ 247 + OBJ_PATH=$(INSTALL_PATH) \ 247 248 O=$(abs_objtree) \ 248 249 $(if $(FORCE_TARGETS),|| exit); \ 249 250 ret=$$((ret * $$?)); \
+5 -2
tools/testing/selftests/drivers/net/bonding/Makefile
··· 15 15 TEST_FILES := \ 16 16 lag_lib.sh \ 17 17 bond_topo_2d1c.sh \ 18 - bond_topo_3d1c.sh \ 19 - net_forwarding_lib.sh 18 + bond_topo_3d1c.sh 19 + 20 + TEST_INCLUDES := \ 21 + ../../../net/forwarding/lib.sh \ 22 + ../../../net/lib.sh 20 23 21 24 include ../../../lib.mk
+1 -1
tools/testing/selftests/drivers/net/bonding/bond-eth-type-change.sh
··· 11 11 REQUIRE_MZ=no 12 12 NUM_NETIFS=0 13 13 lib_dir=$(dirname "$0") 14 - source "$lib_dir"/net_forwarding_lib.sh 14 + source "$lib_dir"/../../../net/forwarding/lib.sh 15 15 16 16 bond_check_flags() 17 17 {
+1 -1
tools/testing/selftests/drivers/net/bonding/bond_topo_2d1c.sh
··· 28 28 REQUIRE_MZ=no 29 29 NUM_NETIFS=0 30 30 lib_dir=$(dirname "$0") 31 - source ${lib_dir}/net_forwarding_lib.sh 31 + source "$lib_dir"/../../../net/forwarding/lib.sh 32 32 33 33 s_ns="s-$(mktemp -u XXXXXX)" 34 34 c_ns="c-$(mktemp -u XXXXXX)"
+1 -1
tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh
··· 14 14 REQUIRE_MZ=no 15 15 NUM_NETIFS=0 16 16 lib_dir=$(dirname "$0") 17 - source "$lib_dir"/net_forwarding_lib.sh 17 + source "$lib_dir"/../../../net/forwarding/lib.sh 18 18 19 19 source "$lib_dir"/lag_lib.sh 20 20
+1 -1
tools/testing/selftests/drivers/net/bonding/mode-1-recovery-updelay.sh
··· 23 23 REQUIRE_JQ=no 24 24 NUM_NETIFS=0 25 25 lib_dir=$(dirname "$0") 26 - source "$lib_dir"/net_forwarding_lib.sh 26 + source "$lib_dir"/../../../net/forwarding/lib.sh 27 27 source "$lib_dir"/lag_lib.sh 28 28 29 29 cleanup()
+1 -1
tools/testing/selftests/drivers/net/bonding/mode-2-recovery-updelay.sh
··· 23 23 REQUIRE_JQ=no 24 24 NUM_NETIFS=0 25 25 lib_dir=$(dirname "$0") 26 - source "$lib_dir"/net_forwarding_lib.sh 26 + source "$lib_dir"/../../../net/forwarding/lib.sh 27 27 source "$lib_dir"/lag_lib.sh 28 28 29 29 cleanup()
+16 -2
tools/testing/selftests/drivers/net/dsa/Makefile
··· 11 11 tc_actions.sh \ 12 12 test_bridge_fdb_stress.sh 13 13 14 - TEST_PROGS_EXTENDED := lib.sh tc_common.sh 14 + TEST_FILES := \ 15 + run_net_forwarding_test.sh \ 16 + forwarding.config 15 17 16 - TEST_FILES := forwarding.config 18 + TEST_INCLUDES := \ 19 + ../../../net/forwarding/bridge_locked_port.sh \ 20 + ../../../net/forwarding/bridge_mdb.sh \ 21 + ../../../net/forwarding/bridge_mld.sh \ 22 + ../../../net/forwarding/bridge_vlan_aware.sh \ 23 + ../../../net/forwarding/bridge_vlan_mcast.sh \ 24 + ../../../net/forwarding/bridge_vlan_unaware.sh \ 25 + ../../../net/forwarding/lib.sh \ 26 + ../../../net/forwarding/local_termination.sh \ 27 + ../../../net/forwarding/no_forwarding.sh \ 28 + ../../../net/forwarding/tc_actions.sh \ 29 + ../../../net/forwarding/tc_common.sh \ 30 + ../../../net/lib.sh 17 31 18 32 include ../../../lib.mk
+9
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") 5 + testname=$(basename "${BASH_SOURCE[0]}") 6 + 7 + source "$libdir"/forwarding.config 8 + cd "$libdir"/../../../net/forwarding/ || exit 1 9 + source "./$testname" "$@"
+1 -1
tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh
··· 19 19 REQUIRE_MZ="no" 20 20 NETIF_CREATE="no" 21 21 lib_dir=$(dirname "$0") 22 - source "$lib_dir"/lib.sh 22 + source "$lib_dir"/../../../net/forwarding/lib.sh 23 23 24 24 cleanup() { 25 25 echo "Cleaning up"
+4 -3
tools/testing/selftests/drivers/net/team/Makefile
··· 3 3 4 4 TEST_PROGS := dev_addr_lists.sh 5 5 6 - TEST_FILES := \ 7 - lag_lib.sh \ 8 - net_forwarding_lib.sh 6 + TEST_INCLUDES := \ 7 + ../bonding/lag_lib.sh \ 8 + ../../../net/forwarding/lib.sh \ 9 + ../../../net/lib.sh 9 10 10 11 include ../../../lib.mk
+2 -2
tools/testing/selftests/drivers/net/team/dev_addr_lists.sh
··· 11 11 REQUIRE_MZ=no 12 12 NUM_NETIFS=0 13 13 lib_dir=$(dirname "$0") 14 - source "$lib_dir"/net_forwarding_lib.sh 14 + source "$lib_dir"/../../../net/forwarding/lib.sh 15 15 16 - source "$lib_dir"/lag_lib.sh 16 + source "$lib_dir"/../bonding/lag_lib.sh 17 17 18 18 19 19 destroy()
+19
tools/testing/selftests/lib.mk
··· 69 69 run_many $(1) 70 70 endef 71 71 72 + define INSTALL_INCLUDES 73 + $(if $(TEST_INCLUDES), \ 74 + relative_files=""; \ 75 + for entry in $(TEST_INCLUDES); do \ 76 + entry_dir=$$(readlink -e "$$(dirname "$$entry")"); \ 77 + entry_name=$$(basename "$$entry"); \ 78 + relative_dir=$${entry_dir#"$$SRC_PATH"/}; \ 79 + if [ "$$relative_dir" = "$$entry_dir" ]; then \ 80 + echo "Error: TEST_INCLUDES entry \"$$entry\" not located inside selftests directory ($$SRC_PATH)" >&2; \ 81 + exit 1; \ 82 + fi; \ 83 + relative_files="$$relative_files $$relative_dir/$$entry_name"; \ 84 + done; \ 85 + cd $(SRC_PATH) && rsync -aR $$relative_files $(OBJ_PATH)/ \ 86 + ) 87 + endef 88 + 72 89 run_tests: all 73 90 ifdef building_out_of_srctree 74 91 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 75 92 rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 76 93 fi 94 + @$(INSTALL_INCLUDES) 77 95 @if [ "X$(TEST_PROGS)" != "X" ]; then \ 78 96 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ 79 97 $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ ··· 121 103 install: all 122 104 ifdef INSTALL_PATH 123 105 $(INSTALL_RULE) 106 + $(INSTALL_INCLUDES) 124 107 else 125 108 $(error Error: set INSTALL_PATH to use install) 126 109 endif
+3
tools/testing/selftests/net/forwarding/Makefile
··· 129 129 sch_tbf_etsprio.sh \ 130 130 tc_common.sh 131 131 132 + TEST_INCLUDES := \ 133 + ../lib.sh 134 + 132 135 include ../../lib.mk
+5 -32
tools/testing/selftests/net/forwarding/lib.sh
··· 29 29 TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=} 30 30 TROUTE6=${TROUTE6:=traceroute6} 31 31 32 - relative_path="${BASH_SOURCE%/*}" 33 - if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then 34 - relative_path="." 32 + net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 33 + 34 + if [[ -f $net_forwarding_dir/forwarding.config ]]; then 35 + source "$net_forwarding_dir/forwarding.config" 35 36 fi 36 37 37 - if [[ -f $relative_path/forwarding.config ]]; then 38 - source "$relative_path/forwarding.config" 39 - fi 40 - 41 - # Kselftest framework requirement - SKIP code is 4. 42 - ksft_skip=4 43 - 44 - busywait() 45 - { 46 - local timeout=$1; shift 47 - 48 - local start_time="$(date -u +%s%3N)" 49 - while true 50 - do 51 - local out 52 - out=$("$@") 53 - local ret=$? 54 - if ((!ret)); then 55 - echo -n "$out" 56 - return 0 57 - fi 58 - 59 - local current_time="$(date -u +%s%3N)" 60 - if ((current_time - start_time > timeout)); then 61 - echo -n "$out" 62 - return 1 63 - fi 64 - done 65 - } 38 + source "$net_forwarding_dir/../lib.sh" 66 39 67 40 ############################################################################## 68 41 # Sanity checks
+1 -1
tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - source "$relative_path/mirror_lib.sh" 3 + source "$net_forwarding_dir/mirror_lib.sh" 4 4 5 5 quick_test_span_gre_dir_ips() 6 6 {
+1 -1
tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh
··· 33 33 # | | 34 34 # +-------------------------------------------------------------------------+ 35 35 36 - source "$relative_path/mirror_topo_lib.sh" 36 + source "$net_forwarding_dir/mirror_topo_lib.sh" 37 37 38 38 mirror_gre_topo_h3_create() 39 39 {