1*e0cc5187SIlya Isaev /* 2*e0cc5187SIlya Isaev Copyright (c) 2022 Intel Corporation 3*e0cc5187SIlya Isaev 4*e0cc5187SIlya Isaev Licensed under the Apache License, Version 2.0 (the "License"); 5*e0cc5187SIlya Isaev you may not use this file except in compliance with the License. 6*e0cc5187SIlya Isaev You may obtain a copy of the License at 7*e0cc5187SIlya Isaev 8*e0cc5187SIlya Isaev http://www.apache.org/licenses/LICENSE-2.0 9*e0cc5187SIlya Isaev 10*e0cc5187SIlya Isaev Unless required by applicable law or agreed to in writing, software 11*e0cc5187SIlya Isaev distributed under the License is distributed on an "AS IS" BASIS, 12*e0cc5187SIlya Isaev WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e0cc5187SIlya Isaev See the License for the specific language governing permissions and 14*e0cc5187SIlya Isaev limitations under the License. 15*e0cc5187SIlya Isaev */ 16*e0cc5187SIlya Isaev 17*e0cc5187SIlya Isaev #define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1 18*e0cc5187SIlya Isaev 19*e0cc5187SIlya Isaev #include "common/config.h" 20*e0cc5187SIlya Isaev 21*e0cc5187SIlya Isaev #include "test_join_node.h" 22*e0cc5187SIlya Isaev #include "common/test_join_node_multiple_predecessors.h" 23*e0cc5187SIlya Isaev #include "common/test_follows_and_precedes_api.h" 24*e0cc5187SIlya Isaev 25*e0cc5187SIlya Isaev #include <array> 26*e0cc5187SIlya Isaev #include <vector> 27*e0cc5187SIlya Isaev 28*e0cc5187SIlya Isaev //! \file test_join_node_preview.cpp 29*e0cc5187SIlya Isaev //! \brief Test for [preview] functionality 30*e0cc5187SIlya Isaev 31*e0cc5187SIlya Isaev void jn_follows_and_precedes() { 32*e0cc5187SIlya Isaev using msg_t = tbb::flow::continue_msg; 33*e0cc5187SIlya Isaev using JoinOutputType = std::tuple<msg_t, msg_t, msg_t>; 34*e0cc5187SIlya Isaev 35*e0cc5187SIlya Isaev std::array<msg_t, 3> messages_for_follows = { {msg_t(), msg_t(), msg_t()} }; 36*e0cc5187SIlya Isaev std::vector<msg_t> messages_for_precedes = {msg_t(), msg_t(), msg_t()}; 37*e0cc5187SIlya Isaev 38*e0cc5187SIlya Isaev follows_and_precedes_testing::test_follows 39*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType>, tbb::flow::buffer_node<msg_t>>(messages_for_follows); 40*e0cc5187SIlya Isaev follows_and_precedes_testing::test_follows 41*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::queueing>>(messages_for_follows); 42*e0cc5187SIlya Isaev follows_and_precedes_testing::test_follows 43*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::reserving>, tbb::flow::buffer_node<msg_t>>(messages_for_follows); 44*e0cc5187SIlya Isaev auto b = [](msg_t) { return msg_t(); }; 45*e0cc5187SIlya Isaev class hash_compare { 46*e0cc5187SIlya Isaev public: 47*e0cc5187SIlya Isaev std::size_t hash(msg_t) const { return 0; } 48*e0cc5187SIlya Isaev bool equal(msg_t, msg_t) const { return true; } 49*e0cc5187SIlya Isaev }; 50*e0cc5187SIlya Isaev follows_and_precedes_testing::test_follows 51*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::key_matching<msg_t, hash_compare>>, tbb::flow::buffer_node<msg_t>> 52*e0cc5187SIlya Isaev (messages_for_follows, b, b, b); 53*e0cc5187SIlya Isaev 54*e0cc5187SIlya Isaev follows_and_precedes_testing::test_precedes 55*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType>>(messages_for_precedes); 56*e0cc5187SIlya Isaev follows_and_precedes_testing::test_precedes 57*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::queueing>>(messages_for_precedes); 58*e0cc5187SIlya Isaev follows_and_precedes_testing::test_precedes 59*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::reserving>>(messages_for_precedes); 60*e0cc5187SIlya Isaev follows_and_precedes_testing::test_precedes 61*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::key_matching<msg_t, hash_compare>>> 62*e0cc5187SIlya Isaev (messages_for_precedes, b, b, b); 63*e0cc5187SIlya Isaev } 64*e0cc5187SIlya Isaev 65*e0cc5187SIlya Isaev void jn_msg_key_matching_follows_and_precedes() { 66*e0cc5187SIlya Isaev using msg_t = MyMessageKeyWithoutKey<int, int>; 67*e0cc5187SIlya Isaev using JoinOutputType = std::tuple<msg_t, msg_t, msg_t>; 68*e0cc5187SIlya Isaev 69*e0cc5187SIlya Isaev std::array<msg_t, 3> messages_for_follows = { {msg_t(), msg_t(), msg_t()} }; 70*e0cc5187SIlya Isaev std::vector<msg_t> messages_for_precedes = { msg_t(), msg_t(), msg_t() }; 71*e0cc5187SIlya Isaev 72*e0cc5187SIlya Isaev follows_and_precedes_testing::test_follows 73*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::key_matching<std::size_t>>, tbb::flow::buffer_node<msg_t>> 74*e0cc5187SIlya Isaev (messages_for_follows); 75*e0cc5187SIlya Isaev follows_and_precedes_testing::test_precedes 76*e0cc5187SIlya Isaev <msg_t, tbb::flow::join_node<JoinOutputType, tbb::flow::key_matching<std::size_t>>> 77*e0cc5187SIlya Isaev (messages_for_precedes); 78*e0cc5187SIlya Isaev } 79*e0cc5187SIlya Isaev 80*e0cc5187SIlya Isaev void test_follows_and_precedes_api() { 81*e0cc5187SIlya Isaev jn_follows_and_precedes(); 82*e0cc5187SIlya Isaev jn_msg_key_matching_follows_and_precedes(); 83*e0cc5187SIlya Isaev } 84*e0cc5187SIlya Isaev 85*e0cc5187SIlya Isaev //! Test follows and precedes API 86*e0cc5187SIlya Isaev //! \brief \ref error_guessing 87*e0cc5187SIlya Isaev TEST_CASE("Test follows and preceedes API"){ 88*e0cc5187SIlya Isaev test_follows_and_precedes_api(); 89*e0cc5187SIlya Isaev } 90*e0cc5187SIlya Isaev 91*e0cc5187SIlya Isaev // TODO: Look deeper into this test to see if it has the right name 92*e0cc5187SIlya Isaev // and if it actually tests some kind of regression. It is possible 93*e0cc5187SIlya Isaev // that `connect_join_via_follows` and `connect_join_via_precedes` 94*e0cc5187SIlya Isaev // functions are redundant. 95*e0cc5187SIlya Isaev 96*e0cc5187SIlya Isaev //! Test maintaining correct count of ports without input 97*e0cc5187SIlya Isaev //! \brief \ref error_guessing 98*e0cc5187SIlya Isaev TEST_CASE("Test removal of the predecessor while having none") { 99*e0cc5187SIlya Isaev using namespace multiple_predecessors; 100*e0cc5187SIlya Isaev 101*e0cc5187SIlya Isaev test(connect_join_via_follows); 102*e0cc5187SIlya Isaev test(connect_join_via_precedes); 103*e0cc5187SIlya Isaev } 104