Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #ifndef TEST_FUNCTION_EQUIVALENCE_TEST_H_ |
| 13 | #define TEST_FUNCTION_EQUIVALENCE_TEST_H_ |
| 14 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 16 | #include "test/acm_random.h" |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 17 | #include "test/clear_system_state.h" |
| 18 | #include "test/util.h" |
| 19 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | using libaom_test::ACMRandom; |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 21 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | namespace libaom_test { |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 23 | // Base class for tests that compare 2 implementations of the same function |
| 24 | // for equivalence. The template parameter should be pointer to a function |
| 25 | // that is being tested. |
| 26 | // |
| 27 | // The test takes a 3-parameters encapsulating struct 'FuncParam', containing: |
| 28 | // - Pointer to reference function |
| 29 | // - Pointer to tested function |
| 30 | // - Integer bit depth (default to 0). |
| 31 | // |
| 32 | // These values are then accessible in the tests as member of params_: |
| 33 | // params_.ref_func, params_.tst_func, and params_.bit_depth. |
| 34 | // |
| 35 | |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 36 | template <typename T> |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 37 | struct FuncParam { |
| 38 | FuncParam(T ref = NULL, T tst = NULL, int bit_depth = 0) |
| 39 | : ref_func(ref), tst_func(tst), bit_depth(bit_depth) {} |
| 40 | T ref_func; |
| 41 | T tst_func; |
| 42 | int bit_depth; |
| 43 | }; |
| 44 | |
| 45 | template <typename T> |
Yaowu Xu | 25c900c | 2016-11-29 16:10:54 -0800 | [diff] [blame] | 46 | std::ostream &operator<<(std::ostream &os, const FuncParam<T> &p) { |
| 47 | return os << "bit_depth:" << p.bit_depth |
| 48 | << " function:" << reinterpret_cast<const void *>(p.ref_func) |
| 49 | << " function:" << reinterpret_cast<const void *>(p.tst_func); |
| 50 | } |
| 51 | |
| 52 | template <typename T> |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 53 | class FunctionEquivalenceTest : public ::testing::TestWithParam<FuncParam<T> > { |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 54 | public: |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 55 | FunctionEquivalenceTest() : rng_(ACMRandom::DeterministicSeed()) {} |
| 56 | |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 57 | virtual ~FunctionEquivalenceTest() {} |
| 58 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 59 | virtual void SetUp() { params_ = this->GetParam(); } |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 60 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 62 | |
| 63 | protected: |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 64 | ACMRandom rng_; |
| 65 | FuncParam<T> params_; |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | } // namespace libaom_test |
Geza Lore | a661bc8 | 2016-05-20 16:33:12 +0100 | [diff] [blame] | 69 | #endif // TEST_FUNCTION_EQUIVALENCE_TEST_H_ |