Line data Source code
1 : #define BOOST_TEST_MODULE CapacityTest_policy_t
2 : #include <boost/test/unit_test.hpp>
3 :
4 : #include "TRACE/tracemf.h"
5 :
6 : #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
7 : #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
8 : #include "fhiclcpp/ParameterSet.h"
9 :
10 : BOOST_AUTO_TEST_SUITE(CapacityTest_policy_t)
11 :
12 2 : BOOST_AUTO_TEST_CASE(Simple)
13 : {
14 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case Simple BEGIN";
15 2 : fhicl::ParameterSet ps = fhicl::ParameterSet::make("tokens_used_per_table_percent: 50");
16 :
17 1 : auto ct = artdaq::makeRoutingManagerPolicy("CapacityTest", ps);
18 :
19 1 : ct->AddReceiverToken(1, 10);
20 1 : ct->AddReceiverToken(2, 10);
21 1 : ct->AddReceiverToken(3, 10);
22 1 : ct->AddReceiverToken(4, 10);
23 1 : BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 4);
24 :
25 1 : auto firstTable = ct->GetCurrentTable();
26 1 : BOOST_REQUIRE_EQUAL(firstTable.size(), 20);
27 1 : BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
28 1 : BOOST_REQUIRE_EQUAL(firstTable[0].sequence_id, 1);
29 1 : BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].destination_rank, 2);
30 1 : BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].sequence_id, 20);
31 :
32 1 : ct->ResetTokensUsedSinceLastUpdate();
33 :
34 : // ct->Reset();
35 1 : ct->AddReceiverToken(1, 1);
36 1 : ct->AddReceiverToken(3, 1);
37 1 : ct->AddReceiverToken(2, 1);
38 1 : ct->AddReceiverToken(4, 1);
39 1 : ct->AddReceiverToken(2, 1);
40 1 : auto secondTable = ct->GetCurrentTable();
41 1 : BOOST_REQUIRE_EQUAL(secondTable.size(), 13);
42 1 : BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
43 1 : BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 21);
44 1 : BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
45 1 : BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 22);
46 1 : BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
47 1 : BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 23);
48 1 : BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 3);
49 1 : BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 24);
50 1 : BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
51 1 : BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 25);
52 1 : BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 3);
53 1 : BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 26);
54 1 : BOOST_REQUIRE_EQUAL(secondTable[6].destination_rank, 3);
55 1 : BOOST_REQUIRE_EQUAL(secondTable[6].sequence_id, 27);
56 1 : BOOST_REQUIRE_EQUAL(secondTable[7].destination_rank, 3);
57 1 : BOOST_REQUIRE_EQUAL(secondTable[7].sequence_id, 28);
58 1 : BOOST_REQUIRE_EQUAL(secondTable[8].destination_rank, 3);
59 1 : BOOST_REQUIRE_EQUAL(secondTable[8].sequence_id, 29);
60 1 : BOOST_REQUIRE_EQUAL(secondTable[9].destination_rank, 3);
61 1 : BOOST_REQUIRE_EQUAL(secondTable[9].sequence_id, 30);
62 1 : BOOST_REQUIRE_EQUAL(secondTable[10].destination_rank, 3);
63 1 : BOOST_REQUIRE_EQUAL(secondTable[10].sequence_id, 31);
64 1 : BOOST_REQUIRE_EQUAL(secondTable[11].destination_rank, 3);
65 1 : BOOST_REQUIRE_EQUAL(secondTable[11].sequence_id, 32);
66 1 : BOOST_REQUIRE_EQUAL(secondTable[12].destination_rank, 3);
67 1 : BOOST_REQUIRE_EQUAL(secondTable[12].sequence_id, 33);
68 :
69 1 : ct->ResetTokensUsedSinceLastUpdate();
70 : // ct->Reset();
71 1 : ct->AddReceiverToken(1, 0);
72 1 : auto thirdTable = ct->GetCurrentTable();
73 1 : BOOST_REQUIRE_EQUAL(thirdTable.size(), 6);
74 1 : BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 3);
75 1 : BOOST_REQUIRE_EQUAL(thirdTable[0].sequence_id, 34);
76 1 : BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 4);
77 1 : BOOST_REQUIRE_EQUAL(thirdTable[1].sequence_id, 35);
78 1 : BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 4);
79 1 : BOOST_REQUIRE_EQUAL(thirdTable[2].sequence_id, 36);
80 1 : BOOST_REQUIRE_EQUAL(thirdTable[3].destination_rank, 4);
81 1 : BOOST_REQUIRE_EQUAL(thirdTable[3].sequence_id, 37);
82 1 : BOOST_REQUIRE_EQUAL(thirdTable[4].destination_rank, 4);
83 1 : BOOST_REQUIRE_EQUAL(thirdTable[4].sequence_id, 38);
84 1 : BOOST_REQUIRE_EQUAL(thirdTable[5].destination_rank, 4);
85 1 : BOOST_REQUIRE_EQUAL(thirdTable[5].sequence_id, 39);
86 :
87 1 : ct->AddReceiverToken(1, 2);
88 1 : ct->AddReceiverToken(2, 1);
89 1 : ct->AddReceiverToken(3, 1);
90 1 : ct->AddReceiverToken(4, 2);
91 1 : ct->ResetTokensUsedSinceLastUpdate();
92 1 : auto fourthTable = ct->GetCurrentTable();
93 1 : BOOST_REQUIRE_EQUAL(fourthTable.size(), 6);
94 1 : BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
95 1 : BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 40);
96 1 : BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 1);
97 1 : BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 41);
98 1 : BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
99 1 : BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 42);
100 1 : BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 3);
101 1 : BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 43);
102 1 : BOOST_REQUIRE_EQUAL(fourthTable[4].destination_rank, 4);
103 1 : BOOST_REQUIRE_EQUAL(fourthTable[4].sequence_id, 44);
104 1 : BOOST_REQUIRE_EQUAL(fourthTable[5].destination_rank, 4);
105 1 : BOOST_REQUIRE_EQUAL(fourthTable[5].sequence_id, 45);
106 :
107 1 : ct->AddReceiverToken(3, 1);
108 1 : ct->ResetTokensUsedSinceLastUpdate();
109 1 : auto fifthTable = ct->GetCurrentTable();
110 1 : BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
111 1 : BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 3);
112 1 : BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 46);
113 1 : BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 4);
114 1 : BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 47);
115 1 : BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 4);
116 1 : BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 48);
117 1 : BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
118 1 : BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 49);
119 :
120 1 : ct->Reset();
121 1 : ct->AddReceiverToken(1, 2);
122 1 : ct->ResetTokensUsedSinceLastUpdate();
123 1 : auto sixthTable = ct->GetCurrentTable();
124 1 : BOOST_REQUIRE_EQUAL(sixthTable.size(), 1);
125 1 : BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
126 1 : BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 1);
127 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case Simple END";
128 1 : }
129 :
130 2 : BOOST_AUTO_TEST_CASE(DataFlowMode)
131 : {
132 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case DataFlowMode BEGIN";
133 2 : fhicl::ParameterSet ps = fhicl::ParameterSet::make("routing_manager_mode: DataFlow");
134 :
135 1 : auto ct = artdaq::makeRoutingManagerPolicy("CapacityTest", ps);
136 :
137 1 : ct->Reset();
138 1 : ct->AddReceiverToken(1, 3);
139 1 : ct->AddReceiverToken(2, 3);
140 1 : BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
141 1 : auto route = ct->GetRouteForSequenceID(1, 4);
142 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
143 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
144 :
145 : // Multiple hits for the same sequence ID are allowed, and should receive different information
146 1 : route = ct->GetRouteForSequenceID(1, 5);
147 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
148 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
149 :
150 : // Except, that the same sequence ID from the same host should always get the same info
151 1 : route = ct->GetRouteForSequenceID(1, 5);
152 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
153 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
154 :
155 1 : route = ct->GetRouteForSequenceID(2, 4);
156 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
157 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
158 :
159 1 : route = ct->GetRouteForSequenceID(2, 5);
160 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
161 :
162 1 : ct->AddReceiverToken(1, 1);
163 1 : route = ct->GetRouteForSequenceID(2, 5);
164 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
165 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
166 :
167 : // Out-of-order sequence IDs are allowed
168 1 : route = ct->GetRouteForSequenceID(1, 6);
169 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
170 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
171 :
172 : // Arbitrary sequence IDs are allowed
173 1 : route = ct->GetRouteForSequenceID(10343, 4);
174 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
175 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 10343);
176 :
177 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case DataFlowMode END";
178 1 : }
179 :
180 2 : BOOST_AUTO_TEST_CASE(RequestBasedEventBuilding)
181 : {
182 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case RequestBasedEventBuilding BEGIN";
183 2 : fhicl::ParameterSet ps = fhicl::ParameterSet::make("routing_manager_mode: RequestBasedEventBuilding routing_cache_size: 2");
184 :
185 1 : auto ct = artdaq::makeRoutingManagerPolicy("CapacityTest", ps);
186 :
187 1 : ct->Reset();
188 1 : ct->AddReceiverToken(1, 3);
189 1 : ct->AddReceiverToken(2, 3);
190 1 : BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
191 :
192 1 : auto route = ct->GetRouteForSequenceID(1, 4);
193 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
194 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
195 :
196 : // Multiple hits for the same sequence ID should receive the same routing
197 1 : route = ct->GetRouteForSequenceID(1, 5);
198 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
199 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
200 :
201 : // Only events which have started routing should be in the table
202 1 : auto firstTable = ct->GetCurrentTable();
203 1 : BOOST_REQUIRE_EQUAL(firstTable.size(), 1);
204 1 : BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
205 :
206 : // Arbitrary Sequence IDs are allowed
207 1 : route = ct->GetRouteForSequenceID(12343, 4);
208 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
209 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 12343);
210 :
211 : // Out-of-order Sequence IDs are allowed
212 1 : route = ct->GetRouteForSequenceID(4, 5);
213 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
214 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 4);
215 :
216 : // Requests that arrive late still get the same info
217 1 : route = ct->GetRouteForSequenceID(1, 6);
218 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
219 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
220 :
221 : // Check that things behave when tokens are exhausted...
222 1 : route = ct->GetRouteForSequenceID(10, 4);
223 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
224 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 10);
225 1 : route = ct->GetRouteForSequenceID(11, 4);
226 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
227 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 11);
228 1 : route = ct->GetRouteForSequenceID(12, 4);
229 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
230 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 12);
231 :
232 1 : route = ct->GetRouteForSequenceID(50, 4);
233 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, -1);
234 :
235 1 : ct->AddReceiverToken(1, 1);
236 1 : route = ct->GetRouteForSequenceID(50, 4);
237 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
238 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
239 :
240 1 : route = ct->GetRouteForSequenceID(50, 5);
241 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
242 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
243 :
244 : // Routing cache is sorted by sequence ID
245 1 : auto secondTable = ct->GetCurrentTable();
246 1 : BOOST_REQUIRE_EQUAL(secondTable.size(), 6);
247 1 : BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
248 1 : BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 4);
249 1 : BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
250 1 : BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 10);
251 1 : BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
252 1 : BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 11);
253 1 : BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 2);
254 1 : BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 12);
255 1 : BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 1);
256 1 : BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 50);
257 1 : BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 1);
258 1 : BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 12343);
259 :
260 : // Since the routing cache has been set to 2, only the highest two events routed are here, as the cache is checked when generating tables
261 1 : BOOST_REQUIRE_EQUAL(ct->GetCacheSize(), 2);
262 1 : auto thirdTable = ct->GetCurrentTable();
263 1 : BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
264 :
265 1 : BOOST_REQUIRE(ct->CacheHasRoute(50));
266 1 : BOOST_REQUIRE(!ct->CacheHasRoute(4));
267 1 : route = ct->GetRouteForSequenceID(50, 6);
268 1 : BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
269 1 : BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
270 :
271 3 : TLOG(TLVL_INFO) << "CapacityTest_policy_t Test Case RequestBasedEventBuilding END";
272 1 : }
273 :
274 : BOOST_AUTO_TEST_SUITE_END()
|