Skip to contentSkip to conversation

tests/unit: Slightly expand FIFO8 tests

PATCH In review Philippe Mathieu-Daudé 2 participants 9 messages Sep 6, 2024 – Sep 7, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover tests/unit: Slightly expand FIFO8 tests

Since v1:
- Correctly place patch hunks in corresponding patch

Mostly add documentation while reviewing them.

Based-on: <[email protected]>

Philippe Mathieu-Daudé (3):
tests/unit: Strengthen FIFO8 tests tests/unit: Expand test_fifo8_peek_buf_wrap() coverage tests/unit: Comment FIFO8 tests

 tests/unit/test-fifo.c | 209 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 201 insertions(+), 8 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/3 tests/unit: Strengthen FIFO8 tests

Replace reused bytes { 0x1, 0x2, 0x3, 0x4 } by { 0x9, 0xa, 0xb, 0xc } to be sure a different value is overwritten.

---
 tests/unit/test-fifo.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/unit/test-fifo.c +6 -6
index 1e54cde871..9b3a4940d0 100644
@@ -22,7 +22,7 @@ static void test_fifo8_pop_bufptr_wrap(void)
 {
     Fifo8 fifo;
     uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa };
     const uint8_t *buf;
     uint32_t count;
 
@@ -65,7 +65,7 @@ static void test_fifo8_peek_bufptr_wrap(void)
 {
     Fifo8 fifo;
     uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa };
     const uint8_t *buf;
     uint32_t count;
 
@@ -112,7 +112,7 @@ static void test_fifo8_pop_buf_wrap(void)
 {
     Fifo8 fifo;
     uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
     uint8_t data_out[4];
     int count;
 
@@ -126,8 +126,8 @@ static void test_fifo8_pop_buf_wrap(void)
     g_assert(count == 4);
     count = fifo8_pop_buf(&fifo, data_out, 4);
     g_assert(count == 4);
-    g_assert(data_out[0] == 0x1 && data_out[1] == 0x2 &&
-             data_out[2] == 0x3 && data_out[3] == 0x4);
+    g_assert(data_out[0] == 0x9 && data_out[1] == 0xa &&
+             data_out[2] == 0xb && data_out[3] == 0xc);
 
     g_assert(fifo8_num_used(&fifo) == 0);
     fifo8_destroy(&fifo);
@@ -157,7 +157,7 @@ static void test_fifo8_peek_buf_wrap(void)
 {
     Fifo8 fifo;
     uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
     uint8_t data_out[4];
     int count;
 
Signature · 1 line
2.45.2
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] tests/unit: Strengthen FIFO8 tests

Quoted 51 lines · Philippe Mathieu-Daudé

Replace reused bytes { 0x1, 0x2, 0x3, 0x4 } by { 0x9, 0xa, 0xb, 0xc } to be sure a different value is overwritten.

---
  tests/unit/test-fifo.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
tests/unit/test-fifo.c +5 -5
index 1e54cde871..9b3a4940d0 100644
@@ -22,7 +22,7 @@ static void test_fifo8_pop_bufptr_wrap(void)
  {
      Fifo8 fifo;
      uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa };
      const uint8_t *buf;
      uint32_t count;
 
@@ -65,7 +65,7 @@ static void test_fifo8_peek_bufptr_wrap(void)
  {
      Fifo8 fifo;
      uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa };
      const uint8_t *buf;
      uint32_t count;
 
@@ -112,7 +112,7 @@ static void test_fifo8_pop_buf_wrap(void)
  {
      Fifo8 fifo;
      uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
      uint8_t data_out[4];
      int count;
 
@@ -126,8 +126,8 @@ static void test_fifo8_pop_buf_wrap(void)
      g_assert(count == 4);
      count = fifo8_pop_buf(&fifo, data_out, 4);
      g_assert(count == 4);
-    g_assert(data_out[0] == 0x1 && data_out[1] == 0x2 &&
-             data_out[2] == 0x3 && data_out[3] == 0x4);
+    g_assert(data_out[0] == 0x9 && data_out[1] == 0xa &&
+             data_out[2] == 0xb && data_out[3] == 0xc);
 
      g_assert(fifo8_num_used(&fifo) == 0);
      fifo8_destroy(&fifo);

tests/unit/test-fifo.c static void test_fifo8_peek_buf_wrap(void) · line 162

Quoted 7 lines
tests/unit/test-fifo.c +1 -1
@@ -157,7 +157,7 @@ static void test_fifo8_peek_buf_wrap(void)
  {
      Fifo8 fifo;
      uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
-    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 };
+    uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
      uint8_t data_out[4];
      int count;

That's a fair point: otherwise it could be easier for a bug in the Fifo8 implementation to slip through:

ATB,

Mark.

#3 lore raw

PATCH v2 2/3 tests/unit: Expand test_fifo8_peek_buf_wrap() coverage

In reply to Philippe Mathieu-Daudé

Test fifo8_peek_buf() can fill a buffer with wrapped data.

---
 tests/unit/test-fifo.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/unit/test-fifo.c +8 -1
index 9b3a4940d0..fada526b6c 100644
@@ -158,7 +158,7 @@ static void test_fifo8_peek_buf_wrap(void)
     Fifo8 fifo;
     uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
     uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
-    uint8_t data_out[4];
+    uint8_t data_out[8];
     int count;
 
     fifo8_create(&fifo, 8);
@@ -174,6 +174,13 @@ static void test_fifo8_peek_buf_wrap(void)
     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);
+    g_assert(count == 8);
+    g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
+             data_out[2] == 0x7 && data_out[3] == 0x8);
+    g_assert(data_out[4] == 0x9 && data_out[5] == 0xa &&
+             data_out[6] == 0xb && data_out[7] == 0xc);
+
     g_assert(fifo8_num_used(&fifo) == 8);
     fifo8_destroy(&fifo);
 }
