artdaq  v3_11_00
NoOp_policy_t.cc
1 #define BOOST_TEST_MODULE NoOp_policy_t
2 #include <boost/test/unit_test.hpp>
3 
4 #include "artdaq-utilities/Plugins/MakeParameterSet.hh"
5 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
6 #include "fhiclcpp/ParameterSet.h"
7 
8 BOOST_AUTO_TEST_SUITE(NoOp_policy_t)
9 
10 BOOST_AUTO_TEST_CASE(Simple)
11 {
12  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case Simple BEGIN";
13  fhicl::ParameterSet ps = artdaq::make_pset("");
14 
15  auto noop = artdaq::makeRoutingManagerPolicy("NoOp", ps);
16 
17 
18  noop->Reset();
19  noop->AddReceiverToken(1, 1);
20  noop->AddReceiverToken(3, 1);
21  noop->AddReceiverToken(2, 1);
22  noop->AddReceiverToken(4, 1);
23  noop->AddReceiverToken(2, 1);
24  BOOST_REQUIRE_EQUAL(noop->GetReceiverCount(), 4);
25  auto secondTable = noop->GetCurrentTable();
26  BOOST_REQUIRE_EQUAL(secondTable.size(), 5);
27  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
28  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 3);
29  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
30  BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
31  BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 2);
32  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
33  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
34  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
35  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
36  BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 5);
37 
38  noop->AddReceiverToken(1, 0);
39 
40  auto thirdTable = noop->GetCurrentTable();
41  BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
42  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case Simple END";
43 }
44 
45 BOOST_AUTO_TEST_CASE(DataFlowMode)
46 {
47  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case DataFlowMode BEGIN";
48  fhicl::ParameterSet ps = artdaq::make_pset("routing_manager_mode: DataFlow");
49 
50  auto noop = artdaq::makeRoutingManagerPolicy("NoOp", ps);
51 
52 
53  noop->Reset();
54  noop->AddReceiverToken(1, 1);
55  noop->AddReceiverToken(3, 1);
56  noop->AddReceiverToken(2, 1);
57  noop->AddReceiverToken(3, 1);
58  noop->AddReceiverToken(2, 1);
59  BOOST_REQUIRE_EQUAL(noop->GetReceiverCount(), 3);
60  auto route = noop->GetRouteForSequenceID(1, 4);
61  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
62  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
63 
64  // Multiple hits for the same sequence ID are allowed, and should receive different information
65  route = noop->GetRouteForSequenceID(1, 5);
66  BOOST_REQUIRE_EQUAL(route.destination_rank, 3);
67  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
68 
69  // Except, that the same sequence ID from the same host should always get the same info
70  route = noop->GetRouteForSequenceID(1, 5);
71  BOOST_REQUIRE_EQUAL(route.destination_rank, 3);
72  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
73 
74  route = noop->GetRouteForSequenceID(2, 4);
75  BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
76  BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
77 
78  noop->AddReceiverToken(1, 1);
79  route = noop->GetRouteForSequenceID(2, 5);
80  BOOST_REQUIRE_EQUAL(route.destination_rank, 3);
81  BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
82 
83  // Out-of-order sequence IDs are allowed
84  route = noop->GetRouteForSequenceID(1, 6);
85  BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
86  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
87 
88  // Arbitrary sequence IDs are allowed
89  route = noop->GetRouteForSequenceID(10343, 4);
90  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
91  BOOST_REQUIRE_EQUAL(route.sequence_id, 10343);
92  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case DataFlowMode END";
93 }
94 
95 BOOST_AUTO_TEST_CASE(RequestBasedEventBuilding)
96 {
97  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case RequestBasedEventBuilding BEGIN";
98  fhicl::ParameterSet ps = artdaq::make_pset("routing_manager_mode: RequestBasedEventBuilding routing_cache_size: 2");
99 
100  auto noop = artdaq::makeRoutingManagerPolicy("NoOp", ps);
101 
102 
103  noop->Reset();
104  noop->AddReceiverToken(1, 1);
105  noop->AddReceiverToken(3, 1);
106  noop->AddReceiverToken(2, 1);
107  noop->AddReceiverToken(3, 1);
108  noop->AddReceiverToken(2, 1);
109  BOOST_REQUIRE_EQUAL(noop->GetReceiverCount(), 3);
110 
111  auto route = noop->GetRouteForSequenceID(1, 4);
112  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
113  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
114 
115  // Multiple hits for the same sequence ID should receive the same routing
116  route = noop->GetRouteForSequenceID(1, 5);
117  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
118  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
119 
120  // Only events which have started routing should be in the table
121  auto firstTable = noop->GetCurrentTable();
122  BOOST_REQUIRE_EQUAL(firstTable.size(), 1);
123  BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
124 
125  // Arbitrary Sequence IDs are allowed
126  route = noop->GetRouteForSequenceID(12343, 4);
127  BOOST_REQUIRE_EQUAL(route.destination_rank, 3);
128  BOOST_REQUIRE_EQUAL(route.sequence_id, 12343);
129 
130  // Out-of-order Sequence IDs are allowed
131  route = noop->GetRouteForSequenceID(4, 5);
132  BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
133  BOOST_REQUIRE_EQUAL(route.sequence_id, 4);
134 
135  // Requests that arrive late still get the same info
136  route = noop->GetRouteForSequenceID(1, 6);
137  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
138  BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
139 
140  // Check that things behave when tokens are exhausted...
141  route = noop->GetRouteForSequenceID(10, 4);
142  BOOST_REQUIRE_EQUAL(route.destination_rank, 3);
143  BOOST_REQUIRE_EQUAL(route.sequence_id, 10);
144  route = noop->GetRouteForSequenceID(11, 4);
145  BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
146  BOOST_REQUIRE_EQUAL(route.sequence_id, 11);
147 
148  route = noop->GetRouteForSequenceID(50, 4);
149  BOOST_REQUIRE_EQUAL(route.destination_rank, -1);
150 
151  noop->AddReceiverToken(1, 1);
152  route = noop->GetRouteForSequenceID(50, 4);
153  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
154  BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
155 
156  route = noop->GetRouteForSequenceID(50, 5);
157  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
158  BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
159 
160  // Routing cache is sorted by sequence ID
161  auto secondTable = noop->GetCurrentTable();
162  BOOST_REQUIRE_EQUAL(secondTable.size(), 5);
163  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 2);
164  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 4);
165  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 3);
166  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 10);
167  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
168  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 11);
169  BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 1);
170  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 50);
171  BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
172  BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 12343);
173 
174  // 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
175  BOOST_REQUIRE_EQUAL(noop->GetCacheSize(), 2);
176  auto thirdTable = noop->GetCurrentTable();
177  BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
178 
179  BOOST_REQUIRE(noop->CacheHasRoute(50));
180  BOOST_REQUIRE(!noop->CacheHasRoute(4));
181  route = noop->GetRouteForSequenceID(50, 6);
182  BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
183  BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
184 
185  TLOG(TLVL_INFO) << "NoOp_policy_t Test Case RequestBasedEventBuilding END";
186 }
187 
188 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingManagerPolicy > makeRoutingManagerPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingManagerPolicy plugin.