1 #define BOOST_TEST_MODULE CapacityTest_policy_t
2 #include <boost/test/unit_test.hpp>
4 #include "TRACE/tracemf.h"
6 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
7 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
8 #include "fhiclcpp/ParameterSet.h"
10 BOOST_AUTO_TEST_SUITE(CapacityTest_policy_t)
14 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case Simple BEGIN";
15 fhicl::ParameterSet ps = fhicl::ParameterSet::make(
"tokens_used_per_table_percent: 50");
19 ct->AddReceiverToken(1, 10);
20 ct->AddReceiverToken(2, 10);
21 ct->AddReceiverToken(3, 10);
22 ct->AddReceiverToken(4, 10);
23 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 4);
25 auto firstTable = ct->GetCurrentTable();
26 BOOST_REQUIRE_EQUAL(firstTable.size(), 20);
27 BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
28 BOOST_REQUIRE_EQUAL(firstTable[0].sequence_id, 1);
29 BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].destination_rank, 2);
30 BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].sequence_id, 20);
32 ct->ResetTokensUsedSinceLastUpdate();
35 ct->AddReceiverToken(1, 1);
36 ct->AddReceiverToken(3, 1);
37 ct->AddReceiverToken(2, 1);
38 ct->AddReceiverToken(4, 1);
39 ct->AddReceiverToken(2, 1);
40 auto secondTable = ct->GetCurrentTable();
41 BOOST_REQUIRE_EQUAL(secondTable.size(), 13);
42 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
43 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 21);
44 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
45 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 22);
46 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
47 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 23);
48 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 3);
49 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 24);
50 BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
51 BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 25);
52 BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 3);
53 BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 26);
54 BOOST_REQUIRE_EQUAL(secondTable[6].destination_rank, 3);
55 BOOST_REQUIRE_EQUAL(secondTable[6].sequence_id, 27);
56 BOOST_REQUIRE_EQUAL(secondTable[7].destination_rank, 3);
57 BOOST_REQUIRE_EQUAL(secondTable[7].sequence_id, 28);
58 BOOST_REQUIRE_EQUAL(secondTable[8].destination_rank, 3);
59 BOOST_REQUIRE_EQUAL(secondTable[8].sequence_id, 29);
60 BOOST_REQUIRE_EQUAL(secondTable[9].destination_rank, 3);
61 BOOST_REQUIRE_EQUAL(secondTable[9].sequence_id, 30);
62 BOOST_REQUIRE_EQUAL(secondTable[10].destination_rank, 3);
63 BOOST_REQUIRE_EQUAL(secondTable[10].sequence_id, 31);
64 BOOST_REQUIRE_EQUAL(secondTable[11].destination_rank, 3);
65 BOOST_REQUIRE_EQUAL(secondTable[11].sequence_id, 32);
66 BOOST_REQUIRE_EQUAL(secondTable[12].destination_rank, 3);
67 BOOST_REQUIRE_EQUAL(secondTable[12].sequence_id, 33);
69 ct->ResetTokensUsedSinceLastUpdate();
71 ct->AddReceiverToken(1, 0);
72 auto thirdTable = ct->GetCurrentTable();
73 BOOST_REQUIRE_EQUAL(thirdTable.size(), 6);
74 BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 3);
75 BOOST_REQUIRE_EQUAL(thirdTable[0].sequence_id, 34);
76 BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 4);
77 BOOST_REQUIRE_EQUAL(thirdTable[1].sequence_id, 35);
78 BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 4);
79 BOOST_REQUIRE_EQUAL(thirdTable[2].sequence_id, 36);
80 BOOST_REQUIRE_EQUAL(thirdTable[3].destination_rank, 4);
81 BOOST_REQUIRE_EQUAL(thirdTable[3].sequence_id, 37);
82 BOOST_REQUIRE_EQUAL(thirdTable[4].destination_rank, 4);
83 BOOST_REQUIRE_EQUAL(thirdTable[4].sequence_id, 38);
84 BOOST_REQUIRE_EQUAL(thirdTable[5].destination_rank, 4);
85 BOOST_REQUIRE_EQUAL(thirdTable[5].sequence_id, 39);
87 ct->AddReceiverToken(1, 2);
88 ct->AddReceiverToken(2, 1);
89 ct->AddReceiverToken(3, 1);
90 ct->AddReceiverToken(4, 2);
91 ct->ResetTokensUsedSinceLastUpdate();
92 auto fourthTable = ct->GetCurrentTable();
93 BOOST_REQUIRE_EQUAL(fourthTable.size(), 6);
94 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
95 BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 40);
96 BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 1);
97 BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 41);
98 BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
99 BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 42);
100 BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 3);
101 BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 43);
102 BOOST_REQUIRE_EQUAL(fourthTable[4].destination_rank, 4);
103 BOOST_REQUIRE_EQUAL(fourthTable[4].sequence_id, 44);
104 BOOST_REQUIRE_EQUAL(fourthTable[5].destination_rank, 4);
105 BOOST_REQUIRE_EQUAL(fourthTable[5].sequence_id, 45);
107 ct->AddReceiverToken(3, 1);
108 ct->ResetTokensUsedSinceLastUpdate();
109 auto fifthTable = ct->GetCurrentTable();
110 BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
111 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 3);
112 BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 46);
113 BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 4);
114 BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 47);
115 BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 4);
116 BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 48);
117 BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
118 BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 49);
121 ct->AddReceiverToken(1, 2);
122 ct->ResetTokensUsedSinceLastUpdate();
123 auto sixthTable = ct->GetCurrentTable();
124 BOOST_REQUIRE_EQUAL(sixthTable.size(), 1);
125 BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
126 BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 1);
127 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case Simple END";
132 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case DataFlowMode BEGIN";
133 fhicl::ParameterSet ps = fhicl::ParameterSet::make(
"routing_manager_mode: DataFlow");
138 ct->AddReceiverToken(1, 3);
139 ct->AddReceiverToken(2, 3);
140 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
141 auto route = ct->GetRouteForSequenceID(1, 4);
142 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
143 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
146 route = ct->GetRouteForSequenceID(1, 5);
147 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
148 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
151 route = ct->GetRouteForSequenceID(1, 5);
152 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
153 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
155 route = ct->GetRouteForSequenceID(2, 4);
156 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
157 BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
159 route = ct->GetRouteForSequenceID(2, 5);
160 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
162 ct->AddReceiverToken(1, 1);
163 route = ct->GetRouteForSequenceID(2, 5);
164 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
165 BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
168 route = ct->GetRouteForSequenceID(1, 6);
169 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
170 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
173 route = ct->GetRouteForSequenceID(10343, 4);
174 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
175 BOOST_REQUIRE_EQUAL(route.sequence_id, 10343);
177 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case DataFlowMode END";
182 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case RequestBasedEventBuilding BEGIN";
183 fhicl::ParameterSet ps = fhicl::ParameterSet::make(
"routing_manager_mode: RequestBasedEventBuilding routing_cache_size: 2");
188 ct->AddReceiverToken(1, 3);
189 ct->AddReceiverToken(2, 3);
190 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
192 auto route = ct->GetRouteForSequenceID(1, 4);
193 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
194 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
197 route = ct->GetRouteForSequenceID(1, 5);
198 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
199 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
202 auto firstTable = ct->GetCurrentTable();
203 BOOST_REQUIRE_EQUAL(firstTable.size(), 1);
204 BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
207 route = ct->GetRouteForSequenceID(12343, 4);
208 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
209 BOOST_REQUIRE_EQUAL(route.sequence_id, 12343);
212 route = ct->GetRouteForSequenceID(4, 5);
213 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
214 BOOST_REQUIRE_EQUAL(route.sequence_id, 4);
217 route = ct->GetRouteForSequenceID(1, 6);
218 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
219 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
222 route = ct->GetRouteForSequenceID(10, 4);
223 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
224 BOOST_REQUIRE_EQUAL(route.sequence_id, 10);
225 route = ct->GetRouteForSequenceID(11, 4);
226 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
227 BOOST_REQUIRE_EQUAL(route.sequence_id, 11);
228 route = ct->GetRouteForSequenceID(12, 4);
229 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
230 BOOST_REQUIRE_EQUAL(route.sequence_id, 12);
232 route = ct->GetRouteForSequenceID(50, 4);
233 BOOST_REQUIRE_EQUAL(route.destination_rank, -1);
235 ct->AddReceiverToken(1, 1);
236 route = ct->GetRouteForSequenceID(50, 4);
237 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
238 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
240 route = ct->GetRouteForSequenceID(50, 5);
241 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
242 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
245 auto secondTable = ct->GetCurrentTable();
246 BOOST_REQUIRE_EQUAL(secondTable.size(), 6);
247 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
248 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 4);
249 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
250 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 10);
251 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
252 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 11);
253 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 2);
254 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 12);
255 BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 1);
256 BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 50);
257 BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 1);
258 BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 12343);
261 BOOST_REQUIRE_EQUAL(ct->GetCacheSize(), 2);
262 auto thirdTable = ct->GetCurrentTable();
263 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
265 BOOST_REQUIRE(ct->CacheHasRoute(50));
266 BOOST_REQUIRE(!ct->CacheHasRoute(4));
267 route = ct->GetRouteForSequenceID(50, 6);
268 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
269 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
271 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case RequestBasedEventBuilding END";
274 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingManagerPolicy > makeRoutingManagerPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingManagerPolicy plugin.