Skip to content

Commit

Permalink
selftests: forwarding: Redefine relative_path variable
Browse files Browse the repository at this point in the history
The following code which is part of lib.sh:
relative_path="${BASH_SOURCE%/*}"
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
       relative_path="."
fi

reimplements functionality that is part of `dirname`:
$ dirname ""
.

To avoid this duplication, replace "relative_path" by "net_forwarding_dir",
a new variable defined using dirname.

Furthermore, to avoid the potential confusion about what "relative_path" is
about (cwd, test script directory or test library directory), define
"net_forwarding_dir" as the absolute path to net/forwarding/.

Tested-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Benjamin Poirier authored and David S. Miller committed Jan 31, 2024
1 parent 4a24560 commit 9f2af91
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ 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.
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 9f2af91

Please sign in to comment.