Skip to contentSkip to conversation

selftests: Add TEST_INCLUDES directive and adjust tests to use it

RFC PATCH In review Benjamin Poirier 3 participants 22 messages Dec 22, 2023 – Dec 28, 2023

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

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

From: Benjamin Poirier <[email protected]>

After commit 25ae948b4478 ("selftests/net: add lib.sh"), some net selftests encounter errors when they are being exported and run. This is because the new net/lib.sh is not exported along with the tests.

After some related fixes to net selftests, this series introduces a new selftests Makefile variable to list extra files to export from other directories and makes use of it to resolve the errors described above.

Benjamin Poirier (9):
selftests: bonding: Change script interpreter
selftests: forwarding: Remove executable bits from lib.sh
selftests: forwarding: Simplify forwarding.config import logic
selftests: Introduce Makefile variable to list shared bash scripts
selftests: forwarding: Add net/lib.sh to TEST_INCLUDES
selftests: bonding: Add lib.sh scripts to TEST_INCLUDES
selftests: team: Add lib.sh scripts to TEST_INCLUDES
selftests: team: Add shared library script to TEST_INCLUDES
selftests: dsa: Replace symlinks by wrapper script

Petr Machata (1):
selftests: forwarding: Import top-level lib.sh through absolute path

 Documentation/dev-tools/kselftest.rst          |  6 ++++++
 tools/testing/selftests/Makefile               |  7 ++++++-
 .../selftests/drivers/net/bonding/Makefile     |  7 +++++--
 .../net/bonding/bond-eth-type-change.sh        |  2 +-
 .../drivers/net/bonding/bond_topo_2d1c.sh      |  2 +-
 .../drivers/net/bonding/dev_addr_lists.sh      |  2 +-
 .../net/bonding/mode-1-recovery-updelay.sh     |  4 ++--
 .../net/bonding/mode-2-recovery-updelay.sh     |  4 ++--
 .../drivers/net/bonding/net_forwarding_lib.sh  |  1 -
 .../testing/selftests/drivers/net/dsa/Makefile | 18 ++++++++++++++++--
 .../drivers/net/dsa/bridge_locked_port.sh      |  2 +-
 .../selftests/drivers/net/dsa/bridge_mdb.sh    |  2 +-
 .../selftests/drivers/net/dsa/bridge_mld.sh    |  2 +-
 .../drivers/net/dsa/bridge_vlan_aware.sh       |  2 +-
 .../drivers/net/dsa/bridge_vlan_mcast.sh       |  2 +-
 .../drivers/net/dsa/bridge_vlan_unaware.sh     |  2 +-
 tools/testing/selftests/drivers/net/dsa/lib.sh |  1 -
 .../drivers/net/dsa/local_termination.sh       |  2 +-
 .../selftests/drivers/net/dsa/no_forwarding.sh |  2 +-
 .../drivers/net/dsa/run_net_forwarding_test.sh |  9 +++++++++
 .../selftests/drivers/net/dsa/tc_actions.sh    |  2 +-
 .../selftests/drivers/net/dsa/tc_common.sh     |  1 -
 .../drivers/net/dsa/test_bridge_fdb_stress.sh  |  2 +-
 .../selftests/drivers/net/team/Makefile        |  7 ++++---
 .../drivers/net/team/dev_addr_lists.sh         |  4 ++--
 .../selftests/drivers/net/team/lag_lib.sh      |  1 -
 .../drivers/net/team/net_forwarding_lib.sh     |  1 -
 tools/testing/selftests/lib.mk                 |  6 ++++++
 .../testing/selftests/net/forwarding/Makefile  |  3 +++
 tools/testing/selftests/net/forwarding/lib.sh  | 12 +++++-------
 30 files changed, 79 insertions(+), 39 deletions(-)
 delete mode 120000 tools/testing/selftests/drivers/net/bonding/net_forwarding_lib.sh
 delete mode 120000 tools/testing/selftests/drivers/net/dsa/lib.sh
 create mode 100755 tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh
 delete mode 120000 tools/testing/selftests/drivers/net/dsa/tc_common.sh
 delete mode 120000 tools/testing/selftests/drivers/net/team/lag_lib.sh
 delete mode 120000 tools/testing/selftests/drivers/net/team/net_forwarding_lib.sh
 mode change 100755 => 100644 tools/testing/selftests/net/forwarding/lib.sh
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/10 selftests: bonding: Change script interpreter

The tests changed by this patch, as well as the scripts they source, use features which are not part of POSIX sh (ex. 'source' and 'local'). As a result, these tests fail when /bin/sh is dash such as on Debian. Change the interpreter to bash so that these tests can run successfully.

Fixes d43eff0b85ae ("selftests: bonding: up/down delay w/ slave link flapping")
---
 .../selftests/drivers/net/bonding/mode-1-recovery-updelay.sh    | 2 +-
 .../selftests/drivers/net/bonding/mode-2-recovery-updelay.sh    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/bonding/mode-1-recovery-updelay.sh +1 -1
index ad4c845a4ac7..b76bf5030952 100755
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
 # Regression Test:
tools/testing/selftests/drivers/net/bonding/mode-2-recovery-updelay.sh +1 -1
index 2330d37453f9..8c2619002147 100755
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
 # Regression Test:
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 2/10 selftests: forwarding: Remove executable bits from lib.sh

In reply to Benjamin Poirier

The lib.sh script is meant to be sourced from other scripts, not executed directly. Therefore, remove the executable bits from lib.sh's permissions.

---
 tools/testing/selftests/net/forwarding/lib.sh | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 tools/testing/selftests/net/forwarding/lib.sh
