From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F316C56201 for ; Tue, 24 Nov 2020 14:33:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D53E420715 for ; Tue, 24 Nov 2020 14:33:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="idvy5nx+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388709AbgKXOdR (ORCPT ); Tue, 24 Nov 2020 09:33:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28076 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388141AbgKXOdR (ORCPT ); Tue, 24 Nov 2020 09:33:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606228395; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ESyS+WMCSEdJqVArdghIaq910vepY8FdPGVN96WIOo=; b=idvy5nx+pqRsrLMX41EL2G4wswr1iOk7IHh2/P/0SEncs6SWifOTBd4Dr2QatCL7yEhFr4 kUeeD9A9h1izyXcxxgVl8T9ql3E6ZGC3mf6t4KxXCQaXIwvd0Nh0SZshXiHKhq+aO/pVud gePlNVKqi4eEuu1cVWBg98rN2LtISK0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-zi4tAsyWOpmdWdk5wacgAA-1; Tue, 24 Nov 2020 09:33:12 -0500 X-MC-Unique: zi4tAsyWOpmdWdk5wacgAA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F48A805BF4; Tue, 24 Nov 2020 14:33:09 +0000 (UTC) Received: from carbon (unknown [10.36.110.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C473660C43; Tue, 24 Nov 2020 14:33:02 +0000 (UTC) Date: Tue, 24 Nov 2020 15:33:01 +0100 From: Jesper Dangaard Brouer To: Andrii Nakryiko Cc: bpf , Networking , Daniel Borkmann , Alexei Starovoitov , Maciej =?UTF-8?B?xbtlbmN6eWtvd3NraQ==?= , Lorenz Bauer , shaun@tigera.io, Lorenzo Bianconi , Marek Majkowski , John Fastabend , Jakub Kicinski , eyal.birger@gmail.com, colrack@gmail.com, brouer@redhat.com Subject: Re: [PATCH bpf-next V7 8/8] bpf/selftests: activating bpf_check_mtu BPF-helper Message-ID: <20201124153301.47abc09c@carbon> In-Reply-To: References: <160588903254.2817268.4861837335793475314.stgit@firesoul> <160588912738.2817268.9380466634324530673.stgit@firesoul> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Fri, 20 Nov 2020 23:41:11 -0800 Andrii Nakryiko wrote: > On Fri, Nov 20, 2020 at 8:21 AM Jesper Dangaard Brouer > wrote: > > > > Adding selftest for BPF-helper bpf_check_mtu(). Making sure > > it can be used from both XDP and TC. > > > > Signed-off-by: Jesper Dangaard Brouer > > --- > > tools/testing/selftests/bpf/prog_tests/check_mtu.c | 37 ++++++++++++= ++++++++ > > tools/testing/selftests/bpf/progs/test_check_mtu.c | 33 ++++++++++++= ++++++ > > 2 files changed, 70 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/check_mtu.c > > create mode 100644 tools/testing/selftests/bpf/progs/test_check_mtu.c > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/check_mtu.c b/tools= /testing/selftests/bpf/prog_tests/check_mtu.c > > new file mode 100644 > > index 000000000000..09b8f986a17b > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/check_mtu.c > > @@ -0,0 +1,37 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* Copyright (c) 2020 Red Hat */ > > +#include > > +#include > > +#include > > + > > +#include "test_check_mtu.skel.h" > > +#define IFINDEX_LO 1 > > + > > +void test_check_mtu_xdp(struct test_check_mtu *skel) =20 >=20 > this should be static func, otherwise it's treated as an independent self= test. Ok, fixed. > > +{ > > + int err =3D 0; > > + int fd; > > + > > + fd =3D bpf_program__fd(skel->progs.xdp_use_helper); > > + err =3D bpf_set_link_xdp_fd(IFINDEX_LO, fd, XDP_FLAGS_SKB_MODE); > > + if (CHECK_FAIL(err)) =20 >=20 > please use CHECK() or one of ASSERT_xxx() helpers. CHECK_FAIL() should > be used for high-volume unlikely to fail test (i.e., very rarely). I could not get CHECK() macro working. I now realize that this is because I've not defined a global static variable named 'duration'. static __u32 duration; I wonder, are there any best-practice documentation or blogpost on howto write these bpf-selftests? Below signature is the compile error for others to Google for, and solution above. -=20 Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer $ make TEST-OBJ [test_progs] check_mtu.test.o In file included from /home/jbrouer/git/kernel/bpf-next/tools/testing/selft= ests/bpf/prog_tests/check_mtu.c:6: /home/jbrouer/git/kernel/bpf-next/tools/testing/selftests/bpf/prog_tests/ch= eck_mtu.c: In function =E2=80=98test_check_mtu=E2=80=99: ./test_progs.h:129:25: error: =E2=80=98duration=E2=80=99 undeclared (first = use in this function) 129 | _CHECK(condition, tag, duration, format) | ^~~~~~~~ ./test_progs.h:111:25: note: in definition of macro =E2=80=98_CHECK=E2=80=99 111 | __func__, tag, duration); \ | ^~~~~~~~ /home/jbrouer/git/kernel/bpf-next/tools/testing/selftests/bpf/prog_tests/ch= eck_mtu.c:33:6: note: in expansion of macro =E2=80=98CHECK=E2=80=99 33 | if (CHECK(!skel, "open and load skel", "failed")) | ^~~~~ ./test_progs.h:129:25: note: each undeclared identifier is reported only on= ce for each function it appears in 129 | _CHECK(condition, tag, duration, format) | ^~~~~~~~ ./test_progs.h:111:25: note: in definition of macro =E2=80=98_CHECK=E2=80=99 111 | __func__, tag, duration); \ | ^~~~~~~~ /home/jbrouer/git/kernel/bpf-next/tools/testing/selftests/bpf/prog_tests/ch= eck_mtu.c:33:6: note: in expansion of macro =E2=80=98CHECK=E2=80=99 33 | if (CHECK(!skel, "open and load skel", "failed")) | ^~~~~ make: *** [Makefile:396: /home/jbrouer/git/kernel/bpf-next/tools/testing/se= lftests/bpf/check_mtu.test.o] Error 1