vp9[loongarch]: Optimize fdct4x4/8x8_lsx
[platform/upstream/libvpx.git] / test / test_vector_test.cc
1 /*
2  *  Copyright (c) 2013 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 <memory>
14 #include <set>
15 #include <string>
16 #include <tuple>
17
18 #include "third_party/googletest/src/include/gtest/gtest.h"
19 #include "../tools_common.h"
20 #include "./vpx_config.h"
21 #include "test/codec_factory.h"
22 #include "test/decode_test_driver.h"
23 #include "test/ivf_video_source.h"
24 #include "test/md5_helper.h"
25 #include "test/test_vectors.h"
26 #include "test/util.h"
27 #if CONFIG_WEBM_IO
28 #include "test/webm_video_source.h"
29 #endif
30 #include "vpx_mem/vpx_mem.h"
31
32 namespace {
33
34 const int kThreads = 0;
35 const int kMtMode = 1;
36 const int kFileName = 2;
37
38 typedef std::tuple<int, int, const char *> DecodeParam;
39
40 class TestVectorTest : public ::libvpx_test::DecoderTest,
41                        public ::libvpx_test::CodecTestWithParam<DecodeParam> {
42  protected:
43   TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(nullptr) {
44 #if CONFIG_VP9_DECODER
45     resize_clips_.insert(::libvpx_test::kVP9TestVectorsResize,
46                          ::libvpx_test::kVP9TestVectorsResize +
47                              ::libvpx_test::kNumVP9TestVectorsResize);
48 #endif
49   }
50
51   virtual ~TestVectorTest() {
52     if (md5_file_) fclose(md5_file_);
53   }
54
55   void OpenMD5File(const std::string &md5_file_name_) {
56     md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
57     ASSERT_NE(md5_file_, nullptr)
58         << "Md5 file open failed. Filename: " << md5_file_name_;
59   }
60
61 #if CONFIG_VP9_DECODER
62   virtual void PreDecodeFrameHook(
63       const libvpx_test::CompressedVideoSource &video,
64       libvpx_test::Decoder *decoder) {
65     if (video.frame_number() == 0 && mt_mode_ >= 0) {
66       if (mt_mode_ == 1) {
67         decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 1);
68         decoder->Control(VP9D_SET_ROW_MT, 0);
69       } else if (mt_mode_ == 2) {
70         decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
71         decoder->Control(VP9D_SET_ROW_MT, 1);
72       } else {
73         decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
74         decoder->Control(VP9D_SET_ROW_MT, 0);
75       }
76     }
77   }
78 #endif
79
80   virtual void DecompressedFrameHook(const vpx_image_t &img,
81                                      const unsigned int frame_number) {
82     ASSERT_NE(md5_file_, nullptr);
83     char expected_md5[33];
84     char junk[128];
85
86     // Read correct md5 checksums.
87     const int res = fscanf(md5_file_, "%s  %s", expected_md5, junk);
88     ASSERT_NE(res, EOF) << "Read md5 data failed";
89     expected_md5[32] = '\0';
90
91     ::libvpx_test::MD5 md5_res;
92     md5_res.Add(&img);
93     const char *actual_md5 = md5_res.Get();
94
95     // Check md5 match.
96     ASSERT_STREQ(expected_md5, actual_md5)
97         << "Md5 checksums don't match: frame number = " << frame_number;
98   }
99
100 #if CONFIG_VP9_DECODER
101   std::set<std::string> resize_clips_;
102 #endif
103   int mt_mode_;
104
105  private:
106   FILE *md5_file_;
107 };
108
109 // This test runs through the whole set of test vectors, and decodes them.
110 // The md5 checksums are computed for each frame in the video file. If md5
111 // checksums match the correct md5 data, then the test is passed. Otherwise,
112 // the test failed.
113 TEST_P(TestVectorTest, MD5Match) {
114   const DecodeParam input = GET_PARAM(1);
115   const std::string filename = std::get<kFileName>(input);
116   vpx_codec_flags_t flags = 0;
117   vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
118   char str[256];
119
120   cfg.threads = std::get<kThreads>(input);
121   mt_mode_ = std::get<kMtMode>(input);
122   snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
123            "file: %s threads: %d MT mode: %d", filename.c_str(), cfg.threads,
124            mt_mode_);
125   SCOPED_TRACE(str);
126
127   // Open compressed video file.
128   std::unique_ptr<libvpx_test::CompressedVideoSource> video;
129   if (filename.substr(filename.length() - 3, 3) == "ivf") {
130     video.reset(new libvpx_test::IVFVideoSource(filename));
131   } else if (filename.substr(filename.length() - 4, 4) == "webm") {
132 #if CONFIG_WEBM_IO
133     video.reset(new libvpx_test::WebMVideoSource(filename));
134 #else
135     fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
136             filename.c_str());
137     return;
138 #endif
139   }
140   ASSERT_NE(video.get(), nullptr);
141   video->Init();
142
143   // Construct md5 file name.
144   const std::string md5_filename = filename + ".md5";
145   OpenMD5File(md5_filename);
146
147   // Set decode config and flags.
148   set_cfg(cfg);
149   set_flags(flags);
150
151   // Decode frame, and check the md5 matching.
152   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg));
153 }
154
155 #if CONFIG_VP8_DECODER
156 VP8_INSTANTIATE_TEST_SUITE(
157     TestVectorTest,
158     ::testing::Combine(
159         ::testing::Values(1),   // Single thread.
160         ::testing::Values(-1),  // LPF opt and Row MT is not applicable
161         ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
162                             libvpx_test::kVP8TestVectors +
163                                 libvpx_test::kNumVP8TestVectors)));
164
165 // Test VP8 decode in with different numbers of threads.
166 INSTANTIATE_TEST_SUITE_P(
167     VP8MultiThreaded, TestVectorTest,
168     ::testing::Combine(
169         ::testing::Values(
170             static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)),
171         ::testing::Combine(
172             ::testing::Range(2, 9),  // With 2 ~ 8 threads.
173             ::testing::Values(-1),   // LPF opt and Row MT is not applicable
174             ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
175                                 libvpx_test::kVP8TestVectors +
176                                     libvpx_test::kNumVP8TestVectors))));
177
178 #endif  // CONFIG_VP8_DECODER
179
180 #if CONFIG_VP9_DECODER
181 VP9_INSTANTIATE_TEST_SUITE(
182     TestVectorTest,
183     ::testing::Combine(
184         ::testing::Values(1),   // Single thread.
185         ::testing::Values(-1),  // LPF opt and Row MT is not applicable
186         ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
187                             libvpx_test::kVP9TestVectors +
188                                 libvpx_test::kNumVP9TestVectors)));
189
190 INSTANTIATE_TEST_SUITE_P(
191     VP9MultiThreaded, TestVectorTest,
192     ::testing::Combine(
193         ::testing::Values(
194             static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
195         ::testing::Combine(
196             ::testing::Range(2, 9),  // With 2 ~ 8 threads.
197             ::testing::Range(0, 3),  // With multi threads modes 0 ~ 2
198                                      // 0: LPF opt and Row MT disabled
199                                      // 1: LPF opt enabled
200                                      // 2: Row MT enabled
201             ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
202                                 libvpx_test::kVP9TestVectors +
203                                     libvpx_test::kNumVP9TestVectors))));
204 #endif
205 }  // namespace