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