Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1359285pxa; Thu, 20 Aug 2020 09:14:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwqU7g+Rl/KH1RxKtmi9flYyi46ClDob+T/JolYgadVHdSEP/q2aqBcmnstr5A14vwnyl8 X-Received: by 2002:a17:907:204e:: with SMTP id pg14mr4170330ejb.324.1597940057230; Thu, 20 Aug 2020 09:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597940057; cv=none; d=google.com; s=arc-20160816; b=rawwXO0uc3l5QxV9ALnMduyYJ54k5UzTu5xeMsd4BiArD64xckcRzxKGkgKZ68bwBm Ab+l6mQo00ukqvXsSiPDFMsKw/Kjx0UrQzqnRHBkws/a5zS5dZIuIvL8/WmAaZJaoeMc qtRb4zt8wBQ7WQbCExBWAhNqUnGQ+U2jVpjlxDkCrnM9ruAq50VKFWmfn6tBIG4DVx3u iagu/bCWEwaZe1v5+bvBm9o9nzlQEYOjmc3gG2O+PEQ2J7lHHGtaJcEwyb1Xi4MknZKa NBkOYLzXmC8a4yTAbpCpeMXZaMpMJL71JC1KWn5S+QlJxJk8D6K5ny0btDSAOkKcrucR yMJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ud0t0O/A9Zxe4AUQrrfIW1bhDjfdc8SKj1ooJkDSnEc=; b=ELgBOjdyG4Otsyg2/g3uPXuuQEXoJl59F67L2+2XN0ManvWaDLnCvRmlYuH84iqZnp 4XGAi89ZDxjpr7kIIXWACDhJs8/M8HyQb1VwpV7PCSCsIew4he88rjIUA3zCT9z9jLUw 2qNdwhU6keS+nmDyaSZFP0wdu4w5ev+Rbyv7xfN7vvEbv5LEpF5W1zXNWIEHq5qMxVxD 8JSGYGoEFixbBsTazDpDpQlrqPH0+TnQHOPHIzx0SxDlELRxdOztpWNNboPPt/7e9ppk bTuGWDZUj3YCkmItVk0Ehrc+jxLcdFAJ+QfucJrz6kIewUR6qs8AclpWoiHzbZPs3rK0 V7jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=OG8nWb3x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si1496205ejz.187.2020.08.20.09.13.52; Thu, 20 Aug 2020 09:14:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=OG8nWb3x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729719AbgHTQMw (ORCPT + 99 others); Thu, 20 Aug 2020 12:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729772AbgHTQMa (ORCPT ); Thu, 20 Aug 2020 12:12:30 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FD8C061385 for ; Thu, 20 Aug 2020 09:12:30 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id a24so2337740oia.6 for ; Thu, 20 Aug 2020 09:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ud0t0O/A9Zxe4AUQrrfIW1bhDjfdc8SKj1ooJkDSnEc=; b=OG8nWb3xyhE1WjhqnLw+bu8z2arHxNdpvBUUxE713nK5l/9FVUUvdMaxu0aiJ/QJkp v0eEF8Y9nrBafzmEg7AiAQzgIMA32FhyYPWEc7o7zz0NRivisQeRFNKh+4x+rgETdweS Ar6aVVMzVPpzpMQYvX3xQg1HRbjItfwGiGDM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ud0t0O/A9Zxe4AUQrrfIW1bhDjfdc8SKj1ooJkDSnEc=; b=kC9W1MDRtZWbvAzxMyl9DXnAHqZ5EzDnubZ0uV5JTJd3n1GCR6SbjmMKv07pZAnoN3 dFQK5y4k4i+zvsJW0/hxUbRc5RtkrP6Hv9r2ZSATGz0qql6QNefaylEresJj05iO6FQN z6P5CNbK0nTPdB+5Gy3Ss+LaPYCeEO/zSE3CRrMZrPl04qNVzPgNAJ3VHf3Zx4/CDtEu UK+/DyW5gG5TM0CE3H35rqgQGBSNCLhn17NiFq358crfZ10rpynLEB5n4X15KNx5N7jw wS0EvtY29LqhCosp+owDPv6zDARqwsoYLKw4XdXC/TR+tSbZCNRowmo7JMKjQncAvFOH epbQ== X-Gm-Message-State: AOAM530XmGf0uLpHaq/JgYEeXJ3EfRqeluvAXt/tFPUnK3eao8CgOYRe W5oQ1r0ZWU3SkzilNP4Qqp7xk8xAtQ71/u3K9KiwcQ== X-Received: by 2002:aca:cfd0:: with SMTP id f199mr2098445oig.102.1597939950149; Thu, 20 Aug 2020 09:12:30 -0700 (PDT) MIME-Version: 1.0 References: <20200819092436.58232-1-lmb@cloudflare.com> <20200819092436.58232-7-lmb@cloudflare.com> <1ad29823-1925-01ee-f042-20b422a62a73@fb.com> <582e57e2-58e6-8a37-7dbc-67a2a1db7ecb@fb.com> In-Reply-To: <582e57e2-58e6-8a37-7dbc-67a2a1db7ecb@fb.com> From: Lorenz Bauer Date: Thu, 20 Aug 2020 17:12:18 +0100 Message-ID: Subject: Re: [PATCH bpf-next 6/6] selftests: bpf: test sockmap update from BPF To: Yonghong Song Cc: Jakub Sitnicki , John Fastabend , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , kernel-team , LKML , linux-kselftest@vger.kernel.org, Networking , bpf Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 20 Aug 2020 at 15:49, Yonghong Song wrote: > > > > On 8/20/20 4:58 AM, Lorenz Bauer wrote: > > On Wed, 19 Aug 2020 at 21:46, Yonghong Song wrote: > >> > >> > >> > >> On 8/19/20 2:24 AM, Lorenz Bauer wrote: > >>> Add a test which copies a socket from a sockmap into another sockmap > >>> or sockhash. This excercises bpf_map_update_elem support from BPF > >>> context. Compare the socket cookies from source and destination to > >>> ensure that the copy succeeded. > >>> > >>> Signed-off-by: Lorenz Bauer > >>> --- > >>> .../selftests/bpf/prog_tests/sockmap_basic.c | 76 +++++++++++++++++++ > >>> .../selftests/bpf/progs/test_sockmap_copy.c | 48 ++++++++++++ > >>> 2 files changed, 124 insertions(+) > >>> create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_copy.c > >>> > >>> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > >>> index 96e7b7f84c65..d30cabc00e9e 100644 > >>> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > >>> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > >>> @@ -4,6 +4,7 @@ > >>> > >>> #include "test_progs.h" > >>> #include "test_skmsg_load_helpers.skel.h" > >>> +#include "test_sockmap_copy.skel.h" > >>> > >>> #define TCP_REPAIR 19 /* TCP sock is under repair right now */ > >>> > >>> @@ -101,6 +102,77 @@ static void test_skmsg_helpers(enum bpf_map_type map_type) > >>> test_skmsg_load_helpers__destroy(skel); > >>> } > >>> > >>> +static void test_sockmap_copy(enum bpf_map_type map_type) > >>> +{ > >>> + struct bpf_prog_test_run_attr attr; > >>> + struct test_sockmap_copy *skel; > >>> + __u64 src_cookie, dst_cookie; > >>> + int err, prog, s, src, dst; > >>> + const __u32 zero = 0; > >>> + char dummy[14] = {0}; > >>> + > >>> + s = connected_socket_v4(); > >> > >> Maybe change variable name to "sk" for better clarity? > > > > Yup! > > > >> > >>> + if (CHECK_FAIL(s == -1)) > >>> + return; > >>> + > >>> + skel = test_sockmap_copy__open_and_load(); > >>> + if (CHECK_FAIL(!skel)) { > >>> + close(s); > >>> + perror("test_sockmap_copy__open_and_load"); > >>> + return; > >>> + } > >> > >> Could you use CHECK instead of CHECK_FAIL? > >> With CHECK, you can print additional information without perror. > > > > I avoid CHECK because it requires `duration`, which doesn't make sense > > for most things that I call CHECK_FAIL on here. So either it outputs 0 > > nsec (which is bogus) or it outputs the value from the last > > bpf_prog_test_run call (which is also bogus). How do other tests > > handle this? Just ignore it? > > Just ignore it. You can define a static variable duration in the > beginning of file and then use CHECK in the rest of file. Ok, will do in v3! > > > > >> > >> > >>> + > >>> + prog = bpf_program__fd(skel->progs.copy_sock_map); > >>> + src = bpf_map__fd(skel->maps.src); > >>> + if (map_type == BPF_MAP_TYPE_SOCKMAP) > >>> + dst = bpf_map__fd(skel->maps.dst_sock_map); > >>> + else > >>> + dst = bpf_map__fd(skel->maps.dst_sock_hash); > >>> + > [...] -- Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com