1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <cstdio>
13*77c1e3ccSAndroid Build Coastguard Worker #include <ostream>
14*77c1e3ccSAndroid Build Coastguard Worker #include <string>
15*77c1e3ccSAndroid Build Coastguard Worker
16*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/ivf_video_source.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/video_source.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker namespace {
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker struct DecodeParam {
25*77c1e3ccSAndroid Build Coastguard Worker int threads;
26*77c1e3ccSAndroid Build Coastguard Worker const char *filename;
27*77c1e3ccSAndroid Build Coastguard Worker const char *res_filename; // If nullptr, the result filename is
28*77c1e3ccSAndroid Build Coastguard Worker // filename + ".res".
29*77c1e3ccSAndroid Build Coastguard Worker };
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker // Constructs result file name.
GetResFilename(const DecodeParam & param)32*77c1e3ccSAndroid Build Coastguard Worker std::string GetResFilename(const DecodeParam ¶m) {
33*77c1e3ccSAndroid Build Coastguard Worker if (param.res_filename != nullptr) return param.res_filename;
34*77c1e3ccSAndroid Build Coastguard Worker const std::string filename = param.filename;
35*77c1e3ccSAndroid Build Coastguard Worker return filename + ".res";
36*77c1e3ccSAndroid Build Coastguard Worker }
37*77c1e3ccSAndroid Build Coastguard Worker
operator <<(std::ostream & os,const DecodeParam & dp)38*77c1e3ccSAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const DecodeParam &dp) {
39*77c1e3ccSAndroid Build Coastguard Worker return os << "threads: " << dp.threads << " file: " << dp.filename
40*77c1e3ccSAndroid Build Coastguard Worker << " result file: " << GetResFilename(dp);
41*77c1e3ccSAndroid Build Coastguard Worker }
42*77c1e3ccSAndroid Build Coastguard Worker
43*77c1e3ccSAndroid Build Coastguard Worker class InvalidFileTest : public ::libaom_test::DecoderTest,
44*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::CodecTestWithParam<DecodeParam> {
45*77c1e3ccSAndroid Build Coastguard Worker protected:
InvalidFileTest()46*77c1e3ccSAndroid Build Coastguard Worker InvalidFileTest() : DecoderTest(GET_PARAM(0)), res_file_(nullptr) {}
47*77c1e3ccSAndroid Build Coastguard Worker
~InvalidFileTest()48*77c1e3ccSAndroid Build Coastguard Worker ~InvalidFileTest() override {
49*77c1e3ccSAndroid Build Coastguard Worker if (res_file_ != nullptr) fclose(res_file_);
50*77c1e3ccSAndroid Build Coastguard Worker }
51*77c1e3ccSAndroid Build Coastguard Worker
OpenResFile(const std::string & res_file_name)52*77c1e3ccSAndroid Build Coastguard Worker void OpenResFile(const std::string &res_file_name) {
53*77c1e3ccSAndroid Build Coastguard Worker res_file_ = libaom_test::OpenTestDataFile(res_file_name);
54*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(res_file_, nullptr)
55*77c1e3ccSAndroid Build Coastguard Worker << "Result file open failed. Filename: " << res_file_name;
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker
DecompressedFrameHook(const aom_image_t & img,const unsigned int)58*77c1e3ccSAndroid Build Coastguard Worker void DecompressedFrameHook(const aom_image_t &img,
59*77c1e3ccSAndroid Build Coastguard Worker const unsigned int /*frame_number*/) override {
60*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NE(img.fb_priv, nullptr);
61*77c1e3ccSAndroid Build Coastguard Worker }
62*77c1e3ccSAndroid Build Coastguard Worker
HandleDecodeResult(const aom_codec_err_t res_dec,const libaom_test::CompressedVideoSource & video,libaom_test::Decoder * decoder)63*77c1e3ccSAndroid Build Coastguard Worker bool HandleDecodeResult(const aom_codec_err_t res_dec,
64*77c1e3ccSAndroid Build Coastguard Worker const libaom_test::CompressedVideoSource &video,
65*77c1e3ccSAndroid Build Coastguard Worker libaom_test::Decoder *decoder) override {
66*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NE(res_file_, nullptr);
67*77c1e3ccSAndroid Build Coastguard Worker int expected_res_dec = -1;
68*77c1e3ccSAndroid Build Coastguard Worker
69*77c1e3ccSAndroid Build Coastguard Worker // Read integer result.
70*77c1e3ccSAndroid Build Coastguard Worker const int res = fscanf(res_file_, "%d", &expected_res_dec);
71*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NE(res, EOF) << "Read result data failed";
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker if (expected_res_dec != -1) {
74*77c1e3ccSAndroid Build Coastguard Worker // Check results match.
75*77c1e3ccSAndroid Build Coastguard Worker const DecodeParam input = GET_PARAM(1);
76*77c1e3ccSAndroid Build Coastguard Worker if (input.threads > 1) {
77*77c1e3ccSAndroid Build Coastguard Worker // The serial decode check is too strict for tile-threaded decoding as
78*77c1e3ccSAndroid Build Coastguard Worker // there is no guarantee on the decode order nor which specific error
79*77c1e3ccSAndroid Build Coastguard Worker // will take precedence. Currently a tile-level error is not forwarded
80*77c1e3ccSAndroid Build Coastguard Worker // so the frame will simply be marked corrupt.
81*77c1e3ccSAndroid Build Coastguard Worker EXPECT_TRUE(res_dec == expected_res_dec ||
82*77c1e3ccSAndroid Build Coastguard Worker res_dec == AOM_CODEC_CORRUPT_FRAME)
83*77c1e3ccSAndroid Build Coastguard Worker << "Results don't match: frame number = " << video.frame_number()
84*77c1e3ccSAndroid Build Coastguard Worker << ". (" << decoder->DecodeError()
85*77c1e3ccSAndroid Build Coastguard Worker << "). Expected: " << expected_res_dec << " or "
86*77c1e3ccSAndroid Build Coastguard Worker << AOM_CODEC_CORRUPT_FRAME;
87*77c1e3ccSAndroid Build Coastguard Worker } else {
88*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_res_dec, res_dec)
89*77c1e3ccSAndroid Build Coastguard Worker << "Results don't match: frame number = " << video.frame_number()
90*77c1e3ccSAndroid Build Coastguard Worker << ". (" << decoder->DecodeError() << ")";
91*77c1e3ccSAndroid Build Coastguard Worker }
92*77c1e3ccSAndroid Build Coastguard Worker }
93*77c1e3ccSAndroid Build Coastguard Worker
94*77c1e3ccSAndroid Build Coastguard Worker return !HasFailure();
95*77c1e3ccSAndroid Build Coastguard Worker }
96*77c1e3ccSAndroid Build Coastguard Worker
HandlePeekResult(libaom_test::Decoder * const,libaom_test::CompressedVideoSource *,const aom_codec_err_t)97*77c1e3ccSAndroid Build Coastguard Worker void HandlePeekResult(libaom_test::Decoder *const /*decoder*/,
98*77c1e3ccSAndroid Build Coastguard Worker libaom_test::CompressedVideoSource * /*video*/,
99*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t /*res_peek*/) override {}
100*77c1e3ccSAndroid Build Coastguard Worker
RunTest()101*77c1e3ccSAndroid Build Coastguard Worker void RunTest() {
102*77c1e3ccSAndroid Build Coastguard Worker const DecodeParam input = GET_PARAM(1);
103*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = { 0, 0, 0, !FORCE_HIGHBITDEPTH_DECODING };
104*77c1e3ccSAndroid Build Coastguard Worker cfg.threads = input.threads;
105*77c1e3ccSAndroid Build Coastguard Worker libaom_test::IVFVideoSource decode_video(input.filename);
106*77c1e3ccSAndroid Build Coastguard Worker decode_video.Init();
107*77c1e3ccSAndroid Build Coastguard Worker
108*77c1e3ccSAndroid Build Coastguard Worker // The result file holds a list of expected integer results, one for each
109*77c1e3ccSAndroid Build Coastguard Worker // decoded frame. Any result that doesn't match the file's list will
110*77c1e3ccSAndroid Build Coastguard Worker // cause a test failure.
111*77c1e3ccSAndroid Build Coastguard Worker const std::string res_filename = GetResFilename(input);
112*77c1e3ccSAndroid Build Coastguard Worker OpenResFile(res_filename);
113*77c1e3ccSAndroid Build Coastguard Worker
114*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&decode_video, cfg));
115*77c1e3ccSAndroid Build Coastguard Worker }
116*77c1e3ccSAndroid Build Coastguard Worker
117*77c1e3ccSAndroid Build Coastguard Worker private:
118*77c1e3ccSAndroid Build Coastguard Worker FILE *res_file_;
119*77c1e3ccSAndroid Build Coastguard Worker };
120*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(InvalidFileTest,ReturnCode)121*77c1e3ccSAndroid Build Coastguard Worker TEST_P(InvalidFileTest, ReturnCode) { RunTest(); }
122*77c1e3ccSAndroid Build Coastguard Worker
123*77c1e3ccSAndroid Build Coastguard Worker // If res_filename (the third field) is nullptr, then the result filename is
124*77c1e3ccSAndroid Build Coastguard Worker // filename + ".res" by default. Set res_filename to a string if the result
125*77c1e3ccSAndroid Build Coastguard Worker // filename differs from the default.
126*77c1e3ccSAndroid Build Coastguard Worker const DecodeParam kAV1InvalidFileTests[] = {
127*77c1e3ccSAndroid Build Coastguard Worker // { threads, filename, res_filename }
128*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-bug-1814.ivf", nullptr },
129*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-chromium-906381.ivf", nullptr },
130*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-google-142530197.ivf", nullptr },
131*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-google-142530197-1.ivf", nullptr },
132*77c1e3ccSAndroid Build Coastguard Worker { 4, "invalid-oss-fuzz-9463.ivf", "invalid-oss-fuzz-9463.ivf.res.2" },
133*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-9720.ivf", nullptr },
134*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10389.ivf", "invalid-oss-fuzz-10389.ivf.res.4" },
135*77c1e3ccSAndroid Build Coastguard Worker #if !defined(CHROMIUM) && !CONFIG_SIZE_LIMIT || \
136*77c1e3ccSAndroid Build Coastguard Worker (CONFIG_SIZE_LIMIT && DECODE_WIDTH_LIMIT >= 5120 && \
137*77c1e3ccSAndroid Build Coastguard Worker DECODE_HEIGHT_LIMIT >= 180)
138*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-11523.ivf", "invalid-oss-fuzz-11523.ivf.res.2" },
139*77c1e3ccSAndroid Build Coastguard Worker #endif
140*77c1e3ccSAndroid Build Coastguard Worker { 4, "invalid-oss-fuzz-15363.ivf", nullptr },
141*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-16437.ivf", "invalid-oss-fuzz-16437.ivf.res.2" },
142*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MAX_DECODE_PROFILE >= 1
143*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-24706.ivf", nullptr },
144*77c1e3ccSAndroid Build Coastguard Worker #endif
145*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
146*77c1e3ccSAndroid Build Coastguard Worker // These test vectors contain 10-bit or 12-bit video.
147*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-9288.ivf", nullptr },
148*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-9482.ivf", nullptr },
149*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10061.ivf", nullptr },
150*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10117-mc-buf-use-highbd.ivf", nullptr },
151*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10227.ivf", nullptr },
152*77c1e3ccSAndroid Build Coastguard Worker { 4, "invalid-oss-fuzz-10555.ivf", nullptr },
153*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10705.ivf", nullptr },
154*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_CWG_C013
155*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10723.ivf", "invalid-oss-fuzz-10723.ivf.res.3" },
156*77c1e3ccSAndroid Build Coastguard Worker #else
157*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10723.ivf", "invalid-oss-fuzz-10723.ivf.res.2" },
158*77c1e3ccSAndroid Build Coastguard Worker #endif
159*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-10779.ivf", nullptr },
160*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-11477.ivf", nullptr },
161*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-11479.ivf", "invalid-oss-fuzz-11479.ivf.res.2" },
162*77c1e3ccSAndroid Build Coastguard Worker { 1, "invalid-oss-fuzz-33030.ivf", nullptr },
163*77c1e3ccSAndroid Build Coastguard Worker #endif
164*77c1e3ccSAndroid Build Coastguard Worker };
165*77c1e3ccSAndroid Build Coastguard Worker
166*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(InvalidFileTest,
167*77c1e3ccSAndroid Build Coastguard Worker ::testing::ValuesIn(kAV1InvalidFileTests));
168*77c1e3ccSAndroid Build Coastguard Worker
169*77c1e3ccSAndroid Build Coastguard Worker } // namespace
170