1 #define BOOST_TEST_MODULE RoundRobin_policy_t
2 #include <boost/test/auto_unit_test.hpp>
4 #include "artdaq/RoutingPolicies/makeRoutingMasterPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
9 BOOST_AUTO_TEST_SUITE(RoundRobin_policy_t)
11 BOOST_AUTO_TEST_CASE(VerifyRMPSharedPtr)
13 fhicl::ParameterSet ps4, ps3, ps2;
14 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4]", ps4);
15 fhicl::make_ParameterSet(
"receiver_ranks: [7,8,9]", ps3);
16 fhicl::make_ParameterSet(
"receiver_ranks: [5,6]", ps2);
19 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 4);
22 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 4);
23 BOOST_REQUIRE_EQUAL(rrB->GetReceiverCount(), 4);
26 BOOST_REQUIRE_EQUAL(rrA->GetReceiverCount(), 3);
27 BOOST_REQUIRE_EQUAL(rrB->GetReceiverCount(), 4);
34 BOOST_AUTO_TEST_CASE(Simple)
36 fhicl::ParameterSet ps;
37 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4]", ps);
41 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
44 rr->AddReceiverToken(1, 1);
45 rr->AddReceiverToken(3, 1);
46 rr->AddReceiverToken(2, 1);
47 rr->AddReceiverToken(4, 1);
48 rr->AddReceiverToken(2, 1);
49 auto secondTable = rr->GetCurrentTable();
50 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
51 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
52 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
53 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
54 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
55 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
56 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
57 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
58 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
60 rr->AddReceiverToken(1, 0);
62 auto thirdTable = rr->GetCurrentTable();
63 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
65 rr->AddReceiverToken(1, 2);
66 rr->AddReceiverToken(2, 1);
67 rr->AddReceiverToken(3, 1);
68 rr->AddReceiverToken(4, 2);
69 auto fourthTable = rr->GetCurrentTable();
70 BOOST_REQUIRE_EQUAL(fourthTable.size(), 4);
71 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
73 rr->AddReceiverToken(3, 1);
74 auto fifthTable = rr->GetCurrentTable();
75 BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
76 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
80 BOOST_AUTO_TEST_CASE(MinimumParticipants)
82 fhicl::ParameterSet ps;
83 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4] minimum_participants: 2", ps);
87 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
90 rr->AddReceiverToken(1, 1);
91 rr->AddReceiverToken(3, 1);
92 rr->AddReceiverToken(2, 1);
93 rr->AddReceiverToken(4, 1);
94 rr->AddReceiverToken(2, 1);
95 auto secondTable = rr->GetCurrentTable();
96 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
97 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
98 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
99 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
100 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
101 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
102 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
103 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
104 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
106 rr->AddReceiverToken(1, 0);
108 auto thirdTable = rr->GetCurrentTable();
109 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
112 rr->AddReceiverToken(1, 1);
113 auto fourthTable = rr->GetCurrentTable();
114 BOOST_REQUIRE_EQUAL(fourthTable.size(), 2);
116 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
117 BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 2);
118 BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 5);
119 BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 6);
121 rr->AddReceiverToken(1, 2);
122 rr->AddReceiverToken(2, 2);
123 rr->AddReceiverToken(3, 1);
124 rr->AddReceiverToken(4, 2);
125 auto fifthTable = rr->GetCurrentTable();
126 BOOST_REQUIRE_EQUAL(fifthTable.size(), 7);
127 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
129 rr->AddReceiverToken(3, 1);
130 auto sixthTable = rr->GetCurrentTable();
131 BOOST_REQUIRE_EQUAL(sixthTable.size(), 0);
135 BOOST_AUTO_TEST_CASE(LargeMinimumParticipants)
137 fhicl::ParameterSet ps;
138 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3] minimum_participants: 5", ps);
142 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 3);
145 rr->AddReceiverToken(1, 1);
146 rr->AddReceiverToken(3, 1);
147 rr->AddReceiverToken(2, 1);
148 rr->AddReceiverToken(3, 1);
149 rr->AddReceiverToken(2, 1);
150 auto secondTable = rr->GetCurrentTable();
151 BOOST_REQUIRE_EQUAL(secondTable.size(), 3);
152 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
153 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
154 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
156 rr->AddReceiverToken(1, 1);
157 auto thirdTable = rr->GetCurrentTable();
158 BOOST_REQUIRE_EQUAL(thirdTable.size(), 3);
159 BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 1);
160 BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 2);
161 BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 3);
164 BOOST_AUTO_TEST_CASE(ManyMissingParticipants)
166 fhicl::ParameterSet ps;
167 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3] minimum_participants: -5", ps);
171 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 3);
174 rr->AddReceiverToken(1, 1);
175 rr->AddReceiverToken(3, 1);
176 rr->AddReceiverToken(2, 1);
177 rr->AddReceiverToken(3, 1);
178 rr->AddReceiverToken(2, 1);
179 auto secondTable = rr->GetCurrentTable();
180 BOOST_REQUIRE_EQUAL(secondTable.size(), 5);
181 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
183 rr->AddReceiverToken(1, 1);
184 auto thirdTable = rr->GetCurrentTable();
185 BOOST_REQUIRE_EQUAL(thirdTable.size(), 1);
188 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingMasterPolicy > makeRoutingMasterPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingMasterPolicy plugin.