diff options
author | Moritz Pflanzer <moritz.pflanzer@arm.com> | 2017-07-18 14:37:35 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-09-17 14:16:42 +0100 |
commit | b7c2a99f847d3baef1710be5cf34f978514101dd (patch) | |
tree | 83d6c6ed83aacf0fea2a4f08c7b39350af4fab0a | |
parent | 0c34fe29c298057091d48cde332cb60bb14efee1 (diff) | |
download | ComputeLibrary-b7c2a99f847d3baef1710be5cf34f978514101dd.tar.gz |
COMPMID-415: Cleanup framework
Change-Id: Ibd5a95a8337ac96bdc1b61af29efa430b4abe2b6
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80938
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
-rw-r--r-- | framework/Asserts.h | 137 | ||||
-rw-r--r-- | framework/Macros.h | 29 | ||||
-rw-r--r-- | framework/datasets/ContainerDataset.h | 4 | ||||
-rw-r--r-- | framework/datasets/RangeDataset.h | 47 | ||||
-rw-r--r-- | framework/datasets/SingletonDataset.h | 2 |
5 files changed, 167 insertions, 52 deletions
diff --git a/framework/Asserts.h b/framework/Asserts.h new file mode 100644 index 0000000000..a1424372e9 --- /dev/null +++ b/framework/Asserts.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS +#define ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS + +#include "Exceptions.h" +#include "Framework.h" + +#include <sstream> +#include <type_traits> + +namespace arm_compute +{ +namespace framework +{ +namespace detail +{ +// Cast char values to int so that their numeric value are printed. +inline int make_printable(int8_t value) +{ + return value; +} + +inline unsigned int make_printable(uint8_t value) +{ + return value; +} + +// Everything else can be printed as its own type. +template <typename T> +inline T &&make_printable(T &&value) +{ + return value; +} +} // namespace detail +} // namespace framework +} // namespace arm_compute + +template <typename T> +void ARM_COMPUTE_ASSERT_EQUAL(T &&x, T &&y) +{ + if(x != y) + { + std::stringstream msg; + msg << "Assertion " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + throw arm_compute::test::framework::TestError(msg.str()); + } +} + +template <typename T> +void ARM_COMPUTE_EXPECT_EQUAL(T &&x, T &&y) +{ + if(x != y) + { + std::stringstream msg; + msg << "Expectation " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); + } +} + +template <typename T> +void ARM_COMPUTE_ASSERT_NOT_EQUAL(T &&x, T &&y) +{ + if(x == y) + { + std::stringstream msg; + msg << "Assertion " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + throw arm_compute::test::framework::TestError(msg.str()); + } +} + +template <typename T> +void ARM_COMPUTE_EXPECT_NOT_EQUAL(T &&x, T &&y) +{ + if(x == y) + { + std::stringstream msg; + msg << "Expectation " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); + } +} + +#define ARM_COMPUTE_ASSERT(X, MSG) \ + do \ + { \ + const auto &x = X; \ + if(!x) \ + { \ + std::stringstream msg; \ + msg << "Failed assertion: " << #X << "\n" \ + << MSG; \ + throw arm_compute::test::framework::TestError(msg.str()); \ + } \ + } while(false) + +#define ARM_COMPUTE_EXPECT(X, MSG) \ + do \ + { \ + const auto &x = X; \ + if(!x) \ + { \ + std::stringstream msg; \ + msg << "Failed assertion: " << #X << "\n" \ + << MSG; \ + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); \ + } \ + } while(false) +#endif /* ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS */ diff --git a/framework/Macros.h b/framework/Macros.h index 8c5afe9304..f5b22b461a 100644 --- a/framework/Macros.h +++ b/framework/Macros.h @@ -24,13 +24,10 @@ #ifndef ARM_COMPUTE_TEST_FRAMEWORK_MACROS #define ARM_COMPUTE_TEST_FRAMEWORK_MACROS -#include "Exceptions.h" #include "Framework.h" #include "Registrars.h" #include "TestCase.h" -#include <sstream> - // // TEST SUITE MACROS // @@ -218,30 +215,4 @@ // // TEST CASE MACROS END // - -#define ARM_COMPUTE_ASSERT_EQUAL(x, y) \ - do \ - { \ - const auto &_x = (x); \ - const auto &_y = (y); \ - if(_x != _y) \ - { \ - std::stringstream msg; \ - msg << "Assertion " << _x << " != " << _y << " failed."; \ - throw arm_compute::test::framework::TestError(msg.str()); \ - } \ - } while(false) - -#define ARM_COMPUTE_EXPECT_EQUAL(x, y) \ - do \ - { \ - const auto &_x = (x); \ - const auto &_y = (y); \ - if(_x != _y) \ - { \ - std::stringstream msg; \ - msg << "Expectation " << _x << " != " << _y << " failed."; \ - arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); \ - } \ - } while(false) #endif /* ARM_COMPUTE_TEST_FRAMEWORK_MACROS */ diff --git a/framework/datasets/ContainerDataset.h b/framework/datasets/ContainerDataset.h index af685439b5..bdca97cbac 100644 --- a/framework/datasets/ContainerDataset.h +++ b/framework/datasets/ContainerDataset.h @@ -55,7 +55,7 @@ struct is_container<std::vector<V, A>> : public std::true_type /** Implementation of a dataset created from a container. */ template <typename T> -class ContainerDataset final : public NamedDataset +class ContainerDataset : public NamedDataset { private: using container_value_type = typename T::value_type; @@ -68,7 +68,7 @@ public: * @param[in] container Values for the dataset. */ ContainerDataset(std::string name, T &&container) - : NamedDataset{ std::move(name) }, _container{ std::forward<T>(container) } + : NamedDataset{ std::move(name) }, _container(std::forward<T>(container)) { } diff --git a/framework/datasets/RangeDataset.h b/framework/datasets/RangeDataset.h index 2489405ff7..637abe0a83 100644 --- a/framework/datasets/RangeDataset.h +++ b/framework/datasets/RangeDataset.h @@ -40,7 +40,10 @@ namespace framework { namespace dataset { -/** Implementation of a dataset created from a range of values. */ +/** Implementation of a dataset created from a range of values. + * + * The range is inclusive of the first value but exclusive of the last, i.e. [start, end). + */ template <typename T> class RangeDataset final : public NamedDataset { @@ -48,47 +51,49 @@ public: /** Construct dataset with given name and values in the specified range. * * @param[in] name Description of the values. - * @param[in] first Iterator to the first value. - * @param[in] last Iterator behind the last value. + * @param[in] start Begin of the range. + * @param[in] end End of the range. + * @param[in] step Step size. */ - RangeDataset(std::string name, T &&first, T &&last) - : NamedDataset{ std::move(name) }, _first{ std::forward<T>(first) }, _last{ std::forward<T>(last) } + RangeDataset(std::string name, T start, T end, T step = 1) + : NamedDataset{ std::move(name) }, _start{ start }, _end{ end }, _step{ step } { } RangeDataset(RangeDataset &&) = default; /** Type of the dataset. */ - using type = std::tuple<typename std::iterator_traits<T>::value_type>; + using type = std::tuple<T>; /** Iterator for the dataset. */ struct iterator { - iterator(std::string name, T iterator) - : _name{ name }, _iterator{ iterator } + iterator(std::string name, T start, T step) + : _name{ name }, _value{ start }, _step{ step } { } std::string description() const { using support::cpp11::to_string; - return _name + "=" + to_string(*_iterator); + return _name + "=" + to_string(_value); } RangeDataset::type operator*() const { - return std::make_tuple(*_iterator); + return std::make_tuple(_value); } iterator &operator++() { - ++_iterator; + _value += _step; return *this; } private: std::string _name; - T _iterator; + T _value; + T _step; }; /** Iterator pointing at the begin of the dataset. @@ -97,7 +102,7 @@ public: */ iterator begin() const { - return iterator(name(), _first); + return iterator(name(), _start, _step); } /** Size of the dataset. @@ -106,26 +111,28 @@ public: */ int size() const { - return std::distance(_first, _last); + return (_end - _start) / std::abs(_step); } private: - T _first; - T _last; + T _start; + T _end; + T _step; }; /** Helper function to create a @ref RangeDataset. * * @param[in] name Name of the dataset. - * @param[in] first Iterator to the first value. - * @param[in] last Iterator behind the last value. + * @param[in] start Begin of the range. + * @param[in] end End of the range. + * @param[in] step Step size. * * @return A range dataset. */ template <typename T> -RangeDataset<T> make(std::string name, T &&first, T &&last) +RangeDataset<T> make(std::string name, T start, T end, T step = 1) { - return RangeDataset<T>(std::move(name), std::forward<T>(first), std::forward<T>(last)); + return RangeDataset<T>(std::move(name), start, end, step); } } // namespace dataset } // namespace framework diff --git a/framework/datasets/SingletonDataset.h b/framework/datasets/SingletonDataset.h index 4b71631d92..1acb5765e5 100644 --- a/framework/datasets/SingletonDataset.h +++ b/framework/datasets/SingletonDataset.h @@ -43,7 +43,7 @@ namespace dataset { /** Implementation of a dataset holding a single value. */ template <typename T> -class SingletonDataset final : public NamedDataset +class SingletonDataset : public NamedDataset { public: /** Construct dataset with given name and value. |