artdaq_demo  v3_00_01
NthEvent_policy_t.cc
1 #define BOOST_TEST_MODULE ( NthEvent_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(NthEvent_policy_t)
10 
11 BOOST_AUTO_TEST_CASE(Simple)
12 {
13  fhicl::ParameterSet ps;
14  fhicl::make_ParameterSet("receiver_ranks: [1,2,3,4] nth_event: 5 target_receiver: 3", ps);
15 
16  auto nth = artdaq::makeRoutingMasterPolicy("NthEvent", ps);
17 
18  BOOST_REQUIRE_EQUAL(nth->GetReceiverCount(), 4);
19 
20  // Extra token, and out of sequence
21  nth->Reset();
22  nth->AddReceiverToken(1, 1);
23  nth->AddReceiverToken(3, 1);
24  nth->AddReceiverToken(2, 1);
25  nth->AddReceiverToken(4, 1);
26  nth->AddReceiverToken(2, 1);
27  auto secondTable = nth->GetCurrentTable();
28  BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
29  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 3);
30  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 0);
31  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 1);
32  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 1);
33  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
34  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 2);
35  BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
36  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 3);
37 
38  // Adding empty number of tokens
39  nth->AddReceiverToken(1, 0);
40  auto thirdTable = nth->GetCurrentTable();
41  BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
42 
43  // Catching up to the extra token
44  nth->AddReceiverToken(1, 2);
45  nth->AddReceiverToken(3, 2);
46  nth->AddReceiverToken(4, 2);
47  auto fourthTable = nth->GetCurrentTable();
48  BOOST_REQUIRE_EQUAL(fourthTable.size(), 4);
49  BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
50  BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 4);
51  BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 3);
52  BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 5);
53  BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
54  BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 6);
55  BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 4);
56  BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 7);
57 
58  // Catching up to the missing token
59  nth->AddReceiverToken(2, 1);
60  auto fifthTable = nth->GetCurrentTable();
61  BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
62  BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
63  BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 8);
64  BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 2);
65  BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 9);
66  BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 3);
67  BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 10);
68  BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
69  BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 11);
70 
71  // Lots of "normal" tokens
72  nth->AddReceiverToken(1, 10);
73  nth->AddReceiverToken(2, 10);
74  nth->AddReceiverToken(4, 10);
75  auto sixthTable = nth->GetCurrentTable();
76  BOOST_REQUIRE_EQUAL(sixthTable.size(), 3);
77  BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
78  BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 12);
79  BOOST_REQUIRE_EQUAL(sixthTable[1].destination_rank, 2);
80  BOOST_REQUIRE_EQUAL(sixthTable[1].sequence_id, 13);
81  BOOST_REQUIRE_EQUAL(sixthTable[2].destination_rank, 4);
82  BOOST_REQUIRE_EQUAL(sixthTable[2].sequence_id, 14);
83 
84  // Still no "nth" token
85  auto blankTable = nth->GetCurrentTable();
86  BOOST_REQUIRE_EQUAL(blankTable.size(), 0);
87 
88  // Some "nth" tokens
89  nth->AddReceiverToken(3, 3);
90  auto seventhTable = nth->GetCurrentTable();
91  BOOST_REQUIRE_EQUAL(seventhTable.size(), 15);
92  BOOST_REQUIRE_EQUAL(seventhTable[0].destination_rank, 3);
93  BOOST_REQUIRE_EQUAL(seventhTable[0].sequence_id, 15);
94  BOOST_REQUIRE_EQUAL(seventhTable[1].destination_rank, 1);
95  BOOST_REQUIRE_EQUAL(seventhTable[1].sequence_id, 16);
96  BOOST_REQUIRE_EQUAL(seventhTable[2].destination_rank, 2);
97  BOOST_REQUIRE_EQUAL(seventhTable[2].sequence_id, 17);
98  BOOST_REQUIRE_EQUAL(seventhTable[3].destination_rank, 4);
99  BOOST_REQUIRE_EQUAL(seventhTable[3].sequence_id, 18);
100  BOOST_REQUIRE_EQUAL(seventhTable[4].destination_rank, 1);
101  BOOST_REQUIRE_EQUAL(seventhTable[4].sequence_id, 19);
102  BOOST_REQUIRE_EQUAL(seventhTable[5].destination_rank, 3);
103  BOOST_REQUIRE_EQUAL(seventhTable[5].sequence_id, 20);
104  BOOST_REQUIRE_EQUAL(seventhTable[6].destination_rank, 2);
105  BOOST_REQUIRE_EQUAL(seventhTable[6].sequence_id, 21);
106  BOOST_REQUIRE_EQUAL(seventhTable[7].destination_rank, 4);
107  BOOST_REQUIRE_EQUAL(seventhTable[7].sequence_id, 22);
108  BOOST_REQUIRE_EQUAL(seventhTable[8].destination_rank, 1);
109  BOOST_REQUIRE_EQUAL(seventhTable[8].sequence_id, 23);
110  BOOST_REQUIRE_EQUAL(seventhTable[9].destination_rank, 2);
111  BOOST_REQUIRE_EQUAL(seventhTable[9].sequence_id, 24);
112  BOOST_REQUIRE_EQUAL(seventhTable[10].destination_rank, 3);
113  BOOST_REQUIRE_EQUAL(seventhTable[10].sequence_id, 25);
114  BOOST_REQUIRE_EQUAL(seventhTable[11].destination_rank, 4);
115  BOOST_REQUIRE_EQUAL(seventhTable[11].sequence_id, 26);
116  BOOST_REQUIRE_EQUAL(seventhTable[12].destination_rank, 1);
117  BOOST_REQUIRE_EQUAL(seventhTable[12].sequence_id, 27);
118  BOOST_REQUIRE_EQUAL(seventhTable[13].destination_rank, 2);
119  BOOST_REQUIRE_EQUAL(seventhTable[13].sequence_id, 28);
120  BOOST_REQUIRE_EQUAL(seventhTable[14].destination_rank, 4);
121  BOOST_REQUIRE_EQUAL(seventhTable[14].sequence_id, 29);
122 
123 
124 }
125 
126 BOOST_AUTO_TEST_SUITE_END()