[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c

Michael Niedermayer michael at niedermayer.cc
Tue Oct 25 23:38:35 EEST 2016


On Sat, Oct 22, 2016 at 11:40:42PM -0700, Thomas Turner wrote:
> Function(s) Tested: av_packet_clone().
> 
> This test checks if av_packet_clone() can successfully make a copy of an AVPacket.
> Compares all data members in AVPacket EXCEPT for "buf" because "buf" is initialized
> to NIL in the original AVPacket [to be cloned].
> 
> This test also prints out the all the contents of the original and cloned AVPackets.
> 
> Signed-off-by: Thomas Turner <thomastdt at googlemail.com>
> ---
>  libavcodec/Makefile         |   3 +-
>  libavcodec/tests/avpacket.c | 303 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/fate/libavcodec.mak   |   5 +
>  3 files changed, 310 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/tests/avpacket.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index f1d5bf1..46e3af7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1019,7 +1019,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..752cf3c
> --- /dev/null
> +++ b/libavcodec/tests/avpacket.c
> @@ -0,0 +1,303 @@
> +/*
> + * 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 <string.h>
> +#include "libavcodec/avcodec.h"
> +#include "libavutil/error.h"
> +
> +
> +
> +
> +#define AVPACKET_FIELDS                                 \
> +    X(static AVBufferRef*, buf, "%p")                   \
> +    X(static int64_t, pts, "%" PRId64)                  \
> +    X(static int64_t, dts, "%" PRId64)                  \
> +    X(static uint8_t*, data, "%p")                      \
> +    X(static int, size, "%d")                           \
> +    X(static int, stream_index, "%d")                   \
> +    X(static int, flags, "%d")                          \
> +    X(static AVPacketSideData*, side_data, "%p")        \
> +    X(static int, side_data_elems, "%d")                \
> +    X(static int64_t, duration, "%" PRId64)             \
> +    X(static int64_t, pos, "%" PRId64)
> +
> +#define AVBUFFERREF_FIELDS                              \
> +    Y(static AVBuffer*, buffer, "%p")                   \
> +    Y(static uint8_t*, data, "%p")                      \
> +    Y(static int, size, "%d")
> +
> +#define AVPACKETSIDEDATA_FIELDS                         \
> +    Z(static uint8_t*, data, "%p")                      \
> +    Z(static int, size, "%d")                           \
> +    Z(static enum AVPacketSideDataType, type, "%d")
> +
> +
> +
> +

> +#define AV_MESSAGE_1(format, name, p1, p2)                                  \
> +    do {                                                                    \
> +        const char* str = "cloned variable \"%s\" equals " format           \
> +                        " but should be " format "\n";                      \
> +        av_log(NULL, AV_LOG_ERROR, str, #name, p2->name, p1->name );        \
> +    } while (0)
> +
> +#define AV_MESSAGE_2(name, p1, p2)                                          \
> +    do {                                                                    \
> +        const char* str = "contents of cloned variable "                    \
> +                        "%s equals \"%.*s\"\nbut should be \"%.*s\"\n";     \
> +        av_log(NULL, AV_LOG_ERROR, str, #name, p1->size,                    \
> +                            p2->data, p1->size, p1->data);                  \
> +    } while(0)
> +
> +#define AV_MESSAGE_3(name)                                                  \
> +    do {                                                                    \
> +        const char* str = "error! did not attempt to compare "              \
> +                        "contents of \"%s\" variable\n";                    \
> +        av_log(NULL, AV_LOG_ERROR, str, #name);                             \
> +    } while(0)

using these macros makes the code harder to read and maintain
direct use of av_log() would be better
also numbering functions like AV_MESSAGE_# is confusing, each
should if used have a descriptive name

> +
> +#define AV_MESSAGE_4(string)                                                \
> +    do { av_log(NULL, AV_LOG_INFO, "%s", string); } while(0)

a plain av_log() is clearer no need for a macro
if you dont like the extra arguments for av_log() you can use printf()
in code in tests/*



> +
> +
> +
> +
> +#define COMPARE(a, b) ( ((a) == (b)) ? 1 : 0 )

this should not be needed

a == b
and
a != b
directly should work fine

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161025/4e0f039f/attachment.sig>


More information about the ffmpeg-devel mailing list