diff mbox

[FFmpeg-devel] Improved selftest coverage for libavutil/fifo.c

Message ID 1476340219-7282-1-git-send-email-thomastdt@gmail.com
State Superseded
Headers show

Commit Message

Thomas Turner Oct. 13, 2016, 6:30 a.m. UTC
Tested functions: av_fifo_generic_peek(), av_fifo_grow()
---
 libavutil/tests/fifo.c | 32 +++++++++++++++++++++++++++++++-
 tests/ref/fate/fifo    | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Oct. 13, 2016, 8:14 p.m. UTC | #1
On Wed, Oct 12, 2016 at 11:30:19PM -0700, Thomas Turner wrote:
> Tested functions: av_fifo_generic_peek(), av_fifo_grow()
> ---
>  libavutil/tests/fifo.c | 32 +++++++++++++++++++++++++++++++-
>  tests/ref/fate/fifo    | 43 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 74 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c
> index e4d7edf..4d598d3 100644
> --- a/libavutil/tests/fifo.c
> +++ b/libavutil/tests/fifo.c
> @@ -24,7 +24,7 @@ int main(void)
>  {
>      /* create a FIFO buffer */
>      AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
> -    int i, j, n;
> +    int i, j, n, *p;
>  
>      /* fill data */
>      for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
> @@ -46,6 +46,19 @@ int main(void)
>      }
>      printf("\n");
>  
> +    /* generic peek at FIFO */
> +
> +    n = av_fifo_size(fifo);
> +    p = malloc(n);

missing malloc() failure test


[...]
diff mbox

Patch

diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c
index e4d7edf..4d598d3 100644
--- a/libavutil/tests/fifo.c
+++ b/libavutil/tests/fifo.c
@@ -24,7 +24,7 @@  int main(void)
 {
     /* create a FIFO buffer */
     AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
-    int i, j, n;
+    int i, j, n, *p;
 
     /* fill data */
     for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
@@ -46,6 +46,19 @@  int main(void)
     }
     printf("\n");
 
+    /* generic peek at FIFO */
+
+    n = av_fifo_size(fifo);
+    p = malloc(n);
+    (void) av_fifo_generic_peek(fifo, p, n, NULL);
+
+    /* read data at p */
+    n /= sizeof(int);
+    for(i = 0; i < n; ++i)
+        printf("%d: %d\n", i, p[i]);
+
+    putchar('\n');
+
     /* read data */
     for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
         av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
@@ -67,8 +80,25 @@  int main(void)
         av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
         printf("%d: %d\n", i, j);
     }
+    putchar('\n');
+
+    /* test fifo_grow */
+    (void) av_fifo_grow(fifo, 15 * sizeof(int));
+
+    /* fill data */
+    n = av_fifo_size(fifo) / sizeof(int);
+    for (i = n; av_fifo_space(fifo) >= sizeof(int); ++i)
+        av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+
+    /* peek_at at FIFO */
+    n = av_fifo_size(fifo) / sizeof(int);
+    for (i = 0; i < n; i++) {
+        av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
+        printf("%d: %d\n", i, j);
+    }
 
     av_fifo_free(fifo);
+    free(p);
 
     return 0;
 }
diff --git a/tests/ref/fate/fifo b/tests/ref/fate/fifo
index 162d754..2b18ed5 100644
--- a/tests/ref/fate/fifo
+++ b/tests/ref/fate/fifo
@@ -38,6 +38,20 @@ 
 11: 11
 12: 12
 
+0: 0
+1: 1
+2: 2
+3: 3
+4: 4
+5: 5
+6: 6
+7: 7
+8: 8
+9: 9
+10: 10
+11: 11
+12: 12
+
 0 1 2 3 4 5 6 7 8 9 10 11 12
 0: 0
 1: 1
@@ -52,3 +66,32 @@ 
 10: 10
 11: 11
 12: 12
+
+0: 0
+1: 1
+2: 2
+3: 3
+4: 4
+5: 5
+6: 6
+7: 7
+8: 8
+9: 9
+10: 10
+11: 11
+12: 12
+13: 13
+14: 14
+15: 15
+16: 16
+17: 17
+18: 18
+19: 19
+20: 20
+21: 21
+22: 22
+23: 23
+24: 24
+25: 25
+26: 26
+27: 27