diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-08-07 17:43:42 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-08-10 19:14:00 +0300 |
commit | 53d203dea8230da4e80f3cc61468a4e24ff6759c (patch) | |
tree | 3f1b7498fb1a3108e60a4355bec0e4eef76110e4 /intern | |
parent | af77bf1f0f94cb07d5bf681d1f771d4106873780 (diff) |
Tests: move remaining gtests into their own module folders
And make them part of the blender_test runner. The one exception is blenlib
performance tests, which we don't want to run by default. They remain in their
own executable.
Differential Revision: https://developer.blender.org/D8498
Diffstat (limited to 'intern')
-rw-r--r-- | intern/CMakeLists.txt | 4 | ||||
-rw-r--r-- | intern/ffmpeg/CMakeLists.txt | 42 | ||||
-rw-r--r-- | intern/ffmpeg/tests/ffmpeg_codecs.cc | 147 | ||||
-rw-r--r-- | intern/guardedalloc/CMakeLists.txt | 16 | ||||
-rw-r--r-- | intern/guardedalloc/tests/guardedalloc_alignment_test.cc | 121 | ||||
-rw-r--r-- | intern/guardedalloc/tests/guardedalloc_overflow_test.cc | 60 |
6 files changed, 390 insertions, 0 deletions
diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt index 0758567bb78..c1792a312b2 100644 --- a/intern/CMakeLists.txt +++ b/intern/CMakeLists.txt @@ -77,6 +77,10 @@ if(WITH_QUADRIFLOW) add_subdirectory(quadriflow) endif() +if(WITH_CODEC_FFMPEG) + add_subdirectory(ffmpeg) +endif() + if(UNIX AND NOT APPLE) add_subdirectory(libc_compat) endif() diff --git a/intern/ffmpeg/CMakeLists.txt b/intern/ffmpeg/CMakeLists.txt new file mode 100644 index 00000000000..e141da9cbca --- /dev/null +++ b/intern/ffmpeg/CMakeLists.txt @@ -0,0 +1,42 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# The Original Code is Copyright (C) 2020, Blender Foundation +# All rights reserved. +# ***** END GPL LICENSE BLOCK ***** + +if(WITH_GTESTS) + set(TEST_SRC + tests/ffmpeg_codecs.cc + ) + set(TEST_INC + ) + set(TEST_INC_SYS + ${FFMPEG_INCLUDE_DIRS} + ${PNG_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIRS} + ) + set(TEST_LIB + ${PNG_LIBRARIES} + ${FFMPEG_LIBRARIES} + ${ZLIB_LIBRARIES} + ) + if(WITH_IMAGE_OPENJPEG) + set(TEST_LIB ${TEST_LIB} ${OPENJPEG_LIBRARIES}) + endif() + include(GTestTesting) + blender_add_test_lib(bf_intern_ffmpeg_tests "${TEST_SRC}" "${TEST_INC}" "${TEST_INC_SYS}" "${TEST_LIB}") +endif() diff --git a/intern/ffmpeg/tests/ffmpeg_codecs.cc b/intern/ffmpeg/tests/ffmpeg_codecs.cc new file mode 100644 index 00000000000..d3cba6d228a --- /dev/null +++ b/intern/ffmpeg/tests/ffmpeg_codecs.cc @@ -0,0 +1,147 @@ +#include "testing/testing.h" + +extern "C" { +#include <libavcodec/avcodec.h> +#include <libavutil/log.h> +} + +bool test_vcodec(AVCodec *codec, AVPixelFormat pixelformat) +{ + av_log_set_level(AV_LOG_QUIET); + bool result = false; + if (codec) { + AVCodecContext *ctx = avcodec_alloc_context3(codec); + if (ctx) { + ctx->time_base.num = 1; + ctx->time_base.den = 25; + ctx->pix_fmt = pixelformat; + ctx->width = 720; + ctx->height = 576; + int open = avcodec_open2(ctx, codec, NULL); + if (open >= 0) { + avcodec_free_context(&ctx); + result = true; + } + } + } + return result; +} +bool test_acodec(AVCodec *codec, AVSampleFormat fmt) +{ + av_log_set_level(AV_LOG_QUIET); + bool result = false; + if (codec) { + AVCodecContext *ctx = avcodec_alloc_context3(codec); + if (ctx) { + ctx->sample_fmt = fmt; + ctx->sample_rate = 48000; + ctx->channel_layout = AV_CH_LAYOUT_MONO; + ctx->bit_rate = 128000; + int open = avcodec_open2(ctx, codec, NULL); + if (open >= 0) { + avcodec_free_context(&ctx); + result = true; + } + } + } + return result; +} + +bool test_codec_video_by_codecid(AVCodecID codec_id, AVPixelFormat pixelformat) +{ + bool result = false; + AVCodec *codec = avcodec_find_encoder(codec_id); + if (codec) + result = test_vcodec(codec, pixelformat); + return result; +} + +bool test_codec_video_by_name(const char *codecname, AVPixelFormat pixelformat) +{ + bool result = false; + AVCodec *codec = avcodec_find_encoder_by_name(codecname); + if (codec) + result = test_vcodec(codec, pixelformat); + return result; +} + +bool test_codec_audio_by_codecid(AVCodecID codec_id, AVSampleFormat fmt) +{ + bool result = false; + AVCodec *codec = avcodec_find_encoder(codec_id); + if (codec) + result = test_acodec(codec, fmt); + return result; +} + +bool test_codec_audio_by_name(const char *codecname, AVSampleFormat fmt) +{ + bool result = false; + AVCodec *codec = avcodec_find_encoder_by_name(codecname); + if (codec) + result = test_acodec(codec, fmt); + return result; +} + +#define str(s) #s +#define FFMPEG_TEST_VCODEC_ID(codec, fmt) \ + TEST(ffmpeg, codec##_##fmt) \ + { \ + EXPECT_TRUE(test_codec_video_by_codecid(codec, fmt)); \ + } + +#define FFMPEG_TEST_VCODEC_NAME(codec, fmt) \ + TEST(ffmpeg, codec##_##fmt) \ + { \ + EXPECT_TRUE(test_codec_video_by_name(str(codec), fmt)); \ + } + +#define FFMPEG_TEST_ACODEC_ID(codec, fmt) \ + TEST(ffmpeg, codec##_##fmt) \ + { \ + EXPECT_TRUE(test_codec_audio_by_codecid(codec, fmt)); \ + } + +#define FFMPEG_TEST_ACODEC_NAME(codec, fmt) \ + TEST(ffmpeg, codec) \ + { \ + EXPECT_TRUE(test_codec_audio_by_name(str(codec), fmt)); \ + } + +/* generic codec ID's used in blender */ + +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_BGRA) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_RGB32) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FFV1, AV_PIX_FMT_RGB32) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_QTRLE, AV_PIX_FMT_ARGB) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_VP9, AV_PIX_FMT_YUVA420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_PNG, AV_PIX_FMT_RGBA) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG4, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_THEORA, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_DVVIDEO, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG1VIDEO, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG2VIDEO, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FLV1, AV_PIX_FMT_YUV420P) + +/* Audio codecs */ + +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AAC, AV_SAMPLE_FMT_FLTP) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AC3, AV_SAMPLE_FMT_FLTP) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_FLAC, AV_SAMPLE_FMT_S16) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP2, AV_SAMPLE_FMT_S16) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP3, AV_SAMPLE_FMT_FLTP) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_OPUS, AV_SAMPLE_FMT_FLT) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_PCM_S16LE, AV_SAMPLE_FMT_S16) +FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_VORBIS, AV_SAMPLE_FMT_FLTP) + +/* Libraries we count on ffmpeg being linked against */ + +FFMPEG_TEST_VCODEC_NAME(libtheora, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_NAME(libx264, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_NAME(libvpx, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_NAME(libopenjpeg, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_VCODEC_NAME(libxvid, AV_PIX_FMT_YUV420P) +FFMPEG_TEST_ACODEC_NAME(libvorbis, AV_SAMPLE_FMT_FLTP) +FFMPEG_TEST_ACODEC_NAME(libopus, AV_SAMPLE_FMT_FLT) +FFMPEG_TEST_ACODEC_NAME(libmp3lame, AV_SAMPLE_FMT_FLTP) diff --git a/intern/guardedalloc/CMakeLists.txt b/intern/guardedalloc/CMakeLists.txt index 1ab365a376a..ccc1500c014 100644 --- a/intern/guardedalloc/CMakeLists.txt +++ b/intern/guardedalloc/CMakeLists.txt @@ -78,3 +78,19 @@ if(WITH_CXX_GUARDEDALLOC) ) blender_add_lib(bf_intern_guardedalloc_cpp "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") endif() + +if(WITH_GTESTS) + set(TEST_SRC + tests/guardedalloc_alignment_test.cc + tests/guardedalloc_overflow_test.cc + ) + set(TEST_INC + ../../source/blender/blenlib + ) + set(TEST_LIB + bf_intern_guardedalloc + bf_blenlib + ) + include(GTestTesting) + blender_add_test_lib(bf_intern_guardedalloc_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}") +endif() diff --git a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc new file mode 100644 index 00000000000..4c676c6cc76 --- /dev/null +++ b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc @@ -0,0 +1,121 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "BLI_utildefines.h" + +#include "MEM_guardedalloc.h" + +#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0) + +namespace { + +void DoBasicAlignmentChecks(const int alignment) +{ + int *foo, *bar; + + foo = (int *)MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test"); + CHECK_ALIGNMENT(foo, alignment); + + bar = (int *)MEM_dupallocN(foo); + CHECK_ALIGNMENT(bar, alignment); + MEM_freeN(bar); + + foo = (int *)MEM_reallocN(foo, sizeof(int) * 5); + CHECK_ALIGNMENT(foo, alignment); + + foo = (int *)MEM_recallocN(foo, sizeof(int) * 5); + CHECK_ALIGNMENT(foo, alignment); + + MEM_freeN(foo); +} + +} // namespace + +TEST(guardedalloc, LockfreeAlignedAlloc1) +{ + DoBasicAlignmentChecks(1); +} + +TEST(guardedalloc, GuardedAlignedAlloc1) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(1); +} + +TEST(guardedalloc, LockfreeAlignedAlloc2) +{ + DoBasicAlignmentChecks(2); +} + +TEST(guardedalloc, GuardedAlignedAlloc2) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(2); +} + +TEST(guardedalloc, LockfreeAlignedAlloc4) +{ + DoBasicAlignmentChecks(4); +} + +TEST(guardedalloc, GuardedAlignedAlloc4) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(4); +} + +TEST(guardedalloc, LockfreeAlignedAlloc8) +{ + DoBasicAlignmentChecks(8); +} + +TEST(guardedalloc, GuardedAlignedAlloc8) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(8); +} + +TEST(guardedalloc, LockfreeAlignedAlloc16) +{ + DoBasicAlignmentChecks(16); +} + +TEST(guardedalloc, GuardedAlignedAlloc16) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(16); +} + +TEST(guardedalloc, LockfreeAlignedAlloc32) +{ + DoBasicAlignmentChecks(32); +} + +TEST(guardedalloc, GuardedAlignedAlloc32) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(32); +} + +TEST(guardedalloc, LockfreeAlignedAlloc256) +{ + DoBasicAlignmentChecks(256); +} + +TEST(guardedalloc, GuardedAlignedAlloc256) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(256); +} + +TEST(guardedalloc, LockfreeAlignedAlloc512) +{ + DoBasicAlignmentChecks(512); +} + +TEST(guardedalloc, GuardedAlignedAlloc512) +{ + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(512); +} diff --git a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc new file mode 100644 index 00000000000..bd47482d033 --- /dev/null +++ b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc @@ -0,0 +1,60 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "MEM_guardedalloc.h" + +/* We expect to abort on integer overflow, to prevent possible exploits. */ +#ifdef _WIN32 +# define ABORT_PREDICATE ::testing::ExitedWithCode(3) +#else +# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT) +#endif + +namespace { + +void MallocArray(size_t len, size_t size) +{ + void *mem = MEM_malloc_arrayN(len, size, "MallocArray"); + if (mem) { + MEM_freeN(mem); + } +} + +void CallocArray(size_t len, size_t size) +{ + void *mem = MEM_calloc_arrayN(len, size, "CallocArray"); + if (mem) { + MEM_freeN(mem); + } +} + +} // namespace + +TEST(guardedalloc, LockfreeIntegerOverflow) +{ + MallocArray(1, SIZE_MAX); + CallocArray(SIZE_MAX, 1); + MallocArray(SIZE_MAX / 2, 2); + CallocArray(SIZE_MAX / 1234567, 1234567); + + EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, ""); + EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, ""); + EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, ""); + EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, ""); +} + +TEST(guardedalloc, GuardedIntegerOverflow) +{ + MEM_use_guarded_allocator(); + + MallocArray(1, SIZE_MAX); + CallocArray(SIZE_MAX, 1); + MallocArray(SIZE_MAX / 2, 2); + CallocArray(SIZE_MAX / 1234567, 1234567); + + EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, ""); + EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, ""); + EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, ""); + EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, ""); +} |