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