Change Wiener unit test allocation to heap

Changed several test data buffers in the Wiener encoder unit tests from
stack allocation to heap allocation.  This reduces maximum stack size in
the test suites by 33% from 360 kB to 240 kB.  I also reduced the stack
usage warning accordingly to avoid regressions.

BUG=aomedia:2135

Change-Id: Idfa15440004e930f8045f3770bd7bf320ecf6027
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index 1215d70..707c986 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -271,7 +271,7 @@
   add_compiler_flag_if_supported("-Wvla")
 
   add_c_flag_if_supported("-Wstack-usage=100000")
-  add_cxx_flag_if_supported("-Wstack-usage=360000")
+  add_cxx_flag_if_supported("-Wstack-usage=240000")
 
   # TODO(jzern): this could be added as a cxx flags for test/*.cc only, avoiding
   # third_party.
diff --git a/test/wiener_test.cc b/test/wiener_test.cc
index aecd95c..ea10626 100644
--- a/test/wiener_test.cc
+++ b/test/wiener_test.cc
@@ -120,20 +120,30 @@
 
 class WienerTest : public ::testing::TestWithParam<WienerTestParam> {
  public:
-  virtual void SetUp() { target_func_ = GET_PARAM(0); }
+  virtual void SetUp() {
+    src_buf = (uint8_t *)aom_memalign(
+        32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint8_t));
+    dgd_buf = (uint8_t *)aom_memalign(
+        32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint8_t));
+    target_func_ = GET_PARAM(0);
+  }
+  virtual void TearDown() {
+    aom_free(src_buf);
+    aom_free(dgd_buf);
+  }
   void runWienerTest(const int32_t wiener_win, int32_t run_times);
   void runWienerTest_ExtremeValues(const int32_t wiener_win);
 
  private:
   compute_stats_Func target_func_;
   ACMRandom rng_;
+  uint8_t *src_buf;
+  uint8_t *dgd_buf;
 };
 
 void WienerTest::runWienerTest(const int32_t wiener_win, int32_t run_times) {
   const int32_t wiener_halfwin = wiener_win >> 1;
   const int32_t wiener_win2 = wiener_win * wiener_win;
-  DECLARE_ALIGNED(32, uint8_t, dgd_buf[MAX_DATA_BLOCK * MAX_DATA_BLOCK]);
-  DECLARE_ALIGNED(32, uint8_t, src_buf[MAX_DATA_BLOCK * MAX_DATA_BLOCK]);
   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
@@ -200,8 +210,6 @@
 void WienerTest::runWienerTest_ExtremeValues(const int32_t wiener_win) {
   const int32_t wiener_halfwin = wiener_win >> 1;
   const int32_t wiener_win2 = wiener_win * wiener_win;
-  DECLARE_ALIGNED(32, uint8_t, dgd_buf[MAX_DATA_BLOCK * MAX_DATA_BLOCK]);
-  DECLARE_ALIGNED(32, uint8_t, src_buf[MAX_DATA_BLOCK * MAX_DATA_BLOCK]);
   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
@@ -390,7 +398,17 @@
 
 class WienerTestHighbd : public ::testing::TestWithParam<WienerTestParam> {
  public:
-  virtual void SetUp() { target_func_ = GET_PARAM(0); }
+  virtual void SetUp() {
+    src_buf = (uint16_t *)aom_memalign(
+        32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint16_t));
+    dgd_buf = (uint16_t *)aom_memalign(
+        32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint16_t));
+    target_func_ = GET_PARAM(0);
+  }
+  virtual void TearDown() {
+    aom_free(src_buf);
+    aom_free(dgd_buf);
+  }
   void runWienerTest(const int32_t wiener_win, int32_t run_times,
                      aom_bit_depth_t bit_depth);
   void runWienerTest_ExtremeValues(const int32_t wiener_win,
@@ -399,6 +417,8 @@
  private:
   compute_stats_Func target_func_;
   ACMRandom rng_;
+  uint16_t *src_buf;
+  uint16_t *dgd_buf;
 };
 
 void WienerTestHighbd::runWienerTest(const int32_t wiener_win,
@@ -406,12 +426,6 @@
                                      aom_bit_depth_t bit_depth) {
   const int32_t wiener_halfwin = wiener_win >> 1;
   const int32_t wiener_win2 = wiener_win * wiener_win;
-  uint16_t *dgd_buf = (uint16_t *)aom_memalign(
-      32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
-  uint16_t *src_buf = (uint16_t *)aom_memalign(
-      32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
-  ASSERT_TRUE(dgd_buf) << "Failed to allocate test buffer.";
-  ASSERT_TRUE(src_buf) << "Failed to allocate test buffer.";
   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
@@ -474,26 +488,14 @@
         break;
       }
     }
-    if (failed != 0) {
-      aom_free(src_buf);
-      aom_free(dgd_buf);
-      ASSERT_EQ(failed, 0);
-    }
+    ASSERT_EQ(failed, 0);
   }
-  aom_free(src_buf);
-  aom_free(dgd_buf);
 }
 
 void WienerTestHighbd::runWienerTest_ExtremeValues(const int32_t wiener_win,
                                                    aom_bit_depth_t bit_depth) {
   const int32_t wiener_halfwin = wiener_win >> 1;
   const int32_t wiener_win2 = wiener_win * wiener_win;
-  uint16_t *dgd_buf = (uint16_t *)aom_memalign(
-      32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
-  uint16_t *src_buf = (uint16_t *)aom_memalign(
-      32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
-  ASSERT_TRUE(dgd_buf) << "Failed to allocate test buffer.";
-  ASSERT_TRUE(src_buf) << "Failed to allocate test buffer.";
   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
@@ -540,14 +542,8 @@
         break;
       }
     }
-    if (failed != 0) {
-      aom_free(src_buf);
-      aom_free(dgd_buf);
-      ASSERT_EQ(failed, 0);
-    }
+    ASSERT_EQ(failed, 0);
   }
-  aom_free(src_buf);
-  aom_free(dgd_buf);
 }
 
 TEST_P(WienerTestHighbd, RandomValues) {