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