Message ID | 20240906132909.78886-4-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | tests/unit: Slightly expand FIFO8 tests | expand |
On 06/09/2024 14:29, Philippe Mathieu-Daudé wrote: > Add comments describing how the FIFO evolves during each test. > > Signed-off-by: Philippe Mathieu-Daudé <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); Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> ATB, Mark.
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);
Add comments describing how the FIFO evolves during each test. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- tests/unit/test-fifo.c | 188 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 187 insertions(+), 1 deletion(-)