tools/testing/selftests/net/forwarding/lib.sh +0 -0
old mode 100755
new mode 100644
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 3/10 selftests: forwarding: Import top-level lib.sh through absolute path

In reply to Benjamin Poirier

From: Petr Machata <[email protected]>

The commit cited below moved code from net/forwarding/lib.sh to net/lib.sh, and had the former source the latter. This causes issues with selftests from directories other than net/forwarding/, in particular drivers/net/... For those files, the line "source ../lib.sh" would look for lib.sh in the directory above the script file's one, which is incorrect.

Instead, use $BASH_SOURCE and dirname to determine which directory the forwarding/lib.sh resides in, and use that to find net/lib.sh.

Some selftests (namely drivers/net/bonding) use a symbolic link to forwarding/lib.sh, and source that instead. Therefore pass $BASH_SOURCE through readlink to resolve to the ultimate file.

Fixes 25ae948b4478 ("selftests/net: add lib.sh")
---
 tools/testing/selftests/net/forwarding/lib.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/net/forwarding/lib.sh +3 -1
index e3740163c384..f9e32152f23d 100644
@@ -38,7 +38,9 @@ if [[ -f $relative_path/forwarding.config ]]; then
 	source "$relative_path/forwarding.config"
 fi
 
-source ../lib.sh
+libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+source "$libdir"/../lib.sh
+
 ##############################################################################
 # Sanity checks
 
Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH 4/10 selftests: forwarding: Simplify forwarding.config import logic

In reply to Benjamin Poirier

The first condition removed by this patch reimplements functionality that is part of dirname:

$ dirname ""
.

Use the libdir variable introduced in the previous patch to import forwarding.config without duplicating functionality.

---
 tools/testing/selftests/net/forwarding/lib.sh | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +5 -9
index f9e32152f23d..481d9b655a40 100644
@@ -29,16 +29,12 @@ 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
-
-if [[ -f $relative_path/forwarding.config ]]; then
-	source "$relative_path/forwarding.config"
-fi
-
 libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+
+if [ -f "$libdir"/forwarding.config ]; then
+       source "$libdir"/forwarding.config
+fi
+
 source "$libdir"/../lib.sh
 
 ##############################################################################
Signature · 1 line
2.43.0
Reviewed-by on v1 4/10
#6 lore raw

Re: [RFC PATCH net-next 04/10] selftests: forwarding: Simplify forwarding.config import logic

Quoted 24 lines · Benjamin Poirier

The first condition removed by this patch reimplements functionality that is part of dirname:

$ dirname ""
.

Use the libdir variable introduced in the previous patch to import forwarding.config without duplicating functionality.

---
 tools/testing/selftests/net/forwarding/lib.sh | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +0 -3
index f9e32152f23d..481d9b655a40 100644
@@ -29,16 +29,12 @@ 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="."

tools/testing/selftests/net/forwarding/lib.sh STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no} · line 35

Quoted 10 lines
tools/testing/selftests/net/forwarding/lib.sh +3 -6
-fi
-
-if [[ -f $relative_path/forwarding.config ]]; then
-	source "$relative_path/forwarding.config"
-fi
-
 libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+
+if [ -f "$libdir"/forwarding.config ]; then
+       source "$libdir"/forwarding.config

Nitpick: this used to be indented with tabs, not spaces. Also, any reason why only "$libdir" is quoted and not the full path, as before? Otherwise:

Quoted 8 lines
tools/testing/selftests/net/forwarding/lib.sh +2 -0
+fi
+
 source "$libdir"/../lib.sh
 
 ##############################################################################
Signature · 1 line
2.43.0
#7 lore raw

Re: [RFC PATCH net-next 04/10] selftests: forwarding: Simplify forwarding.config import logic

Quoted 22 lines · Vladimir Oltean
Quoted 21 lines · Benjamin Poirier

The first condition removed by this patch reimplements functionality that is part of dirname:

$ dirname ""
.

Use the libdir variable introduced in the previous patch to import forwarding.config without duplicating functionality.

---
 tools/testing/selftests/net/forwarding/lib.sh | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +0 -0
index f9e32152f23d..481d9b655a40 100644
@@ -29,16 +29,12 @@ STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no}
 TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=}
 TROUTE6=${TROUTE6:=traceroute6}
 
Quoted 15 lines

tools/testing/selftests/net/forwarding/lib.sh STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no} · line 35

Quoted 13 lines
tools/testing/selftests/net/forwarding/lib.sh +3 -9
-relative_path="${BASH_SOURCE%/*}"
-if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
-	relative_path="."
-fi
-
-if [[ -f $relative_path/forwarding.config ]]; then
-	source "$relative_path/forwarding.config"
-fi
-
 libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+
+if [ -f "$libdir"/forwarding.config ]; then
+       source "$libdir"/forwarding.config

Nitpick: this used to be indented with tabs, not spaces.

Thank you for pointing it out. I have fixed it.

Quoted 2 lines

Also, any
reason why only "$libdir" is quoted and not the full path, as before?

It's not necessary to quote "/forwarding.config" since it doesn't expand or split, so I did not quote it. Also, the previous code was inconsistent in its quoting.

#8 lore raw

RFC PATCH 5/10 selftests: Introduce Makefile variable to list shared bash scripts

In reply to Benjamin Poirier

Some tests written in bash source other files in a parent directory. For example, drivers/net/bonding/dev_addr_lists.sh sources net/forwarding/lib.sh. If a subset of tests is exported and run outside the source tree (for example by using make -C tools/testing/selftests gen_tar TARGETS="drivers/net/bonding"), these other files must be made available as well.

