From patchwork Mon Oct 17 00:01:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Turner X-Patchwork-Id: 1035 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp401915vsd; Mon, 17 Oct 2016 11:06:27 -0700 (PDT) X-Received: by 10.194.171.225 with SMTP id ax1mr14088012wjc.48.1476727587682; Mon, 17 Oct 2016 11:06:27 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sd8si42937229wjb.131.2016.10.17.11.06.26; Mon, 17 Oct 2016 11:06:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE dis=QUARANTINE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC153689A9D; Mon, 17 Oct 2016 21:06:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F449689721 for ; Mon, 17 Oct 2016 03:01:43 +0300 (EEST) Received: by mail-pf0-f194.google.com with SMTP id i85so8136352pfa.0 for ; Sun, 16 Oct 2016 17:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=hOKIOQqUJ3EnSnIs3bk9W2Vf7YRAjtU/whA8AXrhE6w=; b=JDPuRIwYZsmsFcZfYco5UFWMiLqtGnf2JbPbGX2gMu+MaG0W0ALjzBLga37MiXsfAS FrXo8hUsaqs2GoB1vevyrKP6O1Z/LtfYF8Nir2wre7vwYa14fAeVkl7RJ9HlB41uP4E8 IsmnSfH/CLIMU/KA2mD+GJZLRNBnMk2yqoc4BvkFvDVK2JTPn7um9sZYdY9GXGEIEQi9 ROxdHicws44ntNevlMf2hBhaoiKR829r3d9XHXeCKG2dMhGQTvsqBF2PGx96TKbpxQSb Z01tixUWQr+8gt3kib6RxFV37Pb9GvrapQxOWSwL9A+ZMxWXD9Phyci220xpl3leAAcv Z/Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hOKIOQqUJ3EnSnIs3bk9W2Vf7YRAjtU/whA8AXrhE6w=; b=gtzqJ8MzJbJ39jj5vTYj352525TLItl5Fx8zrEO9J9B42iyI/lm7BnyyxVvyC5gpsk pFvDZa2kxGbIm10iKnTnKqsVEqkuaPq0r5q3ipa5OK0HAp6+xozRsfYHmJGeo13tnah6 lQVWSoC+8uICqYF37kf/UGQSVpLTWFA+fhxq4itZ+GA6FfVz6LMZu49MQjXtRZnjluc+ hU/GSuNkgpO6UTn0oUbEsGnpnchod1zSiK5F2Zflb2P30CWrXaNpEQojoxUrJi3g4Znm Dk30kxmfGuKE1XGwy2IksE8FXKmGqkwSRha34eRh3PXduu991QdrNC08dWBWr9VNhulk ZKAA== X-Gm-Message-State: AA6/9RnA5ZS/KQ/2+TQagwgGAL2S+WqPGWe3fh1RwO8wVH5qvzRtSsCkfonLT+hsTD9pVA== X-Received: by 10.98.9.147 with SMTP id 19mr33825992pfj.68.1476662503469; Sun, 16 Oct 2016 17:01:43 -0700 (PDT) Received: from Zany.domain.actdsltmp ([47.136.133.132]) by smtp.gmail.com with ESMTPSA id x1sm13488301pax.7.2016.10.16.17.01.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 16 Oct 2016 17:01:42 -0700 (PDT) From: Thomas Turner X-Google-Original-From: Thomas Turner To: ffmpeg-devel@ffmpeg.org Date: Sun, 16 Oct 2016 17:01:25 -0700 Message-Id: <1476662485-6371-1-git-send-email-thomastdt@gmail.com> X-Mailer: git-send-email 1.9.1 X-Mailman-Approved-At: Mon, 17 Oct 2016 21:06:21 +0300 Subject: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Thomas Turner MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Improved code coverage for libavcodec. Function(s) Tested: av_packet_clone(). Signed-off-by: Thomas Turner --- libavcodec/Makefile | 3 +- libavcodec/tests/avpacket.c | 185 ++++++++++++++++++++++++++++++++++++++++++++ tests/fate/libavcodec.mak | 5 ++ 3 files changed, 192 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..20fc188 --- /dev/null +++ b/libavcodec/tests/avpacket.c @@ -0,0 +1,185 @@ +/* + * 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 +#include +#include +#include +#include "libavcodec/avcodec.h" +#include "libavutil/error.h" + +static int IS_SPRINTF_ERR(int val, int tot_elem) +{ + int ret = 0; + if(val > tot_elem){ + perror("overflow"); + ret = 1; + } + else if(val < 0){ + perror("sprintf"); + ret = 1; + } + if(ret > 0) + return ret; + + return ret; +} + +static void LOG_AVPACKET(AVPacket avpkt, const char* message) +{ + int val, tot_elem; + + /* initialize array's */ + char buf_info[256] = {0}; + char data_info[256] = {0}; + char side_info[256] = {0}; + + /* get buf information */ + if(avpkt.buf){ + val = sprintf(buf_info, "{buffer: %p, data: %p, size: %d}", + avpkt.buf->buffer, avpkt.buf->data, avpkt.buf->size); + tot_elem = strlen(buf_info); + + /** if sprintf error found */ + if(IS_SPRINTF_ERR(val, tot_elem)) + exit(-1); + } + /*get data information*/ + if(avpkt.data){ + val = snprintf(data_info, avpkt.size + 2 + 1, "\"%s\"", avpkt.data); + tot_elem = strlen(data_info); + + /**if snprintf error found*/ + if(val != tot_elem){ + perror("snprintf"); + exit(-1); + } + } + /*get side data information*/ + if(avpkt.side_data){ + val = sprintf(side_info, "{data: %p \"%s\", size: %d, type: %d}", + avpkt.side_data, avpkt.side_data->data, avpkt.side_data->size, + avpkt.side_data->type); + tot_elem = strlen(side_info); + + /** if sprintf error found */ + if(IS_SPRINTF_ERR(val, tot_elem)) + exit(-1); + } + /* 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, + 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 void TEST_AV_PACKET_CLONE(void) +{ + int ret = 0, len; + uint8_t *extra_data = NULL; + const uint8_t *data_name = NULL; + AVPacket avpkt, *avpkt_clone = NULL; + uint8_t data[] = "selftest for av_packet_clone(...)"; + + /* initialize avpkt */ + av_init_packet(&avpkt); + + avpkt.data = data; + avpkt.size = strlen(data); + avpkt.flags = AV_PKT_FLAG_DISCARD; + + /*get side_data_name string*/ + data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA); + + /*Allocate a memory block*/ + len = strlen(data_name); + extra_data = av_malloc(len); + + if(!extra_data){ + ret = AVERROR(ENOMEM); + fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); + exit(1); + } + /*copy side_data_name to extra_data array*/ + memcpy(extra_data, data_name, len); + + /*create side data for AVPacket*/ + ret = av_packet_add_side_data(&avpkt, AV_PKT_DATA_NEW_EXTRADATA, + extra_data, len); + if(ret < 0){ + fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); + exit(1); + } + + /* clone avpkt */ + avpkt_clone = av_packet_clone(&avpkt); + + /* log packet information */ + if(avpkt_clone){ + LOG_AVPACKET(avpkt, "Original Packet info"); + LOG_AVPACKET(*avpkt_clone, "Cloned Packet info"); + } + else{ + av_log(NULL, AV_LOG_ERROR, "av_packet_clone error\n"); + exit(1); + } + + /*cleanup*/ + av_packet_free(&avpkt_clone); + av_packet_unref(&avpkt); + +} + + + +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