invalid_file_test.cc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <string>
  13. #include <vector>
  14. #include "third_party/googletest/src/include/gtest/gtest.h"
  15. #include "./vpx_config.h"
  16. #include "test/codec_factory.h"
  17. #include "test/decode_test_driver.h"
  18. #include "test/ivf_video_source.h"
  19. #include "test/util.h"
  20. #if CONFIG_WEBM_IO
  21. #include "test/webm_video_source.h"
  22. #endif
  23. #include "vpx_mem/vpx_mem.h"
  24. namespace {
  25. struct DecodeParam {
  26. int threads;
  27. const char *filename;
  28. };
  29. std::ostream &operator<<(std::ostream &os, const DecodeParam &dp) {
  30. return os << "threads: " << dp.threads << " file: " << dp.filename;
  31. }
  32. class InvalidFileTest : public ::libvpx_test::DecoderTest,
  33. public ::libvpx_test::CodecTestWithParam<DecodeParam> {
  34. protected:
  35. InvalidFileTest() : DecoderTest(GET_PARAM(0)), res_file_(NULL) {}
  36. virtual ~InvalidFileTest() {
  37. if (res_file_ != NULL) fclose(res_file_);
  38. }
  39. void OpenResFile(const std::string &res_file_name_) {
  40. res_file_ = libvpx_test::OpenTestDataFile(res_file_name_);
  41. ASSERT_TRUE(res_file_ != NULL)
  42. << "Result file open failed. Filename: " << res_file_name_;
  43. }
  44. virtual bool HandleDecodeResult(
  45. const vpx_codec_err_t res_dec,
  46. const libvpx_test::CompressedVideoSource &video,
  47. libvpx_test::Decoder *decoder) {
  48. EXPECT_TRUE(res_file_ != NULL);
  49. int expected_res_dec;
  50. // Read integer result.
  51. const int res = fscanf(res_file_, "%d", &expected_res_dec);
  52. EXPECT_NE(res, EOF) << "Read result data failed";
  53. // Check results match.
  54. const DecodeParam input = GET_PARAM(1);
  55. if (input.threads > 1) {
  56. // The serial decode check is too strict for tile-threaded decoding as
  57. // there is no guarantee on the decode order nor which specific error
  58. // will take precedence. Currently a tile-level error is not forwarded so
  59. // the frame will simply be marked corrupt.
  60. EXPECT_TRUE(res_dec == expected_res_dec ||
  61. res_dec == VPX_CODEC_CORRUPT_FRAME)
  62. << "Results don't match: frame number = " << video.frame_number()
  63. << ". (" << decoder->DecodeError()
  64. << "). Expected: " << expected_res_dec << " or "
  65. << VPX_CODEC_CORRUPT_FRAME;
  66. } else {
  67. EXPECT_EQ(expected_res_dec, res_dec)
  68. << "Results don't match: frame number = " << video.frame_number()
  69. << ". (" << decoder->DecodeError() << ")";
  70. }
  71. return !HasFailure();
  72. }
  73. void RunTest() {
  74. const DecodeParam input = GET_PARAM(1);
  75. vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
  76. cfg.threads = input.threads;
  77. const std::string filename = input.filename;
  78. // Open compressed video file.
  79. testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
  80. if (filename.substr(filename.length() - 3, 3) == "ivf") {
  81. video.reset(new libvpx_test::IVFVideoSource(filename));
  82. } else if (filename.substr(filename.length() - 4, 4) == "webm") {
  83. #if CONFIG_WEBM_IO
  84. video.reset(new libvpx_test::WebMVideoSource(filename));
  85. #else
  86. fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
  87. filename.c_str());
  88. return;
  89. #endif
  90. }
  91. ASSERT_TRUE(video.get() != NULL);
  92. video->Init();
  93. // Construct result file name. The file holds a list of expected integer
  94. // results, one for each decoded frame. Any result that doesn't match
  95. // the files list will cause a test failure.
  96. const std::string res_filename = filename + ".res";
  97. OpenResFile(res_filename);
  98. // Decode frame, and check the md5 matching.
  99. ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg));
  100. }
  101. private:
  102. FILE *res_file_;
  103. };
  104. TEST_P(InvalidFileTest, ReturnCode) { RunTest(); }
  105. #if CONFIG_VP8_DECODER
  106. const DecodeParam kVP8InvalidFileTests[] = {
  107. { 1, "invalid-bug-1443.ivf" },
  108. };
  109. VP8_INSTANTIATE_TEST_CASE(InvalidFileTest,
  110. ::testing::ValuesIn(kVP8InvalidFileTests));
  111. #endif // CONFIG_VP8_DECODER
  112. #if CONFIG_VP9_DECODER
  113. const DecodeParam kVP9InvalidFileTests[] = {
  114. { 1, "invalid-vp90-02-v2.webm" },
  115. #if CONFIG_VP9_HIGHBITDEPTH
  116. { 1, "invalid-vp90-2-00-quantizer-00.webm.ivf.s5861_r01-05_b6-.v2.ivf" },
  117. #endif
  118. { 1, "invalid-vp90-03-v3.webm" },
  119. { 1, "invalid-vp90-2-00-quantizer-11.webm.ivf.s52984_r01-05_b6-.ivf" },
  120. { 1, "invalid-vp90-2-00-quantizer-11.webm.ivf.s52984_r01-05_b6-z.ivf" },
  121. // This file will cause a large allocation which is expected to fail in 32-bit
  122. // environments. Test x86 for coverage purposes as the allocation failure will
  123. // be in platform agnostic code.
  124. #if ARCH_X86
  125. { 1, "invalid-vp90-2-00-quantizer-63.ivf.kf_65527x61446.ivf" },
  126. #endif
  127. { 1, "invalid-vp90-2-12-droppable_1.ivf.s3676_r01-05_b6-.ivf" },
  128. { 1, "invalid-vp90-2-05-resize.ivf.s59293_r01-05_b6-.ivf" },
  129. { 1, "invalid-vp90-2-09-subpixel-00.ivf.s20492_r01-05_b6-.v2.ivf" },
  130. { 1, "invalid-vp91-2-mixedrefcsp-444to420.ivf" },
  131. { 1, "invalid-vp90-2-12-droppable_1.ivf.s73804_r01-05_b6-.ivf" },
  132. { 1, "invalid-vp90-2-03-size-224x196.webm.ivf.s44156_r01-05_b6-.ivf" },
  133. { 1, "invalid-vp90-2-03-size-202x210.webm.ivf.s113306_r01-05_b6-.ivf" },
  134. { 1,
  135. "invalid-vp90-2-10-show-existing-frame.webm.ivf.s180315_r01-05_b6-.ivf" },
  136. { 1, "invalid-crbug-667044.webm" },
  137. };
  138. VP9_INSTANTIATE_TEST_CASE(InvalidFileTest,
  139. ::testing::ValuesIn(kVP9InvalidFileTests));
  140. #endif // CONFIG_VP9_DECODER
  141. // This class will include test vectors that are expected to fail
  142. // peek. However they are still expected to have no fatal failures.
  143. class InvalidFileInvalidPeekTest : public InvalidFileTest {
  144. protected:
  145. InvalidFileInvalidPeekTest() : InvalidFileTest() {}
  146. virtual void HandlePeekResult(libvpx_test::Decoder *const /*decoder*/,
  147. libvpx_test::CompressedVideoSource * /*video*/,
  148. const vpx_codec_err_t /*res_peek*/) {}
  149. };
  150. TEST_P(InvalidFileInvalidPeekTest, ReturnCode) { RunTest(); }
  151. #if CONFIG_VP8_DECODER
  152. const DecodeParam kVP8InvalidPeekTests[] = {
  153. { 1, "invalid-vp80-00-comprehensive-018.ivf.2kf_0x6.ivf" },
  154. };
  155. VP8_INSTANTIATE_TEST_CASE(InvalidFileInvalidPeekTest,
  156. ::testing::ValuesIn(kVP8InvalidPeekTests));
  157. #endif // CONFIG_VP8_DECODER
  158. #if CONFIG_VP9_DECODER
  159. const DecodeParam kVP9InvalidFileInvalidPeekTests[] = {
  160. { 1, "invalid-vp90-01-v3.webm" },
  161. };
  162. VP9_INSTANTIATE_TEST_CASE(InvalidFileInvalidPeekTest,
  163. ::testing::ValuesIn(kVP9InvalidFileInvalidPeekTests));
  164. const DecodeParam kMultiThreadedVP9InvalidFileTests[] = {
  165. { 4, "invalid-vp90-2-08-tile_1x4_frame_parallel_all_key.webm" },
  166. { 4,
  167. "invalid-"
  168. "vp90-2-08-tile_1x2_frame_parallel.webm.ivf.s47039_r01-05_b6-.ivf" },
  169. { 4,
  170. "invalid-vp90-2-08-tile_1x8_frame_parallel.webm.ivf.s288_r01-05_b6-.ivf" },
  171. { 2, "invalid-vp90-2-09-aq2.webm.ivf.s3984_r01-05_b6-.v2.ivf" },
  172. { 4, "invalid-vp90-2-09-subpixel-00.ivf.s19552_r01-05_b6-.v2.ivf" },
  173. { 2, "invalid-crbug-629481.webm" },
  174. };
  175. INSTANTIATE_TEST_CASE_P(
  176. VP9MultiThreaded, InvalidFileTest,
  177. ::testing::Combine(
  178. ::testing::Values(
  179. static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
  180. ::testing::ValuesIn(kMultiThreadedVP9InvalidFileTests)));
  181. #endif // CONFIG_VP9_DECODER
  182. } // namespace