Commit ae108c48b5d2 ("selftests: net: Fix cross-tree inclusion of scripts") addressed this problem by symlinking and copying the sourced files but this only works for direct dependencies. Commit 25ae948b4478 ("selftests/net:
add lib.sh") changed net/forwarding/lib.sh to source net/lib.sh. As a result, that latter file must be included as well when the former is exported. This is not handled currently. Therefore, add a mechanism to list dependent files in a new Makefile variable and export them. This allows sourcing those files using the same expression whether tests are run in-tree or exported.

Dependencies are not resolved recursively so transitive dependencies must be listed in TEST_INCLUDES. For example, net/forwarding/lib.sh sources net/lib.sh; so a script that sources net/forwarding/lib.sh from a parent directory must list:

TEST_INCLUDES := \
	net/forwarding/lib.sh \
	net/lib.sh
---
 Documentation/dev-tools/kselftest.rst | 6 ++++++
 tools/testing/selftests/Makefile      | 7 ++++++-
 tools/testing/selftests/lib.mk        | 6 ++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
Documentation/dev-tools/kselftest.rst +6 -0
index ab376b316c36..8b79843ca514 100644
@@ -255,9 +255,15 @@ 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 lists files which are not in the current directory or one of
+   its descendants but which should be included when exporting or installing
+   the tests. The files are listed with a path relative to
+   tools/testing/selftests/.
+
  * 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
tools/testing/selftests/Makefile +6 -1
index 81f094e7f0f7..3f494a31b479 100644
@@ -188,6 +188,8 @@ run_tests: all
 	@for TARGET in $(TARGETS); do \
 		BUILD_TARGET=$$BUILD/$$TARGET;	\
 		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
+				SRC_PATH=$(shell pwd)               \
+				OBJ_PATH=$(BUILD)                   \
 				O=$(abs_objtree);		    \
 	done;
 
@@ -238,7 +240,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) install OUTPUT=$$BUILD_TARGET -C $$TARGET \
+				INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
+				SRC_PATH=$(shell pwd) \
+				OBJ_PATH=$(INSTALL_PATH) \
 				O=$(abs_objtree)		\
 				$(if $(FORCE_TARGETS),|| exit);	\
 		ret=$$((ret * $$?));		\
tools/testing/selftests/lib.mk +6 -0
index aa646e0661f3..2b6c2be4f356 100644
@@ -74,6 +74,9 @@ 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
+	$(if $(TEST_INCLUDES), \
+		cd $(SRC_PATH) && rsync -aR $(TEST_INCLUDES) $(OBJ_PATH)/ \
+	)
 	@if [ "X$(TEST_PROGS)" != "X" ]; then \
 		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
 				  $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
@@ -103,6 +106,9 @@ endef
 install: all
 ifdef INSTALL_PATH
 	$(INSTALL_RULE)
+	$(if $(TEST_INCLUDES), \
+		cd $(SRC_PATH) && rsync -aR $(TEST_INCLUDES) $(OBJ_PATH)/ \
+	)
 else
 	$(error Error: set INSTALL_PATH to use install)
 endif
Signature · 1 line
2.43.0
#9 lore raw

Re: [RFC PATCH net-next 05/10] selftests: Introduce Makefile variable to list shared bash scripts

Quoted 10 lines · Benjamin Poirier
Documentation/dev-tools/kselftest.rst +1 -0
index ab376b316c36..8b79843ca514 100644
@@ -255,9 +255,15 @@ 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

Documentation/dev-tools/kselftest.rst Contributing new tests (details) · line 269

Quoted 10 lines
Documentation/dev-tools/kselftest.rst +5 -0
    test.
 
+   TEST_INCLUDES lists files which are not in the current directory or one of
+   its descendants but which should be included when exporting or installing
+   the tests. The files are listed with a path relative to
+   tools/testing/selftests/.
+
  * 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

I've never had to touch this infrastructure, but the fact that TEST_INCLUDES is relative to tools/testing/selftests/ when all other TEST_* variables are relative to $PWD seems ... inconsistent?

#10 lore raw

Re: [RFC PATCH net-next 05/10] selftests: Introduce Makefile variable to list shared bash scripts

Quoted 13 lines · Vladimir Oltean
Quoted 12 lines · Benjamin Poirier
Documentation/dev-tools/kselftest.rst +1 -0
index ab376b316c36..8b79843ca514 100644
@@ -255,9 +255,15 @@ 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.
 
Quoted 12 lines

Documentation/dev-tools/kselftest.rst Contributing new tests (details) · line 269

Quoted 8 lines
Documentation/dev-tools/kselftest.rst +5 -0
+   TEST_INCLUDES lists files which are not in the current directory or one of
+   its descendants but which should be included when exporting or installing
+   the tests. The files are listed with a path relative to
+   tools/testing/selftests/.
+
  * 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

I've never had to touch this infrastructure, but the fact that TEST_INCLUDES is relative to tools/testing/selftests/ when all other TEST_* variables are relative to $PWD seems ... inconsistent?

To solve the inconsistency, can it be used like this everywhere?

TEST_INCLUDES := \
	$(SRC_PATH)/net/lib.sh

