From patchwork Fri Feb 15 23:49:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Oskolkov X-Patchwork-Id: 1043291 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="KQohuuWZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 441VNr6nJNz9s5c for ; Sat, 16 Feb 2019 10:49:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389158AbfBOXtm (ORCPT ); Fri, 15 Feb 2019 18:49:42 -0500 Received: from mail-it1-f202.google.com ([209.85.166.202]:54477 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388127AbfBOXtl (ORCPT ); Fri, 15 Feb 2019 18:49:41 -0500 Received: by mail-it1-f202.google.com with SMTP id v125so11593836itc.4 for ; Fri, 15 Feb 2019 15:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=X9Y/79Bhf5MTpQCWCymtbNGxhG1NsGf+zB37YcWFGJM=; b=KQohuuWZ7YY5sCrpTqiBhO0P/yWZGD1gimNN+RJwItFqG0k4/eXMt9xFtLGa+4Gh5A auuBtfSCI16lfcArGK8gVwSx4e1dhNyyGQRpH8dBrohuUaOnqDabDeH295iATEqQ2i9K 9vQ8vAB6wS/q7eGe1giFD+GMJbTx7eIFR3SFPKxCLeIQjM0BYRzrRRnXw/a6+mLTVSFS mw/9FC71PhrghYvp04H7832aACsh0HVHuZuOiYbkwAyBHmClimJuViY044iWSxRJdbNL Uxg3BewoWTFij7o0p0qdTXTo+gAgspJCYcXIV5K9j91lPXvGPkA9f4+e8aMcBs//tX84 adTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=X9Y/79Bhf5MTpQCWCymtbNGxhG1NsGf+zB37YcWFGJM=; b=B/0MbJEexqKpVerFCxkmI8cpH6XTXGtd6h6AYQB6K8PFFkq1F2mIIOsWDBY6zMbz+L +PymFDQY5NFW3rWwBbtT2z8vsQqErIPqUbjy9htovyJ+gMRAgO4SxBt90dZsuZq5kONY BGq1XnGJ3lCotiD/jNtQ/rCCxh8JPn4VoDGWwB7LRQvehYcDfdB98fuQCTt0Q0ZrRZiD Pr7gqvNE3FNuvea5n6FsW+nqVlDTM+T/6FWDgavfxGNzmlXhq5I+3dSx8dCsS+M6T3Bq Mub4giHU15bYlwUxoVVco0lANNiLRxwJ2Nl9O9aoU4FMrLGvLtXpPKbE2JLSLPMbk9I6 hbuw== X-Gm-Message-State: AHQUAubouc0pYVqMkfKDAGbdC079Efn6BDZ60aYNDW49Fipecv4XuSH4 LHA4hnNEGm1hMAnRZOEvnMkif32Z X-Google-Smtp-Source: AHgI3IaxWw77zXK+ZUm5WVR85xufnArVyuCtT01i9SS5e3VERAEv0I6SfAXr5MsGfdKg51CywBpyp9F9 X-Received: by 2002:a24:5348:: with SMTP id n69mr7103938itb.7.1550274580267; Fri, 15 Feb 2019 15:49:40 -0800 (PST) Date: Fri, 15 Feb 2019 15:49:33 -0800 Message-Id: <20190215234933.208398-1-posk@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH bpf-next] selftests: bpf: test_lwt_ip_encap: add negative tests. From: Peter Oskolkov To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org Cc: Peter Oskolkov , David Ahern , Peter Oskolkov Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As requested by David Ahern: - add negative tests (no routes, explicitly unreachable destinations) to exercize error handling code paths; - do not exit on test failures, but instead print a summary of passed/failed tests at the end. Future patches will add TSO and VRF tests. Signed-off-by: Peter Oskolkov Reviewed-by: David Ahern --- .../selftests/bpf/test_lwt_ip_encap.sh | 111 ++++++++++++++---- 1 file changed, 88 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/bpf/test_lwt_ip_encap.sh b/tools/testing/selftests/bpf/test_lwt_ip_encap.sh index 4ca714e23ab0..612632c1425f 100755 --- a/tools/testing/selftests/bpf/test_lwt_ip_encap.sh +++ b/tools/testing/selftests/bpf/test_lwt_ip_encap.sh @@ -38,8 +38,6 @@ # ping: SRC->[encap at veth2:ingress]->GRE:decap->DST # ping replies go DST->SRC directly -set -e # exit on error - if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" echo "FAIL" @@ -76,8 +74,37 @@ readonly IPv6_GRE="fb10::1" readonly IPv6_SRC=$IPv6_1 readonly IPv6_DST=$IPv6_4 -setup() { -set -e # exit on error +TEST_STATUS=0 +TESTS_SUCCEEDED=0 +TESTS_FAILED=0 + +process_test_results() +{ + if [[ "${TEST_STATUS}" -eq 0 ]] ; then + echo "PASS" + TESTS_SUCCEEDED=$((TESTS_SUCCEEDED+1)) + else + echo "FAIL" + TESTS_FAILED=$((TESTS_FAILED+1)) + fi +} + +print_test_summary_and_exit() +{ + echo "passed tests: ${TESTS_SUCCEEDED}" + echo "failed tests: ${TESTS_FAILED}" + if [ "${TESTS_FAILED}" -eq "0" ] ; then + exit 0 + else + exit 1 + fi +} + +setup() +{ + set -e # exit on error + TEST_STATUS=0 + # create devices and namespaces ip netns add "${NS1}" ip netns add "${NS2}" @@ -178,7 +205,7 @@ set -e # exit on error # configure IPv4 GRE device in NS3, and a route to it via the "bottom" route ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local ${IPv4_GRE} ttl 255 ip -netns ${NS3} link set gre_dev up - ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev + ip -netns ${NS3} addr add ${IPv4_GRE} nodad dev gre_dev ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6} ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8} @@ -194,9 +221,13 @@ set -e # exit on error ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0 ip netns exec ${NS2} sysctl -wq net.ipv4.conf.all.rp_filter=0 ip netns exec ${NS3} sysctl -wq net.ipv4.conf.all.rp_filter=0 + + sleep 1 # reduce flakiness + set +e } -cleanup() { +cleanup() +{ ip netns del ${NS1} 2> /dev/null ip netns del ${NS2} 2> /dev/null ip netns del ${NS3} 2> /dev/null @@ -204,12 +235,28 @@ cleanup() { trap cleanup EXIT -test_ping() { +remove_routes_to_gredev() +{ + ip -netns ${NS1} route del ${IPv4_GRE} dev veth5 + ip -netns ${NS2} route del ${IPv4_GRE} dev veth7 + ip -netns ${NS1} -6 route del ${IPv6_GRE}/128 dev veth5 + ip -netns ${NS2} -6 route del ${IPv6_GRE}/128 dev veth7 +} + +add_unreachable_routes_to_gredev() +{ + ip -netns ${NS1} route add unreachable ${IPv4_GRE}/32 + ip -netns ${NS2} route add unreachable ${IPv4_GRE}/32 + ip -netns ${NS1} -6 route add unreachable ${IPv6_GRE}/128 + ip -netns ${NS2} -6 route add unreachable ${IPv6_GRE}/128 +} + +test_ping() +{ local readonly PROTO=$1 local readonly EXPECTED=$2 local RET=0 - set +e if [ "${PROTO}" == "IPv4" ] ; then ip netns exec ${NS1} ping -c 1 -W 1 -I ${IPv4_SRC} ${IPv4_DST} 2>&1 > /dev/null RET=$? @@ -217,29 +264,26 @@ test_ping() { ip netns exec ${NS1} ping6 -c 1 -W 6 -I ${IPv6_SRC} ${IPv6_DST} 2>&1 > /dev/null RET=$? else - echo "test_ping: unknown PROTO: ${PROTO}" - exit 1 + echo " test_ping: unknown PROTO: ${PROTO}" + TEST_STATUS=1 fi - set -e if [ "0" != "${RET}" ]; then RET=1 fi if [ "${EXPECTED}" != "${RET}" ] ; then - echo "FAIL: test_ping: ${RET}" - exit 1 + echo " test_ping failed: expected: ${EXPECTED}; got ${RET}" + TEST_STATUS=1 fi } -test_egress() { +test_egress() +{ local readonly ENCAP=$1 echo "starting egress ${ENCAP} encap test" setup - # need to wait a bit for IPv6 to autoconf, otherwise - # ping6 sometimes fails with "unable to bind to address" - # by default, pings work test_ping IPv4 0 test_ping IPv6 0 @@ -258,16 +302,28 @@ test_egress() { ip -netns ${NS1} route add ${IPv4_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre6 dev veth1 ip -netns ${NS1} -6 route add ${IPv6_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre6 dev veth1 else - echo "FAIL: unknown encap ${ENCAP}" + echo " unknown encap ${ENCAP}" + TEST_STATUS=1 fi test_ping IPv4 0 test_ping IPv6 0 + # a negative test: remove routes to GRE devices: ping fails + remove_routes_to_gredev + test_ping IPv4 1 + test_ping IPv6 1 + + # another negative test + add_unreachable_routes_to_gredev + test_ping IPv4 1 + test_ping IPv6 1 + cleanup - echo "PASS" + process_test_results } -test_ingress() { +test_ingress() +{ local readonly ENCAP=$1 echo "starting ingress ${ENCAP} encap test" setup @@ -298,14 +354,23 @@ test_ingress() { test_ping IPv4 0 test_ping IPv6 0 + # a negative test: remove routes to GRE devices: ping fails + remove_routes_to_gredev + test_ping IPv4 1 + test_ping IPv6 1 + + # another negative test + add_unreachable_routes_to_gredev + test_ping IPv4 1 + test_ping IPv6 1 + cleanup - echo "PASS" + process_test_results } test_egress IPv4 test_egress IPv6 - test_ingress IPv4 test_ingress IPv6 -echo "all tests passed" +print_test_summary_and_exit