Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107724079
D46147.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D46147.diff
View Options
diff --git a/tests/sys/sys/Makefile b/tests/sys/sys/Makefile
--- a/tests/sys/sys/Makefile
+++ b/tests/sys/sys/Makefile
@@ -5,6 +5,7 @@
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
--- /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 <sys/types.h>
+
+#include <machine/cpu.h>
+#include <machine/cpufunc.h>
+
+#include <errno.h>
+
+#include <atf-c.h>
+
+static void critical_enter(void);
+static void critical_exit(void);
+
+#include <sys/buf_ring.h>
+
+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());
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 18, 7:37 PM (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15886733
Default Alt Text
D46147.diff (3 KB)
Attached To
Mode
D46147: tests: Add a buf_ring test
Attached
Detach File
Event Timeline
Log In to Comment