On Tue, Oct 18, 2016 at 01:38:27PM -0700, Thomas Turner wrote: > Improved code coverage for libavcodec > Function(s) Tested: av_packet_clone() > > Signed-off-by: Thomas Turner <[email protected]> > --- > libavcodec/Makefile | 3 +- > libavcodec/tests/avpacket.c | 254 > ++++++++++++++++++++++++++++++++++++++++++++ > tests/fate/libavcodec.mak | 5 + > 3 files changed, 261 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..67ec71b > --- /dev/null > +++ b/libavcodec/tests/avpacket.c > @@ -0,0 +1,254 @@ > +/* > + * 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" > + > + > + > + > + > +static char* getbuffer(AVPacket avpkt, int index) > +{ > + uint8_t *buffer; > + int val, buffer_size = 256; > + > + /* Allocate 256 bytes */ > + if((buffer = malloc(buffer_size)) == NULL){ > + perror("malloc"); > + goto EXIT; > + } > + > + if(index == 0){ > + val = snprintf(buffer, buffer_size, > + "{buffer: %p, data: %p, size: %d}", > + avpkt.buf->buffer, avpkt.buf->data, avpkt.buf->size);
> + }
> + else if(index == 1){
nitpick, the formating for this in ffmpeg is
} else if (index == 1) {
> + val = snprintf(buffer, buffer_size, "\"%s\"", avpkt.data);
> + }
> + else if(index == 2){
> + val = snprintf(buffer, buffer_size,
> + "{data: %p \"%s\", size: %d, type: %d}",
> + avpkt.side_data, avpkt.side_data->data, avpkt.side_data->size,
> + avpkt.side_data->type);
> + }
> +
> + /* snprintf fail check */
> + if(!(val > -1 && val < buffer_size)){
> + perror("snprintf");
> + free(buffer);
> + goto EXIT;
> + }
> +
> + return buffer;
> +
> +EXIT:
> + exit(-1);
exit always uses positive numbers in ffmpeg
> +}
> +
> +static void log_avpacket(AVPacket avpkt, const char* message)
> +{
> + uint8_t *buf_info = 0, *data_info = 0, *side_info = 0;
> +
> + /* get buf information */
> + if(avpkt.buf){
> + buf_info = getbuffer(avpkt, 0);
> + }
> +
> + /* get data information */
> + if(avpkt.data){
> + data_info = getbuffer(avpkt, 1);
> + }
> +
> + /* get side data information */
> + if(avpkt.side_data){
> + side_info = getbuffer(avpkt, 2);
> + }
> +
> + /* log standard packet information */
> + av_log(NULL, AV_LOG_INFO,
> + "\n%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 "
> + "%s\n"
> + "side_data_elems\t: %d\n"
> + "duration\t: %" PRId64 "\n"
> + "pos\t\t: %" PRId64 "\n\n",
> + message,
> + avpkt.buf,
> + buf_info ? (char*)buf_info : "",
> + avpkt.pts,
> + avpkt.dts,
> + avpkt.data,
> + data_info,
> + avpkt.size,
> + avpkt.stream_index,
> + avpkt.flags,
> + avpkt.side_data,
> + side_info,
> + avpkt.side_data_elems,
> + avpkt.duration,
> + avpkt.pos
> + );
> +
> +}
> +
> +static int compare_av_packet(AVPacket* p1, AVPacket* p2)
> +{
> + /* compare data */
> +
> + if(p1->size != p2->size){
> + fprintf(stderr, "size\n");
> + goto fail;
> + }
> + if(strncmp(p1->data, p2->data, p1->size) != 0){
memcmp() seems the better choice as it does not depend on zero
termination
also, if you like you could work on 2 or 3 tests at the same time
so while one patch is reviewed you can work on something else
Thanks
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list [email protected] http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
