<commit_before>/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

#include <cstdlib>
#include <string>

#include "third_party/googletest/src/include/gtest/gtest.h"

#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
#include "aom_ports/aom_timer.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"

using libaom_test::ACMRandom;

namespace {

typedef void (*clpf_block_t)(const uint8_t *src, uint8_t *dst, int sstride,
                             int dstride, int x0, int y0, int sizex, int sizey,
                             int width, int height, unsigned int strength);

typedef std::tr1::tuple<clpf_block_t, clpf_block_t, int, int>
    clpf_block_param_t;

class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> {
 public:
  virtual ~ClpfBlockTest() {}
  virtual void SetUp() {
    clpf = GET_PARAM(0);
    ref_clpf = GET_PARAM(1);
    sizex = GET_PARAM(2);
    sizey = GET_PARAM(3);
  }

  virtual void TearDown() { libaom_test::ClearSystemState(); }

 protected:
  int sizex;
  int sizey;
  clpf_block_t clpf;
  clpf_block_t ref_clpf;
};

typedef ClpfBlockTest ClpfSpeedTest;

TEST_P(ClpfBlockTest, TestSIMDNoMismatch) {
  int w = sizex;
  int h = sizey;
  const int size = 32;
  ACMRandom rnd(ACMRandom::DeterministicSeed());
  DECLARE_ALIGNED(16, uint8_t, s[size * size]);
  DECLARE_ALIGNED(16, uint8_t, d[size * size]);
  DECLARE_ALIGNED(16, uint8_t, ref_d[size * size]);
  memset(ref_d, 0, size * size);
  memset(d, 0, size * size);

  int error = 0;
  int pos = 0;
  int strength = 0;
  int xpos = 0, ypos = 0;
  int bits;
  int level;

  // Test every combination of:
  // * Input with 1-8 bits of noise
  // * Noise level around every value from 0 to 255
  // * Blocks anywhere in the frame (along all egdes and also fully inside)
  // * All strengths
  for (level = 0; level < 256 && !error; level++) {
    for (bits = 1; bits < 9 && !error; bits++) {
      for (int i = 0; i < size * size; i++)
        s[i] = clamp((rnd.Rand8() & ((1 << bits) - 1)) + level, 0, 255);

      for (ypos = 0; ypos < size && !error; ypos += h * !error) {
        for (xpos = 0; xpos < size && !error; xpos += w * !error) {
          for (strength = 0; strength < 3 && !error; strength += !error) {
            ref_clpf(s, ref_d, size, size, xpos, ypos, w, h, size, size,
                     1 << strength);
            ASM_REGISTER_STATE_CHECK(clpf(s, d, size, size, xpos, ypos, w, h,
                                          size, size, 1 << strength));

            for (pos = 0; pos < size * size && !error; pos++) {
              error = ref_d[pos] != d[pos];
            }
          }
        }
      }
    }
  }

  EXPECT_EQ(0, error)
      << "Error: ClpfBlockTest, SIMD and C mismatch." << std::endl
      << "First error at " << pos % size << "," << pos / size << " ("
      << (int16_t)ref_d[pos] << " != " << (int16_t)d[pos] << ") " << std::endl
      << "strength: " << (1 << strength) << std::endl
      << "xpos: " << xpos << std::endl
      << "ypos: " << ypos << std::endl
      << "A=" << (pos > size ? (int16_t)s[pos - size] : -1) << std::endl
      << "B=" << (pos % size - 2 >= 0 ? (int16_t)s[pos - 2] : -1) << std::endl
      << "C=" << (pos % size - 1 >= 0 ? (int16_t)s[pos - 1] : -1) << std::endl
      << "X=" << (int16_t)s[pos] << std::endl
      << "D=" << (pos % size + 1 < size ? (int16_t)s[pos + 1] : -1) << std::endl<commit_msg>Print correct info if CLPF unit tests fail.<commit_after>/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

#include <cstdlib>
#include <string>

#include "third_party/googletest/src/include/gtest/gtest.h"

#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
#include "aom_ports/aom_timer.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"

using libaom_test::ACMRandom;

namespace {

typedef void (*clpf_block_t)(const uint8_t *src, uint8_t *dst, int sstride,
                             int dstride, int x0, int y0, int sizex, int sizey,
                             int width, int height, unsigned int strength);

typedef std::tr1::tuple<clpf_block_t, clpf_block_t, int, int>
    clpf_block_param_t;

class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> {
 public:
  virtual ~ClpfBlockTest() {}
  virtual void SetUp() {
    clpf = GET_PARAM(0);
    ref_clpf = GET_PARAM(1);
    sizex = GET_PARAM(2);
    sizey = GET_PARAM(3);
  }

  virtual void TearDown() { libaom_test::ClearSystemState(); }

 protected:
  int sizex;
  int sizey;
  clpf_block_t clpf;
  clpf_block_t ref_clpf;
};

typedef ClpfBlockTest ClpfSpeedTest;

TEST_P(ClpfBlockTest, TestSIMDNoMismatch) {
  int w = sizex;
  int h = sizey;
  const int size = 32;
  ACMRandom rnd(ACMRandom::DeterministicSeed());
  DECLARE_ALIGNED(16, uint8_t, s[size * size]);
  DECLARE_ALIGNED(16, uint8_t, d[size * size]);
  DECLARE_ALIGNED(16, uint8_t, ref_d[size * size]);
  memset(ref_d, 0, size * size);
  memset(d, 0, size * size);

  int error = 0;
  int pos = 0;
  int strength = 0;
  int xpos = 0, ypos = 0;
  int bits;
  int level;

  // Test every combination of:
  // * Input with 1-8 bits of noise
  // * Noise level around every value from 0 to 255
  // * Blocks anywhere in the frame (along all egdes and also fully inside)
  // * All strengths
  for (level = 0; level < 256 && !error; level++) {
    for (bits = 1; bits < 9 && !error; bits++) {
      for (int i = 0; i < size * size; i++)
        s[i] = clamp((rnd.Rand8() & ((1 << bits) - 1)) + level, 0, 255);

      for (ypos = 0; ypos < size && !error; ypos += h * !error) {
        for (xpos = 0; xpos < size && !error; xpos += w * !error) {
          for (strength = 0; strength < 3 && !error; strength += !error) {
            ref_clpf(s, ref_d, size, size, xpos, ypos, w, h, size, size,
                     1 << strength);
            ASM_REGISTER_STATE_CHECK(clpf(s, d, size, size, xpos, ypos, w, h,
                                          size, size, 1 << strength));

            for (pos = 0; pos < size * size && !error; pos++) {
              error = ref_d[pos] != d[pos];
            }
          }
        }
      }
    }
  }

  pos--;
  EXPECT_EQ(0, error)
      << "Error: ClpfBlockTest, SIMD and C mismatch." << std::endl
      << "First error at " << pos % size << "," << pos / size << " ("
      << (int16_t)ref_d[pos] << " != " << (int16_t)d[pos] << ") " << std::endl
      << "strength: " << (1 << strength) << std::endl
      << "xpos: " << xpos << std::endl
      << "ypos: " << ypos << std::endl
      << "A=" << (pos > size ? (int16_t)s[pos - size] : -1) << std::endl
      << "B=" << (pos % size - 2 >= 0 ? (int16_t)s[pos - 2] : -1) << std::endl
      << "C=" << (pos % size - 1 >= 0 ? (int16_t)s[pos - 1] : -1) << std::endl
      << "X=" << (int16_t)s[pos] << std::endl
      << "D=" << (pos % size + 1 < size ? (int16_t)s[pos + 1] : -1) << std::endl
{'fraction_non_alphanumeric': 0.15623814941221084, 'fraction_numerical': 0.023258753634180257, 'mean_word_length': 2.676579925650558, 'pattern_counts': {'":': 0, '<': 187, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6914351', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2832, 'n_words': 835}