From a09de0c8b2ed0f1481502d3b023375609362d9e3 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Fri, 1 Sep 2017 20:41:12 +0100 Subject: COMPMID-415: Rename and move tests The boost validation is now "standalone" in validation_old and builds as arm_compute_validation_old. The new validation builds now as arm_compute_validation. Change-Id: Ib93ba848a25680ac60afb92b461d574a0757150d Reviewed-on: http://mpd-gerrit.cambridge.arm.com/86187 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- tests/framework/datasets/CartesianProductDataset.h | 165 +++++++++++++++++++++ tests/framework/datasets/ContainerDataset.h | 148 ++++++++++++++++++ tests/framework/datasets/Dataset.h | 86 +++++++++++ tests/framework/datasets/Datasets.h | 35 +++++ tests/framework/datasets/InitializerListDataset.h | 135 +++++++++++++++++ tests/framework/datasets/JoinDataset.h | 148 ++++++++++++++++++ tests/framework/datasets/RangeDataset.h | 141 ++++++++++++++++++ tests/framework/datasets/SingletonDataset.h | 138 +++++++++++++++++ tests/framework/datasets/ZipDataset.h | 139 +++++++++++++++++ 9 files changed, 1135 insertions(+) create mode 100644 tests/framework/datasets/CartesianProductDataset.h create mode 100644 tests/framework/datasets/ContainerDataset.h create mode 100644 tests/framework/datasets/Dataset.h create mode 100644 tests/framework/datasets/Datasets.h create mode 100644 tests/framework/datasets/InitializerListDataset.h create mode 100644 tests/framework/datasets/JoinDataset.h create mode 100644 tests/framework/datasets/RangeDataset.h create mode 100644 tests/framework/datasets/SingletonDataset.h create mode 100644 tests/framework/datasets/ZipDataset.h (limited to 'tests/framework/datasets') diff --git a/tests/framework/datasets/CartesianProductDataset.h b/tests/framework/datasets/CartesianProductDataset.h new file mode 100644 index 0000000000..f6e45ddc12 --- /dev/null +++ b/tests/framework/datasets/CartesianProductDataset.h @@ -0,0 +1,165 @@ +/* + * 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_DATASET_CARTESIAN_PRODUCT +#define ARM_COMPUTE_TEST_DATASET_CARTESIAN_PRODUCT + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing all combinations of values of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {(1, 3), (1, 4), (2, 3), (2, 4)}. + */ +template +class CartesianProductDataset : public Dataset +{ +private: + using T_noref = typename std::remove_reference::type; + using U_noref = typename std::remove_reference::type; + using iter1_type = typename T_noref::iterator; + using iter2_type = typename U_noref::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + CartesianProductDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + CartesianProductDataset(CartesianProductDataset &&) = default; + + /** Type of the dataset. */ + using type = decltype(std::tuple_cat(*std::declval(), *std::declval())); + + /** Iterator for the dataset. */ + struct iterator + { + iterator(const T_noref *dataset1, const U_noref *dataset2) + : _iter1{ dataset1->begin() }, + _dataset2{ dataset2 }, + _iter2{ dataset2->begin() } + { + } + + iterator(const iterator &) = default; + iterator &operator=(const iterator &) = default; + iterator(iterator &&) = default; + iterator &operator=(iterator &&) = default; + + ~iterator() = default; + + std::string description() const + { + return _iter1.description() + ":" + _iter2.description(); + } + + CartesianProductDataset::type operator*() const + { + return std::tuple_cat(*_iter1, *_iter2); + } + + iterator &operator++() + { + ++_second_pos; + + if(_second_pos < _dataset2->size()) + { + ++_iter2; + } + else + { + _second_pos = 0; + _iter2 = _dataset2->begin(); + + ++_iter1; + } + + return *this; + } + + private: + iter1_type _iter1; + const U_noref *_dataset2; + iter2_type _iter2; + int _first_pos{ 0 }; + int _second_pos{ 0 }; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(&_dataset1, &_dataset2); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _dataset1.size() * _dataset2.size(); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref CartesianProductDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A grid dataset. + */ +template +CartesianProductDataset combine(T &&dataset1, U &&dataset2) +{ + return CartesianProductDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_CARTESIAN_PRODUCT */ diff --git a/tests/framework/datasets/ContainerDataset.h b/tests/framework/datasets/ContainerDataset.h new file mode 100644 index 0000000000..bdca97cbac --- /dev/null +++ b/tests/framework/datasets/ContainerDataset.h @@ -0,0 +1,148 @@ +/* + * 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_DATASET_CONTAINER +#define ARM_COMPUTE_TEST_DATASET_CONTAINER + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Base case. Nothing is a container. */ +template +struct is_container : public std::false_type +{ +}; + +/** Vector is considered a container. */ +template +struct is_container> : public std::true_type +{ +}; + +/** Implementation of a dataset created from a container. */ +template +class ContainerDataset : public NamedDataset +{ +private: + using container_value_type = typename T::value_type; + using container_const_iterator = typename T::const_iterator; + +public: + /** Construct dataset with given name and values from the container. + * + * @param[in] name Description of the values. + * @param[in] container Values for the dataset. + */ + ContainerDataset(std::string name, T &&container) + : NamedDataset{ std::move(name) }, _container(std::forward(container)) + { + } + + ContainerDataset(ContainerDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, container_const_iterator iterator) + : _name{ name }, _iterator{ iterator } + { + } + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_iterator); + } + + ContainerDataset::type operator*() const + { + return std::make_tuple(*_iterator); + } + + iterator &operator++() + { + ++_iterator; + return *this; + } + + private: + std::string _name; + container_const_iterator _iterator; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _container.cbegin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _container.size(); + } + +private: + T _container; +}; + +/** Helper function to create a @ref ContainerDataset. + * + * @param[in] name Name of the dataset. + * @param[in] values Container. + * + * @return A container dataset. + */ +template +typename std::enable_if::value, ContainerDataset>::type make(std::string name, T &&values) +{ + return ContainerDataset(std::move(name), std::forward(values)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_CONTAINER */ diff --git a/tests/framework/datasets/Dataset.h b/tests/framework/datasets/Dataset.h new file mode 100644 index 0000000000..d91673073a --- /dev/null +++ b/tests/framework/datasets/Dataset.h @@ -0,0 +1,86 @@ +/* + * 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_DATASET +#define ARM_COMPUTE_TEST_DATASET + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Abstract dataset base class. */ +class Dataset +{ +protected: + Dataset() = default; + ~Dataset() = default; + +public: + Dataset(Dataset &&) = default; +}; + +/** Abstract implementation of a named dataset. + * + * The name should describe the values of the dataset. + */ +class NamedDataset : public Dataset +{ +protected: + /** Construct the dataset with the given name. + * + * @param[in] name Description of the values. + */ + explicit NamedDataset(std::string name) + : _name{ std::move(name) } + { + } + + ~NamedDataset() = default; + +public: + NamedDataset(NamedDataset &&) = default; + + /** Return name of the dataset. + * + * @return Description of the values. + */ + std::string name() const + { + return _name; + } + +protected: + const std::string _name; +}; +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET */ diff --git a/tests/framework/datasets/Datasets.h b/tests/framework/datasets/Datasets.h new file mode 100644 index 0000000000..c0e5822e17 --- /dev/null +++ b/tests/framework/datasets/Datasets.h @@ -0,0 +1,35 @@ +/* + * 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_DATASETS +#define ARM_COMPUTE_TEST_DATASETS + +#include "CartesianProductDataset.h" +#include "ContainerDataset.h" +#include "InitializerListDataset.h" +#include "JoinDataset.h" +#include "RangeDataset.h" +#include "SingletonDataset.h" +#include "ZipDataset.h" + +#endif /* ARM_COMPUTE_TEST_DATASETS */ diff --git a/tests/framework/datasets/InitializerListDataset.h b/tests/framework/datasets/InitializerListDataset.h new file mode 100644 index 0000000000..7d32234fab --- /dev/null +++ b/tests/framework/datasets/InitializerListDataset.h @@ -0,0 +1,135 @@ +/* + * 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_DATASET_LIST +#define ARM_COMPUTE_TEST_DATASET_LIST + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset created from an initializer list. */ +template +class InitializerListDataset final : public NamedDataset +{ +private: + using data_const_iterator = typename std::vector::const_iterator; + +public: + /** Construct dataset with given name and values from the container. + * + * @param[in] name Description of the values. + * @param[in] list Values for the dataset. + */ + InitializerListDataset(std::string name, std::initializer_list &&list) + : NamedDataset{ std::move(name) }, _data(std::forward>(list)) + { + } + + InitializerListDataset(InitializerListDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, data_const_iterator iterator) + : _name{ name }, _iterator{ iterator } + { + } + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_iterator); + } + + InitializerListDataset::type operator*() const + { + return std::make_tuple(*_iterator); + } + + iterator &operator++() + { + ++_iterator; + return *this; + } + + private: + std::string _name; + data_const_iterator _iterator; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _data.cbegin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _data.size(); + } + +private: + std::vector _data; +}; + +/** Helper function to create an @ref InitializerListDataset. + * + * @param[in] name Name of the dataset. + * @param[in] list Initializer list. + * + * @return An initializer list dataset. + */ +template +InitializerListDataset make(std::string name, std::initializer_list &&list) +{ + return InitializerListDataset(std::move(name), std::forward>(list)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_LIST */ diff --git a/tests/framework/datasets/JoinDataset.h b/tests/framework/datasets/JoinDataset.h new file mode 100644 index 0000000000..eded6e0259 --- /dev/null +++ b/tests/framework/datasets/JoinDataset.h @@ -0,0 +1,148 @@ +/* + * 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_DATASET_JOIN +#define ARM_COMPUTE_TEST_DATASET_JOIN + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing the concatenation of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {1, 2, 3, 4}. + */ +template +class JoinDataset : public Dataset +{ +private: + using iter1_type = typename T::iterator; + using iter2_type = typename U::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + JoinDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + JoinDataset(JoinDataset &&) = default; + + /** Type of the dataset. */ + using type = typename T::type; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(const T *dataset1, const U *dataset2) + : _iter1{ dataset1->begin() }, _iter2{ dataset2->begin() }, _first_size{ dataset1->size() } + { + } + + std::string description() const + { + return _first_size > 0 ? _iter1.description() : _iter2.description(); + } + + JoinDataset::type operator*() const + { + return _first_size > 0 ? *_iter1 : *_iter2; + } + + iterator &operator++() + { + if(_first_size > 0) + { + --_first_size; + ++_iter1; + } + else + { + ++_iter2; + } + + return *this; + } + + private: + iter1_type _iter1; + iter2_type _iter2; + int _first_size; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(&_dataset1, &_dataset2); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _dataset1.size() + _dataset2.size(); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref JoinDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A join dataset. + */ +template +JoinDataset concat(T &&dataset1, U &&dataset2) +{ + return JoinDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_JOIN */ diff --git a/tests/framework/datasets/RangeDataset.h b/tests/framework/datasets/RangeDataset.h new file mode 100644 index 0000000000..637abe0a83 --- /dev/null +++ b/tests/framework/datasets/RangeDataset.h @@ -0,0 +1,141 @@ +/* + * 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_DATASET_RANGE +#define ARM_COMPUTE_TEST_DATASET_RANGE + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** 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 +class RangeDataset final : public NamedDataset +{ +public: + /** Construct dataset with given name and values in the specified range. + * + * @param[in] name Description of the values. + * @param[in] start Begin of the range. + * @param[in] end End of the range. + * @param[in] step Step size. + */ + 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; + + /** Iterator for the dataset. */ + struct 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(_value); + } + + RangeDataset::type operator*() const + { + return std::make_tuple(_value); + } + + iterator &operator++() + { + _value += _step; + return *this; + } + + private: + std::string _name; + T _value; + T _step; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _start, _step); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return (_end - _start) / std::abs(_step); + } + +private: + T _start; + T _end; + T _step; +}; + +/** Helper function to create a @ref RangeDataset. + * + * @param[in] name Name of the dataset. + * @param[in] start Begin of the range. + * @param[in] end End of the range. + * @param[in] step Step size. + * + * @return A range dataset. + */ +template +RangeDataset make(std::string name, T start, T end, T step = 1) +{ + return RangeDataset(std::move(name), start, end, step); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_RANGE */ diff --git a/tests/framework/datasets/SingletonDataset.h b/tests/framework/datasets/SingletonDataset.h new file mode 100644 index 0000000000..1acb5765e5 --- /dev/null +++ b/tests/framework/datasets/SingletonDataset.h @@ -0,0 +1,138 @@ +/* + * 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_DATASET_SINGLETON +#define ARM_COMPUTE_TEST_DATASET_SINGLETON + +#include "ContainerDataset.h" +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset holding a single value. */ +template +class SingletonDataset : public NamedDataset +{ +public: + /** Construct dataset with given name and value. + * + * @param[in] name Description of the value. + * @param[in] value Value for the dataset. + */ + SingletonDataset(std::string name, T &&value) + : NamedDataset{ std::move(name) }, _value{ std::forward(value) } + { + } + + SingletonDataset(SingletonDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, const T *value) + : _name{ name }, _value{ value } + { + } + + ~iterator() = default; + + iterator(const iterator &) = default; + iterator &operator=(const iterator &) = default; + iterator(iterator &&) = default; + iterator &operator=(iterator &&) = default; + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_value); + } + + SingletonDataset::type operator*() const + { + return std::make_tuple(*_value); + } + + iterator &operator++() + { + return *this; + } + + private: + std::string _name; + const T *_value; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), &_value); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return 1; + } + +private: + T _value; +}; + +/** Helper function to create a @ref SingletonDataset. + * + * @param[in] name Name of the dataset. + * @param[in] value Value. + * + * @return A singleton dataset. + */ +template +typename std::enable_if < !is_container::value, SingletonDataset>::type make(std::string name, T &&value) +{ + return SingletonDataset(std::move(name), std::forward(value)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_SINGLETON */ diff --git a/tests/framework/datasets/ZipDataset.h b/tests/framework/datasets/ZipDataset.h new file mode 100644 index 0000000000..b95b7209a7 --- /dev/null +++ b/tests/framework/datasets/ZipDataset.h @@ -0,0 +1,139 @@ +/* + * 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_DATASET_ZIP +#define ARM_COMPUTE_TEST_DATASET_ZIP + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing pairs of values of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {(1, 3), (1, 4)}. + */ +template +class ZipDataset : public Dataset +{ +private: + using iter1_type = typename T::iterator; + using iter2_type = typename U::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + ZipDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + ZipDataset(ZipDataset &&) = default; + + /** Type of the dataset. */ + using type = decltype(std::tuple_cat(*std::declval(), *std::declval())); + + /** Iterator for the dataset. */ + struct iterator + { + iterator(iter1_type iter1, iter2_type iter2) + : _iter1{ std::move(iter1) }, _iter2{ std::move(iter2) } + { + } + + std::string description() const + { + return _iter1.description() + ":" + _iter2.description(); + } + + ZipDataset::type operator*() const + { + return std::tuple_cat(*_iter1, *_iter2); + } + + iterator &operator++() + { + ++_iter1; + ++_iter2; + return *this; + } + + private: + iter1_type _iter1; + iter2_type _iter2; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(_dataset1.begin(), _dataset2.begin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return std::min(_dataset1.size(), _dataset2.size()); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref ZipDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A zip dataset. + */ +template +ZipDataset zip(T &&dataset1, U &&dataset2) +{ + return ZipDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_ZIP */ -- cgit v1.2.1