artdaq  v3_07_02
CapacityTest_policy_t.cc
1 #define BOOST_TEST_MODULE CapacityTest_policy_t
2 #include <boost/test/auto_unit_test.hpp>
3 
4 #include "artdaq/RoutingPolicies/makeRoutingMasterPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
7 
8 BOOST_AUTO_TEST_SUITE(CapacityTest_policy_t)
9 
10 BOOST_AUTO_TEST_CASE(Simple)
11 {
12  fhicl::ParameterSet ps;
13  fhicl::make_ParameterSet("receiver_ranks: [1,2,3,4] tokens_used_per_table_percent: 50", ps);
14 
15  auto ct = artdaq::makeRoutingMasterPolicy("CapacityTest", ps);
16 
17  BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 4);
18 
19  ct->AddReceiverToken(1, 10);
20  ct->AddReceiverToken(2, 10);
21  ct->AddReceiverToken(3, 10);
22  ct->AddReceiverToken(4, 10);
23  auto firstTable = ct->GetCurrentTable();
24  BOOST_REQUIRE_EQUAL(firstTable.size(), 20);
25  BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
26  BOOST_REQUIRE_EQUAL(firstTable[0].sequence_id, 1);
27  BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].destination_rank, 2);
28  BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].sequence_id, 20);
29 
30  //ct->Reset();
31  ct->AddReceiverToken(1, 1);
32  ct->AddReceiverToken(3, 1);
33  ct->AddReceiverToken(2, 1);
34  ct->AddReceiverToken(4, 1);
35  ct->AddReceiverToken(2, 1);
36  auto secondTable = ct->GetCurrentTable();
37  BOOST_REQUIRE_EQUAL(secondTable.size(), 13);
38  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
39  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 21);
40  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
41  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 22);
42  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
43  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 23);
44  BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 3);
45  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 24);
46  BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
47  BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 25);
48  BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 3);
49  BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 26);
50  BOOST_REQUIRE_EQUAL(secondTable[6].destination_rank, 3);
51  BOOST_REQUIRE_EQUAL(secondTable[6].sequence_id, 27);
52  BOOST_REQUIRE_EQUAL(secondTable[7].destination_rank, 3);
53  BOOST_REQUIRE_EQUAL(secondTable[7].sequence_id, 28);
54  BOOST_REQUIRE_EQUAL(secondTable[8].destination_rank, 3);
55  BOOST_REQUIRE_EQUAL(secondTable[8].sequence_id, 29);
56  BOOST_REQUIRE_EQUAL(secondTable[9].destination_rank, 3);
57  BOOST_REQUIRE_EQUAL(secondTable[9].sequence_id, 30);
58  BOOST_REQUIRE_EQUAL(secondTable[10].destination_rank, 3);
59  BOOST_REQUIRE_EQUAL(secondTable[10].sequence_id, 31);
60  BOOST_REQUIRE_EQUAL(secondTable[11].destination_rank, 3);
61  BOOST_REQUIRE_EQUAL(secondTable[11].sequence_id, 32);
62  BOOST_REQUIRE_EQUAL(secondTable[12].destination_rank, 3);
63  BOOST_REQUIRE_EQUAL(secondTable[12].sequence_id, 33);
64 
65  //ct->Reset();
66  ct->AddReceiverToken(1, 0);
67  auto thirdTable = ct->GetCurrentTable();
68  BOOST_REQUIRE_EQUAL(thirdTable.size(), 6);
69  BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 3);
70  BOOST_REQUIRE_EQUAL(thirdTable[0].sequence_id, 34);
71  BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 4);
72  BOOST_REQUIRE_EQUAL(thirdTable[1].sequence_id, 35);
73  BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 4);
74  BOOST_REQUIRE_EQUAL(thirdTable[2].sequence_id, 36);
75  BOOST_REQUIRE_EQUAL(thirdTable[3].destination_rank, 4);
76  BOOST_REQUIRE_EQUAL(thirdTable[3].sequence_id, 37);
77  BOOST_REQUIRE_EQUAL(thirdTable[4].destination_rank, 4);
78  BOOST_REQUIRE_EQUAL(thirdTable[4].sequence_id, 38);
79  BOOST_REQUIRE_EQUAL(thirdTable[5].destination_rank, 4);
80  BOOST_REQUIRE_EQUAL(thirdTable[5].sequence_id, 39);
81 
82  ct->AddReceiverToken(1, 2);
83  ct->AddReceiverToken(2, 1);
84  ct->AddReceiverToken(3, 1);
85  ct->AddReceiverToken(4, 2);
86  auto fourthTable = ct->GetCurrentTable();
87  BOOST_REQUIRE_EQUAL(fourthTable.size(), 6);
88  BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
89  BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 40);
90  BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 1);
91  BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 41);
92  BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
93  BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 42);
94  BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 3);
95  BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 43);
96  BOOST_REQUIRE_EQUAL(fourthTable[4].destination_rank, 4);
97  BOOST_REQUIRE_EQUAL(fourthTable[4].sequence_id, 44);
98  BOOST_REQUIRE_EQUAL(fourthTable[5].destination_rank, 4);
99  BOOST_REQUIRE_EQUAL(fourthTable[5].sequence_id, 45);
100 
101  ct->AddReceiverToken(3, 1);
102  auto fifthTable = ct->GetCurrentTable();
103  BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
104  BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 3);
105  BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 46);
106  BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 4);
107  BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 47);
108  BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 4);
109  BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 48);
110  BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
111  BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 49);
112 
113  ct->Reset();
114  ct->AddReceiverToken(1, 2);
115  auto sixthTable = ct->GetCurrentTable();
116  BOOST_REQUIRE_EQUAL(sixthTable.size(), 1);
117  BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
118  BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 1);
119 }
120 
121 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingMasterPolicy > makeRoutingMasterPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingMasterPolicy plugin.