1 #define BOOST_TEST_MODULE RoundRobin_policy_t
2 #include <boost/test/unit_test.hpp>
4 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
8 BOOST_AUTO_TEST_SUITE(RoundRobin_policy_t)
12 fhicl::ParameterSet ps4, ps3, ps2;
13 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4]", ps4);
14 fhicl::make_ParameterSet(
"receiver_ranks: [7,8,9]", ps3);
15 fhicl::make_ParameterSet(
"receiver_ranks: [5,6]", ps2);
18 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 4);
21 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 4);
22 BOOST_REQUIRE_EQUAL(rrB->GetReceiverCount(), 4);
25 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 3);
26 BOOST_REQUIRE_EQUAL(rrB->GetReceiverCount(), 4);
35 fhicl::ParameterSet ps;
36 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4]", ps);
40 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
43 rr->AddReceiverToken(1, 1);
44 rr->AddReceiverToken(3, 1);
45 rr->AddReceiverToken(2, 1);
46 rr->AddReceiverToken(4, 1);
47 rr->AddReceiverToken(2, 1);
48 auto secondTable = rr->GetCurrentTable();
49 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
50 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
51 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
52 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
53 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
54 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
55 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
56 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
57 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
59 rr->AddReceiverToken(1, 0);
61 auto thirdTable = rr->GetCurrentTable();
62 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
64 rr->AddReceiverToken(1, 2);
65 rr->AddReceiverToken(2, 1);
66 rr->AddReceiverToken(3, 1);
67 rr->AddReceiverToken(4, 2);
68 auto fourthTable = rr->GetCurrentTable();
69 BOOST_REQUIRE_EQUAL(fourthTable.size(), 4);
70 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
72 rr->AddReceiverToken(3, 1);
73 auto fifthTable = rr->GetCurrentTable();
74 BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
75 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
80 fhicl::ParameterSet ps;
81 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4] minimum_participants: 2", ps);
85 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
88 rr->AddReceiverToken(1, 1);
89 rr->AddReceiverToken(3, 1);
90 rr->AddReceiverToken(2, 1);
91 rr->AddReceiverToken(4, 1);
92 rr->AddReceiverToken(2, 1);
93 auto secondTable = rr->GetCurrentTable();
94 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
95 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
96 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
97 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
98 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
99 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
100 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
101 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
102 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
104 rr->AddReceiverToken(1, 0);
106 auto thirdTable = rr->GetCurrentTable();
107 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
109 rr->AddReceiverToken(1, 1);
110 auto fourthTable = rr->GetCurrentTable();
111 BOOST_REQUIRE_EQUAL(fourthTable.size(), 2);
113 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
114 BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 2);
115 BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 5);
116 BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 6);
118 rr->AddReceiverToken(1, 2);
119 rr->AddReceiverToken(2, 2);
120 rr->AddReceiverToken(3, 1);
121 rr->AddReceiverToken(4, 2);
122 auto fifthTable = rr->GetCurrentTable();
123 BOOST_REQUIRE_EQUAL(fifthTable.size(), 7);
124 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
126 rr->AddReceiverToken(3, 1);
127 auto sixthTable = rr->GetCurrentTable();
128 BOOST_REQUIRE_EQUAL(sixthTable.size(), 0);
133 fhicl::ParameterSet ps;
134 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3] minimum_participants: 5", ps);
138 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 3);
141 rr->AddReceiverToken(1, 1);
142 rr->AddReceiverToken(3, 1);
143 rr->AddReceiverToken(2, 1);
144 rr->AddReceiverToken(3, 1);
145 rr->AddReceiverToken(2, 1);
146 auto secondTable = rr->GetCurrentTable();
147 BOOST_REQUIRE_EQUAL(secondTable.size(), 3);
148 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
149 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
150 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
152 rr->AddReceiverToken(1, 1);
153 auto thirdTable = rr->GetCurrentTable();
154 BOOST_REQUIRE_EQUAL(thirdTable.size(), 3);
155 BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 1);
156 BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 2);
157 BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 3);
162 fhicl::ParameterSet ps;
163 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3] minimum_participants: -5", ps);
167 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 3);
170 rr->AddReceiverToken(1, 1);
171 rr->AddReceiverToken(3, 1);
172 rr->AddReceiverToken(2, 1);
173 rr->AddReceiverToken(3, 1);
174 rr->AddReceiverToken(2, 1);
175 auto secondTable = rr->GetCurrentTable();
176 BOOST_REQUIRE_EQUAL(secondTable.size(), 5);
177 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
179 rr->AddReceiverToken(1, 1);
180 auto thirdTable = rr->GetCurrentTable();
181 BOOST_REQUIRE_EQUAL(thirdTable.size(), 1);
184 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingManagerPolicy > makeRoutingManagerPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingManagerPolicy plugin.