diff mbox

[FFmpeg-devel] Improved Selftest Coverage for libavcodec

Message ID 1476525912-26321-1-git-send-email-thomastdt@gmail.com
State Changes Requested
Headers show

Commit Message

Thomas Turner Oct. 15, 2016, 10:05 a.m. UTC
Added test for libavcodec/avpacket.c
Function(s) tested: av_packet_clone()

Signed-off-by: Thomas Turner <thomastdt@gmail.com>
---
 libavcodec/Makefile         |   3 +-
 libavcodec/tests/avpacket.c | 115 ++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavcodec.mak   |   5 ++
 3 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/tests/avpacket.c

Comments

Michael Niedermayer Oct. 15, 2016, 7:38 p.m. UTC | #1
On Sat, Oct 15, 2016 at 03:05:11AM -0700, Thomas Turner wrote:
> Added test for libavcodec/avpacket.c
> Function(s) tested: av_packet_clone()
> 
> Signed-off-by: Thomas Turner <thomastdt@gmail.com>
> ---
>  libavcodec/Makefile         |   3 +-
>  libavcodec/tests/avpacket.c | 115 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/fate/libavcodec.mak   |   5 ++
>  3 files changed, 122 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/tests/avpacket.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index a1560ba..d64b8df 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1016,7 +1016,8 @@ SKIPHEADERS-$(CONFIG_VDA)              += vda.h vda_vt_internal.h
>  SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
>  SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX)     += videotoolbox.h vda_vt_internal.h
>  
> -TESTPROGS = imgconvert                                                  \
> +TESTPROGS = avpacket                                                    \
> +            imgconvert                                                  \
>              jpeg2000dwt                                                 \
>              mathops                                                    \
>              options                                                     \
> diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c
> new file mode 100644
> index 0000000..d02f2e2
> --- /dev/null
> +++ b/libavcodec/tests/avpacket.c
> @@ -0,0 +1,115 @@
> +/*
> + * 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 <stdlib.h>
> +#include <inttypes.h>
> +#include "libavcodec/avcodec.h"
> +
> +
> +
> +static void LOG_AVPACKET(AVPacket* avpkt, const char* message)
> +{
> +    char buf_info[256];
> +    char data_info[256];                                                  
> +               
> +    if(avpkt->buf)                                                         
> +        sprintf(buf_info, "{buffer: %p,  data: %p, size: %d}",             
> +            avpkt->buf->buffer, avpkt->buf->data, avpkt->buf->size);       
> +    else                                                                   
> +        sprintf(buf_info, "{}");                                           

length checks (as in snprintf() are needed for saftey)

also the code segfaults:
#0  0x00007ffff764ca60 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x0000000000402ae3 in av_packet_ref (dst=0x60e040, src=0x7fffffffe350) at /usr/include/x86_64-linux-gnu/bits/string3.h:52
#2  0x0000000000402bd1 in av_packet_clone (src=0x7fffffffe350) at libavcodec/avpacket.c:616
#3  0x00000000004010d1 in TEST_AV_PACKET_CLONE () at libavcodec/tests/avpacket.c:87
#4  main () at libavcodec/tests/avpacket.c:11

[...]
Michael Niedermayer Oct. 15, 2016, 7:43 p.m. UTC | #2
On Sat, Oct 15, 2016 at 03:05:11AM -0700, Thomas Turner wrote:
> Added test for libavcodec/avpacket.c
> Function(s) tested: av_packet_clone()

The commit message should also have a first line that is
"topic: short description"

see the "Development Policy" for more information
http://ffmpeg.org/developer.html#Development-Policy

[...]
diff mbox

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a1560ba..d64b8df 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1016,7 +1016,8 @@  SKIPHEADERS-$(CONFIG_VDA)              += vda.h vda_vt_internal.h
 SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
 SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX)     += videotoolbox.h vda_vt_internal.h
 
-TESTPROGS = imgconvert                                                  \
+TESTPROGS = avpacket                                                    \
+            imgconvert                                                  \
             jpeg2000dwt                                                 \
             mathops                                                    \
             options                                                     \
diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c
new file mode 100644
index 0000000..d02f2e2
--- /dev/null
+++ b/libavcodec/tests/avpacket.c
@@ -0,0 +1,115 @@ 
+/*
+ * 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 <stdlib.h>
+#include <inttypes.h>
+#include "libavcodec/avcodec.h"
+
+
+
+static void LOG_AVPACKET(AVPacket* avpkt, const char* message)
+{
+    char buf_info[256];
+    char data_info[256];                                                  
+               
+    if(avpkt->buf)                                                         
+        sprintf(buf_info, "{buffer: %p,  data: %p, size: %d}",             
+            avpkt->buf->buffer, avpkt->buf->data, avpkt->buf->size);       
+    else                                                                   
+        sprintf(buf_info, "{}");                                           
+                                                                           
+    if(avpkt->data)                                                        
+        snprintf(data_info, avpkt->size + 3, "{%s}", avpkt->data);         
+    else                                                                   
+        sprintf(data_info, "{}");                                          
+                                                                           
+    av_log(NULL, AV_LOG_INFO,                                              
+           "%s:\n\n"
+           "buf\t\t: %p "
+           "%s\n"
+           "pts\t\t: %" PRId64 "\n"
+           "dts\t\t: %" PRId64 "\n"
+           "data\t\t: %p "
+           "%s\n"
+           "size\t\t: %d\n"
+           "stream_index\t: %d\n"
+           "flags\t\t: %d\n"
+           "side_data\t: %p\n"
+           "side_data_elems\t: %d\n"
+           "duration\t: %" PRId64 "\n"
+           "pos\t\t: %" PRId64 "\n\n",
+           message,
+           avpkt->buf,
+           buf_info,
+           avpkt->pts,
+           avpkt->dts,
+           avpkt->data,
+           data_info,
+           avpkt->size,
+           avpkt->stream_index,
+           avpkt->flags,
+           avpkt->side_data,
+           avpkt->side_data_elems,
+           avpkt->duration,
+           avpkt->pos
+    );
+}
+
+static void TEST_AV_PACKET_CLONE(void)
+{
+
+    AVPacket avpkt, *avpkt_ptr, *avpkt_clone;
+
+    unsigned char buffer[] = "\x73\x65\x6c\x66\x74\x65\x73\x74\x20\x66\x6f\x72"
+        "\x20\x61\x76\x5f\x70\x61\x63\x6b\x65\x74\x5f\x63\x6c\x6f\x6e\x65\x28"
+        "\x2e\x2e\x2e\x29";
+   
+    /* initialize avpkt */
+    av_init_packet(&avpkt);
+    
+    /* try to make av_packet_clone fail */
+    avpkt_clone = av_packet_clone(&avpkt);
+
+    if(!avpkt_clone){
+        av_log(NULL, AV_LOG_ERROR, "Error cloning packet.\n\n");
+    }
+    
+    /* make av_packet_clone succeed */
+    
+    /* fill data buffer */
+    avpkt.data = buffer;
+    avpkt.size = sizeof(buffer);
+
+    /* clone avpkt */
+    avpkt_clone = av_packet_clone(&avpkt);
+
+    if(avpkt_clone){
+        avpkt_ptr= &avpkt;
+        LOG_AVPACKET(avpkt_ptr, "Original Packet info");
+        LOG_AVPACKET(avpkt_clone, "Cloned Packet info");
+    }
+
+}
+
+int main(void)
+{
+    TEST_AV_PACKET_CLONE();
+
+    return 0;
+}
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index cf25285..3bc74c1 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -1,3 +1,8 @@ 
+FATE_LIBAVCODEC-yes += fate-avpacket
+fate-avpacket: libavcodec/tests/avpacket$(EXESUF)
+fate-avpacket: CMD = run libavcodec/tests/avpacket
+fate-avpacket: REF = /dev/null
+
 FATE_LIBAVCODEC-$(CONFIG_CABAC) += fate-cabac
 fate-cabac: libavcodec/tests/cabac$(EXESUF)
 fate-cabac: CMD = run libavcodec/tests/cabac