Skip to content

Commit

Permalink
Merge branch 'selftests-TEST_INCLUDES'
Browse files Browse the repository at this point in the history
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/20231222135836.992841-1-bpoirier@nvidia.com/

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

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 31, 2024
2 parents bc34d10 + 521ed1c commit 1485082
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 63 deletions.
12 changes: 12 additions & 0 deletions Documentation/dev-tools/kselftest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,21 @@ 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
Expand Down
7 changes: 6 additions & 1 deletion tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 * $$?)); \
Expand Down
7 changes: 5 additions & 2 deletions tools/testing/selftests/drivers/net/bonding/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ TEST_PROGS := \
TEST_FILES := \
lag_lib.sh \
bond_topo_2d1c.sh \
bond_topo_3d1c.sh \
net_forwarding_lib.sh
bond_topo_3d1c.sh

TEST_INCLUDES := \
../../../net/forwarding/lib.sh \
../../../net/lib.sh

include ../../../lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ALL_TESTS="
REQUIRE_MZ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh

bond_check_flags()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
REQUIRE_MZ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source ${lib_dir}/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh

s_ns="s-$(mktemp -u XXXXXX)"
c_ns="c-$(mktemp -u XXXXXX)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ALL_TESTS="
REQUIRE_MZ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh

source "$lib_dir"/lag_lib.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REQUIRE_MZ=no
REQUIRE_JQ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh
source "$lib_dir"/lag_lib.sh

cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REQUIRE_MZ=no
REQUIRE_JQ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh
source "$lib_dir"/lag_lib.sh

cleanup()
Expand Down

This file was deleted.

18 changes: 16 additions & 2 deletions tools/testing/selftests/drivers/net/dsa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ TEST_PROGS = bridge_locked_port.sh \
tc_actions.sh \
test_bridge_fdb_stress.sh

TEST_PROGS_EXTENDED := lib.sh tc_common.sh
TEST_FILES := \
run_net_forwarding_test.sh \
forwarding.config

TEST_FILES := forwarding.config
TEST_INCLUDES := \
../../../net/forwarding/bridge_locked_port.sh \
../../../net/forwarding/bridge_mdb.sh \
../../../net/forwarding/bridge_mld.sh \
../../../net/forwarding/bridge_vlan_aware.sh \
../../../net/forwarding/bridge_vlan_mcast.sh \
../../../net/forwarding/bridge_vlan_unaware.sh \
../../../net/forwarding/lib.sh \
../../../net/forwarding/local_termination.sh \
../../../net/forwarding/no_forwarding.sh \
../../../net/forwarding/tc_actions.sh \
../../../net/forwarding/tc_common.sh \
../../../net/lib.sh

include ../../../lib.mk
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/dsa/bridge_mdb.sh
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/dsa/bridge_mld.sh
1 change: 0 additions & 1 deletion tools/testing/selftests/drivers/net/dsa/lib.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/dsa/no_forwarding.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
testname=$(basename "${BASH_SOURCE[0]}")

source "$libdir"/forwarding.config
cd "$libdir"/../../../net/forwarding/ || exit 1
source "./$testname" "$@"
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/dsa/tc_actions.sh
1 change: 0 additions & 1 deletion tools/testing/selftests/drivers/net/dsa/tc_common.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ REQUIRE_JQ="no"
REQUIRE_MZ="no"
NETIF_CREATE="no"
lib_dir=$(dirname "$0")
source "$lib_dir"/lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh

cleanup() {
echo "Cleaning up"
Expand Down
7 changes: 4 additions & 3 deletions tools/testing/selftests/drivers/net/team/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

TEST_PROGS := dev_addr_lists.sh

TEST_FILES := \
lag_lib.sh \
net_forwarding_lib.sh
TEST_INCLUDES := \
../bonding/lag_lib.sh \
../../../net/forwarding/lib.sh \
../../../net/lib.sh

include ../../../lib.mk
4 changes: 2 additions & 2 deletions tools/testing/selftests/drivers/net/team/dev_addr_lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ ALL_TESTS="
REQUIRE_MZ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
source "$lib_dir"/../../../net/forwarding/lib.sh

source "$lib_dir"/lag_lib.sh
source "$lib_dir"/../bonding/lag_lib.sh


destroy()
Expand Down
1 change: 0 additions & 1 deletion tools/testing/selftests/drivers/net/team/lag_lib.sh

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))) ; \
Expand Down Expand Up @@ -103,6 +121,7 @@ endef
install: all
ifdef INSTALL_PATH
$(INSTALL_RULE)
$(INSTALL_INCLUDES)
else
$(error Error: set INSTALL_PATH to use install)
endif
Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/net/forwarding/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ TEST_PROGS_EXTENDED := devlink_lib.sh \
sch_tbf_etsprio.sh \
tc_common.sh

TEST_INCLUDES := \
../lib.sh

include ../../lib.mk
35 changes: 4 additions & 31 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,13 @@ STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no}
TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=}
TROUTE6=${TROUTE6:=traceroute6}

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

if [[ -f $relative_path/forwarding.config ]]; then
source "$relative_path/forwarding.config"
if [[ -f $net_forwarding_dir/forwarding.config ]]; then
source "$net_forwarding_dir/forwarding.config"
fi

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

busywait()
{
local timeout=$1; shift

local start_time="$(date -u +%s%3N)"
while true
do
local out
out=$("$@")
local ret=$?
if ((!ret)); then
echo -n "$out"
return 0
fi

local current_time="$(date -u +%s%3N)"
if ((current_time - start_time > timeout)); then
echo -n "$out"
return 1
fi
done
}
source "$net_forwarding_dir/../lib.sh"

##############################################################################
# Sanity checks
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0

source "$relative_path/mirror_lib.sh"
source "$net_forwarding_dir/mirror_lib.sh"

quick_test_span_gre_dir_ips()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# | |
# +-------------------------------------------------------------------------+

source "$relative_path/mirror_topo_lib.sh"
source "$net_forwarding_dir/mirror_topo_lib.sh"

mirror_gre_topo_h3_create()
{
Expand Down

0 comments on commit 1485082

Please sign in to comment.