(I haven't tried this)

#11 lore raw

Re: [RFC PATCH net-next 05/10] selftests: Introduce Makefile variable to list shared bash scripts

Quoted 14 lines · Vladimir Oltean
Quoted 13 lines · Vladimir Oltean
Quoted 12 lines · Benjamin Poirier
Documentation/dev-tools/kselftest.rst +1 -0
index ab376b316c36..8b79843ca514 100644
@@ -255,9 +255,15 @@ 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.
 
Quoted 12 lines
Quoted 9 lines

Documentation/dev-tools/kselftest.rst Contributing new tests (details) · line 269

Quoted 8 lines
Documentation/dev-tools/kselftest.rst +5 -0
+   TEST_INCLUDES lists files which are not in the current directory or one of
+   its descendants but which should be included when exporting or installing
+   the tests. The files are listed with a path relative to
+   tools/testing/selftests/.
+
  * 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
Quoted 3 lines

I've never had to touch this infrastructure, but the fact that TEST_INCLUDES is relative to tools/testing/selftests/ when all other TEST_* variables are relative to $PWD seems ... inconsistent?

I agree with your point about consistency. I have changed TEST_INCLUDES to take paths relative to PWD. The implementation is more complicated since the paths have to be converted to the old values anyways for rsync -R but it works. I pasted the overall diff below and it'll be part of the next version of the series.

Quoted 5 lines

To solve the inconsistency, can it be used like this everywhere?

TEST_INCLUDES := \
	$(SRC_PATH)/net/lib.sh

After the changes, it's possible to list files using SRC_PATH but I didn't do it. Since the point is to make TEST_INCLUDES be more like TEST_PROGS, TEST_FILES, ..., I used relative paths.
For example in net/forwarding/Makefile:

TEST_INCLUDES := \
	../lib.sh
Documentation/dev-tools/kselftest.rst +8 -4
index 8b79843ca514..470cc7913647 100644
@@ -259,10 +259,14 @@ Contributing new tests (details)
    TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
    test.
 
-   TEST_INCLUDES lists files which are not in the current directory or one of
-   its descendants but which should be included when exporting or installing
-   the tests. The files are listed with a path relative to
-   tools/testing/selftests/.
+   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
tools/testing/selftests/Makefile +2 -2
index 3f494a31b479..c289505245f5 100644
@@ -188,7 +188,7 @@ run_tests: all
 	@for TARGET in $(TARGETS); do \
 		BUILD_TARGET=$$BUILD/$$TARGET;	\
 		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
-				SRC_PATH=$(shell pwd)               \
+				SRC_PATH=$(shell readlink -e $$(pwd)) \
 				OBJ_PATH=$(BUILD)                   \
 				O=$(abs_objtree);		    \
 	done;
@@ -242,7 +242,7 @@ ifdef INSTALL_PATH
 		BUILD_TARGET=$$BUILD/$$TARGET;	\
 		$(MAKE) install OUTPUT=$$BUILD_TARGET -C $$TARGET \
 				INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
-				SRC_PATH=$(shell pwd) \
+				SRC_PATH=$(shell readlink -e $$(pwd)) \
 				OBJ_PATH=$(INSTALL_PATH) \
 				O=$(abs_objtree)		\
 				$(if $(FORCE_TARGETS),|| exit);	\
tools/testing/selftests/drivers/net/bonding/Makefile +2 -2
index a61fe339b9be..03a089165d3f 100644
@@ -18,7 +18,7 @@ TEST_FILES := \
 	bond_topo_3d1c.sh
 
 TEST_INCLUDES := \
-	net/forwarding/lib.sh \
-	net/lib.sh
+	../../../net/forwarding/lib.sh \
+	../../../net/lib.sh
 
 include ../../../lib.mk
tools/testing/selftests/drivers/net/dsa/Makefile +12 -12
index 8259eac80c3b..cd6817fe5be6 100644
@@ -16,17 +16,17 @@ 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
+	../../../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
tools/testing/selftests/drivers/net/team/Makefile +3 -3
index 8a9846b5a209..2d5a76d99181 100644
@@ -4,8 +4,8 @@
 TEST_PROGS := dev_addr_lists.sh
 
 TEST_INCLUDES := \
-	drivers/net/bonding/lag_lib.sh \
-	net/forwarding/lib.sh \
-	net/lib.sh
+	../bonding/lag_lib.sh \
+	../../../net/forwarding/lib.sh \
+	../../../net/lib.sh
 
 include ../../../lib.mk
tools/testing/selftests/lib.mk +19 -6
index 2b6c2be4f356..087fee22dd53 100644
@@ -69,14 +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
-	$(if $(TEST_INCLUDES), \
-		cd $(SRC_PATH) && rsync -aR $(TEST_INCLUDES) $(OBJ_PATH)/ \
-	)
+	@$(INSTALL_INCLUDES)
 	@if [ "X$(TEST_PROGS)" != "X" ]; then \
 		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
 				  $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
@@ -106,9 +121,7 @@ endef
 install: all
 ifdef INSTALL_PATH
 	$(INSTALL_RULE)
-	$(if $(TEST_INCLUDES), \
-		cd $(SRC_PATH) && rsync -aR $(TEST_INCLUDES) $(OBJ_PATH)/ \
-	)
+	$(INSTALL_INCLUDES)
 else
 	$(error Error: set INSTALL_PATH to use install)
 endif
tools/testing/selftests/net/forwarding/Makefile +1 -1
index 5b55c0467eed..1fba2717738d 100644
@@ -130,6 +130,6 @@ TEST_PROGS_EXTENDED := devlink_lib.sh \
 	tc_common.sh
 
 TEST_INCLUDES := \
-	net/lib.sh
+	../lib.sh
 
 include ../../lib.mk
#12 lore raw

Re: [RFC PATCH net-next 05/10] selftests: Introduce Makefile variable to list shared bash scripts

Quoted 12 lines · Benjamin Poirier

I agree with your point about consistency. I have changed TEST_INCLUDES to take paths relative to PWD. The implementation is more complicated since the paths have to be converted to the old values anyways for rsync -R but it works. I pasted the overall diff below and it'll be part of the next version of the series.

Quoted 5 lines

To solve the inconsistency, can it be used like this everywhere?

TEST_INCLUDES := \
	$(SRC_PATH)/net/lib.sh
Quoted 6 lines

After the changes, it's possible to list files using SRC_PATH but I didn't do it. Since the point is to make TEST_INCLUDES be more like TEST_PROGS, TEST_FILES, ..., I used relative paths.
For example in net/forwarding/Makefile:

TEST_INCLUDES := \
	../lib.sh

I thought you wanted to avoid the cascade of ../../../ which is confusing, so I recommended $(SRC_PATH) as a way to avoid that by using absolute paths instead - which makes it easier to track down the include file being sourced.

My inconsistency issue was with TEST_INCLUDES being relative to a different directory than the rest. With that being addressed, I don't think that using absolute paths for some files would be inconsistent in a similar way. But I don't mind too much either way. Feel free to keep the ../../../ scheme.

#13 lore raw

RFC PATCH 6/10 selftests: forwarding: Add net/lib.sh to TEST_INCLUDES

In reply to Benjamin Poirier

Since commit 25ae948b4478 ("selftests/net: add lib.sh"), when exporting the forwarding tests and running them, the tests that import net/forwarding/lib.sh fail to import net/lib.sh. This is especially a problem for the tests that use functions from net/lib.sh, like pedit_ip.sh:

$ make install TARGETS="drivers/net/forwarding"
$ cd kselftest_install/net/forwarding
$ ./pedit_ip.sh veth{0..3}
lib.sh: line 38: /src/linux/tools/testing/selftests/kselftest_install/net/forwarding/../lib.sh: No such file or directory
TEST: ping                                                          [ OK ]
TEST: ping6                                                         [ OK ]
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth1 ingress pedit ip src set 198.51.100.1               [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth2 egress pedit ip src set 198.51.100.1                [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth1 ingress pedit ip dst set 198.51.100.1               [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth2 egress pedit ip dst set 198.51.100.1                [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth1 ingress pedit ip6 src set 2001:db8:2::1             [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth2 egress pedit ip6 src set 2001:db8:2::1              [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth1 ingress pedit ip6 dst set 2001:db8:2::1             [FAIL]
        Expected to get 10 packets, but got .
./pedit_ip.sh: line 135: busywait: command not found
TEST: dev veth2 egress pedit ip6 dst set 2001:db8:2::1              [FAIL]
        Expected to get 10 packets, but got .

In order for net/lib.sh to be exported along with forwarding tests, add net/lib.sh to TEST_INCLUDES. This is the result after this commit:

$ ./pedit_ip.sh veth{0..3}
TEST: ping                                                          [ OK ]
TEST: ping6                                                         [ OK ]
TEST: dev veth1 ingress pedit ip src set 198.51.100.1               [ OK ]
TEST: dev veth2 egress pedit ip src set 198.51.100.1                [ OK ]
TEST: dev veth1 ingress pedit ip dst set 198.51.100.1               [ OK ]
TEST: dev veth2 egress pedit ip dst set 198.51.100.1                [ OK ]
TEST: dev veth1 ingress pedit ip6 src set 2001:db8:2::1             [ OK ]
TEST: dev veth2 egress pedit ip6 src set 2001:db8:2::1              [ OK ]
TEST: dev veth1 ingress pedit ip6 dst set 2001:db8:2::1             [ OK ]
TEST: dev veth2 egress pedit ip6 dst set 2001:db8:2::1              [ OK ]
Fixes 25ae948b4478 ("selftests/net: add lib.sh")
---
 tools/testing/selftests/net/forwarding/Makefile | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/net/forwarding/Makefile +3 -0
index 452693514be4..5b55c0467eed 100644
@@ -129,4 +129,7 @@ TEST_PROGS_EXTENDED := devlink_lib.sh \
 	sch_tbf_etsprio.sh \
 	tc_common.sh
 
+TEST_INCLUDES := \
+	net/lib.sh
+
 include ../../lib.mk
Signature · 1 line
2.43.0
#14 lore raw

RFC PATCH 7/10 selftests: bonding: Add lib.sh scripts to TEST_INCLUDES

In reply to Benjamin Poirier

Since commit 25ae948b4478 ("selftests/net: add lib.sh"), when exporting the bonding tests and running them, the tests that import net/forwarding/lib.sh fail to import net/lib.sh. This prints an error message but since the bonding tests do not use functions from net/lib.sh, this does not affect the test results.

Example:
kselftest_install# ./run_kselftest.sh -t drivers/net/bonding:dev_addr_lists.sh
TAP version 13
1..1
# timeout set to 120
# selftests: drivers/net/bonding: dev_addr_lists.sh
# ./net_forwarding_lib.sh: line 38: /src/linux/tools/testing/selftests/kselftest_install/drivers/net/bonding/../lib.sh: No such file or directory
# TEST: bonding cleanup mode active-backup [ OK ]
# TEST: bonding cleanup mode 802.3ad [ OK ]
# TEST: bonding LACPDU multicast address to slave (from bond down) [ OK ]
# TEST: bonding LACPDU multicast address to slave (from bond up) [ OK ]
ok 1 selftests: drivers/net/bonding: dev_addr_lists.sh

In order to avoid the error message, net/forwarding/lib.sh is exported and included via its relative path and net/lib.sh is also exported.

Fixes 25ae948b4478 ("selftests/net: add lib.sh")
---
 tools/testing/selftests/drivers/net/bonding/Makefile       | 7 +++++--
 .../selftests/drivers/net/bonding/bond-eth-type-change.sh  | 2 +-
 .../selftests/drivers/net/bonding/bond_topo_2d1c.sh        | 2 +-
 .../selftests/drivers/net/bonding/dev_addr_lists.sh        | 2 +-
 .../drivers/net/bonding/mode-1-recovery-updelay.sh         | 2 +-
 .../drivers/net/bonding/mode-2-recovery-updelay.sh         | 2 +-
 .../selftests/drivers/net/bonding/net_forwarding_lib.sh    | 1 -
 7 files changed, 10 insertions(+), 8 deletions(-)
 delete mode 120000 tools/testing/selftests/drivers/net/bonding/net_forwarding_lib.sh
tools/testing/selftests/drivers/net/bonding/Makefile +5 -2
index 8a72bb7de70f..a61fe339b9be 100644
@@ -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
tools/testing/selftests/drivers/net/bonding/bond-eth-type-change.sh +1 -1
index 862e947e17c7..8293dbc7c18f 100755
@@ -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()
 {
tools/testing/selftests/drivers/net/bonding/bond_topo_2d1c.sh +1 -1
index a509ef949dcf..0eb7edfb584c 100644
@@ -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)"
tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh +1 -1
index 5cfe7d8ebc25..e6fa24eded5b 100755
@@ -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
 
tools/testing/selftests/drivers/net/bonding/mode-1-recovery-updelay.sh +1 -1
index b76bf5030952..9d26ab4cad0b 100755
@@ -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()
tools/testing/selftests/drivers/net/bonding/mode-2-recovery-updelay.sh +1 -1
index 8c2619002147..2d275b3e47dd 100755
@@ -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()
tools/testing/selftests/drivers/net/bonding/net_forwarding_lib.sh deleted +0 -1
deleted file mode 120000
index 39c96828c5ef..000000000000
@@ -1 +0,0 @@
-../../../net/forwarding/lib.sh
\ No newline at end of file
Signature · 1 line
2.43.0
#15 lore raw

RFC PATCH 8/10 selftests: team: Add lib.sh scripts to TEST_INCLUDES

In reply to Benjamin Poirier

Since commit 25ae948b4478 ("selftests/net: add lib.sh"), when exporting the team test and running it, the test fails to import net/lib.sh. This prints an error message but since the test does not use functions from net/lib.sh, this does not affect the test result.

Example:

	# make install TARGETS="drivers/net/team"
	# kselftest_install/run_kselftest.sh
	TAP version 13
	1..1
	# timeout set to 45
	# selftests: drivers/net/team: dev_addr_lists.sh
	# ./net_forwarding_lib.sh: line 38: /src/linux/tools/testing/selftests/kselftest_install/drivers/net/team/../lib.sh:
	 No such file or directory
	# This program is not intended to be run as root.
	# TEST: team cleanup mode lacp                                        [ OK ]
	ok 1 selftests: drivers/net/team: dev_addr_lists.sh

In order to avoid the error message, net/forwarding/lib.sh is exported and included via its relative path and net/lib.sh is also exported.

Fixes 25ae948b4478 ("selftests/net: add lib.sh")
---
 tools/testing/selftests/drivers/net/team/Makefile            | 5 ++++-
 tools/testing/selftests/drivers/net/team/dev_addr_lists.sh   | 2 +-
 .../testing/selftests/drivers/net/team/net_forwarding_lib.sh | 1 -
 3 files changed, 5 insertions(+), 3 deletions(-)
 delete mode 120000 tools/testing/selftests/drivers/net/team/net_forwarding_lib.sh
tools/testing/selftests/drivers/net/team/Makefile +4 -1
index 6a86e61e8bfe..d31af127ca29 100644
@@ -5,6 +5,9 @@ TEST_PROGS := dev_addr_lists.sh
 
 TEST_FILES := \
 	lag_lib.sh \
-	net_forwarding_lib.sh
+
+TEST_INCLUDES := \
+	net/forwarding/lib.sh \
+	net/lib.sh
 
 include ../../../lib.mk
tools/testing/selftests/drivers/net/team/dev_addr_lists.sh +1 -1
index 33913112d5ca..bea2565486f7 100755
@@ -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
 
 source "$lib_dir"/lag_lib.sh
 
tools/testing/selftests/drivers/net/team/net_forwarding_lib.sh deleted +0 -1
deleted file mode 120000
index 39c96828c5ef..000000000000
@@ -1 +0,0 @@
-../../../net/forwarding/lib.sh
\ No newline at end of file
Signature · 1 line
2.43.0
#16 lore raw

RFC PATCH 9/10 selftests: team: Add shared library script to TEST_INCLUDES

In reply to Benjamin Poirier

lag_lib.sh is added to TEST_INCLUDES to avoid duplication when both the bonding and team tests are exported together.

---
 tools/testing/selftests/drivers/net/team/Makefile          | 4 +---
 tools/testing/selftests/drivers/net/team/dev_addr_lists.sh | 2 +-
 tools/testing/selftests/drivers/net/team/lag_lib.sh        | 1 -
 3 files changed, 2 insertions(+), 5 deletions(-)
 delete mode 120000 tools/testing/selftests/drivers/net/team/lag_lib.sh
tools/testing/selftests/drivers/net/team/Makefile +1 -3
index d31af127ca29..8a9846b5a209 100644
@@ -3,10 +3,8 @@
 
 TEST_PROGS := dev_addr_lists.sh
 
-TEST_FILES := \
-	lag_lib.sh \
-
 TEST_INCLUDES := \
+	drivers/net/bonding/lag_lib.sh \
 	net/forwarding/lib.sh \
 	net/lib.sh
 
tools/testing/selftests/drivers/net/team/dev_addr_lists.sh +1 -1
index bea2565486f7..b1ec7755b783 100755
@@ -13,7 +13,7 @@ NUM_NETIFS=0
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
 
-source "$lib_dir"/lag_lib.sh
+source "$lib_dir"/../bonding/lag_lib.sh
 
 
 destroy()
tools/testing/selftests/drivers/net/team/lag_lib.sh deleted +0 -1
deleted file mode 120000
index e1347a10afde..000000000000
@@ -1 +0,0 @@
-../bonding/lag_lib.sh
\ No newline at end of file
Signature · 1 line
2.43.0
#17 lore raw

RFC PATCH 10/10 selftests: dsa: Replace symlinks by wrapper script

In reply to Benjamin Poirier

Since commit 25ae948b4478 ("selftests/net: add lib.sh"), when exporting the dsa tests and running them, the tests which import net/forwarding/lib.sh (via the lib.sh symlink) fail to import net/lib.sh. This is especially a problem for the tc_actions.sh test which uses busywait from net/lib.sh:

$ make install TARGETS="drivers/net/dsa"
$ cd kselftest_install/drivers/net/dsa
$ ./tc_actions.sh veth{0..3}
lib.sh: line 38: /src/linux/tools/testing/selftests/kselftest_install/drivers/net/dsa/../lib.sh: No such file or directory
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: gact drop and ok (skip_hw)                                    [FAIL]
        Packet was not dropped
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: mirred egress flower redirect (skip_hw)                       [FAIL]
        Did not match incoming redirect packet
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: mirred egress flower mirror (skip_hw)                         [FAIL]
        Did not match incoming mirror packet
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: mirred egress matchall mirror (skip_hw)                       [FAIL]
        Did not match incoming mirror packet
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: mirred_egress_to_ingress (skip_hw)                            [FAIL]
        didn't mirror first packet
tc_common.sh: line 15: busywait: command not found
tc_common.sh: line 15: busywait: command not found
TEST: mirred_egress_to_ingress_tcp (skip_hw)                        [FAIL]
        didn't mirred redirect ICMP
INFO: Could not test offloaded functionality

(I manually created the veth interfaces just to demonstrate running the test.)

The dsa tests which are symlinks of tests from net/forwarding/ (like tc_actions.sh) become regular files after export (because rsync --copy-unsafe-links is used) and expect to source lib.sh (net/forwarding/lib.sh) from the same directory. That lib.sh then expects to source net/lib.sh from the parent directory but this does not work because net/lib.sh is not present under drivers/net/.

Since the tests in net/forwarding/ are not meant to be copied and run from another directory, the failure to source net/lib.sh is solved by replacing the test symlinks by a wrapper script which runs the original tests under net/forwarding/. The links to shared library scripts can then be removed and all the files needed from parent directories are added to TEST_INCLUDES.

Fixes 25ae948b4478 ("selftests/net: add lib.sh")
---
 .../testing/selftests/drivers/net/dsa/Makefile | 18 ++++++++++++++++--
 .../drivers/net/dsa/bridge_locked_port.sh      |  2 +-
 .../selftests/drivers/net/dsa/bridge_mdb.sh    |  2 +-
 .../selftests/drivers/net/dsa/bridge_mld.sh    |  2 +-
 .../drivers/net/dsa/bridge_vlan_aware.sh       |  2 +-
 .../drivers/net/dsa/bridge_vlan_mcast.sh       |  2 +-
 .../drivers/net/dsa/bridge_vlan_unaware.sh     |  2 +-
 tools/testing/selftests/drivers/net/dsa/lib.sh |  1 -
 .../drivers/net/dsa/local_termination.sh       |  2 +-
 .../selftests/drivers/net/dsa/no_forwarding.sh |  2 +-
 .../drivers/net/dsa/run_net_forwarding_test.sh |  9 +++++++++
 .../selftests/drivers/net/dsa/tc_actions.sh    |  2 +-
 .../selftests/drivers/net/dsa/tc_common.sh     |  1 -
 .../drivers/net/dsa/test_bridge_fdb_stress.sh  |  2 +-
 14 files changed, 35 insertions(+), 14 deletions(-)
 delete mode 120000 tools/testing/selftests/drivers/net/dsa/lib.sh
 create mode 100755 tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh
 delete mode 120000 tools/testing/selftests/drivers/net/dsa/tc_common.sh
tools/testing/selftests/drivers/net/dsa/Makefile +16 -2
index c393e7b73805..8259eac80c3b 100644
@@ -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
tools/testing/selftests/drivers/net/dsa/bridge_locked_port.sh +1 -1
index f5eb940c4c7c..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_locked_port.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/bridge_mdb.sh +1 -1
index 76492da525f7..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_mdb.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/bridge_mld.sh +1 -1
index 81a7e0df0474..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_mld.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/bridge_vlan_aware.sh +1 -1
index 9831ed74376a..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_vlan_aware.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/bridge_vlan_mcast.sh +1 -1
index 7f3c3f0bf719..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_vlan_mcast.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/bridge_vlan_unaware.sh +1 -1
index bf1a57e6bde1..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/bridge_vlan_unaware.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/lib.sh deleted +0 -1
deleted file mode 120000
index 39c96828c5ef..000000000000
@@ -1 +0,0 @@
-../../../net/forwarding/lib.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/local_termination.sh +1 -1
index c08166f84501..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/local_termination.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/no_forwarding.sh +1 -1
index b9757466bc97..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/no_forwarding.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +9 -0
new file mode 100755
index 000000000000..4106c0a102ea
@@ -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" "$@"
tools/testing/selftests/drivers/net/dsa/tc_actions.sh +1 -1
index 306213d9430e..d16a65e7595d 120000
@@ -1 +1 @@
-../../../net/forwarding/tc_actions.sh
\ No newline at end of file
+run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/tc_common.sh deleted +0 -1
deleted file mode 120000
index bc3465bdc36b..000000000000
@@ -1 +0,0 @@
-../../../net/forwarding/tc_common.sh
\ No newline at end of file
tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh +1 -1
index 92acab83fbe2..74682151d04d 100755
@@ -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"
Signature · 1 line
2.43.0
#18 lore raw

Re: [RFC PATCH net-next 10/10] selftests: dsa: Replace symlinks by wrapper script

Quoted 6 lines · Benjamin Poirier
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +0 -0
new file mode 100755
index 000000000000..4106c0a102ea

tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh line 9

Quoted 9 lines
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +9 -0
@@ -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" "$@"

Thanks for working on this. I don't dislike the solution. Just one question. Can "run_net_forwarding_test.sh" be one day moved from tools/testing/selftests/drivers/net/dsa/ without duplicating it, should anyone else need the same setup?

#19 lore raw

Re: [RFC PATCH net-next 10/10] selftests: dsa: Replace symlinks by wrapper script

Quoted 13 lines · Vladimir Oltean
Quoted 12 lines · Benjamin Poirier
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +6 -0
new file mode 100755
index 000000000000..4106c0a102ea
@@ -0,0 +1,9 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+testname=$(basename "${BASH_SOURCE[0]}")
+
Quoted 8 lines

tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh line 9

Quoted 3 lines
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +3 -0
+source "$libdir"/forwarding.config
+cd "$libdir"/../../../net/forwarding/ || exit 1
+source "./$testname" "$@"

Thanks for working on this. I don't dislike the solution. Just one question. Can "run_net_forwarding_test.sh" be one day moved from tools/testing/selftests/drivers/net/dsa/ without duplicating it, should anyone else need the same setup?

Yes, it's possible. I didn't think about it before but I tested the approach below. It applies over the changes I just sent in my previous mail about patch 5.

Thank you for your review and suggestions.

tools/testing/selftests/drivers/net/dsa/Makefile +2 -1
index cd6817fe5be6..5ff77c851642 100644
@@ -12,10 +12,10 @@ TEST_PROGS = bridge_locked_port.sh \
 	test_bridge_fdb_stress.sh
 
 TEST_FILES := \
-	run_net_forwarding_test.sh \
 	forwarding.config
 
 TEST_INCLUDES := \
+	run_net_forwarding_test.sh \
 	../../../net/forwarding/bridge_locked_port.sh \
 	../../../net/forwarding/bridge_mdb.sh \
 	../../../net/forwarding/bridge_mld.sh \
@@ -25,6 +25,7 @@ TEST_INCLUDES := \
 	../../../net/forwarding/lib.sh \
 	../../../net/forwarding/local_termination.sh \
 	../../../net/forwarding/no_forwarding.sh \
+	../../../net/forwarding/run_net_forwarding_test.sh \
 	../../../net/forwarding/tc_actions.sh \
 	../../../net/forwarding/tc_common.sh \
 	../../../net/lib.sh
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh deleted +0 -9
deleted file mode 100755
index 4106c0a102ea..000000000000
@@ -1,9 +0,0 @@
-#!/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" "$@"
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +1 -0
new file mode 120000
index 000000000000..2e7e656349e6
@@ -0,0 +1 @@
+../../../net/forwarding/run_net_forwarding_test.sh
\ No newline at end of file
tools/testing/selftests/net/forwarding/run_net_forwarding_test.sh new file +10 -0
new file mode 100755
index 000000000000..cfddadb57fe7
@@ -0,0 +1,10 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+linkdir=$(readlink -f "$(dirname "$0")")
+libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+testname=$(basename "${BASH_SOURCE[0]}")
+
+source "$linkdir"/forwarding.config
+cd "$libdir" || exit 1
+source "./$testname" "$@"
#20 lore raw

Re: [RFC PATCH net-next 10/10] selftests: dsa: Replace symlinks by wrapper script

Quoted 23 lines · Benjamin Poirier
Quoted 13 lines · Vladimir Oltean
Quoted 12 lines · Benjamin Poirier
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +6 -0
new file mode 100755
index 000000000000..4106c0a102ea
@@ -0,0 +1,9 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+libdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
+testname=$(basename "${BASH_SOURCE[0]}")
+
Quoted 8 lines

tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh line 9

Quoted 3 lines
tools/testing/selftests/drivers/net/dsa/run_net_forwarding_test.sh new file +3 -0
+source "$libdir"/forwarding.config
+cd "$libdir"/../../../net/forwarding/ || exit 1
+source "./$testname" "$@"

Thanks for working on this. I don't dislike the solution. Just one question. Can "run_net_forwarding_test.sh" be one day moved from tools/testing/selftests/drivers/net/dsa/ without duplicating it, should anyone else need the same setup?

Quoted 5 lines

Yes, it's possible. I didn't think about it before but I tested the approach below. It applies over the changes I just sent in my previous mail about patch 5.

Thank you for your review and suggestions.

Thanks. I tested it too and it works.

Tested-by Reviewed-by on the v1 series
#21 lore raw
In reply to Benjamin Poirier
Quoted 11 lines · Benjamin Poirier

From: Benjamin Poirier <[email protected]>

After commit 25ae948b4478 ("selftests/net: add lib.sh"), some net selftests encounter errors when they are being exported and run. This is because the new net/lib.sh is not exported along with the tests.

After some related fixes to net selftests, this series introduces a new selftests Makefile variable to list extra files to export from other directories and makes use of it to resolve the errors described above.

Tested with

make TARGETS="drivers/net/team drivers/net/bonding drivers/net/dsa" \
-j8 -C tools/testing/selftests gen_tar

and all looks good to me. Thanks for your works!