[FFmpeg-devel] [PATCH 1/3] Improve selftest coverage for libavutil library

Thomas Turner thomastdt at googlemail.com
Tue Oct 11 06:56:51 EEST 2016


Code coverage for av_fifo_generic_peek(...) and av_fifo_grow(...) .
---
 libavutil/tests/fifo2.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 libavutil/tests/fifo2.c

diff --git a/libavutil/tests/fifo2.c b/libavutil/tests/fifo2.c
new file mode 100644
index 0000000..923feee
--- /dev/null
+++ b/libavutil/tests/fifo2.c
@@ -0,0 +1,77 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+#include "libavutil/fifo.h"
+
+
+
+int main(void)
+{
+
+    int16_t offset, fifo_size, space_size, data_size;
+    int32_t data, *data_arr;
+    int32_t elem[] = {0, 2, 4, 6, 8, 10, 12};
+    AVFifoBuffer* fifo;
+
+    data_size = sizeof(elem[0]);
+    fifo = av_fifo_alloc(sizeof(elem));
+
+    /*fill fifo buffer*/
+
+    if (av_fifo_generic_write(fifo, (void*)elem, av_fifo_space(fifo), NULL) != sizeof(elem)) {
+
+        fprintf(stderr, "written incorrect number of bytes\n");
+        return 1;
+    }
+
+
+    /* generic peek at fifo */
+
+    fifo_size = av_fifo_size(fifo);
+    data_arr = (int32_t*)malloc(fifo_size);
+
+    (void) av_fifo_generic_peek(fifo, data_arr, fifo_size, NULL);
+
+    printf("fifo->buffer: ");
+    for(offset = 0; offset < fifo_size/data_size; ++offset){
+        printf("%" PRId32 ", ", data_arr[offset]);
+    }
+
+    space_size = av_fifo_space(fifo);
+    printf("\nspace before av_fifo_grow\t:%" PRId16 "\n", space_size);
+
+    /* grow AVFifoBuffer */
+
+    data = av_fifo_grow(fifo, data_size);
+    if(data < 0)
+        printf("\n%s\n", "failure growing fifo\n");
+
+
+    space_size = av_fifo_space(fifo);
+    printf("space after av_fifo_grow\t:%" PRId16 "\n", space_size);
+
+    
+    /* free AVFifoBuffer and data_arr */
+
+    av_fifo_free(fifo);
+    free(data_arr);
+
+    return 0;
+}
-- 
1.9.1



More information about the ffmpeg-devel mailing list