AV1 levels: add some tests for level monitoring

Each test takes up to 5 minutes to run locally.

Change-Id: Ic9ec121e3457b1bd3c1240a7625dbe259f86fdd3
diff --git a/test/level_test.cc b/test/level_test.cc
index c730826..29b9245 100644
--- a/test/level_test.cc
+++ b/test/level_test.cc
@@ -14,11 +14,15 @@
 
 #include "test/codec_factory.h"
 #include "test/encode_test_driver.h"
+#include "test/i420_video_source.h"
 #include "test/util.h"
 #include "test/y4m_video_source.h"
 #include "test/yuv_video_source.h"
 
 namespace {
+const int kLevelMin = 0;
+const int kLevelMax = 31;
+const int kLevelKeepStats = 24;
 // Speed settings tested
 static const int kCpuUsedVectors[] = {
   1,
@@ -63,11 +67,16 @@
         encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
       }
     }
+
+    encoder->Control(AV1E_GET_SEQ_LEVEL_IDX, level_);
+    ASSERT_LE(level_[0], kLevelMax);
+    ASSERT_GE(level_[0], kLevelMin);
   }
 
   libaom_test::TestMode encoding_mode_;
   int cpu_used_;
   int target_level_;
+  int level_[32];
 };
 
 TEST_P(LevelTest, TestTargetLevelApi) {
@@ -102,6 +111,30 @@
   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
 }
 
+TEST_P(LevelTest, TestLevelMonitoringLowBitrate) {
+  // To save run time, we only test speed 4.
+  if (cpu_used_ == 4) {
+    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
+                                       30, 1, 0, 40);
+    target_level_ = kLevelKeepStats;
+    cfg_.rc_target_bitrate = 1000;
+    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+    ASSERT_EQ(level_[0], 0);
+  }
+}
+
+TEST_P(LevelTest, TestLevelMonitoringHighBitrate) {
+  // To save run time, we only test speed 4.
+  if (cpu_used_ == 4) {
+    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
+                                       30, 1, 0, 40);
+    target_level_ = kLevelKeepStats;
+    cfg_.rc_target_bitrate = 3000;
+    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+    ASSERT_EQ(level_[0], 1);
+  }
+}
+
 AV1_INSTANTIATE_TEST_CASE(LevelTest,
                           ::testing::Values(::libaom_test::kTwoPassGood),
                           ::testing::ValuesIn(kCpuUsedVectors));