selftests: net: add tests for PPP
PATCH v2 1/1 selftests: net: add tests for PPP
Add ping and iperf3 tests for ppp_async.c and pppoe.c.
---
v2: fix shellcheck and add trailing backslashes.
- https://lore.kernel.org/netdev/[email protected]/
MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ppp/Makefile | 15 +++++++ tools/testing/selftests/net/ppp/config | 8 ++++ tools/testing/selftests/net/ppp/ppp_async.sh | 37 ++++++++++++++++ tools/testing/selftests/net/ppp/ppp_common.sh | 42 +++++++++++++++++++ .../selftests/net/ppp/pppoe-server-options | 2 + tools/testing/selftests/net/ppp/pppoe.sh | 36 ++++++++++++++++ 8 files changed, 142 insertions(+) create mode 100644 tools/testing/selftests/net/ppp/Makefile create mode 100644 tools/testing/selftests/net/ppp/config create mode 100755 tools/testing/selftests/net/ppp/ppp_async.sh create mode 100644 tools/testing/selftests/net/ppp/ppp_common.sh create mode 100644 tools/testing/selftests/net/ppp/pppoe-server-options create mode 100755 tools/testing/selftests/net/ppp/pppoe.sh
MAINTAINERS +1 -0
@@ -21078,6 +21078,7 @@ PPP PROTOCOL DRIVERS AND COMPRESSORS L: [email protected] S: Orphan F: drivers/net/ppp/ppp_* +F: tools/testing/selftests/net/ppp/ PPS SUPPORT M: Rodolfo Giometti <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -78,6 +78,7 @@ TARGETS += net/netfilter TARGETS += net/openvswitch TARGETS += net/ovpn TARGETS += net/packetdrill +TARGETS += net/ppp TARGETS += net/rds TARGETS += net/tcp_ao TARGETS += nolibc
tools/testing/selftests/net/ppp/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +top_srcdir = ../../../../.. + +TEST_PROGS := \ + ppp_async.sh \ + pppoe.sh \ +# end of TEST_PROGS + +TEST_FILES := \ + ppp_common.sh \ + pppoe-server-options \ +# end of TEST_FILES + +include ../../lib.mk
tools/testing/selftests/net/ppp/config new file +8 -0
@@ -0,0 +1,8 @@ +CONFIG_PACKET=y +CONFIG_PPP=m +CONFIG_PPP_ASYNC=m +CONFIG_PPP_BSDCOMP=m +CONFIG_PPP_DEFLATE=m +CONFIG_PPPOE=m +CONFIG_PPPOE_HASH_BITS_4=y +CONFIG_TTY=y
tools/testing/selftests/net/ppp/ppp_async.sh new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +set -e +source ppp_common.sh + +# Temporary files for PTY symlinks +TTY_SERVER=$(mktemp -u /tmp/ppp_async_server.XXXXXX) +TTY_CLIENT=$(mktemp -u /tmp/ppp_async_client.XXXXXX) + +cleanup() { + cleanup_all_ns + [ -n "$SOCAT_PID" ] && kill "$SOCAT_PID" 2>/dev/null || true +} + +trap cleanup EXIT + +require_command socat +ppp_common_init + +# Create the virtual serial device +socat -d PTY,link="$TTY_SERVER",rawer PTY,link="$TTY_CLIENT",rawer & +SOCAT_PID=$! + +# Wait for symlinks to be created +slowwait 5 [ -L "$TTY_SERVER" ] + +# Start the PPP Server +ip netns exec "$NS_SERVER" pppd "$TTY_SERVER" 115200 \ + "$IP_SERVER":"$IP_CLIENT" \ + local noauth nodefaultroute debug + +# Start the PPP Client +ip netns exec "$NS_CLIENT" pppd "$TTY_CLIENT" 115200 \ + local noauth updetach nodefaultroute debug + +ppp_test_connectivity
tools/testing/selftests/net/ppp/ppp_common.sh new file +42 -0
42 lines not on this page · raw message
tools/testing/selftests/net/ppp/pppoe-server-options new file +2 -0
@@ -0,0 +1,2 @@ +noauth +noipdefault
tools/testing/selftests/net/ppp/pppoe.sh new file +36 -0
@@ -0,0 +1,36 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +set -e +source ppp_common.sh + +VETH_SERVER="veth-server" +VETH_CLIENT="veth-client" + +cleanup() { + cleanup_all_ns +} + +trap cleanup EXIT + +require_command pppoe-server +ppp_common_init + +# Create the veth pair +ip link add "$VETH_SERVER" type veth peer name "$VETH_CLIENT" +ip link set "$VETH_SERVER" netns "$NS_SERVER" +ip link set "$VETH_CLIENT" netns "$NS_CLIENT" +ip -netns "$NS_SERVER" link set "$VETH_SERVER" up +ip -netns "$NS_CLIENT" link set "$VETH_CLIENT" up + +# Start the PPP Server +ip netns exec "$NS_SERVER" pppoe-server -I "$VETH_SERVER" \ + -L "$IP_SERVER" -R "$IP_CLIENT" -N 1 -q "$(command -v pppd)" \ + -k -O "$(pwd)/pppoe-server-options" + +# Start the PPP Client +ip netns exec "$NS_CLIENT" pppd \ + local debug updetach noipdefault noauth nodefaultroute \ + plugin pppoe.so nic-"$VETH_CLIENT" + +ppp_test_connectivity
Signature · 1 line
2.43.0
Paolo Abeni
maintainerQuoted 74 lines · Qingfang Deng
Add ping and iperf3 tests for
ppp_async.candpppoe.c.Signed-off-by Qingfang Deng <[email protected]>---
v2: fix shellcheck and add trailing backslashes.
- https://lore.kernel.org/netdev/[email protected]/MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ppp/Makefile | 15 +++++++ tools/testing/selftests/net/ppp/config | 8 ++++ tools/testing/selftests/net/ppp/ppp_async.sh | 37 ++++++++++++++++ tools/testing/selftests/net/ppp/ppp_common.sh | 42 +++++++++++++++++++ .../selftests/net/ppp/pppoe-server-options | 2 + tools/testing/selftests/net/ppp/pppoe.sh | 36 ++++++++++++++++ 8 files changed, 142 insertions(+) create mode 100644 tools/testing/selftests/net/ppp/Makefile create mode 100644 tools/testing/selftests/net/ppp/config create mode 100755 tools/testing/selftests/net/ppp/ppp_async.sh create mode 100644 tools/testing/selftests/net/ppp/ppp_common.sh create mode 100644 tools/testing/selftests/net/ppp/pppoe-server-options create mode 100755 tools/testing/selftests/net/ppp/pppoe.shMAINTAINERS +1
-0@@ -21078,6 +21078,7 @@ PPP PROTOCOL DRIVERS AND COMPRESSORS L: [email protected] S: Orphan F: drivers/net/ppp/ppp_* +F: tools/testing/selftests/net/ppp/ PPS SUPPORT M: Rodolfo Giometti <[email protected]>tools/testing/selftests/Makefile +1
-0@@ -78,6 +78,7 @@ TARGETS += net/netfilter TARGETS += net/openvswitch TARGETS += net/ovpn TARGETS += net/packetdrill +TARGETS += net/ppp TARGETS += net/rds TARGETS += net/tcp_ao TARGETS += nolibctools/testing/selftests/net/ppp/Makefile new file +15
-0@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +top_srcdir = ../../../../.. + +TEST_PROGS := \ + ppp_async.sh \ + pppoe.sh \ +# end of TEST_PROGS + +TEST_FILES := \ + ppp_common.sh \ + pppoe-server-options \ +# end of TEST_FILES + +include ../../lib.mktools/testing/selftests/net/ppp/config new file +0
-0
tools/testing/selftests/net/ppp/config line 8
Quoted 8 lines
tools/testing/selftests/net/ppp/config new file +8
-0@@ -0,0 +1,8 @@ +CONFIG_PACKET=y +CONFIG_PPP=m +CONFIG_PPP_ASYNC=m +CONFIG_PPP_BSDCOMP=m +CONFIG_PPP_DEFLATE=m +CONFIG_PPPOE=m +CONFIG_PPPOE_HASH_BITS_4=y +CONFIG_TTY=y
The config list looks quite tiny. Have you double-checked that it's enough to run successfully the self-tests via the nipa-like setup:
https://github.com/linux-netdev/nipa/wiki/How-to-run-netdev-selftests-CI-style
?
Quoted 6 lines
tools/testing/selftests/net/ppp/ppp_async.sh new file +0
-0
tools/testing/selftests/net/ppp/ppp_async.sh line 9
Quoted 9 lines
tools/testing/selftests/net/ppp/ppp_async.sh new file +9
-0@@ -0,0 +1,37 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +set -e +source ppp_common.sh + +# Temporary files for PTY symlinks +TTY_SERVER=$(mktemp -u /tmp/ppp_async_server.XXXXXX) +TTY_CLIENT=$(mktemp -u /tmp/ppp_async_client.XXXXXX)
You need to delete the above files at cleanup time
Quoted 65 lines
tools/testing/selftests/net/ppp/ppp_async.sh new file +28
-0+ +cleanup() { + cleanup_all_ns + [ -n "$SOCAT_PID" ] && kill "$SOCAT_PID" 2>/dev/null || true +} + +trap cleanup EXIT + +require_command socat +ppp_common_init + +# Create the virtual serial device +socat -d PTY,link="$TTY_SERVER",rawer PTY,link="$TTY_CLIENT",rawer & +SOCAT_PID=$! + +# Wait for symlinks to be created +slowwait 5 [ -L "$TTY_SERVER" ] + +# Start the PPP Server +ip netns exec "$NS_SERVER" pppd "$TTY_SERVER" 115200 \ + "$IP_SERVER":"$IP_CLIENT" \ + local noauth nodefaultroute debug + +# Start the PPP Client +ip netns exec "$NS_CLIENT" pppd "$TTY_CLIENT" 115200 \ + local noauth updetach nodefaultroute debug + +ppp_test_connectivitytools/testing/selftests/net/ppp/ppp_common.sh new file +31
-0@@ -0,0 +1,42 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# shellcheck disable=SC2153 + +source ../lib.sh + +IP_SERVER="192.168.200.1" +IP_CLIENT="192.168.200.2" + +ppp_common_init() { + # Package requirements + require_command pppd + require_command iperf3 + + # Check for root privileges + if [ "$(id -u)" -ne 0 ];then + echo "SKIP: Need root privileges" + exit $ksft_skip + fi + + # Namespaces + setup_ns NS_SERVER NS_CLIENT +} + +ppp_check_addr() { + dev=$1 + addr=$2 + ns=$3 + ip -netns "$ns" -4 addr show dev "$dev" 2>/dev/null | grep -q "$addr" + return $? +}
tools/testing/selftests/net/ppp/ppp_common.sh line 41
Quoted 10 lines
tools/testing/selftests/net/ppp/ppp_common.sh new file +10
-0+ +ppp_test_connectivity() { + slowwait 10 ppp_check_addr "ppp0" "$IP_CLIENT" "$NS_CLIENT" + + ip netns exec "$NS_CLIENT" ping -c 3 "$IP_SERVER" + + ip netns exec "$NS_SERVER" iperf3 -s -1 -D + wait_local_port_listen "$NS_SERVER" 5201 tcp + + ip netns exec "$NS_CLIENT" iperf3 -c "$IP_SERVER" -Z -t 2
It would be possibly helpful to let the test emit a one line test name/description followed by [ ok ] / [fail] as most test cases currently do
/P