Bug 1771985 [wpt PR 34266] - [FedCM] Move set_cookie into the helper file to share...
[gecko.git] / third_party / aom / test / corner_match_test.cc
blob58e3139c5f9bb9ab3e8a25e9df0ca39d04c33a0a
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
11 #include "config/av1_rtcd.h"
13 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14 #include "test/acm_random.h"
15 #include "test/util.h"
16 #include "test/clear_system_state.h"
17 #include "test/register_state_check.h"
19 #include "av1/encoder/corner_match.h"
21 namespace test_libaom {
23 namespace AV1CornerMatch {
25 using libaom_test::ACMRandom;
27 using ::testing::make_tuple;
28 using ::testing::tuple;
29 typedef tuple<int> CornerMatchParam;
31 class AV1CornerMatchTest : public ::testing::TestWithParam<CornerMatchParam> {
32 public:
33 virtual ~AV1CornerMatchTest();
34 virtual void SetUp();
36 virtual void TearDown();
38 protected:
39 void RunCheckOutput();
41 libaom_test::ACMRandom rnd_;
44 AV1CornerMatchTest::~AV1CornerMatchTest() {}
45 void AV1CornerMatchTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
46 void AV1CornerMatchTest::TearDown() { libaom_test::ClearSystemState(); }
48 void AV1CornerMatchTest::RunCheckOutput() {
49 const int w = 128, h = 128;
50 const int num_iters = 10000;
51 int i, j;
53 uint8_t *input1 = new uint8_t[w * h];
54 uint8_t *input2 = new uint8_t[w * h];
56 // Test the two extreme cases:
57 // i) Random data, should have correlation close to 0
58 // ii) Linearly related data + noise, should have correlation close to 1
59 int mode = GET_PARAM(0);
60 if (mode == 0) {
61 for (i = 0; i < h; ++i)
62 for (j = 0; j < w; ++j) {
63 input1[i * w + j] = rnd_.Rand8();
64 input2[i * w + j] = rnd_.Rand8();
66 } else if (mode == 1) {
67 for (i = 0; i < h; ++i)
68 for (j = 0; j < w; ++j) {
69 int v = rnd_.Rand8();
70 input1[i * w + j] = v;
71 input2[i * w + j] = (v / 2) + (rnd_.Rand8() & 15);
75 for (i = 0; i < num_iters; ++i) {
76 int x1 = MATCH_SZ_BY2 + rnd_.PseudoUniform(w - 2 * MATCH_SZ_BY2);
77 int y1 = MATCH_SZ_BY2 + rnd_.PseudoUniform(h - 2 * MATCH_SZ_BY2);
78 int x2 = MATCH_SZ_BY2 + rnd_.PseudoUniform(w - 2 * MATCH_SZ_BY2);
79 int y2 = MATCH_SZ_BY2 + rnd_.PseudoUniform(h - 2 * MATCH_SZ_BY2);
81 double res_c =
82 compute_cross_correlation_c(input1, w, x1, y1, input2, w, x2, y2);
83 double res_sse4 =
84 compute_cross_correlation_sse4_1(input1, w, x1, y1, input2, w, x2, y2);
86 ASSERT_EQ(res_sse4, res_c);
89 delete[] input1;
90 delete[] input2;
93 TEST_P(AV1CornerMatchTest, CheckOutput) { RunCheckOutput(); }
95 INSTANTIATE_TEST_CASE_P(SSE4_1, AV1CornerMatchTest,
96 ::testing::Values(make_tuple(0), make_tuple(1)));
98 } // namespace AV1CornerMatch
100 } // namespace test_libaom