xref: /aosp_15_r20/external/libaom/test/ethread_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include <string>
13 #include <vector>
14 #include "gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/md5_helper.h"
18 #include "test/util.h"
19 #include "test/y4m_video_source.h"
20 #include "test/yuv_video_source.h"
21 #include "av1/encoder/enc_enums.h"
22 #include "av1/encoder/firstpass.h"
23 
24 namespace {
25 const unsigned int kCqLevel = 18;
26 
27 #if !CONFIG_REALTIME_ONLY
28 const size_t kFirstPassStatsSz = sizeof(FIRSTPASS_STATS);
29 class AVxFirstPassEncoderThreadTest
30     : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
31                                                  int, int>,
32       public ::libaom_test::EncoderTest {
33  protected:
AVxFirstPassEncoderThreadTest()34   AVxFirstPassEncoderThreadTest()
35       : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
36         encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)),
37         tile_rows_(GET_PARAM(3)), tile_cols_(GET_PARAM(4)) {
38     init_flags_ = AOM_CODEC_USE_PSNR;
39 
40     row_mt_ = 1;
41     firstpass_stats_.buf = nullptr;
42     firstpass_stats_.sz = 0;
43   }
~AVxFirstPassEncoderThreadTest()44   ~AVxFirstPassEncoderThreadTest() override { free(firstpass_stats_.buf); }
45 
SetUp()46   void SetUp() override {
47     InitializeConfig(encoding_mode_);
48 
49     cfg_.g_lag_in_frames = 35;
50     cfg_.rc_end_usage = AOM_VBR;
51     cfg_.rc_2pass_vbr_minsection_pct = 5;
52     cfg_.rc_2pass_vbr_maxsection_pct = 2000;
53     cfg_.rc_max_quantizer = 56;
54     cfg_.rc_min_quantizer = 0;
55   }
56 
BeginPassHook(unsigned int)57   void BeginPassHook(unsigned int /*pass*/) override {
58     encoder_initialized_ = false;
59     abort_ = false;
60   }
61 
EndPassHook()62   void EndPassHook() override {
63     // For first pass stats test, only run first pass encoder.
64     if (cfg_.g_pass == AOM_RC_FIRST_PASS) abort_ = true;
65   }
66 
PreEncodeFrameHook(::libaom_test::VideoSource *,::libaom_test::Encoder * encoder)67   void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
68                           ::libaom_test::Encoder *encoder) override {
69     if (!encoder_initialized_) {
70       // Encode in 2-pass mode.
71       SetTileSize(encoder);
72       encoder->Control(AV1E_SET_ROW_MT, row_mt_);
73       encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
74       encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
75       encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
76       encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
77       encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
78 
79       encoder_initialized_ = true;
80     }
81   }
82 
SetTileSize(libaom_test::Encoder * encoder)83   virtual void SetTileSize(libaom_test::Encoder *encoder) {
84     encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
85     encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
86   }
87 
StatsPktHook(const aom_codec_cx_pkt_t * pkt)88   void StatsPktHook(const aom_codec_cx_pkt_t *pkt) override {
89     const uint8_t *const pkt_buf =
90         reinterpret_cast<uint8_t *>(pkt->data.twopass_stats.buf);
91     const size_t pkt_size = pkt->data.twopass_stats.sz;
92 
93     // First pass stats size equals sizeof(FIRSTPASS_STATS)
94     EXPECT_EQ(pkt_size, kFirstPassStatsSz)
95         << "Error: First pass stats size doesn't equal kFirstPassStatsSz";
96 
97     firstpass_stats_.buf =
98         realloc(firstpass_stats_.buf, firstpass_stats_.sz + pkt_size);
99     ASSERT_NE(firstpass_stats_.buf, nullptr);
100     memcpy((uint8_t *)firstpass_stats_.buf + firstpass_stats_.sz, pkt_buf,
101            pkt_size);
102     firstpass_stats_.sz += pkt_size;
103   }
104 
105   void DoTest();
106 
107   bool encoder_initialized_;
108   ::libaom_test::TestMode encoding_mode_;
109   int set_cpu_used_;
110   int tile_rows_;
111   int tile_cols_;
112   int row_mt_;
113   aom_fixed_buf_t firstpass_stats_;
114 };
115 
compare_fp_stats_md5(aom_fixed_buf_t * fp_stats)116 static void compare_fp_stats_md5(aom_fixed_buf_t *fp_stats) {
117   // fp_stats consists of 2 set of first pass encoding stats. These 2 set of
118   // stats are compared to check if the stats match.
119   uint8_t *stats1 = reinterpret_cast<uint8_t *>(fp_stats->buf);
120   uint8_t *stats2 = stats1 + fp_stats->sz / 2;
121   ::libaom_test::MD5 md5_row_mt_0, md5_row_mt_1;
122 
123   md5_row_mt_0.Add(stats1, fp_stats->sz / 2);
124   const char *md5_row_mt_0_str = md5_row_mt_0.Get();
125 
126   md5_row_mt_1.Add(stats2, fp_stats->sz / 2);
127   const char *md5_row_mt_1_str = md5_row_mt_1.Get();
128 
129   // Check md5 match.
130   ASSERT_STREQ(md5_row_mt_0_str, md5_row_mt_1_str)
131       << "MD5 checksums don't match";
132 }
133 
DoTest()134 void AVxFirstPassEncoderThreadTest::DoTest() {
135   ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
136   aom_fixed_buf_t firstpass_stats;
137   size_t single_run_sz;
138 
139   cfg_.rc_target_bitrate = 1000;
140 
141   // 5 encodes will be run:
142   // 1. row_mt_=0 and threads=1
143   // 2. row_mt_=1 and threads=1
144   // 3. row_mt_=1 and threads=2
145   // 4. row_mt_=1 and threads=4
146   // 5. row_mt_=1 and threads=8
147 
148   // 4 comparisons will be made:
149   // 1. Between run 1 and run 2.
150   // 2. Between run 2 and run 3.
151   // 3. Between run 3 and run 4.
152   // 4. Between run 4 and run 5.
153 
154   // Test row_mt_: 0 vs 1 at single thread case(threads = 1)
155   cfg_.g_threads = 1;
156 
157   row_mt_ = 0;
158   init_flags_ = AOM_CODEC_USE_PSNR;
159   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
160 
161   row_mt_ = 1;
162   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
163 
164   firstpass_stats.buf = firstpass_stats_.buf;
165   firstpass_stats.sz = firstpass_stats_.sz;
166   single_run_sz = firstpass_stats_.sz / 2;
167 
168   // Compare to check if using or not using row-mt are bit exact.
169   // Comparison 1 (between row_mt_=0 and row_mt_=1).
170   ASSERT_NO_FATAL_FAILURE(compare_fp_stats_md5(&firstpass_stats));
171 
172   // Test single thread vs multiple threads
173   row_mt_ = 1;
174 
175   cfg_.g_threads = 2;
176   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
177 
178   // offset to the 2nd and 3rd run.
179   firstpass_stats.buf = reinterpret_cast<void *>(
180       reinterpret_cast<uint8_t *>(firstpass_stats_.buf) + single_run_sz);
181 
182   // Compare to check if single-thread and multi-thread stats are bit exact.
183   // Comparison 2 (between threads=1 and threads=2).
184   ASSERT_NO_FATAL_FAILURE(compare_fp_stats_md5(&firstpass_stats));
185 
186   cfg_.g_threads = 4;
187   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
188 
189   // offset to the 3rd and 4th run
190   firstpass_stats.buf = reinterpret_cast<void *>(
191       reinterpret_cast<uint8_t *>(firstpass_stats_.buf) + single_run_sz * 2);
192 
193   // Comparison 3 (between threads=2 and threads=4).
194   ASSERT_NO_FATAL_FAILURE(compare_fp_stats_md5(&firstpass_stats));
195 
196   cfg_.g_threads = 8;
197   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
198 
199   // offset to the 4th and 5th run.
200   firstpass_stats.buf = reinterpret_cast<void *>(
201       reinterpret_cast<uint8_t *>(firstpass_stats_.buf) + single_run_sz * 3);
202 
203   // Comparison 4 (between threads=4 and threads=8).
204   compare_fp_stats_md5(&firstpass_stats);
205 }
206 
TEST_P(AVxFirstPassEncoderThreadTest,FirstPassStatsTest)207 TEST_P(AVxFirstPassEncoderThreadTest, FirstPassStatsTest) { DoTest(); }
208 
209 using AVxFirstPassEncoderThreadTestLarge = AVxFirstPassEncoderThreadTest;
210 
TEST_P(AVxFirstPassEncoderThreadTestLarge,FirstPassStatsTest)211 TEST_P(AVxFirstPassEncoderThreadTestLarge, FirstPassStatsTest) { DoTest(); }
212 
213 #endif  // !CONFIG_REALTIME_ONLY
214 
215 class AVxEncoderThreadTest
216     : public ::libaom_test::CodecTestWith5Params<libaom_test::TestMode, int,
217                                                  int, int, int>,
218       public ::libaom_test::EncoderTest {
219  protected:
AVxEncoderThreadTest()220   AVxEncoderThreadTest()
221       : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
222         encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)),
223         tile_cols_(GET_PARAM(3)), tile_rows_(GET_PARAM(4)),
224         row_mt_(GET_PARAM(5)) {
225     init_flags_ = AOM_CODEC_USE_PSNR;
226     aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
227     cfg.w = 1280;
228     cfg.h = 720;
229     cfg.allow_lowbitdepth = 1;
230     decoder_ = codec_->CreateDecoder(cfg, 0);
231     if (decoder_->IsAV1()) {
232       decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
233       decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
234     }
235 
236     size_enc_.clear();
237     md5_dec_.clear();
238     md5_enc_.clear();
239   }
~AVxEncoderThreadTest()240   ~AVxEncoderThreadTest() override { delete decoder_; }
241 
SetUp()242   void SetUp() override {
243     InitializeConfig(encoding_mode_);
244 
245     if (encoding_mode_ == ::libaom_test::kOnePassGood ||
246         encoding_mode_ == ::libaom_test::kTwoPassGood) {
247       cfg_.g_lag_in_frames = 6;
248       cfg_.rc_2pass_vbr_minsection_pct = 5;
249       cfg_.rc_2pass_vbr_maxsection_pct = 2000;
250     } else if (encoding_mode_ == ::libaom_test::kRealTime) {
251       cfg_.g_error_resilient = 1;
252     }
253     cfg_.rc_max_quantizer = 56;
254     cfg_.rc_min_quantizer = 0;
255   }
256 
BeginPassHook(unsigned int)257   void BeginPassHook(unsigned int /*pass*/) override {
258     encoder_initialized_ = false;
259   }
260 
PreEncodeFrameHook(::libaom_test::VideoSource *,::libaom_test::Encoder * encoder)261   void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
262                           ::libaom_test::Encoder *encoder) override {
263     if (!encoder_initialized_) {
264       SetTileSize(encoder);
265       encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
266       encoder->Control(AV1E_SET_ROW_MT, row_mt_);
267       if (encoding_mode_ == ::libaom_test::kOnePassGood ||
268           encoding_mode_ == ::libaom_test::kTwoPassGood) {
269         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
270         encoder->Control(AOME_SET_ARNR_MAXFRAMES, 5);
271         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
272         encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
273         encoder->Control(AV1E_SET_MAX_GF_INTERVAL, 4);
274         // In row_mt_=0 case, the output of single thread (1 thread) will be
275         // compared with multi thread (4 thread) output (as per line no:340).
276         // Currently, Loop restoration stage is conditionally disabled for speed
277         // 5, 6 when num_workers > 1. Due to this, the match between single
278         // thread and multi thread output can not be achieved. Hence, testing
279         // this case alone with LR disabled.
280         // TODO(aomedia:3446): Remove the constraint on this test case once Loop
281         // restoration state is same in both single and multi thread path.
282         if (set_cpu_used_ >= 5 && row_mt_ == 0)
283           encoder->Control(AV1E_SET_ENABLE_RESTORATION, 0);
284       } else if (encoding_mode_ == ::libaom_test::kRealTime) {
285         encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
286         encoder->Control(AV1E_SET_AQ_MODE, 3);
287         encoder->Control(AV1E_SET_COEFF_COST_UPD_FREQ, 2);
288         encoder->Control(AV1E_SET_MODE_COST_UPD_FREQ, 2);
289         encoder->Control(AV1E_SET_MV_COST_UPD_FREQ, 3);
290         encoder->Control(AV1E_SET_DV_COST_UPD_FREQ, 3);
291       } else {
292         encoder->Control(AOME_SET_CQ_LEVEL, kCqLevel);
293       }
294       encoder_initialized_ = true;
295     }
296   }
297 
SetTileSize(libaom_test::Encoder * encoder)298   virtual void SetTileSize(libaom_test::Encoder *encoder) {
299     encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
300     encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
301   }
302 
FramePktHook(const aom_codec_cx_pkt_t * pkt)303   void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
304     size_enc_.push_back(pkt->data.frame.sz);
305 
306     ::libaom_test::MD5 md5_enc;
307     md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
308                 pkt->data.frame.sz);
309     md5_enc_.push_back(md5_enc.Get());
310 
311     const aom_codec_err_t res = decoder_->DecodeFrame(
312         reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
313     if (res != AOM_CODEC_OK) {
314       abort_ = true;
315       ASSERT_EQ(AOM_CODEC_OK, res);
316     }
317     const aom_image_t *img = decoder_->GetDxData().Next();
318 
319     if (img) {
320       ::libaom_test::MD5 md5_res;
321       md5_res.Add(img);
322       md5_dec_.push_back(md5_res.Get());
323     }
324   }
325 
DoTest()326   void DoTest() {
327     ::libaom_test::YUVVideoSource video(
328         "niklas_640_480_30.yuv", AOM_IMG_FMT_I420, 640, 480, 30, 1, 15, 26);
329     cfg_.rc_target_bitrate = 1000;
330 
331     if (row_mt_ == 0) {
332       // Encode using single thread.
333       cfg_.g_threads = 1;
334       init_flags_ = AOM_CODEC_USE_PSNR;
335       ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
336       std::vector<size_t> single_thr_size_enc;
337       std::vector<std::string> single_thr_md5_enc;
338       std::vector<std::string> single_thr_md5_dec;
339       single_thr_size_enc = size_enc_;
340       single_thr_md5_enc = md5_enc_;
341       single_thr_md5_dec = md5_dec_;
342       size_enc_.clear();
343       md5_enc_.clear();
344       md5_dec_.clear();
345 
346       // Encode using multiple threads.
347       cfg_.g_threads = 4;
348       ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
349       std::vector<size_t> multi_thr_size_enc;
350       std::vector<std::string> multi_thr_md5_enc;
351       std::vector<std::string> multi_thr_md5_dec;
352       multi_thr_size_enc = size_enc_;
353       multi_thr_md5_enc = md5_enc_;
354       multi_thr_md5_dec = md5_dec_;
355       size_enc_.clear();
356       md5_enc_.clear();
357       md5_dec_.clear();
358 
359       // Check that the vectors are equal.
360       ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
361       ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
362       ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
363 
364       DoTestMaxThreads(&video, single_thr_size_enc, single_thr_md5_enc,
365                        single_thr_md5_dec);
366     } else if (row_mt_ == 1) {
367       // Encode using multiple threads row-mt enabled.
368       cfg_.g_threads = 2;
369       ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
370       std::vector<size_t> multi_thr2_row_mt_size_enc;
371       std::vector<std::string> multi_thr2_row_mt_md5_enc;
372       std::vector<std::string> multi_thr2_row_mt_md5_dec;
373       multi_thr2_row_mt_size_enc = size_enc_;
374       multi_thr2_row_mt_md5_enc = md5_enc_;
375       multi_thr2_row_mt_md5_dec = md5_dec_;
376       size_enc_.clear();
377       md5_enc_.clear();
378       md5_dec_.clear();
379 
380       // Disable threads=3 test for now to reduce the time so that the nightly
381       // test would not time out.
382       // cfg_.g_threads = 3;
383       // ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
384       // std::vector<size_t> multi_thr3_row_mt_size_enc;
385       // std::vector<std::string> multi_thr3_row_mt_md5_enc;
386       // std::vector<std::string> multi_thr3_row_mt_md5_dec;
387       // multi_thr3_row_mt_size_enc = size_enc_;
388       // multi_thr3_row_mt_md5_enc = md5_enc_;
389       // multi_thr3_row_mt_md5_dec = md5_dec_;
390       // size_enc_.clear();
391       // md5_enc_.clear();
392       // md5_dec_.clear();
393       // Check that the vectors are equal.
394       // ASSERT_EQ(multi_thr3_row_mt_size_enc, multi_thr2_row_mt_size_enc);
395       // ASSERT_EQ(multi_thr3_row_mt_md5_enc, multi_thr2_row_mt_md5_enc);
396       // ASSERT_EQ(multi_thr3_row_mt_md5_dec, multi_thr2_row_mt_md5_dec);
397 
398       cfg_.g_threads = 4;
399       ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
400       std::vector<size_t> multi_thr4_row_mt_size_enc;
401       std::vector<std::string> multi_thr4_row_mt_md5_enc;
402       std::vector<std::string> multi_thr4_row_mt_md5_dec;
403       multi_thr4_row_mt_size_enc = size_enc_;
404       multi_thr4_row_mt_md5_enc = md5_enc_;
405       multi_thr4_row_mt_md5_dec = md5_dec_;
406       size_enc_.clear();
407       md5_enc_.clear();
408       md5_dec_.clear();
409 
410       // Check that the vectors are equal.
411       ASSERT_EQ(multi_thr4_row_mt_size_enc, multi_thr2_row_mt_size_enc);
412       ASSERT_EQ(multi_thr4_row_mt_md5_enc, multi_thr2_row_mt_md5_enc);
413       ASSERT_EQ(multi_thr4_row_mt_md5_dec, multi_thr2_row_mt_md5_dec);
414 
415       DoTestMaxThreads(&video, multi_thr2_row_mt_size_enc,
416                        multi_thr2_row_mt_md5_enc, multi_thr2_row_mt_md5_dec);
417     }
418   }
419 
DoTestMaxThreads(::libaom_test::YUVVideoSource * video,const std::vector<size_t> ref_size_enc,const std::vector<std::string> ref_md5_enc,const std::vector<std::string> ref_md5_dec)420   virtual void DoTestMaxThreads(::libaom_test::YUVVideoSource *video,
421                                 const std::vector<size_t> ref_size_enc,
422                                 const std::vector<std::string> ref_md5_enc,
423                                 const std::vector<std::string> ref_md5_dec) {
424     cfg_.g_threads = MAX_NUM_THREADS;
425     ASSERT_NO_FATAL_FAILURE(RunLoop(video));
426     std::vector<size_t> multi_thr_max_row_mt_size_enc;
427     std::vector<std::string> multi_thr_max_row_mt_md5_enc;
428     std::vector<std::string> multi_thr_max_row_mt_md5_dec;
429     multi_thr_max_row_mt_size_enc = size_enc_;
430     multi_thr_max_row_mt_md5_enc = md5_enc_;
431     multi_thr_max_row_mt_md5_dec = md5_dec_;
432     size_enc_.clear();
433     md5_enc_.clear();
434     md5_dec_.clear();
435 
436     // Check that the vectors are equal.
437     ASSERT_EQ(ref_size_enc, multi_thr_max_row_mt_size_enc);
438     ASSERT_EQ(ref_md5_enc, multi_thr_max_row_mt_md5_enc);
439     ASSERT_EQ(ref_md5_dec, multi_thr_max_row_mt_md5_dec);
440   }
441 
442   bool encoder_initialized_;
443   ::libaom_test::TestMode encoding_mode_;
444   int set_cpu_used_;
445   int tile_cols_;
446   int tile_rows_;
447   int row_mt_;
448   ::libaom_test::Decoder *decoder_;
449   std::vector<size_t> size_enc_;
450   std::vector<std::string> md5_enc_;
451   std::vector<std::string> md5_dec_;
452 };
453 
454 class AVxEncoderThreadRTTest : public AVxEncoderThreadTest {};
455 
TEST_P(AVxEncoderThreadRTTest,EncoderResultTest)456 TEST_P(AVxEncoderThreadRTTest, EncoderResultTest) {
457   cfg_.large_scale_tile = 0;
458   decoder_->Control(AV1_SET_TILE_MODE, 0);
459   DoTest();
460 }
461 
462 // For real time mode, test speed 5, 6, 7, 8, 9, 10.
463 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadRTTest,
464                            ::testing::Values(::libaom_test::kRealTime),
465                            ::testing::Values(5, 6, 7, 8, 9, 10),
466                            ::testing::Values(0, 2), ::testing::Values(0, 2),
467                            ::testing::Values(0, 1));
468 
469 #if !CONFIG_REALTIME_ONLY
470 
471 // The AVxEncoderThreadTestLarge takes up ~14% of total run-time of the
472 // Valgrind long tests. Exclude it; the smaller tests are still run.
473 #if !defined(AOM_VALGRIND_BUILD)
474 class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
475 
TEST_P(AVxEncoderThreadTestLarge,EncoderResultTest)476 TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) {
477   cfg_.large_scale_tile = 0;
478   decoder_->Control(AV1_SET_TILE_MODE, 0);
479   DoTest();
480 }
481 
482 // Test cpu_used 0, 1, 3 and 5.
483 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadTestLarge,
484                            ::testing::Values(::libaom_test::kTwoPassGood,
485                                              ::libaom_test::kOnePassGood),
486                            ::testing::Values(0, 1, 3, 5),
487                            ::testing::Values(1, 6), ::testing::Values(1, 6),
488                            ::testing::Values(0, 1));
489 #endif  // !defined(AOM_VALGRIND_BUILD)
490 
TEST_P(AVxEncoderThreadTest,EncoderResultTest)491 TEST_P(AVxEncoderThreadTest, EncoderResultTest) {
492   cfg_.large_scale_tile = 0;
493   decoder_->Control(AV1_SET_TILE_MODE, 0);
494   DoTest();
495 }
496 
497 class AVxEncoderThreadAllIntraTest : public AVxEncoderThreadTest {};
498 
TEST_P(AVxEncoderThreadAllIntraTest,EncoderResultTest)499 TEST_P(AVxEncoderThreadAllIntraTest, EncoderResultTest) {
500   cfg_.large_scale_tile = 0;
501   decoder_->Control(AV1_SET_TILE_MODE, 0);
502   DoTest();
503 }
504 
505 class AVxEncoderThreadAllIntraTestLarge : public AVxEncoderThreadTest {};
506 
TEST_P(AVxEncoderThreadAllIntraTestLarge,EncoderResultTest)507 TEST_P(AVxEncoderThreadAllIntraTestLarge, EncoderResultTest) {
508   cfg_.large_scale_tile = 0;
509   decoder_->Control(AV1_SET_TILE_MODE, 0);
510   DoTest();
511 }
512 
513 // first pass stats test
514 AV1_INSTANTIATE_TEST_SUITE(AVxFirstPassEncoderThreadTest,
515                            ::testing::Values(::libaom_test::kTwoPassGood),
516                            ::testing::Values(4), ::testing::Range(0, 2),
517                            ::testing::Range(1, 3));
518 
519 AV1_INSTANTIATE_TEST_SUITE(AVxFirstPassEncoderThreadTestLarge,
520                            ::testing::Values(::libaom_test::kTwoPassGood),
521                            ::testing::Values(0, 2), ::testing::Range(0, 2),
522                            ::testing::Range(1, 3));
523 
524 // Only test cpu_used 2 here.
525 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadTest,
526                            ::testing::Values(::libaom_test::kTwoPassGood),
527                            ::testing::Values(2), ::testing::Values(0, 2),
528                            ::testing::Values(0, 2), ::testing::Values(0, 1));
529 
530 // For all intra mode, test speed 0, 2, 4, 6, 8.
531 // Only test cpu_used 6 here.
532 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadAllIntraTest,
533                            ::testing::Values(::libaom_test::kAllIntra),
534                            ::testing::Values(6), ::testing::Values(0, 2),
535                            ::testing::Values(0, 2), ::testing::Values(0, 1));
536 
537 // Test cpu_used 0, 2, 4 and 8.
538 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadAllIntraTestLarge,
539                            ::testing::Values(::libaom_test::kAllIntra),
540                            ::testing::Values(0, 2, 4, 8),
541                            ::testing::Values(1, 6), ::testing::Values(1, 6),
542                            ::testing::Values(0, 1));
543 #endif  // !CONFIG_REALTIME_ONLY
544 
545 class AVxEncoderThreadLSTest : public AVxEncoderThreadTest {
SetTileSize(libaom_test::Encoder * encoder)546   void SetTileSize(libaom_test::Encoder *encoder) override {
547     encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
548     encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
549   }
550 
DoTestMaxThreads(::libaom_test::YUVVideoSource * video,const std::vector<size_t> ref_size_enc,const std::vector<std::string> ref_md5_enc,const std::vector<std::string> ref_md5_dec)551   void DoTestMaxThreads(::libaom_test::YUVVideoSource *video,
552                         const std::vector<size_t> ref_size_enc,
553                         const std::vector<std::string> ref_md5_enc,
554                         const std::vector<std::string> ref_md5_dec) override {
555     (void)video;
556     (void)ref_size_enc;
557     (void)ref_md5_enc;
558     (void)ref_md5_dec;
559   }
560 };
561 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AVxEncoderThreadLSTest);
562 
TEST_P(AVxEncoderThreadLSTest,EncoderResultTest)563 TEST_P(AVxEncoderThreadLSTest, EncoderResultTest) {
564   cfg_.large_scale_tile = 1;
565   decoder_->Control(AV1_SET_TILE_MODE, 1);
566   decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
567   DoTest();
568 }
569 
570 // AVxEncoderThreadLSTestLarge takes up about 2% of total run-time of
571 // the Valgrind long tests. Since we already run AVxEncoderThreadLSTest,
572 // skip this one for Valgrind.
573 #if !CONFIG_REALTIME_ONLY && !defined(AOM_VALGRIND_BUILD)
574 class AVxEncoderThreadLSTestLarge : public AVxEncoderThreadLSTest {};
575 
TEST_P(AVxEncoderThreadLSTestLarge,EncoderResultTest)576 TEST_P(AVxEncoderThreadLSTestLarge, EncoderResultTest) {
577   cfg_.large_scale_tile = 1;
578   decoder_->Control(AV1_SET_TILE_MODE, 1);
579   decoder_->Control(AV1D_EXT_TILE_DEBUG, 1);
580   DoTest();
581 }
582 
583 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderThreadLSTestLarge,
584                            ::testing::Values(::libaom_test::kTwoPassGood,
585                                              ::libaom_test::kOnePassGood),
586                            ::testing::Values(1, 3), ::testing::Values(0, 6),
587                            ::testing::Values(0, 6), ::testing::Values(1));
588 #endif  // !CONFIG_REALTIME_ONLY && !defined(AOM_VALGRIND_BUILD)
589 }  // namespace
590