From patchwork Tue Mar 8 22:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 12774439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0738CC433EF for ; Tue, 8 Mar 2022 22:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350637AbiCHWQE (ORCPT ); Tue, 8 Mar 2022 17:16:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350570AbiCHWQD (ORCPT ); Tue, 8 Mar 2022 17:16:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55955546B3 for ; Tue, 8 Mar 2022 14:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646777705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ELpwnjudnka3fEDvbHfxHTpR5nqbjypRAXzu0I8fztU=; b=jDXve67EeHF3hhZDg9WMiH9GG0vZW7kgtSFaRtYym2hRFBi/6jmSas4F7kwm/42q2l5Qoq DuJNpa6isrgnvzQRqSRbBc6EsC0nl2phIKHg/3NmJLk1/2qeE6L19KwUTA35xFimNRW1ZZ ViTPkF7EXvzPzdjIzHmWFXPoayu2r8w= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-uCvLd28-O9e6nBjFFGFvjA-1; Tue, 08 Mar 2022 17:15:04 -0500 X-MC-Unique: uCvLd28-O9e6nBjFFGFvjA-1 Received: by mail-wm1-f72.google.com with SMTP id l2-20020a1ced02000000b0038482a47e7eso1744520wmh.5 for ; Tue, 08 Mar 2022 14:15:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ELpwnjudnka3fEDvbHfxHTpR5nqbjypRAXzu0I8fztU=; b=3wttKHXvEDTTyEItMcH0eR40+cbh/sFAWRo5z0VG9Aj8GCJNdvj7tG5THf5lImvc2W zGKLMvUtEn3YIMMCTIUSPrYO86jvcvFaa/ojMP/EgL+Ba2vvQoDiQnsGVY8nS7YC+her zfxugEL0o9ArS1TpZg3pE9AeSvUfyoaR935y9P8WxqMavh7MaEx+5qQ9MCgmdYAwJJge HVc8ckYQ6wYmMSzzKizHmNLjJwESayYRC8tAddAR56LYPnYcIInwhsLBydsx77zfo9/Q p+8ras0hr5lMQtyiX8/GqSbMYGlgUo8aeBD5FW9FyES9Qqq9d3R4ovnLJnN/3ra8NG// yG6g== X-Gm-Message-State: AOAM531JeEj3cZ+w7VHLgmGUwf5i97Rtx3MMxg974J6T/lf74TDEiCDb tmhl062wrzPKhY+o8m5qE6gzZVEQ34Mo38uLHazUpUMJJ7ELvdj0kcsRHEbUFekrRIqg7bTBjTt uhHjH2pBGRwzWDTc0bQWDx8lIQ3O0 X-Received: by 2002:a05:6000:1683:b0:1f1:eb7c:be70 with SMTP id y3-20020a056000168300b001f1eb7cbe70mr10378267wrd.129.1646777702893; Tue, 08 Mar 2022 14:15:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHMtCrmeazeUHh4F62qhxxUsIHBP4mefLMF4CUNEhC+M/2Dzt2H+6jL7QMEFw7arPxOI+6jw== X-Received: by 2002:a05:6000:1683:b0:1f1:eb7c:be70 with SMTP id y3-20020a056000168300b001f1eb7cbe70mr10378255wrd.129.1646777702676; Tue, 08 Mar 2022 14:15:02 -0800 (PST) Received: from debian.home (2a01cb058d3818005c1e4a7b0f47339f.ipv6.abo.wanadoo.fr. [2a01:cb05:8d38:1800:5c1e:4a7b:f47:339f]) by smtp.gmail.com with ESMTPSA id 11-20020a05600c22cb00b00382a960b17csm3242256wmg.7.2022.03.08.14.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 14:15:02 -0800 (PST) Date: Tue, 8 Mar 2022 23:15:00 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, David Ahern , Vadim Fedorenko , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH net 1/2] selftests: pmtu.sh: Kill tcpdump processes launched by subshell. Message-ID: <42a8a8194988cd3f37f437b11686a5e468efb0b2.1646776561.git.gnault@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The cleanup() function takes care of killing processes launched by the test functions. It relies on variables like ${tcpdump_pids} to get the relevant PIDs. But tests are run in their own subshell, so updated *_pids values are invisible to other shells. Therefore cleanup() never sees any process to kill: $ ./tools/testing/selftests/net/pmtu.sh -t pmtu_ipv4_exception TEST: ipv4: PMTU exceptions [ OK ] TEST: ipv4: PMTU exceptions - nexthop objects [ OK ] $ pgrep -af tcpdump 6084 tcpdump -s 0 -i veth_A-R1 -w pmtu_ipv4_exception_veth_A-R1.pcap 6085 tcpdump -s 0 -i veth_R1-A -w pmtu_ipv4_exception_veth_R1-A.pcap 6086 tcpdump -s 0 -i veth_R1-B -w pmtu_ipv4_exception_veth_R1-B.pcap 6087 tcpdump -s 0 -i veth_B-R1 -w pmtu_ipv4_exception_veth_B-R1.pcap 6088 tcpdump -s 0 -i veth_A-R2 -w pmtu_ipv4_exception_veth_A-R2.pcap 6089 tcpdump -s 0 -i veth_R2-A -w pmtu_ipv4_exception_veth_R2-A.pcap 6090 tcpdump -s 0 -i veth_R2-B -w pmtu_ipv4_exception_veth_R2-B.pcap 6091 tcpdump -s 0 -i veth_B-R2 -w pmtu_ipv4_exception_veth_B-R2.pcap 6228 tcpdump -s 0 -i veth_A-R1 -w pmtu_ipv4_exception_veth_A-R1.pcap 6229 tcpdump -s 0 -i veth_R1-A -w pmtu_ipv4_exception_veth_R1-A.pcap 6230 tcpdump -s 0 -i veth_R1-B -w pmtu_ipv4_exception_veth_R1-B.pcap 6231 tcpdump -s 0 -i veth_B-R1 -w pmtu_ipv4_exception_veth_B-R1.pcap 6232 tcpdump -s 0 -i veth_A-R2 -w pmtu_ipv4_exception_veth_A-R2.pcap 6233 tcpdump -s 0 -i veth_R2-A -w pmtu_ipv4_exception_veth_R2-A.pcap 6234 tcpdump -s 0 -i veth_R2-B -w pmtu_ipv4_exception_veth_R2-B.pcap 6235 tcpdump -s 0 -i veth_B-R2 -w pmtu_ipv4_exception_veth_B-R2.pcap Fix this by running cleanup() in the context of the test subshell. Now that each test cleans the environment after completion, there's no need for calling cleanup() again when the next test starts. So let's drop it from the setup() function. This is okay because cleanup() is also called when pmtu.sh starts, so even the first test starts in a clean environment. Also, use tcpdump's immediate mode. Otherwise it might not have time to process buffered packets, resulting in missing packets or even empty pcap files for short tests. Note: PAUSE_ON_FAIL is still evaluated before cleanup(), so one can still inspect the test environment upon failure when using -p. Fixes: a92a0a7b8e7c ("selftests: pmtu: Simplify cleanup and namespace names") Signed-off-by: Guillaume Nault --- tools/testing/selftests/net/pmtu.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh index 543ad7513a8e..2e8972573d91 100755 --- a/tools/testing/selftests/net/pmtu.sh +++ b/tools/testing/selftests/net/pmtu.sh @@ -865,7 +865,6 @@ setup_ovs_bridge() { setup() { [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip - cleanup for arg do eval setup_${arg} || { echo " ${arg} not supported"; return 1; } done @@ -876,7 +875,7 @@ trace() { for arg do [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue - ${ns_cmd} tcpdump -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null & + ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null & tcpdump_pids="${tcpdump_pids} $!" ns_cmd= done @@ -1836,6 +1835,10 @@ run_test() { unset IFS + # Since cleanup() relies on variables modified by this subshell, it + # has to run in this context. + trap cleanup EXIT + if [ "$VERBOSE" = "1" ]; then printf "\n##########################################################################\n\n" fi From patchwork Tue Mar 8 22:15:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 12774440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DFA8C433EF for ; Tue, 8 Mar 2022 22:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350638AbiCHWQL (ORCPT ); Tue, 8 Mar 2022 17:16:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350600AbiCHWQG (ORCPT ); Tue, 8 Mar 2022 17:16:06 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 440F154BCE for ; Tue, 8 Mar 2022 14:15:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646777708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6nIHOJmJA+rkjvbg8O1o1KH0J2z0YqG4K70ZRzEJTXc=; b=aKHQeQcGLsSV7wZF+hUASjuVUffkP39f7RXVIAMut7HlrL4mk77j1rV3zOFzCPkVZrLDTS Vd+M2r16Vjheh7shMBFHgoA2hsQ00+5nWN73Nim9QoLC60Z8X0+wFJejv6cHfINh8NaqAB XivCuI0ousLxXzXraQ8mRcGs3EtqYx4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-482-fV8B-aMoNV-7lTKVZFz7aw-1; Tue, 08 Mar 2022 17:15:07 -0500 X-MC-Unique: fV8B-aMoNV-7lTKVZFz7aw-1 Received: by mail-wr1-f70.google.com with SMTP id m18-20020a5d4a12000000b00203731460e6so26552wrq.3 for ; Tue, 08 Mar 2022 14:15:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6nIHOJmJA+rkjvbg8O1o1KH0J2z0YqG4K70ZRzEJTXc=; b=Cvek+p0Wf1Il+pN+S8Zi9UcvBtWaV5L+cJEmqR6vyoYq3DwBN88yGaFye0T0CepbL+ eNXEFjhR4WG3VcbRVI/HiTVsZ1D8pIy63v6dcFdbzxlo+X4PpBbYxXn4sANjiap1lB5k 1B15KoUdGzJv89am88z4vQbVC6AAF/clYa+kWthrBbCZVD5aNwBFylWkwsRrEgAyliel 0bak7yWJ2VlHrG7uFNgnNwFspTMjI7x+Ps9d0T2wNLOF2ZBvK7fRhG6IPmkpRSjOoCI+ Q8EOU255A5Z86Bg1BRnpRbu+Lf4AFo7ThoAfQHDsexBAoduxWqswRmQp9VX6/w3YcTtU ncbQ== X-Gm-Message-State: AOAM532tUa+4mmTHsFlEBJ2fEprPqRWiYbDmXOG7fo2L+ACd3v8q+8Rp 5/ulzECgfrCr1+tL98l2pCEj5AAHmG4XFFVQq8e+GQ4Obs2WJDX8Kyse0+cbQRa77tywJ5Wfjrm IALeHnxLgfvBVPSfEByLelELR+jHP X-Received: by 2002:a5d:61ca:0:b0:1f0:22ef:bb9f with SMTP id q10-20020a5d61ca000000b001f022efbb9fmr14177712wrv.56.1646777706060; Tue, 08 Mar 2022 14:15:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUAdR2fAB8NkHsGlS31dTIoi/XqT+nhHeo0/XxxKYEYFt+c1zOjvRcGUy9zE1VzDBSBimJzA== X-Received: by 2002:a5d:61ca:0:b0:1f0:22ef:bb9f with SMTP id q10-20020a5d61ca000000b001f022efbb9fmr14177703wrv.56.1646777705864; Tue, 08 Mar 2022 14:15:05 -0800 (PST) Received: from debian.home (2a01cb058d3818005c1e4a7b0f47339f.ipv6.abo.wanadoo.fr. [2a01:cb05:8d38:1800:5c1e:4a7b:f47:339f]) by smtp.gmail.com with ESMTPSA id a17-20020a5d5091000000b001edb61b2687sm126364wrt.63.2022.03.08.14.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 14:15:05 -0800 (PST) Date: Tue, 8 Mar 2022 23:15:03 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, David Ahern , Vadim Fedorenko , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH net 2/2] selftests: pmtu.sh: Kill nettest processes launched in subshell. Message-ID: <55cb9255471e73eaa481779329d9d47c430dbd0a.1646776561.git.gnault@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When using "run_cmd &", then "$!" refers to the PID of the subshell used to run , not the command itself. Therefore nettest_pids actually doesn't contain the list of the nettest commands running in the background. So cleanup() can't kill them and the nettest processes run until completion (fortunately they have a 5s timeout). Fix this by defining a new command for running processes in the background, for which "$!" really refers to the PID of the command run. Also, double quote variables on the modified lines, to avoid shellcheck warnings. Fixes: ece1278a9b81 ("selftests: net: add ESP-in-UDP PMTU test") Signed-off-by: Guillaume Nault --- tools/testing/selftests/net/pmtu.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh index 2e8972573d91..694732e4b344 100755 --- a/tools/testing/selftests/net/pmtu.sh +++ b/tools/testing/selftests/net/pmtu.sh @@ -374,6 +374,16 @@ run_cmd() { return $rc } +run_cmd_bg() { + cmd="$*" + + if [ "$VERBOSE" = "1" ]; then + printf " COMMAND: %s &\n" "${cmd}" + fi + + $cmd 2>&1 & +} + # Find the auto-generated name for this namespace nsname() { eval echo \$NS_$1 @@ -670,10 +680,10 @@ setup_nettest_xfrm() { [ ${1} -eq 6 ] && proto="-6" || proto="" port=${2} - run_cmd ${ns_a} nettest ${proto} -q -D -s -x -p ${port} -t 5 & + run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 nettest_pids="${nettest_pids} $!" - run_cmd ${ns_b} nettest ${proto} -q -D -s -x -p ${port} -t 5 & + run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 nettest_pids="${nettest_pids} $!" }