artdaq_core  v3_09_06
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 "cetlib/quiet_unit_test.hpp"
6 
7 #include "cetlib_except/exception.h"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "fhiclcpp/make_ParameterSet.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
11 
12 #include <boost/filesystem.hpp>
13 
14 #define TRACE_NAME "configureMessageFacility_t"
15 #include "TRACE/tracemf.h"
16 
17 BOOST_AUTO_TEST_SUITE(configureMessageFacility_test)
18 
19 BOOST_AUTO_TEST_CASE(configureTRACETest)
20 {
21  fhicl::ParameterSet pset;
22  pset.put("TRACE_MODE", "3");
23  fhicl::ParameterSet namlvlset;
24  namlvlset.put<std::vector<uint64_t>>("ConfigureMessageFacility_t", {0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0});
25  pset.put("TRACE_NAMLVLSET", namlvlset);
27 }
28 
29 BOOST_AUTO_TEST_CASE(generateMessageFacilityConfigurationTest)
30 {
31  auto str = artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
32  std::string badDir = "/this/directory/doesn't/exist";
33  setenv("ARTDAQ_LOG_TIMESTAMPS_TO_CONSOLE", "0", 1);
34  setenv("ARTDAQ_LOG_ROOT", badDir.c_str(), 1);
35  BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "ConfigureMessageFacility"; });
36  setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
37 
38  setenv("ARTDAQ_LOG_FHICL", "/this/file/doesn't/exist.fcl", 1);
39  BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "ConfigureMessageFacility"; });
40  unsetenv("ARTDAQ_LOG_FHICL");
41 
42  artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
43 
44  boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
45 }
46 
47 BOOST_AUTO_TEST_CASE(configureMessageFacilityTest)
48 {
49  setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
50  artdaq::configureMessageFacility("configureMessageFacility_t");
51  mf::LogInfo("Test") << "Test Message";
52  TLOG(TLVL_INFO) << "Test TRACE";
53 
54  boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
55 }
56 
57 BOOST_AUTO_TEST_CASE(setMsgFacAppNameTest)
58 {
59  auto appName = artdaq::setMsgFacAppName("test", 1000);
60  BOOST_REQUIRE(!appName.empty());
61 }
62 
63 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.