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