Line data Source code
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 2 : BOOST_AUTO_TEST_CASE(configureTRACETest)
20 : {
21 1 : fhicl::ParameterSet pset;
22 1 : pset.put("TRACE_MODE", "3");
23 1 : fhicl::ParameterSet namlvlset;
24 5 : namlvlset.put<std::vector<uint64_t>>("ConfigureMessageFacility_t", {0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0});
25 1 : pset.put("TRACE_NAMLVLSET", namlvlset);
26 1 : artdaq::configureTRACE(pset);
27 1 : }
28 :
29 2 : BOOST_AUTO_TEST_CASE(generateMessageFacilityConfigurationTest)
30 : {
31 1 : auto str = artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
32 1 : std::string badDir = "/this/directory/doesn't/exist";
33 1 : setenv("ARTDAQ_LOG_TIMESTAMPS_TO_CONSOLE", "0", 1);
34 1 : setenv("ARTDAQ_LOG_ROOT", badDir.c_str(), 1);
35 2 : BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "ConfigureMessageFacility"; });
36 1 : setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
37 :
38 1 : setenv("ARTDAQ_LOG_FHICL", "/this/file/doesn't/exist.fcl", 1);
39 2 : BOOST_REQUIRE_EXCEPTION(artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t"), cet::exception, [](cet::exception const& e) { return e.category() == "ConfigureMessageFacility"; });
40 1 : unsetenv("ARTDAQ_LOG_FHICL");
41 :
42 1 : artdaq::generateMessageFacilityConfiguration("configureMessageFacility_t");
43 :
44 1 : boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
45 1 : }
46 :
47 2 : BOOST_AUTO_TEST_CASE(configureMessageFacilityTest)
48 : {
49 1 : setenv("ARTDAQ_LOG_ROOT", "/tmp", 1);
50 1 : artdaq::configureMessageFacility("configureMessageFacility_t");
51 3 : mf::LogInfo("Test") << "Test Message";
52 3 : TLOG(TLVL_INFO) << "Test TRACE";
53 :
54 1 : boost::filesystem::remove_all("/tmp/configureMessageFacility_t");
55 1 : }
56 :
57 2 : BOOST_AUTO_TEST_CASE(setMsgFacAppNameTest)
58 : {
59 2 : auto appName = artdaq::setMsgFacAppName("test", 1000);
60 1 : BOOST_REQUIRE(!appName.empty());
61 1 : }
62 :
63 : BOOST_AUTO_TEST_SUITE_END()
|