Signature · 1 line
2.45.2
Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] tests/unit: Expand test_fifo8_peek_buf_wrap() coverage

Quoted 24 lines · Philippe Mathieu-Daudé

Test fifo8_peek_buf() can fill a buffer with wrapped data.

---
  tests/unit/test-fifo.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
tests/unit/test-fifo.c +1 -1
index 9b3a4940d0..fada526b6c 100644
@@ -158,7 +158,7 @@ static void test_fifo8_peek_buf_wrap(void)
      Fifo8 fifo;
      uint8_t data_in1[] = { 0x1, 0x2, 0x3, 0x4 };
      uint8_t data_in2[] = { 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
-    uint8_t data_out[4];
+    uint8_t data_out[8];
      int count;
 
      fifo8_create(&fifo, 8);
@@ -174,6 +174,13 @@ static void test_fifo8_peek_buf_wrap(void)
      g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
               data_out[2] == 0x7 && data_out[3] == 0x8);
 

tests/unit/test-fifo.c static void test_fifo8_peek_buf_wrap(void) · line 186

Quoted 10 lines
tests/unit/test-fifo.c +7 -0
+    count = fifo8_peek_buf(&fifo, data_out, 8);
+    g_assert(count == 8);
+    g_assert(data_out[0] == 0x5 && data_out[1] == 0x6 &&
+             data_out[2] == 0x7 && data_out[3] == 0x8);
+    g_assert(data_out[4] == 0x9 && data_out[5] == 0xa &&
+             data_out[6] == 0xb && data_out[7] == 0xc);
+
      g_assert(fifo8_num_used(&fifo) == 8);
      fifo8_destroy(&fifo);
  }

ATB,

Mark.

#5 lore raw

PATCH v2 3/3 tests/unit: Comment FIFO8 tests

In reply to Philippe Mathieu-Daudé

Add comments describing how the FIFO evolves during each test.

---
 tests/unit/test-fifo.c | 188 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 187 insertions(+), 1 deletion(-)
tests/unit/test-fifo.c +187 -1
index fada526b6c..14153c41fa 100644
@@ -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);
Signature · 1 line
2.45.2
Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] tests/unit: Comment FIFO8 tests

Quoted 328 lines · Philippe Mathieu-Daudé

Add comments describing how the FIFO evolves during each test.

---
  tests/unit/test-fifo.c | 188 ++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 187 insertions(+), 1 deletion(-)
tests/unit/test-fifo.c +182 -1
index fada526b6c..14153c41fa 100644
@@ -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 . . . . . . }

tests/unit/test-fifo.c static void test_fifo8_pushpop(void) · line 431

Quoted 10 lines
tests/unit/test-fifo.c +5 -0
+     */
      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);

ATB,

Mark.

#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Since v1:
- Correctly place patch hunks in corresponding patch

Mostly add documentation while reviewing them.

Based-on: <[email protected]>

Quoted 7 lines

Philippe Mathieu-Daudé (3):
tests/unit: Strengthen FIFO8 tests tests/unit: Expand test_fifo8_peek_buf_wrap() coverage tests/unit: Comment FIFO8 tests

  tests/unit/test-fifo.c | 209 +++++++++++++++++++++++++++++++++++++++--
  1 file changed, 201 insertions(+), 8 deletions(-)

This is great! Thanks for taking the time to review the Fifo8 patches in enough detail to be able to produce the ASCII art :)

ATB,

Mark.

#8 lore raw
Quoted 9 lines · Mark Cave-Ayland
Quoted 7 lines

Philippe Mathieu-Daudé (3):
   tests/unit: Strengthen FIFO8 tests tests/unit: Expand test_fifo8_peek_buf_wrap() coverage tests/unit: Comment FIFO8 tests

  tests/unit/test-fifo.c | 209 +++++++++++++++++++++++++++++++++++++++--

  1 file changed, 201 insertions(+), 8 deletions(-)

This is great! Thanks for taking the time to review the Fifo8 patches in enough detail to be able to produce the ASCII art :)

Series queued, thanks!