1 #define TRACE_NAME "TokenSender_t"
3 #include "artdaq/DAQrate/detail/TokenSender.hh"
5 #define BOOST_TEST_MODULE TokenSender_t
9 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
10 #include "cetlib/quiet_unit_test.hpp"
11 #include "cetlib_except/exception.h"
13 BOOST_AUTO_TEST_SUITE(TokenSender_test)
15 #define TRACE_REQUIRE_EQUAL(l, r) \
20 TLOG(TLVL_DEBUG) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...YES!"; \
24 TLOG(TLVL_ERROR) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...NO!"; \
26 BOOST_REQUIRE_EQUAL((l), (r)); \
29 BOOST_AUTO_TEST_CASE(Construct)
31 artdaq::configureMessageFacility(
"TokenSender_t",
true,
true);
32 metricMan->initialize(fhicl::ParameterSet());
33 metricMan->do_start();
34 TLOG(TLVL_INFO) <<
"Construct Test Case BEGIN";
35 fhicl::ParameterSet pset;
37 TLOG(TLVL_INFO) <<
"Construct Test Case END";
40 BOOST_AUTO_TEST_CASE(Tokens)
42 artdaq::configureMessageFacility(
"TokenSender_t",
true,
true);
43 metricMan->initialize(fhicl::ParameterSet());
44 metricMan->do_start();
45 TLOG(TLVL_INFO) <<
"Tokens Test Case BEGIN";
46 const int TOKEN_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
47 TLOG(TLVL_DEBUG) <<
"Opening token listener socket";
50 fhicl::ParameterSet token_pset;
51 token_pset.put(
"routing_token_port", TOKEN_PORT);
52 token_pset.put(
"use_routing_manager",
true);
53 fhicl::ParameterSet pset;
54 pset.put(
"routing_token_config", token_pset);
59 BOOST_REQUIRE(token_socket != -1);
60 if (token_socket == -1)
62 TLOG(TLVL_ERROR) <<
"Token listener socket was not opened successfully.";
63 BOOST_REQUIRE_EQUAL(
false,
true);
67 TLOG(TLVL_DEBUG) <<
"Accepting new connection on token_socket";
69 socklen_t arglen =
sizeof(addr);
70 auto conn_sock = accept(token_socket, reinterpret_cast<struct sockaddr*>(&addr), &arglen);
72 t.SendRoutingToken(120, 130);
78 TRACE_REQUIRE_EQUAL(buff.
header, TOKEN_MAGIC);
81 TRACE_REQUIRE_EQUAL(buff.
rank, 0);
84 t.SendRoutingToken(335, 17);
89 TRACE_REQUIRE_EQUAL(buff.
header, TOKEN_MAGIC);
92 TRACE_REQUIRE_EQUAL(buff.
rank, 13);
96 TLOG(TLVL_INFO) <<
"Tokens Test Case END";
99 BOOST_AUTO_TEST_SUITE_END()
unsigned new_slots_free
The number of slots free in the token sender (usually 1)
The TokenSender contains methods used to send data requests and Routing tokens.
The RoutingToken contains the magic bytes, the rank of the token sender, and the number of slots free...
int TCP_listen_fd(int port, int rcvbuf)
Create a TCP listening socket on the given port and INADDR_ANY, with the given receive buffer...
int rank
The rank from which the RoutingToken came.
unsigned run_number
The Run with which this token should be associated.
uint32_t header
The magic bytes that help validate the RoutingToken.