From nobody Mon Sep 30 12:23:43 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XHKxD4TQrz5YCs3; Mon, 30 Sep 2024 12:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XHKxD0Rd2z4LYJ; Mon, 30 Sep 2024 12:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727699024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PMS2ks4TAjIM5hDICj6ulTdRKiTwKHZJjM/g3OI4siY=; b=Wm482MnD+dr1qkKcbRF8iSIsat7G2yfNiDia84R99/FJnR0tANKXk8MRMyrC0GEG66Ulfs ygonRkJ8harrmhfwlagUzCPFSo2xUiXKnB/9NYktDjEu3tcubPS+pniuZEzSwvH72nFiyK RJp+Gxe1S8hIDl4b0x/CuFLIAER1P1Fdh2ujrHMTtrspfgK40DyIDc6aTjH+i0xeOz8hf4 AkqZNleGd5IZD5IPlCWaGletOmFt1NQBXBnx2CdOItgmNde6fEcYO0Hwt32kTHNoNHrAMA Z+efiOdTMcDXSkzhR4YULBj4yGSQ6NSRkbs849mLJ/1eqZQG+DiLTwjzQsf5oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727699024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PMS2ks4TAjIM5hDICj6ulTdRKiTwKHZJjM/g3OI4siY=; b=gN3/dZsRaNtlw7ExdbPEqUSOalQClgQIBQfLlXa348MAvP0YC3lVCsw3Xblo4aFYJoJw8J WINa/D0ehbDUlMXHPq3xr3GYJw20KcTlU4jRpx2d4agkUft2A1QcQfvMKoYThKEq7pLKRe 0JqJ3nL6yTX5vSqv+n10AkJtWqUP4uWZzr3fZRsC498/2SECzBkxKGacl6EOT+NIHVIAJD 2cZPksOoUhTTfeMaK7M0X+HJ+AMeEDizYnu12sMnVsUlpwwzh3pXXsEyTczgMVISqgTlj8 51poxzf6pfUP054In9Xf6v+vezcHgZaKdqazvR+cLKdxo7jU40Sz6hInsfp8rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727699024; a=rsa-sha256; cv=none; b=uTu7fQbcrNjgV4j7MnqVvgQ202m9gnB3HYgalOcoWUmRRUMmSvL/6MJ0cvRKvzTy9OQZhn lpcqjWH03ZPHOmPKj9n1sdXsuxooSFpMd8CSqkY+uW3pKSJwLd/ym7K0ol/Nx3uZoZDXhm nq+pyt/Gyf5AR00xWwM+Hz351ttu5LRrrw73DEc6klJ3dcsodK+klnDs6MDtionePRA/mi y5judHtUNT3mVLlHGe62gJ50AT+d0GZNk1wSK84osDksejIcHMWcpKrtAON44GdQriEOYx F3BZXbHPrP0nVUEI0VQSyW6R77oD+AN2TClGRbC0Wr0zBYHxHWuI+M89Eb997Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XHKxD01x8ztBx; Mon, 30 Sep 2024 12:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48UCNhvm071206; Mon, 30 Sep 2024 12:23:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48UCNhil071203; Mon, 30 Sep 2024 12:23:43 GMT (envelope-from git) Date: Mon, 30 Sep 2024 12:23:43 GMT Message-Id: <202409301223.48UCNhil071203@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: a707b81ccb31 - main - tests: Add a buf_ring test List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a707b81ccb31e621f2e0325de150d730ed717419 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=a707b81ccb31e621f2e0325de150d730ed717419 commit a707b81ccb31e621f2e0325de150d730ed717419 Author: Andrew Turner AuthorDate: 2024-09-27 15:13:25 +0000 Commit: Andrew Turner CommitDate: 2024-09-30 12:04:23 +0000 tests: Add a buf_ring test Add a simple test for sys/buf_ring.h. This enqueues and dequeues items in the buf_ring to ensure the simple operations are correct. There are no checks for multiple threads operating on buf_ring_enqueue or buf_ring_dequeue_mc as they can be probabilistic and depend on the architecture memory model. Reviewed by: markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46147 --- tests/sys/sys/Makefile | 1 + tests/sys/sys/buf_ring_test.c | 126 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/tests/sys/sys/Makefile b/tests/sys/sys/Makefile index 8d9cd552d9d2..40060911856f 100644 --- a/tests/sys/sys/Makefile +++ b/tests/sys/sys/Makefile @@ -5,6 +5,7 @@ TESTSDIR= ${TESTSBASE}/sys/sys ATF_TESTS_C= arb_test \ bitset_test \ bitstring_test \ + buf_ring_test \ qmath_test \ rb_test \ splay_test \ diff --git a/tests/sys/sys/buf_ring_test.c b/tests/sys/sys/buf_ring_test.c new file mode 100644 index 000000000000..5ee1b1cc094b --- /dev/null +++ b/tests/sys/sys/buf_ring_test.c @@ -0,0 +1,126 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Arm Ltd + */ + +#include + +#include +#include + +#include + +#include + +static void critical_enter(void); +static void critical_exit(void); + +#include + +static void +critical_enter(void) +{ +} + +static void +critical_exit(void) +{ +} + +static void * +buf_ring_dequeue_peek(struct buf_ring *br) +{ + void *val; + + val = buf_ring_peek(br); + if (val != NULL) + buf_ring_advance_sc(br); + return (val); +} + +static void * +buf_ring_dequeue_peek_clear_sc(struct buf_ring *br) +{ + void *val; + + val = buf_ring_peek_clear_sc(br); + if (val != NULL) + buf_ring_advance_sc(br); + return (val); +} + +#define MC_SC_TEST(dequeue_func) \ +ATF_TC_WITHOUT_HEAD(dequeue_func); \ +ATF_TC_BODY(dequeue_func, tc) \ +{ \ + struct buf_ring *br; \ + \ + br = buf_ring_alloc(4); \ + ATF_REQUIRE_MSG(br != NULL, "buf_ring_alloc returned NULL"); \ + \ + ATF_REQUIRE(dequeue_func(br) == NULL); \ + ATF_REQUIRE(buf_ring_count(br) == 0); \ + ATF_REQUIRE(!buf_ring_full(br)); \ + ATF_REQUIRE(buf_ring_empty(br)); \ + \ + /* Try filling the buf_ring */ \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)1) == 0); \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)2) == 0); \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)3) == 0); \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)4) == ENOBUFS); \ + \ + ATF_REQUIRE(buf_ring_count(br) == 3); \ + ATF_REQUIRE(buf_ring_full(br)); \ + ATF_REQUIRE(!buf_ring_empty(br)); \ + \ + /* Partially empty it */ \ + ATF_REQUIRE(dequeue_func(br) == (void *)1); \ + ATF_REQUIRE(dequeue_func(br) == (void *)2); \ + \ + ATF_REQUIRE(buf_ring_count(br) == 1); \ + ATF_REQUIRE(!buf_ring_full(br)); \ + ATF_REQUIRE(!buf_ring_empty(br)); \ + \ + /* Add more items */ \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)5) == 0); \ + ATF_REQUIRE(buf_ring_count(br) == 2); \ + \ + /* Finish emptying it */ \ + ATF_REQUIRE(dequeue_func(br) == (void *)3); \ + ATF_REQUIRE(dequeue_func(br) == (void *)5); \ + ATF_REQUIRE(dequeue_func(br) == NULL); \ + \ + ATF_REQUIRE(buf_ring_count(br) == 0); \ + ATF_REQUIRE(!buf_ring_full(br)); \ + ATF_REQUIRE(buf_ring_empty(br)); \ + \ + for (uintptr_t i = 0; i < 8; i++) { \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)(i + 100)) == 0); \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)(i + 200)) == 0); \ + ATF_REQUIRE(buf_ring_enqueue(br, (void *)(i + 300)) == 0); \ + ATF_REQUIRE(buf_ring_count(br) == 3); \ + ATF_REQUIRE(dequeue_func(br) == (void *)(i + 100)); \ + ATF_REQUIRE(dequeue_func(br) == (void *)(i + 200)); \ + ATF_REQUIRE(dequeue_func(br) == (void *)(i + 300)); \ + \ + ATF_REQUIRE(!buf_ring_full(br)); \ + ATF_REQUIRE(buf_ring_empty(br)); \ + } \ + \ + buf_ring_free(br); \ +} + +MC_SC_TEST(buf_ring_dequeue_sc) +MC_SC_TEST(buf_ring_dequeue_mc) +MC_SC_TEST(buf_ring_dequeue_peek) +MC_SC_TEST(buf_ring_dequeue_peek_clear_sc) + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, buf_ring_dequeue_sc); + ATF_TP_ADD_TC(tp, buf_ring_dequeue_mc); + ATF_TP_ADD_TC(tp, buf_ring_dequeue_peek); + ATF_TP_ADD_TC(tp, buf_ring_dequeue_peek_clear_sc); + return (atf_no_error()); +}