1 /* 2 Copyright (c) 2020-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #if __INTEL_COMPILER && _MSC_VER 18 #pragma warning(disable : 2586) // decorated name length exceeded, name was truncated 19 #endif 20 21 #define CONFORMANCE_BUFFERING_NODES 22 23 #include "conformance_flowgraph.h" 24 25 //! \file conformance_buffer_node.cpp 26 //! \brief Test for [flow_graph.buffer_node] specification 27 28 //! Test buffer_node broadcast 29 //! \brief \ref requirement 30 TEST_CASE("buffer_node single_push"){ 31 conformance::test_forwarding_single_push<oneapi::tbb::flow::buffer_node<int>>(); 32 } 33 34 //! Test function_node buffering 35 //! \brief \ref requirement 36 TEST_CASE("buffer_node buffering"){ 37 conformance::test_buffering<oneapi::tbb::flow::buffer_node<int>, int>(); 38 } 39 40 //! Constructs an empty buffer_node that belongs to the same graph g as src. 41 //! Any intermediate state of src, including its links to predecessors and successors, is not copied. 42 //! \brief \ref requirement 43 TEST_CASE("buffer_node copy constructor"){ 44 conformance::test_copy_ctor_for_buffering_nodes<oneapi::tbb::flow::buffer_node<int>>(); 45 } 46 47 //! Test inheritance relations 48 //! \brief \ref interface 49 TEST_CASE("buffer_node superclasses"){ 50 conformance::test_inheritance<oneapi::tbb::flow::buffer_node<int>, int, int>(); 51 conformance::test_inheritance<oneapi::tbb::flow::buffer_node<void*>, void*, void*>(); 52 } 53 54 //! Test buffer_node node `try_put()` and `try_get()` 55 //! \brief \ref requirement 56 TEST_CASE("buffer_node methods"){ 57 oneapi::tbb::flow::graph g; 58 oneapi::tbb::flow::buffer_node<int> testing_node(g); 59 60 int tmp1 = -1; 61 int tmp2 = -1; 62 63 CHECK_MESSAGE((!testing_node.try_get(tmp1) && tmp1 == -1), "`try_get` must returns false if there is no non-reserved item currently in the node."); 64 65 testing_node.try_put(1); 66 testing_node.try_put(2); 67 68 g.wait_for_all(); 69 testing_node.try_get(tmp1); 70 CHECK_MESSAGE((tmp1 == 1 || tmp1 == 2), "Messages must be an arbitrary order"); 71 72 testing_node.try_get(tmp2); 73 CHECK_MESSAGE((tmp2 != -1 && tmp2 != tmp1), "Additional `try_get()' does not receive the same value as previous"); 74 } 75