From f5ca8fe42a08c8a15c30255b6cca0a500f0dfa8b Mon Sep 17 00:00:00 2001 From: lucapegolotti Date: Fri, 29 Apr 2016 16:06:14 +0200 Subject: [PATCH] containers_cpp: fix cpplint warnings in tests + changin name of test for blocking push and pop container --- containers_cpp/test/blocking_container_test-inl.h | 121 ------------------------------------------------------------------------------------------------------------------------- containers_cpp/test/blocking_container_test.h | 67 ------------------------------------------------------------------- containers_cpp/test/blocking_map_test-inl.h | 126 ------------------------------------------------------------------------------------------------------------------------------ containers_cpp/test/blocking_map_test.h | 66 ------------------------------------------------------------------ containers_cpp/test/blocking_push_and_pop_container_test-inl.h | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ containers_cpp/test/blocking_push_and_pop_container_test.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ containers_cpp/test/blocking_queue_test-inl.h | 10 +++++----- containers_cpp/test/blocking_queue_test.h | 17 +++++++++-------- containers_cpp/test/blocking_stack_test-inl.h | 7 +++---- containers_cpp/test/blocking_stack_test.h | 17 +++++++++-------- containers_cpp/test/main.cc | 4 +--- containers_cpp/test/map_test-inl.h | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ containers_cpp/test/map_test.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ containers_cpp/test/set_test-inl.h | 30 ++++++++++++++++-------------- containers_cpp/test/set_test.h | 15 ++++++++------- 15 files changed, 431 insertions(+), 429 deletions(-) delete mode 100755 containers_cpp/test/blocking_container_test-inl.h delete mode 100755 containers_cpp/test/blocking_container_test.h delete mode 100755 containers_cpp/test/blocking_map_test-inl.h delete mode 100755 containers_cpp/test/blocking_map_test.h create mode 100755 containers_cpp/test/blocking_push_and_pop_container_test-inl.h create mode 100755 containers_cpp/test/blocking_push_and_pop_container_test.h create mode 100755 containers_cpp/test/map_test-inl.h create mode 100755 containers_cpp/test/map_test.h diff --git a/containers_cpp/test/blocking_container_test-inl.h b/containers_cpp/test/blocking_container_test-inl.h deleted file mode 100755 index be94a3e..0000000 --- a/containers_cpp/test/blocking_container_test-inl.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2014-2016, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ -#define CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ - -#include -#include - -namespace embb { -namespace containers { -namespace test { -template -BlockingContainerTest::BlockingContainerTest() : -n_threads(static_cast - (partest::TestSuite::GetDefaultNumThreads())), - n_iterations(200), - n_container_elements_per_thread(100), - n_container_elements(n_container_elements_per_thread*n_threads), - container(){ - CreateUnit("BlockingContainerTestThreadsPushAndPopToGlobalBlockingContainer"). - Pre(&BlockingContainerTest::BlockingContainerTest1_Pre, this). - Add(&BlockingContainerTest::BlockingContainerTest1_ThreadMethod, this, - static_cast(n_threads), - static_cast(n_iterations)). - Post(&BlockingContainerTest::BlockingContainerTest1_Post, this); -} - -template -void BlockingContainerTest::BlockingContainerTest1_Pre() { - embb_internal_thread_index_reset(); - thread_local_vectors = - new std::vector[static_cast(n_threads)]; - - for (int i = 0; i != n_threads; ++i) { - int offset = n_container_elements_per_thread * 2; - - for (int i2 = 0; i2 != n_container_elements_per_thread; ++i2) { - int push_element = i2 + (offset*i); - thread_local_vectors[i].push_back(push_element); - expected_container_elements.push_back(push_element); - } - } -} - -template -void BlockingContainerTest::BlockingContainerTest1_Post() { - std::vector produced; - for (int i = 0; i != n_threads; ++i) { - std::vector& loc_elements = thread_local_vectors[i]; - for (std::vector::iterator it = loc_elements.begin(); - it != loc_elements.end(); - ++it) { - produced.push_back(*it); - } - } - - PT_ASSERT(produced.size() == expected_container_elements.size()); - - std::sort(expected_container_elements.begin(), expected_container_elements.end()); - std::sort(produced.begin(), produced.end()); - - for (unsigned int i = 0; - i != static_cast(produced.size()); ++i) { - PT_ASSERT(expected_container_elements[i] == produced[i]); - } - - delete[] thread_local_vectors; -} - -template -void BlockingContainerTest::BlockingContainerTest1_ThreadMethod() { - unsigned int thread_index; - int return_val = embb_internal_thread_index(&thread_index); - - PT_ASSERT(EMBB_SUCCESS == return_val); - - std::vector& my_elements = thread_local_vectors[thread_index]; - - for (std::vector::iterator it = my_elements.begin(); - it != my_elements.end(); - ++it) { - SpecializedPush(*it); - } - - my_elements.clear(); - - for (int i = 0; i != n_container_elements_per_thread; ++i) { - int return_elem; - SpecializedPop(return_elem); - my_elements.push_back(return_elem); - } -} -} // namespace test -} // namespace containers -} // namespace embb - -#endif // CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ diff --git a/containers_cpp/test/blocking_container_test.h b/containers_cpp/test/blocking_container_test.h deleted file mode 100755 index 624bc62..0000000 --- a/containers_cpp/test/blocking_container_test.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2016, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ -#define CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ - -#include -#include -#include - -namespace embb { -namespace containers { -namespace test { -template -class BlockingContainerTest : public partest::TestCase { - protected: - int n_threads; - int n_iterations; - int n_container_elements_per_thread; - int n_container_elements; - Container_t container; - std::vector expected_container_elements; - std::vector* thread_local_vectors; - - virtual void SpecializedPush(const int& element) = 0; - - virtual void SpecializedPop(int& element) = 0; - - public: - BlockingContainerTest(); - - void BlockingContainerTest1_Pre(); - - void BlockingContainerTest1_Post(); - - void BlockingContainerTest1_ThreadMethod(); - -}; -} // namespace test -} // namespace containers -} // namespace embb - -#include "./blocking_container_test-inl.h" - -#endif // CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ diff --git a/containers_cpp/test/blocking_map_test-inl.h b/containers_cpp/test/blocking_map_test-inl.h deleted file mode 100755 index 1dc8d94..0000000 --- a/containers_cpp/test/blocking_map_test-inl.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -* Copyright (c) 2014-2016, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ -#define CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ - -namespace embb { - namespace containers { - namespace test { - -template -MapTest::MapTest() : - n_threads(static_cast - (partest::TestSuite::GetDefaultNumThreads())), - n_iterations(200), - n_operations_per_iteration(200), - n_map_elements_per_thread(100), - map(), - map_contain_vector(static_cast - (n_map_elements_per_thread*n_threads)) { - CreateUnit("MapTestThreadsInsertAndEraseToGlobalMap"). - Pre(&MapTest::MapTest1_Pre, this). - Add(&MapTest::MapTest1_ThreadMethod, this, - static_cast(n_threads), - static_cast(n_iterations)). - Post(&MapTest::MapTest1_Post, this); - -} - -template -void MapTest::MapTest1_Pre() { - embb_internal_thread_index_reset(); - thread_local_vectors_key = - new std::vector[static_cast(n_threads)]; - - thread_local_vectors_value = - new std::vector[static_cast(n_threads)]; - - for (int i = 0; i != n_threads; ++i) { - int offset = n_map_elements_per_thread; - - for (int i2 = 0; i2 != n_map_elements_per_thread; ++i2) { - int insert_element = i2 + (offset*i); - thread_local_vectors_key[i].push_back(insert_element); - thread_local_vectors_value[i].push_back(insert_element * 2); - map_contain_vector[static_cast(insert_element)] = false; - } - - } -} - -template -void MapTest::MapTest1_Post() { - unsigned int map_elements = map_contain_vector.size(); - for (unsigned int i = 0; i < map_elements; i++) { - PT_ASSERT(map_contain_vector[i] == map.Contains(static_cast(i))); - if (map_contain_vector[i]) - PT_ASSERT((map[i] == i * 2)); - } -} - -template -void MapTest::MapTest1_ThreadMethod() { - unsigned int thread_index; - int return_val = embb_internal_thread_index(&thread_index); - - PT_ASSERT((EMBB_SUCCESS == return_val)); - - srand(time(NULL)); - - std::vector& my_values = thread_local_vectors_value[thread_index]; - std::vector& my_keys = thread_local_vectors_key[thread_index]; - - - for (int i = 0; i < n_operations_per_iteration; i++) { - int random_number = rand() % 100; - int inserting = rand() % 2; - - int key = my_keys[static_cast(random_number)]; - int value = my_values[static_cast(random_number)]; - - if (inserting) { - PT_ASSERT(map.Insert(key, value) != map_contain_vector[static_cast(key)]); - map_contain_vector[static_cast(key)] = true; - - } - else { - PT_ASSERT(map.Erase(key) == map_contain_vector[static_cast(key)]); - map_contain_vector[static_cast(key)] = false; - } - } - -} - - - - -} // namespace test -} // namespace containers -} // namespace embb - - -#endif // CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ \ No newline at end of file diff --git a/containers_cpp/test/blocking_map_test.h b/containers_cpp/test/blocking_map_test.h deleted file mode 100755 index d43f3c2..0000000 --- a/containers_cpp/test/blocking_map_test.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright (c) 2014-2016, Siemens AG. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef CONTAINERS_CPP_TEST_MAP_TEST_H_ -#define CONTAINERS_CPP_TEST_MAP_TEST_H_ - -#include -#include -#include -#include - -namespace embb { -namespace containers { -namespace test { -template -class MapTest : public partest::TestCase { - private: - int n_threads; - int n_iterations; - int n_operations_per_iteration; - int n_map_elements_per_thread; - Map_t map; - std::vector* thread_local_vectors_key; - std::vector* thread_local_vectors_value; - std::vector map_contain_vector; - - public: - MapTest(); - - void MapTest1_Pre(); - - void MapTest1_Post(); - - void MapTest1_ThreadMethod(); - -}; -} // namespace test -} // namespace containers -} // namespace embb - -#include "./blocking_map_test-inl.h" - -#endif \ No newline at end of file diff --git a/containers_cpp/test/blocking_push_and_pop_container_test-inl.h b/containers_cpp/test/blocking_push_and_pop_container_test-inl.h new file mode 100755 index 0000000..8d7205d --- /dev/null +++ b/containers_cpp/test/blocking_push_and_pop_container_test-inl.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ +#define CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ + +#include +#include + +namespace embb { +namespace containers { +namespace test { +template +BlockingContainerTest::BlockingContainerTest() : +n_threads(static_cast + (partest::TestSuite::GetDefaultNumThreads())), + n_iterations(200), + n_container_elements_per_thread(100), + n_container_elements(n_container_elements_per_thread*n_threads), + container() { + CreateUnit("BlockingContainerTestThreadsPushAndPopToGlobalBlockingContainer"). + Pre(&BlockingContainerTest::BlockingContainerTest1_Pre, this). + Add(&BlockingContainerTest::BlockingContainerTest1_ThreadMethod, this, + static_cast(n_threads), + static_cast(n_iterations)). + Post(&BlockingContainerTest::BlockingContainerTest1_Post, this); +} + +template +void BlockingContainerTest::BlockingContainerTest1_Pre() { + embb_internal_thread_index_reset(); + thread_local_vectors = + new std::vector[static_cast(n_threads)]; + + for (int i = 0; i != n_threads; ++i) { + int offset = n_container_elements_per_thread * 2; + + for (int i2 = 0; i2 != n_container_elements_per_thread; ++i2) { + int push_element = i2 + (offset*i); + thread_local_vectors[i].push_back(push_element); + expected_container_elements.push_back(push_element); + } + } +} + +template +void BlockingContainerTest::BlockingContainerTest1_Post() { + std::vector produced; + for (int i = 0; i != n_threads; ++i) { + std::vector& loc_elements = thread_local_vectors[i]; + for (std::vector::iterator it = loc_elements.begin(); + it != loc_elements.end(); + ++it) { + produced.push_back(*it); + } + } + + PT_ASSERT(produced.size() == expected_container_elements.size()); + + std::sort(expected_container_elements.begin(), + expected_container_elements.end()); + std::sort(produced.begin(), produced.end()); + + for (unsigned int i = 0; + i != static_cast(produced.size()); ++i) { + PT_ASSERT(expected_container_elements[i] == produced[i]); + } + + delete[] thread_local_vectors; +} + +template +void BlockingContainerTest::BlockingContainerTest1_ThreadMethod() { + unsigned int thread_index; + int return_val = embb_internal_thread_index(&thread_index); + + PT_ASSERT(EMBB_SUCCESS == return_val); + + std::vector& my_elements = thread_local_vectors[thread_index]; + + for (std::vector::iterator it = my_elements.begin(); + it != my_elements.end(); + ++it) { + SpecializedPush(*it); + } + + my_elements.clear(); + + for (int i = 0; i != n_container_elements_per_thread; ++i) { + int return_elem; + SpecializedPop(return_elem); + my_elements.push_back(return_elem); + } +} +} // namespace test +} // namespace containers +} // namespace embb + +#endif // CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_INL_H_ diff --git a/containers_cpp/test/blocking_push_and_pop_container_test.h b/containers_cpp/test/blocking_push_and_pop_container_test.h new file mode 100755 index 0000000..a4f02ed --- /dev/null +++ b/containers_cpp/test/blocking_push_and_pop_container_test.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014-2016, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ +#define CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ + +#include +#include +#include + +namespace embb { +namespace containers { +namespace test { +template +class BlockingContainerTest : public partest::TestCase { + protected: + int n_threads; + int n_iterations; + int n_container_elements_per_thread; + int n_container_elements; + Container_t container; + std::vector expected_container_elements; + std::vector* thread_local_vectors; + + virtual void SpecializedPush(const int& element) = 0; + + virtual void SpecializedPop(int& element) = 0; + + public: + BlockingContainerTest(); + + void BlockingContainerTest1_Pre(); + + void BlockingContainerTest1_Post(); + + void BlockingContainerTest1_ThreadMethod(); +}; +} // namespace test +} // namespace containers +} // namespace embb + +#include "./blocking_push_and_pop_container_test-inl.h" + +#endif // CONTAINERS_CPP_TEST_BLOCKING_CONTAINER_TEST_H_ diff --git a/containers_cpp/test/blocking_queue_test-inl.h b/containers_cpp/test/blocking_queue_test-inl.h index 1dbccd5..26b6cc1 100755 --- a/containers_cpp/test/blocking_queue_test-inl.h +++ b/containers_cpp/test/blocking_queue_test-inl.h @@ -35,17 +35,17 @@ namespace containers { namespace test { template -void BlockingQueueTest::SpecializedPush(const int& element){ +void BlockingQueueTest::SpecializedPush(const int& element) { container.Enqueue(element); } template -void BlockingQueueTest::SpecializedPop(int& element){ +void BlockingQueueTest::SpecializedPop(int& element) { container.Dequeue(element); } -} // namespace test -} // namespace containers -} // namespace embb +} // namespace test +} // namespace containers +} // namespace embb #endif // CONTAINERS_CPP_TEST_BLOCKING_QUEUE_TEST_INL_H_ diff --git a/containers_cpp/test/blocking_queue_test.h b/containers_cpp/test/blocking_queue_test.h index 6bc773f..fe6c316 100755 --- a/containers_cpp/test/blocking_queue_test.h +++ b/containers_cpp/test/blocking_queue_test.h @@ -26,24 +26,25 @@ #ifndef CONTAINERS_CPP_TEST_BLOCKING_QUEUE_TEST_H_ #define CONTAINERS_CPP_TEST_BLOCKING_QUEUE_TEST_H_ -#include #include +#include <./blocking_push_and_pop_container_test.h> #include -#include <./blocking_container_test.h> + +#include namespace embb { namespace containers { namespace test { template class BlockingQueueTest : public BlockingContainerTest { - protected: - virtual void SpecializedPush(const int& element); + private: + void SpecializedPush(const int& element); - virtual void SpecializedPop(int& element); + void SpecializedPop(int& element); }; -} // namespace test -} // namespace containers -} // namespace embb +} // namespace test +} // namespace containers +} // namespace embb #include "./blocking_queue_test-inl.h" diff --git a/containers_cpp/test/blocking_stack_test-inl.h b/containers_cpp/test/blocking_stack_test-inl.h index c6ab0a3..71a969e 100755 --- a/containers_cpp/test/blocking_stack_test-inl.h +++ b/containers_cpp/test/blocking_stack_test-inl.h @@ -44,9 +44,8 @@ void BlockingStackTest::SpecializedPop(int& element) { container.Pop(element); } - -} // namespace test -} // namespace containers -} // namespace embb +} // namespace test +} // namespace containers +} // namespace embb #endif // CONTAINERS_CPP_TEST_BLOCKING_STACK_TEST_INL_H_ diff --git a/containers_cpp/test/blocking_stack_test.h b/containers_cpp/test/blocking_stack_test.h index 3eb140d..a2ce8a8 100755 --- a/containers_cpp/test/blocking_stack_test.h +++ b/containers_cpp/test/blocking_stack_test.h @@ -26,24 +26,25 @@ #ifndef CONTAINERS_CPP_TEST_BLOCKING_STACK_TEST_H_ #define CONTAINERS_CPP_TEST_BLOCKING_STACK_TEST_H_ -#include #include #include -#include <./blocking_container_test.h> +#include <./blocking_push_and_pop_container_test.h> + +#include namespace embb { namespace containers { namespace test { template class BlockingStackTest : public BlockingContainerTest { - protected: - virtual void SpecializedPush(const int& element); + private: + void SpecializedPush(const int& element); - virtual void SpecializedPop(int& element); + void SpecializedPop(int& element); }; -} // namespace test -} // namespace stacks -} // namespace embb +} // namespace test +} // namespace containers +} // namespace embb #include "./blocking_stack_test-inl.h" diff --git a/containers_cpp/test/main.cc b/containers_cpp/test/main.cc index 0d45b03..24408d2 100644 --- a/containers_cpp/test/main.cc +++ b/containers_cpp/test/main.cc @@ -48,7 +48,7 @@ #include "./hazard_pointer_test.h" #include "./object_pool_test.h" #include "./set_test.h" -#include "./blocking_map_test.h" +#include "./map_test.h" #define COMMA , @@ -76,7 +76,6 @@ using embb::containers::test::HazardPointerTest2; using embb::containers::test::MapTest; PT_MAIN("Data Structures C++") { - unsigned int max_threads = static_cast( 2 * partest::TestSuite::GetDefaultNumThreads()); embb_thread_set_max_count(max_threads); @@ -96,5 +95,4 @@ PT_MAIN("Data Structures C++") { PT_RUN(ObjectPoolTest< LockFreeTreeValuePool >); PT_RUN(ObjectPoolTest< WaitFreeArrayValuePool >); PT_EXPECT(embb_get_bytes_allocated() == 0); - } diff --git a/containers_cpp/test/map_test-inl.h b/containers_cpp/test/map_test-inl.h new file mode 100755 index 0000000..1ce5d64 --- /dev/null +++ b/containers_cpp/test/map_test-inl.h @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2014-2016, Siemens AG. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ +#define CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ + +#include + +namespace embb { +namespace containers { +namespace test { + +template +MapTest::MapTest() : + n_threads(static_cast + (partest::TestSuite::GetDefaultNumThreads())), + n_iterations(200), + n_operations_per_iteration(200), + n_map_elements_per_thread(100), + map(), + map_contain_vector(static_cast + (n_map_elements_per_thread*n_threads)) { + CreateUnit("MapTestThreadsInsertAndEraseToGlobalMap"). + Pre(&MapTest::MapTest1_Pre, this). + Add(&MapTest::MapTest1_ThreadMethod, this, + static_cast(n_threads), + static_cast(n_iterations)). + Post(&MapTest::MapTest1_Post, this); +} + +template +void MapTest::MapTest1_Pre() { + embb_internal_thread_index_reset(); + thread_local_vectors_key = + new std::vector[static_cast(n_threads)]; + + thread_local_vectors_value = + new std::vector[static_cast(n_threads)]; + + for (int i = 0; i != n_threads; ++i) { + int offset = n_map_elements_per_thread; + + for (int i2 = 0; i2 != n_map_elements_per_thread; ++i2) { + int insert_element = i2 + (offset*i); + thread_local_vectors_key[i].push_back(insert_element); + thread_local_vectors_value[i].push_back(insert_element * 2); + map_contain_vector[static_cast(insert_element)] = false; + } + } +} + +template +void MapTest::MapTest1_Post() { + unsigned int map_elements = map_contain_vector.size(); + for (unsigned int i = 0; i < map_elements; i++) { + PT_ASSERT(map_contain_vector[i] == map.Contains(static_cast(i))); + if (map_contain_vector[i]) + PT_ASSERT((map[i] == i * 2)); + } +} + +template +void MapTest::MapTest1_ThreadMethod() { + unsigned int thread_index; + int return_val = embb_internal_thread_index(&thread_index); + + PT_ASSERT((EMBB_SUCCESS == return_val)); + + srand(time(NULL)); + + std::vector& my_values = thread_local_vectors_value[thread_index]; + std::vector& my_keys = thread_local_vectors_key[thread_index]; + + + for (int i = 0; i < n_operations_per_iteration; i++) { + int random_number = rand() % 100; + int inserting = rand() % 2; + + int key = my_keys[static_cast(random_number)]; + int value = my_values[static_cast(random_number)]; + + if (inserting) { + PT_ASSERT(map.Insert(key, value) != + map_contain_vector[static_cast(key)]); + map_contain_vector[static_cast(key)] = true; + + } else { + PT_ASSERT(map.Erase(key) == + map_contain_vector[static_cast(key)]); + map_contain_vector[static_cast(key)] = false; + } + } +} + + + + +} // namespace test +} // namespace containers +} // namespace embb + + +#endif // CONTAINERS_CPP_TEST_MAP_TEST_INL_H_ diff --git a/containers_cpp/test/map_test.h b/containers_cpp/test/map_test.h new file mode 100755 index 0000000..8bcf095 --- /dev/null +++ b/containers_cpp/test/map_test.h @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2014-2016, Siemens AG. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CONTAINERS_CPP_TEST_MAP_TEST_H_ +#define CONTAINERS_CPP_TEST_MAP_TEST_H_ + +#include +#include +#include + +#include + +namespace embb { +namespace containers { +namespace test { +template +class MapTest : public partest::TestCase { + private: + int n_threads; + int n_iterations; + int n_operations_per_iteration; + int n_map_elements_per_thread; + Map_t map; + std::vector* thread_local_vectors_key; + std::vector* thread_local_vectors_value; + std::vector map_contain_vector; + + public: + MapTest(); + + void MapTest1_Pre(); + + void MapTest1_Post(); + + void MapTest1_ThreadMethod(); +}; +} // namespace test +} // namespace containers +} // namespace embb + +#include "./map_test-inl.h" + +#endif // CONTAINERS_CPP_TEST_MAP_TEST_H_ diff --git a/containers_cpp/test/set_test-inl.h b/containers_cpp/test/set_test-inl.h index 129b059..d99896e 100755 --- a/containers_cpp/test/set_test-inl.h +++ b/containers_cpp/test/set_test-inl.h @@ -28,10 +28,11 @@ #ifndef CONTAINERS_CPP_TEST_SET_TEST_INL_H_ #define CONTAINERS_CPP_TEST_SET_TEST_INL_H_ -#include -#include #include +#include +#include + namespace embb { namespace containers { namespace test { @@ -55,7 +56,7 @@ SetTest::SetTest() : } template -void SetTest::SetTest1_Pre(){ +void SetTest::SetTest1_Pre() { embb_internal_thread_index_reset(); thread_local_vectors = new std::vector[static_cast(n_threads)]; @@ -72,7 +73,7 @@ void SetTest::SetTest1_Pre(){ } template -void SetTest::SetTest1_Post(){ +void SetTest::SetTest1_Post() { unsigned int set_elements = set_contain_vector.size(); for (unsigned int i = 0; i < set_elements; i++) { PT_ASSERT(set_contain_vector[i] == set.Contains(static_cast(i))); @@ -87,7 +88,7 @@ void SetTest::SetTest1_ThreadMethod() { int return_val = embb_internal_thread_index(&thread_index); PT_ASSERT(EMBB_SUCCESS == return_val); - + srand(time(NULL)); std::vector& my_elements = thread_local_vectors[thread_index]; @@ -99,19 +100,20 @@ void SetTest::SetTest1_ThreadMethod() { int element = my_elements[static_cast(random_number)]; if (inserting) { - PT_ASSERT(set.Insert(element) != set_contain_vector[static_cast(element)]); + PT_ASSERT(set.Insert(element) != + set_contain_vector[static_cast(element)]); set_contain_vector[static_cast(element)] = true; - } - else { - PT_ASSERT(set.Erase(element) == set_contain_vector[static_cast(element)]); + } else { + PT_ASSERT(set.Erase(element) == + set_contain_vector[static_cast(element)]); set_contain_vector[static_cast(element)] = false; } } } - -} // namespace test -} // namespace containers -} // namespace embb -#endif // CONTAINERS_CPP_TEST_SET_TEST_INL_H_ \ No newline at end of file +} // namespace test +} // namespace containers +} // namespace embb + +#endif // CONTAINERS_CPP_TEST_SET_TEST_INL_H_ diff --git a/containers_cpp/test/set_test.h b/containers_cpp/test/set_test.h index 3cc3a5f..3631043 100755 --- a/containers_cpp/test/set_test.h +++ b/containers_cpp/test/set_test.h @@ -26,16 +26,17 @@ #ifndef CONTAINERS_CPP_TEST_SET_TEST_H_ #define CONTAINERS_CPP_TEST_SET_TEST_H_ -#include #include #include +#include + namespace embb { namespace containers { namespace test { template class SetTest : public partest::TestCase { -private: + private: int n_threads; int n_iterations; int n_operations_per_iteration; @@ -44,7 +45,7 @@ private: std::vector* thread_local_vectors; std::vector set_contain_vector; -public: + public: SetTest(); void SetTest1_Pre(); @@ -53,10 +54,10 @@ public: void SetTest1_ThreadMethod(); }; -} // namespace test -} // namespace containers -} // namespace embb +} // namespace test +} // namespace containers +} // namespace embb #include "./set_test-inl.h" -#endif // CONTAINERS_CPP_TEST_SET_TEST_H_ \ No newline at end of file +#endif // CONTAINERS_CPP_TEST_SET_TEST_H_ -- libgit2 0.26.0