LCOV - code coverage report
Current view: top level - test/ExternalComms - commander_test.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 71.3 % 129 92
Test Date: 2025-09-04 00:45:34 Functions: 69.6 % 56 39

            Line data    Source code
       1              : #include "TRACE/tracemf.h"
       2              : #define TRACE_NAME "commander_test"
       3              : 
       4              : #include "artdaq-core/Utilities/configureMessageFacility.hh"
       5              : #include "artdaq/Application/LoadParameterSet.hh"
       6              : #include "artdaq/DAQdata/Globals.hh"
       7              : #include "artdaq/ExternalComms/CommanderInterface.hh"
       8              : #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
       9              : 
      10              : #include "fhiclcpp/types/Atom.h"
      11              : #include "fhiclcpp/types/Comment.h"
      12              : #include "fhiclcpp/types/Name.h"
      13              : #include "fhiclcpp/types/TableFragment.h"
      14              : 
      15              : #include <boost/thread.hpp>
      16              : 
      17              : // NOLINTNEXTLINE(readability-function-size)
      18            1 : int main(int argc, char** argv)
      19              : try
      20              : {
      21              :         struct Config
      22              :         {
      23              :                 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;  ///< Configuration for the CommanderInterface. See artdaq::CommanderInterface::Config
      24              : 
      25              :                 fhicl::Atom<std::string> partition_number{fhicl::Name{"partition_number"}, fhicl::Comment{"Partition to run in"}, ""};
      26              :         };
      27            1 :         artdaq::configureMessageFacility("commander_test", true, true);
      28            3 :         fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv, "commander_test", "A test driver for CommanderInterface plugins");
      29              : 
      30            2 :         artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number", 1);
      31              : 
      32            1 :         auto id_rand = artdaq::Globals::SeedAndRandom();
      33            2 :         if (config_ps.has_key("id"))
      34              :         {
      35            3 :                 TLOG(TLVL_DEBUG) << "Ignoring set id and using random!";
      36            2 :                 config_ps.erase("id");
      37              :         }
      38            2 :         config_ps.put("id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
      39              : 
      40            1 :         std::unique_ptr<artdaq::Commandable> cmdble(new artdaq::Commandable());
      41              : 
      42            1 :         auto commander = artdaq::MakeCommanderPlugin(config_ps, *cmdble);
      43              : 
      44              :         // Start server thread
      45            2 :         boost::thread commanderThread([&] { commander->run_server(); });
      46            2 :         while (!commander->GetStatus())
      47              :         {
      48            1 :                 usleep(10000);
      49              :         }
      50            1 :         sleep(1);
      51              : 
      52            1 :         uint64_t arg = 0;
      53            1 :         fhicl::ParameterSet pset;
      54              : 
      55            3 :         TLOG(TLVL_INFO) << "START";
      56              : 
      57            3 :         TLOG(TLVL_DEBUG) << "Sending init";
      58            1 :         std::string sts = commander->send_init(pset, arg, arg);
      59            3 :         TLOG(TLVL_DEBUG) << "init res=" << sts;
      60            1 :         if (sts != "Success")
      61              :         {
      62            0 :                 TLOG(TLVL_ERROR) << "init returned " << sts << ", exiting with error";
      63            0 :                 exit(1);
      64              :         }
      65              : 
      66            3 :         TLOG(TLVL_DEBUG) << "Sending soft_init";
      67            1 :         sts = commander->send_soft_init(pset, arg, arg);
      68            3 :         TLOG(TLVL_DEBUG) << "soft_init res=" << sts;
      69            1 :         if (sts != "Success")
      70              :         {
      71            0 :                 TLOG(TLVL_ERROR) << "soft_init returned " << sts << ", exiting with error";
      72            0 :                 exit(2);
      73              :         }
      74              : 
      75            3 :         TLOG(TLVL_DEBUG) << "Sending legal_commands";
      76            1 :         sts = commander->send_legal_commands();
      77            3 :         TLOG(TLVL_DEBUG) << "legal_commands res=" << sts;
      78            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
      79              :         {
      80            0 :                 TLOG(TLVL_ERROR) << "legal_commands returned " << sts << ", exiting with error";
      81            0 :                 exit(3);
      82              :         }
      83              : 
      84            3 :         TLOG(TLVL_DEBUG) << "Sending meta_command";
      85            4 :         sts = commander->send_meta_command("test", "test");
      86            3 :         TLOG(TLVL_DEBUG) << "meta_command res=" << sts;
      87            1 :         if (sts != "Success")
      88              :         {
      89            0 :                 TLOG(TLVL_ERROR) << "meta_command returned " << sts << ", exiting with error";
      90            0 :                 exit(4);
      91              :         }
      92              : 
      93            3 :         TLOG(TLVL_DEBUG) << "Sending report";
      94            2 :         sts = commander->send_report("test");
      95            3 :         TLOG(TLVL_DEBUG) << "report res=" << sts;
      96            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
      97              :         {
      98            0 :                 TLOG(TLVL_ERROR) << "report returned " << sts << ", exiting with error";
      99            0 :                 exit(5);
     100              :         }
     101              : 
     102            3 :         TLOG(TLVL_DEBUG) << "Sending start";
     103            1 :         sts = commander->send_start(art::RunID(0x7357), arg, arg);
     104            3 :         TLOG(TLVL_DEBUG) << "start res=" << sts;
     105            1 :         if (sts != "Success")
     106              :         {
     107            0 :                 TLOG(TLVL_ERROR) << "start returned " << sts << ", exiting with error";
     108            0 :                 exit(6);
     109              :         }
     110              : 
     111            3 :         TLOG(TLVL_DEBUG) << "Sending status";
     112            1 :         sts = commander->send_status();
     113            3 :         TLOG(TLVL_DEBUG) << "status res=" << sts;
     114            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
     115              :         {
     116            0 :                 TLOG(TLVL_ERROR) << "status returned " << sts << ", exiting with error";
     117            0 :                 exit(7);
     118              :         }
     119              : 
     120            3 :         TLOG(TLVL_DEBUG) << "Sending pause";
     121            1 :         sts = commander->send_pause(arg, arg);
     122            3 :         TLOG(TLVL_DEBUG) << "pause res=" << sts;
     123            1 :         if (sts != "Success")
     124              :         {
     125            0 :                 TLOG(TLVL_ERROR) << "pause returned " << sts << ", exiting with error";
     126            0 :                 exit(8);
     127              :         }
     128              : 
     129            3 :         TLOG(TLVL_DEBUG) << "Sending resume";
     130            1 :         sts = commander->send_resume(arg, arg);
     131            3 :         TLOG(TLVL_DEBUG) << "resume res=" << sts;
     132            1 :         if (sts != "Success")
     133              :         {
     134            0 :                 TLOG(TLVL_ERROR) << "resume returned " << sts << ", exiting with error";
     135            0 :                 exit(9);
     136              :         }
     137              : 
     138            3 :         TLOG(TLVL_DEBUG) << "Sending rollover_subrun";
     139            1 :         sts = commander->send_rollover_subrun(arg, static_cast<uint32_t>(arg));
     140            3 :         TLOG(TLVL_DEBUG) << "rollover_subrun res=" << sts;
     141            1 :         if (sts != "Success")
     142              :         {
     143            0 :                 TLOG(TLVL_ERROR) << "rollover_subrun returned " << sts << ", exiting with error";
     144            0 :                 exit(10);
     145              :         }
     146              : 
     147            3 :         TLOG(TLVL_DEBUG) << "Sending stop";
     148            1 :         sts = commander->send_stop(arg, arg);
     149            3 :         TLOG(TLVL_DEBUG) << "stop res=" << sts;
     150            1 :         if (sts != "Success")
     151              :         {
     152            0 :                 TLOG(TLVL_ERROR) << "stop returned " << sts << ", exiting with error";
     153            0 :                 exit(11);
     154              :         }
     155              : 
     156            3 :         TLOG(TLVL_DEBUG) << "Sending reinit";
     157            1 :         sts = commander->send_reinit(pset, arg, arg);
     158            3 :         TLOG(TLVL_DEBUG) << "reinit res=" << sts;
     159            1 :         if (sts != "Success")
     160              :         {
     161            0 :                 TLOG(TLVL_ERROR) << "reinit returned " << sts << ", exiting with error";
     162            0 :                 exit(12);
     163              :         }
     164              : 
     165            3 :         TLOG(TLVL_DEBUG) << "Sending trace_set";
     166            6 :         sts = commander->send_trace_set("TRACE", "M", "0x7357AAAABBBBCCCC");
     167            3 :         TLOG(TLVL_DEBUG) << "trace_set res=" << sts;
     168            1 :         if (sts != "Success")
     169              :         {
     170            0 :                 TLOG(TLVL_ERROR) << "trace_set returned " << sts << ", exiting with error";
     171            0 :                 exit(13);
     172              :         }
     173              : 
     174            3 :         TLOG(TLVL_DEBUG) << "Sending trace_get";
     175            2 :         sts = commander->send_trace_get("TRACE");
     176            3 :         TLOG(TLVL_DEBUG) << "trace_get res=" << sts;
     177            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
     178              :         {
     179            0 :                 TLOG(TLVL_ERROR) << "trace_get returned " << sts << ", exiting with error";
     180            0 :                 exit(14);
     181              :         }
     182              : 
     183            3 :         TLOG(TLVL_DEBUG) << "Sending register_monitor";
     184            2 :         sts = commander->send_register_monitor("unqiue_label: test");
     185            3 :         TLOG(TLVL_DEBUG) << "register_monitor res=" << sts;
     186            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
     187              :         {
     188            0 :                 TLOG(TLVL_ERROR) << "register_monitor returned " << sts << ", exiting with error";
     189            0 :                 exit(15);
     190              :         }
     191              : 
     192            3 :         TLOG(TLVL_DEBUG) << "Sending unregister_monitor";
     193            2 :         sts = commander->send_unregister_monitor("test");
     194            3 :         TLOG(TLVL_DEBUG) << "unregister_monitor res=" << sts;
     195            1 :         if (sts.empty() || sts.find("Exception", 0) != std::string::npos || sts.find("Error", 0) != std::string::npos)
     196              :         {
     197            0 :                 TLOG(TLVL_ERROR) << "unregister_monitor returned " << sts << ", exiting with error";
     198            0 :                 exit(16);
     199              :         }
     200              : 
     201            3 :         TLOG(TLVL_DEBUG) << "Sending shutdown";
     202            1 :         sts = commander->send_shutdown(arg);
     203            3 :         TLOG(TLVL_DEBUG) << "shutdown res=" << sts;
     204            1 :         if (sts != "Success")
     205              :         {
     206            0 :                 TLOG(TLVL_ERROR) << "shutdown returned " << sts << ", exiting with error";
     207            0 :                 exit(17);
     208              :         }
     209              : 
     210            3 :         TLOG(TLVL_INFO) << "DONE";
     211              : 
     212            1 :         if (commanderThread.joinable())
     213              :         {
     214            1 :                 commanderThread.join();
     215              :         }
     216            1 :         artdaq::Globals::CleanUpGlobals();
     217              : 
     218            1 :         return 0;
     219            1 : }
     220            0 : catch (...)
     221              : {
     222            0 :         return -1;
     223            0 : }
        

Generated by: LCOV version 2.0-1