Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp736643lqe; Sun, 7 Apr 2024 01:10:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9rHDAqfxwzXLWdNe+RJ1Ge0eJ/U8rMumtQmoEnp8jzWcarkNIXPCHrXURaJGNCvLg9GpZXkLmCsNAHXWWlSylw8F79KMf1FFuTu8nRQ== X-Google-Smtp-Source: AGHT+IEBc3ISnFVp4J4buXhxpGLs+xMdQZJAIl+W8jXybCUyVIXtpRrpjXLVOHXztuAHxX620kI3 X-Received: by 2002:a17:902:c20d:b0:1e2:59d8:be7c with SMTP id 13-20020a170902c20d00b001e259d8be7cmr5978652pll.25.1712477418236; Sun, 07 Apr 2024 01:10:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712477418; cv=pass; d=google.com; s=arc-20160816; b=erLKCkyqhFF0CwHXyrLX88ib4tzxlRI1E2dzZRjTYTlwcSZzedskdVGbgQr+T0Em7q VM0IcPJgXt2f4OCVx+mk+bAMrxRfi80wt7hgJ1afkgbfXETfsEZ2gj6nH0EBGvSZw2FL nlKg3KPWlm/JcZL9roToBCohUX7pTI95nz+dFY21x/WmwWg5tsZKoByGEAlyZlxHhICc 6NH2Fyy5ex2Cbh+9jZs75WwsUinLUn2Eon+3LyFpSS1MyckYZmKwLK0cVMzwecnBJPl1 vxHUE305W9v2h7TPQL7loMJ9x1vg0fjFczV8IO/5IUdUlhzjfsfFcZZu1BfT7Eq+oLkS DAIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MRAOR6NXs+WDh7P3Pk4nsf9IHt46kV2t0C6KeL8Xd0c=; fh=t7FziRFM21VS7l+vIyAAeKQakPhAxrSwCj5REIQZV0A=; b=EzDIgBz5jygXza7VwmlmbIHIEcFfrhviSPwMQ9CsVecx2xl2bP6eFgU8HPLNy+ekQZ eQhK/L/G5xa4z7uQr/9d3DB9WevilvrFXu/UO57rWr37xO8rfPLtbzyLKP9bajDFsuRv VIh66ot8Dy5hV6JVJzZ9oELFq6x9dE2wgpC0C1K9uDPcvpiBEszAou7LKoGEdZS9Mnrf cdKbc/tcfh5bqUSbQy7h2qF4BieJ0hlUnxulZYI1HdXtxBwTCHfv0utgo50w2/MLRWrQ CDLNthHTPzFWh3krtSuOfPsHLlkFtkCe4q2JMIrRaNjaFfFPMBAu2U2sF+wtoQDD2X8o rMZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=b9p9hNm0; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-134246-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a15-20020a170902eccf00b001e0b0353f10si4344850plh.116.2024.04.07.01.10.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 01:10:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134246-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=b9p9hNm0; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-134246-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CE272282475 for ; Sun, 7 Apr 2024 08:10:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FD54111A8; Sun, 7 Apr 2024 08:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="b9p9hNm0" Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46400107A8 for ; Sun, 7 Apr 2024 08:10:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477410; cv=none; b=QX0S3Xa1qSXJ0D5SlIC3GOCgvyCa/oehhN9FSHEChJtqVjDKc7qn5+Izu2Fr8NC+V7G5+F12zxRPcC7zo2IG05JbqZoElkXbTsSFk7X7YMSv5wIZ2GGM04nNBDV7H14PFZwsTAZpwWIRYJkGq9m0ISjbFKuwLCFSBfFmUGnP2f8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477410; c=relaxed/simple; bh=VBnMmaY/jSdSTkC4TB/mxJq/6u5SVhMScG2xHkwOpHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TU4dNV+9t3vAxnnR/b5F1PSpE9zqf4WaNbeTaXAJeh5LO6DSLiPeHAX72eTYP/K01b18totEMvf6FwcjESYD+uHMo/DQDucm31jT09/eU33CDIsu1cmK3Id7S7qe0+utJ3tZLIpgkFVWATWMsiYWVMnHwFF551IT6o5pp1PpQ9c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=b9p9hNm0; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id C4D7E3FE51 for ; Sun, 7 Apr 2024 08:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1712477400; bh=MRAOR6NXs+WDh7P3Pk4nsf9IHt46kV2t0C6KeL8Xd0c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=b9p9hNm0mjZX6AOvcv6/CZTiNMgZ68/IlpQlXKJraDA4sV2vZnbuKpZAr4Jxy3nXU qwfPk4IREfZk/yQmCi2dpTWhZ2FGPhLlnMN8GqeqxkJcEcId052qJUN5IGwk6jXXRp sO/x78hgUw6aSNs4bcLEQSc9KKo/xc6L6BL3M3JNTKOvBAC075NQM2Q99Dpa87eb2H DeJl9Fz+D1pBZO3IljJ1UAwdc1v7YLLH/iT0CSjb4J9NvBWojIaIGmGO++xfFSleW7 Cdct/kBvB0yqxEJF1kQtwxoG+BqN914Bf/OfFlSNvC7+onGa1VrypNU9b532WnMFnv E8rWtdfjMzdjQ== Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-343da0a889dso1826763f8f.0 for ; Sun, 07 Apr 2024 01:10:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712477399; x=1713082199; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MRAOR6NXs+WDh7P3Pk4nsf9IHt46kV2t0C6KeL8Xd0c=; b=OFMg9lJG1dwVY4gLOyr4nnJFKVwmR5AxJFksZZFhfprIdiDqkwcVTlXMSqpOVip4kY LJEXOb5J8J2ap1b9pob/FDK22m1E15ntsF0AgcxevmwnbXPmqUJxLZ3KbXU368lLDWaG m1ceAU4JfnCZ8JXkuuHwSpGyV+a45YiEtm6ekSgilHU/QKVHmNN27D2wB53r+q5AHXrf GMPevF9xQQZYFcNPW4EEUBOrtCC9mqDjY6kbIWohrXfrf6vYECVqh/z8c0ck6I9AJovI dH8b0613h1KAe0qiETU08IbfjGAu4lnHCS1eDXo9T14GLr5O3irDjGe2X6EiiEqv08xN s6kA== X-Forwarded-Encrypted: i=1; AJvYcCXpMjCFASoPHZNtK+Gq3vW65BgHYCPPhDgtNfAXInfWxVskmb23GoRmdjCFfTxThRT0geNkBDad3Yvqwf49FxKFfIAQo6YpPz1xM5CV X-Gm-Message-State: AOJu0Yzls3XhXZFBM5fa3Y4XXVIoQAUMxDqa+SoNsR5+J1B+bKKTWaHx 6kk9EJbEpxwTuuYgLh6J4xlr3h3VBKGHIdY5yoPjNTvM7xC7mBjfAwZEEc7OxMjOj1gno8RnJgP +Eez9pe6xh/d1/PixSLonYqxX7GwlT99mbvNbs/dGNWD775+gETZB0t3F3CzOg8x42LAaXQcder QnHg== X-Received: by 2002:adf:fed1:0:b0:343:a183:4218 with SMTP id q17-20020adffed1000000b00343a1834218mr4431409wrs.52.1712477394381; Sun, 07 Apr 2024 01:09:54 -0700 (PDT) X-Received: by 2002:adf:fed1:0:b0:343:a183:4218 with SMTP id q17-20020adffed1000000b00343a1834218mr4431370wrs.52.1712477393487; Sun, 07 Apr 2024 01:09:53 -0700 (PDT) Received: from localhost (net-2-39-142-110.cust.vodafonedsl.it. [2.39.142.110]) by smtp.gmail.com with ESMTPSA id q13-20020a056000136d00b00343e3023fbasm5866411wrz.34.2024.04.07.01.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 01:09:52 -0700 (PDT) Date: Sun, 7 Apr 2024 10:09:47 +0200 From: Andrea Righi To: Andrii Nakryiko Cc: Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Vernet , Tejun Heo , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 4/4] selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n Message-ID: References: <20240406092005.92399-1-andrea.righi@canonical.com> <20240406092005.92399-5-andrea.righi@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Sat, Apr 06, 2024 at 10:52:10AM -0700, Andrii Nakryiko wrote: > On Sat, Apr 6, 2024 at 10:39 AM Andrii Nakryiko > wrote: > > > > On Sat, Apr 6, 2024 at 2:20 AM Andrea Righi wrote: > > > > > > Add tests for new API ring__consume_n() and ring_buffer__consume_n(). > > > > > > Signed-off-by: Andrea Righi > > > --- > > > tools/testing/selftests/bpf/prog_tests/ringbuf.c | 8 ++++++++ > > > 1 file changed, 8 insertions(+) > > > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > > index 48c5695b7abf..33aba7684ab9 100644 > > > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > > @@ -304,10 +304,18 @@ static void ringbuf_subtest(void) > > > err = ring_buffer__consume(ringbuf); > > > CHECK(err < 0, "rb_consume", "failed: %d\b", err); > > > > > > + /* try to consume up to one item */ > > > + err = ring_buffer__consume_n(ringbuf, 1); > > > + CHECK(err < 0 || err > 1, "rb_consume_n", "failed: %d\b", err); > > > + > > > /* also consume using ring__consume to make sure it works the same */ > > > err = ring__consume(ring); > > > ASSERT_GE(err, 0, "ring_consume"); > > > > > > + /* try to consume up to one item */ > > > + err = ring__consume_n(ring, 1); > > > + CHECK(err < 0 || err > 1, "ring_consume_n", "failed: %d\b", err); > > > + > > > > Did you actually run this test? There is ring_buffer__consume() and > > ring__consume() calls right before your added calls, so consume_n will > > return zero. > > > > I dropped this broken patch. Please send a proper test as a follow up. > > Sorry, technically, it's not broken, it just doesn't test much (CHECK > conditions confused me, I didn't realize you allow zero initially). We > will never consume anything and the result will be zero, which isn't > very meaningful. > > "Interesting" test would set up things so that we have >1 item in > ringbuf and we consume exactly one at a time, because that's the new > logic you added. > > I think it will be simpler to add a dedicated and simpler ringbuf test > for this, where you can specify how many items to submit, and then do > a bunch of consume/consume_n invocations, checking exact results. > > Plus, please don't add new CHECK() uses, use ASSERT_XXX() ones instead. > > I've applied first three patches because they look correct and it's > good to setup libbpf 1.5 dev cycle, but please do follow up with a > better test. Thanks. Yeah, sorry, I tried to add a minimal test to the existing one, but I agree that it not very meaningful. I already have a better dedicated test case for this (https://github.com/arighi/ebpf-maps/blob/libbpf-consume-n/src/main.c#L118), I just need to integrate it in the kselftest properly (and maybe pre-generate more than N records in the ring buffer, so that we can better test if the limit works as expected). I'll send another patch to add a proper test case. Thanks for applying the other patches! -Andrea > > > > > > /* 3 rounds, 2 samples each */ > > > cnt = atomic_xchg(&sample_cnt, 0); > > > CHECK(cnt != 6, "cnt", "exp %d samples, got %d\n", 6, cnt); > > > -- > > > 2.43.0 > > >