Clean-up test code: nn_predict, pickrst, wiener
Cleanup to style guidelines of the C++ code of the test suites for the
Wiener filter encoder, SGR filter encoder, and neural network predictor:
* Remove unused includes
* Remove unused code
* Remove dead (commented) code
* Name functions with upper camel case
* sizeof(variable) instead of sizeof(type)
Change-Id: I810882c605d5bf285b45c9feee230ae78b4bfd72
diff --git a/test/av1_nn_predict_test.cc b/test/av1_nn_predict_test.cc
index 4a36428..6c4eed4 100644
--- a/test/av1_nn_predict_test.cc
+++ b/test/av1_nn_predict_test.cc
@@ -9,30 +9,24 @@
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
-#include <vector>
-
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
-#include "test/function_equivalence_test.h"
-#include "test/register_state_check.h"
-
+#include "aom/aom_integer.h"
+#include "aom_ports/aom_timer.h"
+#include "av1/encoder/ml.h"
#include "config/aom_config.h"
#include "config/aom_dsp_rtcd.h"
#include "config/av1_rtcd.h"
-
-#include "aom/aom_integer.h"
-#include "aom_ports/system_state.h"
-#include "av1/encoder/ml.h"
-
-using libaom_test::FunctionEquivalenceTest;
+#include "test/util.h"
+#include "test/register_state_check.h"
+#include "test/acm_random.h"
+#include "test/clear_system_state.h"
namespace {
typedef void (*NnPredict_Func)(const float *const input_nodes,
const NN_CONFIG *const nn_config,
float *const output);
-typedef libaom_test::FuncParam<NnPredict_Func> TestFuncs;
-
typedef ::testing::tuple<const NnPredict_Func> NnPredictTestParam;
const float epsilon = 1e-3f; // Error threshold for functional equivalence
@@ -60,31 +54,29 @@
aom_free(weights_buf);
aom_free(bias_buf);
}
- void runNnPredictTest(const NN_CONFIG *const shape);
- void runNnPredictSpeedTest(const NN_CONFIG *const shape, const int run_times);
- void runNnPredictTest_all(const NN_CONFIG *const shapes,
+ void RunNnPredictTest(const NN_CONFIG *const shape);
+ void RunNnPredictSpeedTest(const NN_CONFIG *const shape, const int run_times);
+ void RunNnPredictTest_all(const NN_CONFIG *const shapes,
const int num_shapes);
- void runNnPredictSpeedTest_all(const NN_CONFIG *const shapes,
+ void RunNnPredictSpeedTest_all(const NN_CONFIG *const shapes,
const int num_shapes, const int run_times);
- void predict_original(const float *features, const NN_CONFIG *nn_config,
- float *output);
private:
NnPredict_Func target_func_;
- ACMRandom rng_;
+ libaom_test::ACMRandom rng_;
float *weights[NN_MAX_HIDDEN_LAYERS + 1] = { 0 };
float *bias[NN_MAX_HIDDEN_LAYERS + 1] = { 0 };
float *weights_buf = nullptr, *bias_buf = nullptr;
};
-void NnPredictTest::runNnPredictTest(const NN_CONFIG *const shape) {
- aom_clear_system_state();
+void NnPredictTest::RunNnPredictTest(const NN_CONFIG *const shape) {
+ libaom_test::ClearSystemState();
float inputs[NN_MAX_NODES_PER_LAYER] = { 0 };
float outputs_test[NN_MAX_NODES_PER_LAYER] = { 0 };
float outputs_ref[NN_MAX_NODES_PER_LAYER] = { 0 };
NN_CONFIG nn_config;
- memcpy(&nn_config, shape, sizeof(NN_CONFIG));
+ memcpy(&nn_config, shape, sizeof(nn_config));
char shape_str[32] = { 0 };
snprintf(shape_str, sizeof(shape_str), "%d", shape->num_inputs);
@@ -125,7 +117,7 @@
av1_nn_predict_c(inputs, &nn_config, outputs_ref);
target_func_(inputs, &nn_config, outputs_test);
- aom_clear_system_state();
+ libaom_test::ClearSystemState();
for (int node = 0; node < shape->num_outputs; node++) {
if (outputs_ref[node] < epsilon) {
@@ -141,18 +133,17 @@
}
}
}
- // printf("Network shape %s passed\n", shape_str);
}
-void NnPredictTest::runNnPredictSpeedTest(const NN_CONFIG *const shape,
+void NnPredictTest::RunNnPredictSpeedTest(const NN_CONFIG *const shape,
const int run_times) {
- aom_clear_system_state();
+ libaom_test::ClearSystemState();
float inputs[NN_MAX_NODES_PER_LAYER] = { 0 };
float outputs_test[NN_MAX_NODES_PER_LAYER] = { 0 };
float outputs_ref[NN_MAX_NODES_PER_LAYER] = { 0 };
NN_CONFIG nn_config;
- memcpy(&nn_config, shape, sizeof(NN_CONFIG));
+ memcpy(&nn_config, shape, sizeof(nn_config));
for (int i = 0; i < NN_MAX_HIDDEN_LAYERS; i++) {
nn_config.weights[i] = weights[i];
@@ -173,7 +164,7 @@
target_func_(inputs, &nn_config, outputs_test);
}
aom_usec_timer_mark(&timer);
- aom_clear_system_state();
+ libaom_test::ClearSystemState();
const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer));
printf("%d", shape->num_inputs);
@@ -196,25 +187,24 @@
{ 9, 3, 1, { 32 }, { 0 }, { 0 } }, { 4, 4, 1, { 8 }, { 0 }, { 0 } },
};
-void NnPredictTest::runNnPredictTest_all(const NN_CONFIG *const shapes,
+void NnPredictTest::RunNnPredictTest_all(const NN_CONFIG *const shapes,
const int num_shapes) {
- for (int i = 0; i < num_shapes; i++) runNnPredictTest(&shapes[i]);
+ for (int i = 0; i < num_shapes; i++) RunNnPredictTest(&shapes[i]);
}
-void NnPredictTest::runNnPredictSpeedTest_all(const NN_CONFIG *const shapes,
+void NnPredictTest::RunNnPredictSpeedTest_all(const NN_CONFIG *const shapes,
const int num_shapes,
const int run_times) {
for (int i = 0; i < num_shapes; i++)
- NnPredictTest::runNnPredictSpeedTest(&shapes[i], run_times);
+ NnPredictTest::RunNnPredictSpeedTest(&shapes[i], run_times);
}
TEST_P(NnPredictTest, RandomValues) {
- runNnPredictTest_all(shapes, sizeof(shapes) / sizeof(NN_CONFIG));
+ RunNnPredictTest_all(shapes, sizeof(shapes) / sizeof(*shapes));
}
TEST_P(NnPredictTest, DISABLED_Speed) {
- runNnPredictSpeedTest_all(shapes, sizeof(shapes) / sizeof(NN_CONFIG),
- 10000000);
+ RunNnPredictSpeedTest_all(shapes, sizeof(shapes) / sizeof(*shapes), 10000000);
}
#if HAVE_SSE3
diff --git a/test/pickrst_test.cc b/test/pickrst_test.cc
index 0ccd609..0aa49b6 100644
--- a/test/pickrst_test.cc
+++ b/test/pickrst_test.cc
@@ -11,15 +11,16 @@
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
-#include "test/function_equivalence_test.h"
#include "test/register_state_check.h"
+#include "test/acm_random.h"
+#include "test/util.h"
#include "config/aom_config.h"
#include "config/aom_dsp_rtcd.h"
#include "aom/aom_integer.h"
+#include "aom_ports/aom_timer.h"
#include "av1/encoder/pickrst.h"
-using libaom_test::FunctionEquivalenceTest;
#define MAX_DATA_BLOCK 384
@@ -31,8 +32,6 @@
const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
int32_t *flt1, int flt1_stride, int xq[2], const sgr_params_type *params);
-typedef libaom_test::FuncParam<lowbd_pixel_proj_error_func> TestFuncs;
-
////////////////////////////////////////////////////////////////////////////////
// 8 bit
////////////////////////////////////////////////////////////////////////////////
@@ -46,16 +45,16 @@
virtual void SetUp() {
target_func_ = GET_PARAM(0);
src_ = (uint8_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
- sizeof(uint8_t)));
+ sizeof(*src_)));
ASSERT_NE(src_, nullptr);
dgd_ = (uint8_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
- sizeof(uint8_t)));
+ sizeof(*dgd_)));
ASSERT_NE(dgd_, nullptr);
flt0_ = (int32_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
- sizeof(int32_t)));
+ sizeof(*flt0_)));
ASSERT_NE(flt0_, nullptr);
flt1_ = (int32_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
- sizeof(int32_t)));
+ sizeof(*flt1_)));
ASSERT_NE(flt1_, nullptr);
}
virtual void TearDown() {
@@ -64,19 +63,19 @@
aom_free(flt0_);
aom_free(flt1_);
}
- void runPixelProjErrorTest(int32_t run_times);
- void runPixelProjErrorTest_ExtremeValues();
+ void RunPixelProjErrorTest(int32_t run_times);
+ void RunPixelProjErrorTest_ExtremeValues();
private:
lowbd_pixel_proj_error_func target_func_;
- ACMRandom rng_;
+ libaom_test::ACMRandom rng_;
uint8_t *src_;
uint8_t *dgd_;
int32_t *flt0_;
int32_t *flt1_;
};
-void PixelProjErrorTest::runPixelProjErrorTest(int32_t run_times) {
+void PixelProjErrorTest::RunPixelProjErrorTest(int32_t run_times) {
int h_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
int v_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
const int dgd_stride = MAX_DATA_BLOCK;
@@ -128,7 +127,7 @@
}
}
-void PixelProjErrorTest::runPixelProjErrorTest_ExtremeValues() {
+void PixelProjErrorTest::RunPixelProjErrorTest_ExtremeValues() {
const int h_start = 0;
int h_end = 192;
const int v_start = 0;
@@ -169,13 +168,13 @@
}
}
-TEST_P(PixelProjErrorTest, RandomValues) { runPixelProjErrorTest(1); }
+TEST_P(PixelProjErrorTest, RandomValues) { RunPixelProjErrorTest(1); }
TEST_P(PixelProjErrorTest, ExtremeValues) {
- runPixelProjErrorTest_ExtremeValues();
+ RunPixelProjErrorTest_ExtremeValues();
}
-TEST_P(PixelProjErrorTest, DISABLED_Speed) { runPixelProjErrorTest(200000); }
+TEST_P(PixelProjErrorTest, DISABLED_Speed) { RunPixelProjErrorTest(200000); }
#if HAVE_SSE4_1
INSTANTIATE_TEST_CASE_P(SSE4_1, PixelProjErrorTest,
@@ -198,8 +197,6 @@
const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
int32_t *flt1, int flt1_stride, int xq[2], const sgr_params_type *params);
-typedef libaom_test::FuncParam<highbd_pixel_proj_error_func> TestFuncs;
-
////////////////////////////////////////////////////////////////////////////////
// High bit-depth
////////////////////////////////////////////////////////////////////////////////
@@ -231,19 +228,19 @@
aom_free(flt0_);
aom_free(flt1_);
}
- void runPixelProjErrorTest(int32_t run_times);
- void runPixelProjErrorTest_ExtremeValues();
+ void RunPixelProjErrorTest(int32_t run_times);
+ void RunPixelProjErrorTest_ExtremeValues();
private:
highbd_pixel_proj_error_func target_func_;
- ACMRandom rng_;
+ libaom_test::ACMRandom rng_;
uint16_t *src_;
uint16_t *dgd_;
int32_t *flt0_;
int32_t *flt1_;
};
-void PixelProjHighbdErrorTest::runPixelProjErrorTest(int32_t run_times) {
+void PixelProjHighbdErrorTest::RunPixelProjErrorTest(int32_t run_times) {
int h_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
int v_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
const int dgd_stride = MAX_DATA_BLOCK;
@@ -295,7 +292,7 @@
}
}
-void PixelProjHighbdErrorTest::runPixelProjErrorTest_ExtremeValues() {
+void PixelProjHighbdErrorTest::RunPixelProjErrorTest_ExtremeValues() {
const int h_start = 0;
int h_end = 192;
const int v_start = 0;
@@ -336,14 +333,14 @@
}
}
-TEST_P(PixelProjHighbdErrorTest, RandomValues) { runPixelProjErrorTest(1); }
+TEST_P(PixelProjHighbdErrorTest, RandomValues) { RunPixelProjErrorTest(1); }
TEST_P(PixelProjHighbdErrorTest, ExtremeValues) {
- runPixelProjErrorTest_ExtremeValues();
+ RunPixelProjErrorTest_ExtremeValues();
}
TEST_P(PixelProjHighbdErrorTest, DISABLED_Speed) {
- runPixelProjErrorTest(200000);
+ RunPixelProjErrorTest(200000);
}
#if HAVE_SSE4_1
diff --git a/test/wiener_test.cc b/test/wiener_test.cc
index ea10626..8f49af6 100644
--- a/test/wiener_test.cc
+++ b/test/wiener_test.cc
@@ -13,18 +13,19 @@
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
-#include "test/function_equivalence_test.h"
#include "test/register_state_check.h"
+#include "test/acm_random.h"
+#include "test/util.h"
#include "config/aom_config.h"
#include "config/aom_dsp_rtcd.h"
#include "aom/aom_integer.h"
+#include "aom_ports/aom_timer.h"
#include "av1/encoder/pickrst.h"
#define MAX_WIENER_BLOCK 384
#define MAX_DATA_BLOCK (MAX_WIENER_BLOCK + WIENER_WIN)
-using libaom_test::FunctionEquivalenceTest;
// 8-bit-depth tests
namespace wiener_lowbd {
@@ -110,8 +111,6 @@
int v_start, int v_end, int dgd_stride,
int src_stride, int64_t *M, int64_t *H);
-typedef libaom_test::FuncParam<compute_stats_Func> TestFuncs;
-
////////////////////////////////////////////////////////////////////////////////
// 8 bit
////////////////////////////////////////////////////////////////////////////////
@@ -122,26 +121,26 @@
public:
virtual void SetUp() {
src_buf = (uint8_t *)aom_memalign(
- 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint8_t));
+ 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
dgd_buf = (uint8_t *)aom_memalign(
- 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint8_t));
+ 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
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);
+ 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_;
+ libaom_test::ACMRandom rng_;
uint8_t *src_buf;
uint8_t *dgd_buf;
};
-void WienerTest::runWienerTest(const int32_t wiener_win, int32_t run_times) {
+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, int64_t, M_ref[WIENER_WIN2]);
@@ -194,7 +193,6 @@
break;
}
}
- // ASSERT_EQ(failed, 0);
for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
if (H_ref[i] != H_test[i]) {
failed = 1;
@@ -207,7 +205,7 @@
}
}
-void WienerTest::runWienerTest_ExtremeValues(const int32_t wiener_win) {
+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, int64_t, M_ref[WIENER_WIN2]);
@@ -244,7 +242,6 @@
break;
}
}
- // ASSERT_EQ(failed, 0);
for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
if (H_ref[i] != H_test[i]) {
failed = 1;
@@ -258,18 +255,18 @@
}
TEST_P(WienerTest, RandomValues) {
- runWienerTest(WIENER_WIN, 1);
- runWienerTest(WIENER_WIN_CHROMA, 1);
+ RunWienerTest(WIENER_WIN, 1);
+ RunWienerTest(WIENER_WIN_CHROMA, 1);
}
TEST_P(WienerTest, ExtremeValues) {
- runWienerTest_ExtremeValues(WIENER_WIN);
- runWienerTest_ExtremeValues(WIENER_WIN_CHROMA);
+ RunWienerTest_ExtremeValues(WIENER_WIN);
+ RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA);
}
TEST_P(WienerTest, DISABLED_Speed) {
- runWienerTest(WIENER_WIN, 200);
- runWienerTest(WIENER_WIN_CHROMA, 200);
+ RunWienerTest(WIENER_WIN, 200);
+ RunWienerTest(WIENER_WIN_CHROMA, 200);
}
INSTANTIATE_TEST_CASE_P(C, WienerTest, ::testing::Values(compute_stats_opt_c));
@@ -392,36 +389,34 @@
int src_stride, int64_t *M, int64_t *H,
aom_bit_depth_t bit_depth);
-typedef libaom_test::FuncParam<compute_stats_Func> TestFuncs;
-
typedef ::testing::tuple<const compute_stats_Func> WienerTestParam;
class WienerTestHighbd : public ::testing::TestWithParam<WienerTestParam> {
public:
virtual void SetUp() {
src_buf = (uint16_t *)aom_memalign(
- 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint16_t));
+ 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
dgd_buf = (uint16_t *)aom_memalign(
- 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(uint16_t));
+ 32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
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(const int32_t wiener_win, int32_t run_times,
aom_bit_depth_t bit_depth);
- void runWienerTest_ExtremeValues(const int32_t wiener_win,
+ void RunWienerTest_ExtremeValues(const int32_t wiener_win,
aom_bit_depth_t bit_depth);
private:
compute_stats_Func target_func_;
- ACMRandom rng_;
+ libaom_test::ACMRandom rng_;
uint16_t *src_buf;
uint16_t *dgd_buf;
};
-void WienerTestHighbd::runWienerTest(const int32_t wiener_win,
+void WienerTestHighbd::RunWienerTest(const int32_t wiener_win,
int32_t run_times,
aom_bit_depth_t bit_depth) {
const int32_t wiener_halfwin = wiener_win >> 1;
@@ -492,7 +487,7 @@
}
}
-void WienerTestHighbd::runWienerTest_ExtremeValues(const int32_t wiener_win,
+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;
@@ -547,30 +542,30 @@
}
TEST_P(WienerTestHighbd, RandomValues) {
- runWienerTest(WIENER_WIN, 1, AOM_BITS_8);
- runWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_8);
- runWienerTest(WIENER_WIN, 1, AOM_BITS_10);
- runWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_10);
- runWienerTest(WIENER_WIN, 1, AOM_BITS_12);
- runWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_12);
+ RunWienerTest(WIENER_WIN, 1, AOM_BITS_8);
+ RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_8);
+ RunWienerTest(WIENER_WIN, 1, AOM_BITS_10);
+ RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_10);
+ RunWienerTest(WIENER_WIN, 1, AOM_BITS_12);
+ RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_12);
}
TEST_P(WienerTestHighbd, ExtremeValues) {
- runWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_8);
- runWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_8);
- runWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_10);
- runWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_10);
- runWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_12);
- runWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_12);
+ RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_8);
+ RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_8);
+ RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_10);
+ RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_10);
+ RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_12);
+ RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_12);
}
TEST_P(WienerTestHighbd, DISABLED_Speed) {
- runWienerTest(WIENER_WIN, 200, AOM_BITS_8);
- runWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_8);
- runWienerTest(WIENER_WIN, 200, AOM_BITS_10);
- runWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_10);
- runWienerTest(WIENER_WIN, 200, AOM_BITS_12);
- runWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_12);
+ RunWienerTest(WIENER_WIN, 200, AOM_BITS_8);
+ RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_8);
+ RunWienerTest(WIENER_WIN, 200, AOM_BITS_10);
+ RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_10);
+ RunWienerTest(WIENER_WIN, 200, AOM_BITS_12);
+ RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_12);
}
INSTANTIATE_TEST_CASE_P(C, WienerTestHighbd,