artdaq_core  v3_06_11
configureMessageFacility_t.cc
1 #include "artdaq-core/Utilities/ExceptionHandler.hh"
2 #include "artdaq-core/Utilities/configureMessageFacility.hh"
3 
4 #define BOOST_TEST_MODULE configureMessageFacility_t
5 #include <fhiclcpp/make_ParameterSet.h>
6 #include <boost/filesystem.hpp>
7 #include "cetlib/quiet_unit_test.hpp"
8 #include "cetlib_except/exception.h"
9 
10 #define TRACE_NAME "configureMessageFacility_t"
11 #include "tracemf.h"
12 
13 BOOST_AUTO_TEST_SUITE(configureMessageFacility_test)
14 
15 BOOST_AUTO_TEST_CASE(configureTRACETest)
16 {
17  fhicl::ParameterSet pset;
18  pset.put("TRACE_MODE", "3");
19  fhicl::ParameterSet namlvlset;
20  namlvlset.put<std::vector<uint64_t>>("ConfigureMessageFacility_t", {0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0});
21  pset.put("TRACE_NAMLVLSET", namlvlset);
23 }
24 
25 BOOST_AUTO_TEST_CASE(generateMessageFacilityConfigurationTest)
26 {
27  auto str = artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
28  std::string badDir = "/this/directory/doesn't/exist";
29  setenv("ARTDAQ_LOG_TIMESTAMPS_TO_CONSOLE", "0", 1);
30  setenv("ARTDAQ_LOG_ROOT", badDir.c_str(), 1);
31  BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "ConfigureMessageFacility"; });
32  setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
33 
34  setenv("ARTDAQ_LOG_FHICL", "/this/file/doesn't/exist.fcl", 1);
35  BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "configureMessageFacility"; });
36  unsetenv("ARTDAQ_LOG_FHICL");
37 
38  artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
39 
40  boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
41 }
42 
43 BOOST_AUTO_TEST_CASE(configureMessageFacilityTest)
44 {
45  setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
46  artdaq::configureMessageFacility("configureMessageFacility_t");
47  mf::LogInfo("Test") << "Test Message";
48  TLOG(TLVL_INFO) << "Test TRACE";
49 
50  boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
51 }
52 
53 BOOST_AUTO_TEST_CASE(setMsgFacAppNameTest)
54 {
55  auto appName = artdaq::setMsgFacAppName("test", 1000);
56  BOOST_REQUIRE(!appName.empty());
57 }
58 
59 BOOST_AUTO_TEST_SUITE_END()
void configureTRACE(fhicl::ParameterSet &trace_pset)
Configure TRACE.
void configureMessageFacility(char const *progname, bool useConsole=true, bool printDebug=false)
Configure and start the message facility. Provide the program name so that messages will be appropria...
std::string setMsgFacAppName(const std::string &appType, unsigned short port)
Set the message facility application name using the specified application type and port number...
std::string generateMessageFacilityConfiguration(char const *progname, bool useConsole=true, bool printDebug=false, char const *fileExtraName="")
Create the MessageFacility configuration Fhicl string.