summaryrefslogtreecommitdiff
path: root/src/kernel/tests/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/tests/util.c')
-rw-r--r--src/kernel/tests/util.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/kernel/tests/util.c b/src/kernel/tests/util.c
index e7dcb82..2442d47 100644
--- a/src/kernel/tests/util.c
+++ b/src/kernel/tests/util.c
@@ -1,5 +1,6 @@
#include <kernel/tests/base.h>
#include <kernel/tests/tests.h>
+#include <shared/container/ring.h>
#include <shared/mem.h>
TEST(memcmp) {
@@ -30,7 +31,37 @@ TEST(strcmp) {
TEST_COND(0 != strcmp("stress", "string"));
}
+TEST(ring) {
+ char buf[16], backbuf[16];
+ size_t num_read = 0, num_written = 0;
+ uint8_t c;
+
+ ring_t r = {backbuf, 16, 0, 0};
+
+ TEST_COND(ring_size(&r) == 0);
+ for (size_t i = 0; i < 7; i++)
+ ring_put1b(&r, num_written++);
+ TEST_COND(ring_size(&r) == 7);
+ for (size_t i = 0; i < 3; i++) {
+ ring_get(&r, &c, 1);
+ TEST_COND(num_read++ == c);
+ }
+ TEST_COND(ring_size(&r) == 4);
+
+ for (size_t j = 0; j < 40; j++) {
+ for (size_t i = 0; i < 7; i++)
+ ring_put1b(&r, num_written++ & 0xff);
+ TEST_COND(ring_size(&r) == 11);
+ for (size_t i = 0; i < 7; i++) {
+ ring_get(&r, &c, 1);
+ TEST_COND((num_read++ & 0xff) == c);
+ }
+ TEST_COND(ring_size(&r) == 4);
+ }
+}
+
void tests_utils(void) {
TEST_RUN(memcmp);
TEST_RUN(strcmp);
+ TEST_RUN(ring);
}