Skip to content

Commit 1485082

Browse files
committed
Merge branch 'selftests-TEST_INCLUDES'
Benjamin Poirier says: ==================== selftests: Add TEST_INCLUDES directive and adjust tests to use it After commit 25ae948 ("selftests/net: add lib.sh") but before commit 2114e83 ("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 2114e83. 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 2114e83 ("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 2114e83 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/[email protected]/ Link: https://lore.kernel.org/netdev/ZXu7dGj7F9Ng8iIX@Laptop-X1/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents bc34d10 + 521ed1c commit 1485082

32 files changed

+97
-63
lines changed

Documentation/dev-tools/kselftest.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,21 @@ Contributing new tests (details)
255255

256256
TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
257257
executable which is not tested by default.
258+
258259
TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
259260
test.
260261

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.
272+
261273
* First use the headers inside the kernel source and/or git repo, and then the
262274
system headers. Headers for the kernel release as opposed to headers
263275
installed by the distro on the system should be the primary focus to be able

tools/testing/selftests/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ run_tests: all
191191
@for TARGET in $(TARGETS); do \
192192
BUILD_TARGET=$$BUILD/$$TARGET; \
193193
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
194+
SRC_PATH=$(shell readlink -e $$(pwd)) \
195+
OBJ_PATH=$(BUILD) \
194196
O=$(abs_objtree); \
195197
done;
196198

@@ -241,7 +243,10 @@ ifdef INSTALL_PATH
241243
@ret=1; \
242244
for TARGET in $(TARGETS); do \
243245
BUILD_TARGET=$$BUILD/$$TARGET; \
244-
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
246+
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
247+
INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
248+
SRC_PATH=$(shell readlink -e $$(pwd)) \
249+
OBJ_PATH=$(INSTALL_PATH) \
245250
O=$(abs_objtree) \
246251
$(if $(FORCE_TARGETS),|| exit); \
247252
ret=$$((ret * $$?)); \

tools/testing/selftests/drivers/net/bonding/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ TEST_PROGS := \
1515
TEST_FILES := \
1616
lag_lib.sh \
1717
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
2023

2124
include ../../../lib.mk

tools/testing/selftests/drivers/net/bonding/bond-eth-type-change.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ALL_TESTS="
1111
REQUIRE_MZ=no
1212
NUM_NETIFS=0
1313
lib_dir=$(dirname "$0")
14-
source "$lib_dir"/net_forwarding_lib.sh
14+
source "$lib_dir"/../../../net/forwarding/lib.sh
1515

1616
bond_check_flags()
1717
{

tools/testing/selftests/drivers/net/bonding/bond_topo_2d1c.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
REQUIRE_MZ=no
2929
NUM_NETIFS=0
3030
lib_dir=$(dirname "$0")
31-
source ${lib_dir}/net_forwarding_lib.sh
31+
source "$lib_dir"/../../../net/forwarding/lib.sh
3232

3333
s_ns="s-$(mktemp -u XXXXXX)"
3434
c_ns="c-$(mktemp -u XXXXXX)"

tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ALL_TESTS="
1414
REQUIRE_MZ=no
1515
NUM_NETIFS=0
1616
lib_dir=$(dirname "$0")
17-
source "$lib_dir"/net_forwarding_lib.sh
17+
source "$lib_dir"/../../../net/forwarding/lib.sh
1818

1919
source "$lib_dir"/lag_lib.sh
2020

tools/testing/selftests/drivers/net/bonding/mode-1-recovery-updelay.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ REQUIRE_MZ=no
2323
REQUIRE_JQ=no
2424
NUM_NETIFS=0
2525
lib_dir=$(dirname "$0")
26-
source "$lib_dir"/net_forwarding_lib.sh
26+
source "$lib_dir"/../../../net/forwarding/lib.sh
2727
source "$lib_dir"/lag_lib.sh
2828

2929
cleanup()

tools/testing/selftests/drivers/net/bonding/mode-2-recovery-updelay.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ REQUIRE_MZ=no
2323
REQUIRE_JQ=no
2424
NUM_NETIFS=0
2525
lib_dir=$(dirname "$0")
26-
source "$lib_dir"/net_forwarding_lib.sh
26+
source "$lib_dir"/../../../net/forwarding/lib.sh
2727
source "$lib_dir"/lag_lib.sh
2828

2929
cleanup()

tools/testing/selftests/drivers/net/bonding/net_forwarding_lib.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/testing/selftests/drivers/net/dsa/Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@ TEST_PROGS = bridge_locked_port.sh \
1111
tc_actions.sh \
1212
test_bridge_fdb_stress.sh
1313

14-
TEST_PROGS_EXTENDED := lib.sh tc_common.sh
14+
TEST_FILES := \
15+
run_net_forwarding_test.sh \
16+
forwarding.config
1517

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
1731

1832
include ../../../lib.mk
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_locked_port.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_mdb.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_mld.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_vlan_aware.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_vlan_mcast.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/bridge_vlan_unaware.sh
1+
run_net_forwarding_test.sh

tools/testing/selftests/drivers/net/dsa/lib.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/local_termination.sh
1+
run_net_forwarding_test.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/no_forwarding.sh
1+
run_net_forwarding_test.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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" "$@"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../net/forwarding/tc_actions.sh
1+
run_net_forwarding_test.sh

tools/testing/selftests/drivers/net/dsa/tc_common.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ REQUIRE_JQ="no"
1919
REQUIRE_MZ="no"
2020
NETIF_CREATE="no"
2121
lib_dir=$(dirname "$0")
22-
source "$lib_dir"/lib.sh
22+
source "$lib_dir"/../../../net/forwarding/lib.sh
2323

2424
cleanup() {
2525
echo "Cleaning up"

tools/testing/selftests/drivers/net/team/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
TEST_PROGS := dev_addr_lists.sh
55

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
910

1011
include ../../../lib.mk

tools/testing/selftests/drivers/net/team/dev_addr_lists.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ ALL_TESTS="
1111
REQUIRE_MZ=no
1212
NUM_NETIFS=0
1313
lib_dir=$(dirname "$0")
14-
source "$lib_dir"/net_forwarding_lib.sh
14+
source "$lib_dir"/../../../net/forwarding/lib.sh
1515

16-
source "$lib_dir"/lag_lib.sh
16+
source "$lib_dir"/../bonding/lag_lib.sh
1717

1818

1919
destroy()

tools/testing/selftests/drivers/net/team/lag_lib.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/testing/selftests/drivers/net/team/net_forwarding_lib.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/testing/selftests/lib.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,29 @@ define RUN_TESTS
6969
run_many $(1)
7070
endef
7171

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+
7289
run_tests: all
7390
ifdef building_out_of_srctree
7491
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
7592
rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
7693
fi
94+
@$(INSTALL_INCLUDES)
7795
@if [ "X$(TEST_PROGS)" != "X" ]; then \
7896
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
7997
$(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
@@ -103,6 +121,7 @@ endef
103121
install: all
104122
ifdef INSTALL_PATH
105123
$(INSTALL_RULE)
124+
$(INSTALL_INCLUDES)
106125
else
107126
$(error Error: set INSTALL_PATH to use install)
108127
endif

tools/testing/selftests/net/forwarding/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ TEST_PROGS_EXTENDED := devlink_lib.sh \
129129
sch_tbf_etsprio.sh \
130130
tc_common.sh
131131

132+
TEST_INCLUDES := \
133+
../lib.sh
134+
132135
include ../../lib.mk

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,13 @@ STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no}
2929
TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=}
3030
TROUTE6=${TROUTE6:=traceroute6}
3131

32-
relative_path="${BASH_SOURCE%/*}"
33-
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
34-
relative_path="."
35-
fi
32+
net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
3633

37-
if [[ -f $relative_path/forwarding.config ]]; then
38-
source "$relative_path/forwarding.config"
34+
if [[ -f $net_forwarding_dir/forwarding.config ]]; then
35+
source "$net_forwarding_dir/forwarding.config"
3936
fi
4037

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"
6639

6740
##############################################################################
6841
# Sanity checks

tools/testing/selftests/net/forwarding/mirror_gre_lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
source "$relative_path/mirror_lib.sh"
3+
source "$net_forwarding_dir/mirror_lib.sh"
44

55
quick_test_span_gre_dir_ips()
66
{

tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# | |
3434
# +-------------------------------------------------------------------------+
3535

36-
source "$relative_path/mirror_topo_lib.sh"
36+
source "$net_forwarding_dir/mirror_topo_lib.sh"
3737

3838
mirror_gre_topo_h3_create()
3939
{

0 commit comments

Comments
 (0)