invalid_file_test.cc 7.8 KB

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