From: Yohei Kojima This patch adds a testcase to check if linking already-connected netdevsim interfaces fails. This patch also moves the testcase on invalid ifidx before linking two netdevsims so that the test would fail if argument validation code got broken: after linking two netdevsims, the test might not fail because it attempts to link an already-connected netdevsim with non-existing netdevsim. Additionally, this patch adds comments for readability and details the error message. Signed-off-by: Yohei Kojima --- .../selftests/drivers/net/netdevsim/peer.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/net/netdevsim/peer.sh b/tools/testing/selftests/drivers/net/netdevsim/peer.sh index 7f32b5600925..338c844fe632 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/peer.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh @@ -76,6 +76,7 @@ NSIM_DEV_2_FD=$((256 + RANDOM % 256)) exec {NSIM_DEV_2_FD} $NSIM_DEV_SYS_LINK 2>/dev/null if [ $? -eq 0 ]; then echo "linking with non-existent netdevsim should fail" @@ -97,6 +98,14 @@ if [ $? -eq 0 ]; then exit 1 fi +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:a" > $NSIM_DEV_SYS_LINK 2>/dev/null +if [ $? -eq 0 ]; then + echo "linking with invalid ifidx should fail" + cleanup_ns + exit 1 +fi + +# link two netdevsim interfaces echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK if [ $? -ne 0 ]; then echo "linking netdevsim1 with netdevsim2 should succeed" @@ -104,11 +113,10 @@ if [ $? -ne 0 ]; then exit 1 fi -# argument error checking - -echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:a" > $NSIM_DEV_SYS_LINK 2>/dev/null +# semantic error checking +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK 2>/dev/null if [ $? -eq 0 ]; then - echo "invalid arg should fail" + echo "linking already-connected netdevsim should fail" cleanup_ns exit 1 fi -- 2.51.2