Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Mon, Nov 07, 2016 at 08:38:59PM -0800, Thomas Turner wrote: > Signed-off-by: Thomas Turner> --- > libavcodec/Makefile | 3 +- > libavcodec/tests/avpacket.c | 134 > > tests/fate/libavcodec.mak | 5 ++ > 3 files changed, 141 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 000..4826522 > --- /dev/null > +++ b/libavcodec/tests/avpacket.c > @@ -0,0 +1,134 @@ > +/* > + * 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 setup_side_data_entry(AVPacket* avpkt) > +{ > +const uint8_t *data_name = NULL; > +int ret = 0, bytes; > +uint8_t *extra_data = NULL; > + > + > +/* get side_data_name string */ > +data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA); > + > +/* Allocate a memory bloc */ > +bytes = strlen(data_name); > + > +if(!(extra_data = av_malloc(bytes))){ > +ret = AVERROR(ENOMEM); > +fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); > +return 1; error codes in ffmpeg are generally negative AVERROR() / AVERROR_* while only cosmetic, i think its better to be consistent here except where other things are needed for interfacing (like main() return or oter APIs) > +} > +/* copy side_data_name to extra_data array */ > +memcpy(extra_data, data_name, bytes); > + > +/* create side data for AVPacket */ > +ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, > +extra_data, bytes); > +if(ret < 0){ > +fprintf(stderr, > +"Error occurred in av_packet_add_side_data: %s\n", > +av_err2str(ret)); > +return 1; > +} > + > +return 0; > +} > + > +static int initializations(AVPacket* avpkt) > +{ > +static uint8_t data[] = "selftest for av_packet_clone(...)"; const static ... thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry. signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
Signed-off-by: Thomas Turner--- libavcodec/Makefile | 3 +- libavcodec/tests/avpacket.c | 134 tests/fate/libavcodec.mak | 5 ++ 3 files changed, 141 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 000..4826522 --- /dev/null +++ b/libavcodec/tests/avpacket.c @@ -0,0 +1,134 @@ +/* + * 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 setup_side_data_entry(AVPacket* avpkt) +{ +const uint8_t *data_name = NULL; +int ret = 0, bytes; +uint8_t *extra_data = NULL; + + +/* get side_data_name string */ +data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA); + +/* Allocate a memory bloc */ +bytes = strlen(data_name); + +if(!(extra_data = av_malloc(bytes))){ +ret = AVERROR(ENOMEM); +fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); +return 1; +} +/* copy side_data_name to extra_data array */ +memcpy(extra_data, data_name, bytes); + +/* create side data for AVPacket */ +ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, +extra_data, bytes); +if(ret < 0){ +fprintf(stderr, +"Error occurred in av_packet_add_side_data: %s\n", +av_err2str(ret)); +return 1; +} + +return 0; +} + +static int initializations(AVPacket* avpkt) +{ +static uint8_t data[] = "selftest for av_packet_clone(...)"; +int ret = 0; + +/* initialize avpkt */ +av_init_packet(avpkt); + +/* set values for avpkt */ +avpkt->pts = 17; +avpkt->dts = 2; +avpkt->data = data; +avpkt->size = strlen(data); +avpkt->flags = AV_PKT_FLAG_DISCARD; +avpkt->duration = 100; +avpkt->pos = 3; + +if(setup_side_data_entry(avpkt)) +ret = 1; + +return ret; +} + +int main(void) +{ +AVPacket avpkt; +AVPacket *avpkt_clone = NULL; +int ret = 0; + +if(initializations()){ +printf("failed to initialize variables\n"); +return 1; +} + +/* test av_packet_clone*/ +avpkt_clone = av_packet_clone(); + +if(!avpkt_clone) { +av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n"); +return 1; +} +/* test size error check in av_new_packet*/ +if(av_new_packet(avpkt_clone, INT_MAX) == 0){ +printf( "av_new_packet failed to return error " +"when \"size\" parameter is too large.\n" ); +ret = 1; +} + +/*test av_grow_packet*/ +if(av_grow_packet(avpkt_clone, INT_MAX) == 0){ +printf( "av_grow_packet failed to return error " +"when \"grow_by\" parameter is too large.\n" ); +ret = 1; +} +if(av_grow_packet(avpkt_clone, 20) < 0){ +av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n"); +return 1; +} + +/*test av_packet_from_data*/ +if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){ +printf("av_packet_from_data failed to return error " +"when \"size\" parameter is too large.\n" ); +ret = 1; +} + +/*clean up*/ +av_packet_free(_clone);
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Thu, Nov 03, 2016 at 04:55:40AM -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]. > > Signed-off-by: Thomas Turner> --- > libavcodec/Makefile | 3 +- > libavcodec/tests/avpacket.c | 205 > > tests/fate/libavcodec.mak | 5 ++ > 3 files changed, 212 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 000..784a5a4 > --- /dev/null > +++ b/libavcodec/tests/avpacket.c > @@ -0,0 +1,205 @@ > +/* > + * 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 const char* str = "Error @"; > + > +static int compare_AVPacketsSideData(AVPacketSideData* sdata1, > + AVPacketSideData* sdata2) > +{ > +int ret = 0; > + > +if(!sdata1 || !sdata2) > +return; > +av_log(NULL, AV_LOG_INFO, "Comparing sidedata data memebers...\n"); > + > +if(sdata1->size != sdata2->size){ > +fprintf(stderr, "%s size\n", str); > +ret = 1; > +} > +if(sdata1->size > 0){ > +if(memcmp(sdata1->data, sdata2->data, sdata1->size) != 0){ > +fprintf(stderr, "%s data\n", str); > +ret = 1; > +} > +} > +else { > +av_log(NULL, AV_LOG_INFO, "size is <= 0"); > +ret = 1; > +} > +if(sdata1->type != sdata2->type){ > +fprintf(stderr, "%s type\n", str); > +ret = 1; > +} indention is wrong here also forcing a failure in one of these if() does not cause the fate test to fail, the test still succeeds as it returns 0 and its stdout/err output is not checked make fate-avpacket TESTavpacket Also i think the whole test is much more verbose than needed. I think spending time on testing more functions makes more sense than analysing the error case of one. Code to analyze errors can be written if we ever hit an error. Its different with tests outputing checksums, there details are usefull so the developer can determine if a change is an error or a intended consequence of some change to the codebase. Here simply saying "error" if theres a difference is fine. Code to print the details can be written if it actually gets hit. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Complexity theory is the science of finding the exact solution to an approximation. Benchmarking OTOH is finding an approximation of the exact signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
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]. Signed-off-by: Thomas Turner--- libavcodec/Makefile | 3 +- libavcodec/tests/avpacket.c | 205 tests/fate/libavcodec.mak | 5 ++ 3 files changed, 212 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 000..784a5a4 --- /dev/null +++ b/libavcodec/tests/avpacket.c @@ -0,0 +1,205 @@ +/* + * 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 const char* str = "Error @"; + +static int compare_AVPacketsSideData(AVPacketSideData* sdata1, + AVPacketSideData* sdata2) +{ +int ret = 0; + +if(!sdata1 || !sdata2) +return; +av_log(NULL, AV_LOG_INFO, "Comparing sidedata data memebers...\n"); + +if(sdata1->size != sdata2->size){ +fprintf(stderr, "%s size\n", str); +ret = 1; +} +if(sdata1->size > 0){ +if(memcmp(sdata1->data, sdata2->data, sdata1->size) != 0){ +fprintf(stderr, "%s data\n", str); +ret = 1; +} +} +else { +av_log(NULL, AV_LOG_INFO, "size is <= 0"); +ret = 1; +} +if(sdata1->type != sdata2->type){ +fprintf(stderr, "%s type\n", str); +ret = 1; +} +return ret; +} + +static int compare_AVPackets(AVPacket* p1, AVPacket* p2) +{ +int ret = 0; + +if(!p1 || !p2) +return; + +av_log(NULL, AV_LOG_INFO, "Comparing AVPacket data memebers...\n"); + +if(p1->size != p2->size){ +fprintf(stderr, "%s size\n", str); +ret = 1; +} +if(p1->size > 0){ +if(memcmp(p1->data, p2->data, p1->size) != 0){ +fprintf(stderr, "%s data\n", str); +ret = 1; +} +} +else { +av_log(NULL, AV_LOG_INFO, "size is <= 0"); +ret = 1; +} +if(p1->pts != p2->pts){ +fprintf(stderr, "%s pts\n", str); +ret = 1; +} +if(p1->dts != p2->dts){ +fprintf(stderr, "%s dts\n", str); +ret = 1; +} +if(p1->stream_index != p2->stream_index){ +fprintf(stderr, "%s stream_index\n", str); +ret = 1; +} +if(p1->flags != p2->flags){ +fprintf(stderr, "%s flags\n", str); +ret = 1; +} +if(p1->side_data_elems != p2->side_data_elems){ +fprintf(stderr, "%s side_data_elems\n", str); +ret = 1; +} +if(p1->duration != p2->duration){ +fprintf(stderr, "%s duration\n", str); +ret = 1; +} +if(p1->pos != p2->pos){ +fprintf(stderr, "%s pos\n", str); +ret = 1; +} + +if(compare_AVPacketsSideData(p1->side_data, p2->side_data) > 0) +ret = 1; + +av_log(NULL, AV_LOG_INFO, "Done comparing!\n"); + +return ret; +} + +static void setup_side_data_entry(AVPacket* avpkt) +{ +const uint8_t *data_name = NULL; +int ret = 0, bytes; +uint8_t *extra_data = NULL; + + +/* get side_data_name string */ +data_name =
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Wed, Oct 26, 2016 at 03:03:07PM +0200, wm4 wrote: > On Wed, 26 Oct 2016 14:56:01 +0200 > Michael Niedermayerwrote: > > > On Wed, Oct 26, 2016 at 02:00:46PM +0200, wm4 wrote: > > > On Sat, 22 Oct 2016 23:40:42 -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 > > > > --- > > > > > > Am I the only one who thinks this test is overly complex and worthless? > > > (Checks if each field got copied... come on, that's not useful. And > > > would probably bitrot quickly as nobody would add new fields to the > > > test anyway.) > > > > what do you suggest, how to test it ? > > or should we deprecate av_packet_clone() > > nothing uses it, so the total lack of tests and uses means noone > > would notice (quickly) if it broke ever > > > > [...] > > I don't think it's the choice between either adding a test > for av_packet_clone or deprecating it? Its desirable to have code tested to identify problems, code thats not tested at all bit rots eventually. The issue is propotional to the complexity of the code and how activly it changes so the risk is low with av_packet_clone() but still > > Also, av_packet_clone is 100% implemented using public functions and > doesn't access any AVPacket fields itself. yes but these public functions themselfs arent tested for completness either. iam not arguing for a specific way of testing this, but that some clean test would be desirable [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The greatest way to live with honor in this world is to be what we pretend to be. -- Socrates signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Wed, 26 Oct 2016 14:56:01 +0200 Michael Niedermayerwrote: > On Wed, Oct 26, 2016 at 02:00:46PM +0200, wm4 wrote: > > On Sat, 22 Oct 2016 23:40:42 -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 > > > --- > > > > Am I the only one who thinks this test is overly complex and worthless? > > (Checks if each field got copied... come on, that's not useful. And > > would probably bitrot quickly as nobody would add new fields to the > > test anyway.) > > what do you suggest, how to test it ? > or should we deprecate av_packet_clone() > nothing uses it, so the total lack of tests and uses means noone > would notice (quickly) if it broke ever > > [...] I don't think it's the choice between either adding a test for av_packet_clone or deprecating it? Also, av_packet_clone is 100% implemented using public functions and doesn't access any AVPacket fields itself. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Wed, Oct 26, 2016 at 02:00:46PM +0200, wm4 wrote: > On Sat, 22 Oct 2016 23:40:42 -0700 > Thomas Turnerwrote: > > > 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 > > --- > > Am I the only one who thinks this test is overly complex and worthless? > (Checks if each field got copied... come on, that's not useful. And > would probably bitrot quickly as nobody would add new fields to the > test anyway.) what do you suggest, how to test it ? or should we deprecate av_packet_clone() nothing uses it, so the total lack of tests and uses means noone would notice (quickly) if it broke ever [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Dictatorship naturally arises out of democracy, and the most aggravated form of tyranny and slavery out of the most extreme liberty. -- Plato signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
On Sat, 22 Oct 2016 23:40:42 -0700 Thomas Turnerwrote: > 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 > --- Am I the only one who thinks this test is overly complex and worthless? (Checks if each field got copied... come on, that's not useful. And would probably bitrot quickly as nobody would add new fields to the test anyway.) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
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> --- > 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 000..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 > +#include > +#include > +#include > +#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 {
[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
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--- 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 000..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 +#include +#include +#include +#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); \
[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
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--- libavcodec/Makefile | 3 ++- libavcodec/tests/avpacket | Bin 0 -> 70467 bytes tests/fate/libavcodec.mak | 5 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 libavcodec/tests/avpacket 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 b/libavcodec/tests/avpacket new file mode 100755 index ..15773ee8dc801aeb4fac7a84ef13c60247e39164 GIT binary patch literal 70467 zcmd443w#vS**`v;i!2zOs8NGbS#^=5+!8^}3dj!G4YRnbsetfSDa0jc ASypbMNkCzL-{+i}-A#bn-~WC8 z|Ia^4X3m*`&$(oY+gp}lu?Xf*hH#fasek4TDRq>)!5^cI}L4Z`)p zCCJIfKPUS_PyS{;yNssIr`0HziDwr6m1OXYk_;z%F`xZ-wqQO@2FmXPwh}=2dBg 7r3I_b<)2vQoqkj{P z?-MheNKx8J55dKLr=C=ne#$>pX3+cWzp^BrPWECx-!clCPqW_lP> ycw47_(C z1EtRYc@`C~JU?4_`6BtpFOq-bMe;92+qMg|f7eCI6Z{u~XTwGE-51HXUL^l77s;;& zj2G%Rc9Hx&7s;=?Nc-N4 ?A73Q@p^M}{dJ*_{T%`O!l(*qu~nQ zQvMwjybwM^7b)NOBKfN>l7HJp@^44Kww^#DJp=zP1ka(1
Re: [FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
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> --- > 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 000..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 > +#include > +#include > +#include > +#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, > +
[FFmpeg-devel] [PATCH] libavcodec/tests: Added test for libavcodec/avpacket.c
Improved code coverage for libavcodec Function(s) Tested: av_packet_clone() Signed-off-by: Thomas Turner--- 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 000..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 +#include +#include +#include +#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){ +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); +} + +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){ +fprintf(stderr, "data\n"); +goto fail; +} +if(p1->pts != p2->pts){ +