From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>
Subject: [PULL 43/56] tests/unit: Comment FIFO8 tests
Date: Wed, 11 Sep 2024 14:14:08 +0200 [thread overview]
Message-ID: <20240911121422.52585-44-philmd@linaro.org> (raw)
In-Reply-To: <20240911121422.52585-1-philmd@linaro.org>
Add comments describing how the FIFO evolves during each test.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20240906132909.78886-4-philmd@linaro.org>
---
tests/unit/test-fifo.c | 188 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 187 insertions(+), 1 deletion(-)
diff --git a/tests/unit/test-fifo.c b/tests/unit/test-fifo.c
index fada526b6c..14153c41fa 100644
--- a/tests/unit/test-fifo.c
+++ b/tests/unit/test-fifo.c
@@ -27,14 +27,36 @@ static void test_fifo8_pop_bufptr_wrap(void)
uint32_t count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: [ . . . . . . . . ]
+ */
fifo8_push_all(&fifo, data_in1, sizeof(data_in1));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: [ 1 2 3 4 . . . . ]
+ */
buf = fifo8_pop_bufptr(&fifo, 2, &count);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: [ 1 2 3 4 . . . . ]
+ * buf --^ count = 2
+ */
g_assert(count == 2);
g_assert(buf[0] == 0x1 && buf[1] == 0x2);
fifo8_push_all(&fifo, data_in2, sizeof(data_in2));
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: [ 9 a 3 4 5 6 7 8 ]
+ */
buf = fifo8_pop_bufptr(&fifo, 8, &count);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: [ 9 a 3 4 5 6 7 8 ]
+ * buf --^ count = 6
+ */
g_assert(count == 6);
g_assert(buf[0] == 0x3 && buf[1] == 0x4 && buf[2] == 0x5 &&
buf[3] == 0x6 && buf[4] == 0x7 && buf[5] == 0x8);
@@ -51,9 +73,22 @@ static void test_fifo8_pop_bufptr(void)
uint32_t count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: [ . . . . . . . . ]
+ */
fifo8_push_all(&fifo, data_in, sizeof(data_in));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: [ 1 2 3 4 . . . . ]
+ */
buf = fifo8_pop_bufptr(&fifo, 2, &count);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: [ 1 2 3 4 . . . . ]
+ * buf --^ count = 2
+ */
g_assert(count == 2);
g_assert(buf[0] == 0x1 && buf[1] == 0x2);
@@ -70,18 +105,45 @@ static void test_fifo8_peek_bufptr_wrap(void)
uint32_t count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in1, sizeof(data_in1));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
buf = fifo8_peek_bufptr(&fifo, 2, &count);
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ * buf: [ 1 2 ] count = 2
+ */
g_assert(count == 2);
g_assert(buf[0] == 0x1 && buf[1] == 0x2);
buf = fifo8_pop_bufptr(&fifo, 2, &count);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: { 1 2 3 4 . . . . }
+ * buf: [ 1 2 ] count = 2
+ */
g_assert(count == 2);
g_assert(buf[0] == 0x1 && buf[1] == 0x2);
fifo8_push_all(&fifo, data_in2, sizeof(data_in2));
+ /*
+ * tail ---]v-- head used = 8
+ * FIFO: { 9 a 3 4 5 6 7 8 }
+ */
buf = fifo8_peek_bufptr(&fifo, 8, &count);
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: { 9 a 3 4 5 6 7 8 }
+ * buf: [ 3 4 5 6 7 8 ] count = 6
+ */
g_assert(count == 6);
g_assert(buf[0] == 0x3 && buf[1] == 0x4 && buf[2] == 0x5 &&
buf[3] == 0x6 && buf[4] == 0x7 && buf[5] == 0x8);
@@ -98,9 +160,22 @@ static void test_fifo8_peek_bufptr(void)
uint32_t count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in, sizeof(data_in));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
buf = fifo8_peek_bufptr(&fifo, 2, &count);
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ * buf: [ 1 2 ] count = 2
+ */
g_assert(count == 2);
g_assert(buf[0] == 0x1 && buf[1] == 0x2);
@@ -117,14 +192,38 @@ static void test_fifo8_pop_buf_wrap(void)
int count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in1, sizeof(data_in1));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
fifo8_pop_buf(&fifo, NULL, 4);
+ /*
+ * tail --]v-- head used = 0
+ * FIFO: [ 1 2 3 4 . . . . ]
+ */
fifo8_push_all(&fifo, data_in2, sizeof(data_in2));
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: { 9 a b c 5 6 7 8 }
+ */
count = fifo8_pop_buf(&fifo, NULL, 4);
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 9 a b c 5 6 7 8 }
+ */
g_assert(count == 4);
count = fifo8_pop_buf(&fifo, data_out, 4);
+ /*
+ * tail --]v-- head used = 0
+ * FIFO: { 9 a b c 5 6 7 8 }
+ */
g_assert(count == 4);
g_assert(data_out[0] == 0x9 && data_out[1] == 0xa &&
data_out[2] == 0xb && data_out[3] == 0xc);
@@ -141,9 +240,21 @@ static void test_fifo8_pop_buf(void)
int count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in, sizeof(data_in));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
count = fifo8_pop_buf(&fifo, NULL, 4);
+ /*
+ * tail --]v-- head used = 0
+ * FIFO: { 1 2 3 4 . . . . }
+ */
g_assert(count == 4);
count = fifo8_pop_buf(&fifo, data_out, 4);
g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
@@ -162,19 +273,45 @@ static void test_fifo8_peek_buf_wrap(void)
int count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in1, sizeof(data_in1));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
fifo8_pop_buf(&fifo, NULL, 4);
+ /*
+ * tail --]v-- head used = 0
+ * FIFO: { 1 2 3 4 . . . . }
+ */
fifo8_push_all(&fifo, data_in2, sizeof(data_in2));
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: { 9 a b c 5 6 7 8 }
+ */
count = fifo8_peek_buf(&fifo, NULL, 4);
g_assert(count == 4);
count = fifo8_peek_buf(&fifo, data_out, 4);
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: { 9 a b c 5 6 7 8 }
+ * buf: [ 5 6 7 8 ] count = 4
+ */
g_assert(count == 4);
g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
data_out[2] == 0x7 && data_out[3] == 0x8);
count = fifo8_peek_buf(&fifo, data_out, 8);
+ /*
+ * tail --]v-- head used = 8
+ * FIFO: { 9 a b c 5 6 7 8 }
+ * buf: [ 5 6 7 8 9 a b c ] count = 8
+ */
g_assert(count == 8);
g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
data_out[2] == 0x7 && data_out[3] == 0x8);
@@ -193,14 +330,27 @@ static void test_fifo8_peek_buf(void)
int count;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push_all(&fifo, data_in, sizeof(data_in));
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ */
count = fifo8_peek_buf(&fifo, NULL, 4);
g_assert(count == 4);
+
g_assert(data_out[0] == 0xff && data_out[1] == 0xff &&
data_out[2] == 0xff && data_out[3] == 0xff);
-
count = fifo8_peek_buf(&fifo, data_out, 4);
+ /*
+ * head --v ]-- tail used = 4
+ * FIFO: { 1 2 3 4 . . . . }
+ * buf: [ 1 2 3 4 ] count = 4
+ */
g_assert(count == 4);
g_assert(data_out[0] == 0x1 && data_out[1] == 0x2 &&
data_out[2] == 0x3 && data_out[3] == 0x4);
@@ -215,12 +365,28 @@ static void test_fifo8_peek(void)
uint8_t c;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push(&fifo, 0x1);
+ /*
+ * head --v]-- tail used = 1
+ * FIFO: { 1 . . . . . . . }
+ */
fifo8_push(&fifo, 0x2);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: { 1 2 . . . . . . }
+ */
c = fifo8_peek(&fifo);
g_assert(c == 0x1);
fifo8_pop(&fifo);
+ /*
+ * head --v]-- tail used = 1
+ * FIFO: { 1 2 . . . . . . }
+ */
c = fifo8_peek(&fifo);
g_assert(c == 0x2);
@@ -234,12 +400,32 @@ static void test_fifo8_pushpop(void)
uint8_t c;
fifo8_create(&fifo, 8);
+ /*
+ * head --v-- tail used = 0
+ * FIFO: { . . . . . . . . }
+ */
fifo8_push(&fifo, 0x1);
+ /*
+ * head --v]-- tail used = 1
+ * FIFO: { 1 . . . . . . . }
+ */
fifo8_push(&fifo, 0x2);
+ /*
+ * head --v ]-- tail used = 2
+ * FIFO: { 1 2 . . . . . . }
+ */
c = fifo8_pop(&fifo);
+ /*
+ * head --v]-- tail used = 1
+ * FIFO: { 1 2 . . . . . . }
+ */
g_assert(c == 0x1);
c = fifo8_pop(&fifo);
+ /*
+ * tail --]v-- head used = 0
+ * FIFO: { 1 2 . . . . . . }
+ */
g_assert(c == 0x2);
g_assert(fifo8_num_used(&fifo) == 0);
--
2.45.2
next prev parent reply other threads:[~2024-09-11 12:34 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 12:13 [PULL 00/56] Misc HW & UI patches Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 01/56] hw/pci-host/designware: Declare CPU QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 02/56] hw/pci-host/designware: Add 'host_mem' variable for clarity Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 03/56] hw/intc/loongson_ipi: Remove unused headers Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 04/56] hw/sh4: Remove the deprecated SHIX machine Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 05/56] hw/block: Remove TC58128 NAND EEPROM Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 06/56] hw/sh4: Remove sh7750_register_io_device() helper Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 07/56] tests/tcg: Remove CRIS libc test files Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 08/56] tests/tcg: Remove CRIS bare " Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 09/56] buildsys: Remove CRIS cross container Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 10/56] linux-user: Remove support for CRIS target Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 11/56] hw/cris: Remove the axis-dev88 machine Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 12/56] hw/cris: Remove image loader helper Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 13/56] hw/intc: Remove TYPE_ETRAX_FS_PIC device Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 14/56] hw/char: Remove TYPE_ETRAX_FS_SERIAL device Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 15/56] hw/net: Remove TYPE_ETRAX_FS_ETH device Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 16/56] hw/dma: Remove ETRAX_FS DMA device Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 17/56] hw/timer: Remove TYPE_ETRAX_FS_TIMER device Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 18/56] system: Remove support for CRIS target Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 19/56] target/cris: Remove the deprecated " Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 20/56] seccomp: Remove check for CRIS host Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 21/56] target/riscv: Remove the deprecated 'any' CPU type Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 22/56] hw/audio/virtio-sound: fix heap buffer overflow Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 23/56] hw/char/pl011: Remove unused 'readbuff' field Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 24/56] hw/char/pl011: Move pl011_put_fifo() earlier Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 25/56] hw/char/pl011: Move pl011_loopback_enabled|tx() around Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 26/56] hw/char/pl011: Split RX/TX path of pl011_reset_fifo() Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 27/56] hw/char/pl011: Extract pl011_write_txdata() from pl011_write() Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 28/56] hw/char/pl011: Extract pl011_read_rxdata() from pl011_read() Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 29/56] hw/char/pl011: Warn when using disabled transmitter Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 30/56] hw/char/pl011: Rename RX FIFO methods Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 31/56] MAINTAINERS: Add myself as a reviewer of VT-d Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 32/56] fifo8: rename fifo8_peekpop_buf() to fifo8_peekpop_bufptr() Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 33/56] fifo8: introduce head variable for fifo8_peekpop_bufptr() Philippe Mathieu-Daudé
2024-09-11 12:13 ` [PULL 34/56] fifo8: add skip parameter to fifo8_peekpop_bufptr() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 35/56] fifo8: replace fifo8_pop_bufptr() with fifo8_peekpop_bufptr() in fifo8_pop_buf() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 36/56] fifo8: rename fifo8_pop_buf() to fifo8_peekpop_buf() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 37/56] fifo8: honour do_pop argument in fifo8_peekpop_buf() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 38/56] fifo8: add fifo8_peek_buf() function Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 39/56] fifo8: introduce fifo8_peek() function Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 40/56] tests/unit: add test-fifo unit test Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 41/56] tests/unit: Strengthen FIFO8 tests Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 42/56] tests/unit: Expand test_fifo8_peek_buf_wrap() coverage Philippe Mathieu-Daudé
2024-09-11 12:14 ` Philippe Mathieu-Daudé [this message]
2024-09-11 12:14 ` [PULL 44/56] hw/char/escc: convert Sun mouse to use QemuInputHandler Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 45/56] hw/input/adb-mouse: convert " Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 46/56] hw/char: replace assert(0) with g_assert_not_reached() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 47/56] hw/core: " Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 48/56] hw/watchdog: " Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 49/56] hw/gpio: remove break after g_assert_not_reached() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 50/56] hw/misc: " Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 51/56] hw/pci-host: " Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 52/56] system: replace assert(0) with g_assert_not_reached() Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 53/56] ui/sdl2: release all modifiers Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 54/56] ui/sdl2: ignore GUI keys in SDL_TEXTINPUT handler Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 55/56] ui/sdl2: set swap interval explicitly when OpenGL is enabled Philippe Mathieu-Daudé
2024-09-11 12:14 ` [PULL 56/56] ui: remove break after g_assert_not_reached() Philippe Mathieu-Daudé
2024-09-12 6:54 ` [PULL 00/56] Misc HW & UI patches Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240911121422.52585-44-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).