LCOV - code coverage report
Current view: top level - otsdaq-utilities/test - ots_mm_udp_test.cpp (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 0.0 % 103 0
Test Date: 2026-07-30 01:56:44 Functions: 0.0 % 1 0

            Line data    Source code
       1              : 
       2              : #include "test/ots_mm_udp_interface.h"
       3              : 
       4              : ///==============================================================================
       5              : /// To access Macro Maker with this tool
       6              : ///     first export...
       7              : /// export OTS_MACROMAKER_UDP_PORT=<YOUR_PORT>
       8              : /// export OTS_MACROMAKER_UDP_IP=127.0.0.1 #or the IP of the machine running Macro Maker
       9              : ///             then run... Macro Maker app
      10            0 : int main(int argc, char* argv[])
      11              : try
      12              : {
      13            0 :         if(argc < 3)
      14              :         {
      15            0 :                 fprintf(stderr,
      16              :                         "usage: ots_mm_udp_test <mm IP> <mm Port> <Front-end UID> <FEMacro "
      17              :                         "Name> <Macro Input args...> \n");
      18            0 :                 fprintf(stderr,
      19              :                         "\t If <Front-end UID> not specified, then the list of existing FE UIDs "
      20              :                         "will be output \n");
      21            0 :                 fprintf(stderr,
      22              :                         "\t If <FEMacro Name> not specified, then the list of existing FE Macro "
      23              :                         "Names will be output associated with the specified FE UID\n");
      24            0 :                 fprintf(stderr,
      25              :                         "\t Note: use quotes around command line arguments with spaces to "
      26              :                         "prevent them from being interpreted as multiple arguments.\n");
      27            0 :                 exit(1);
      28              :         }
      29              : 
      30            0 :         std::string target_mm_ip   = argv[1];
      31            0 :         int         target_mm_port = atoi(argv[2]);
      32              : 
      33              :         __COUTV__(target_mm_ip);
      34              :         __COUTV__(target_mm_port);
      35              : 
      36              :         __COUT__ << "instantiating..." << __E__;
      37            0 :         ots_mm_udp_interface mm(target_mm_ip.c_str(), target_mm_port);
      38              : 
      39            0 :         std::string feStr = mm.getFrontendList();
      40              :         __COUTV__(feStr);
      41            0 :         std::vector<std::string> fes = getVectorFromString(feStr, {';'});
      42            0 :         if(fes.size() == 0 || (fes.size() == 1 && fes[0] == ""))
      43              :         {
      44            0 :                 __COUT_ERR__
      45              :                     << "No Front-ends found in FE list! Check that a MacroMaker Supervisor is "
      46              :                     << "configured with UDP Remote Control enabled and accessible at "
      47            0 :                     << target_mm_ip << ":" << target_mm_port << "." << __E__;
      48            0 :                 return 1;
      49              :         }
      50              : 
      51            0 :         uint32_t fe  = -1;
      52            0 :         uint32_t cmd = -1;
      53              : 
      54            0 :         if(argc >= 4)
      55              :         {
      56              :                 //look for FE
      57            0 :                 std::string target_fe = argv[3];
      58            0 :                 for(fe = 0; fe < fes.size(); ++fe)
      59            0 :                         if(fes[fe] == target_fe)
      60            0 :                                 break;
      61            0 :                 if(fe >= fes.size())
      62              :                 {
      63            0 :                         __COUT_ERR__ << "Illegal front-end UID " << target_fe
      64            0 :                                      << " not found in FE list: " << vectorToString(fes, {';'}) << "."
      65            0 :                                      << __E__;
      66            0 :                         return 1;
      67              :                 }
      68            0 :         }
      69              :         else
      70              :         {
      71            0 :                 __COUT_INFO__
      72            0 :                     << "No front-end UID specified, here is the list of existing Front-end UIDs:"
      73            0 :                     << __E__;
      74            0 :                 for(fe = 0; fe < fes.size(); ++fe)
      75            0 :                         __COUT_INFO__ << "\t\t" << fes[fe] << __E__;
      76              : 
      77            0 :                 return 0;
      78              :         }
      79              : 
      80            0 :         if(fe >= fes.size())
      81              :         {
      82            0 :                 __COUT_ERR__ << "Illegal front-end index " << fe << " vs " << fes.size()
      83            0 :                              << " count." << __E__;
      84            0 :                 return 1;
      85              :         }
      86              : 
      87              :         __COUTV__(fes[fe]);
      88            0 :         std::string commandStr = mm.getCommandList(fes[fe]);
      89              :         __COUTV__(commandStr);
      90              : 
      91            0 :         std::vector<std::string> commands = getVectorFromString(commandStr, {';'});
      92              : 
      93            0 :         if(argc >= 5)
      94              :         {
      95              :                 //look for command
      96            0 :                 std::string target_command = argv[4];
      97            0 :                 for(cmd = 0; cmd < commands.size(); ++cmd)
      98            0 :                         if(commands[cmd] == target_command)
      99            0 :                                 break;
     100            0 :                 if(cmd >= commands.size())
     101              :                 {
     102            0 :                         __COUT_ERR__ << "Illegal Front-end Macro Command name '" << target_command
     103            0 :                                      << "' not found in '" << fes[fe]
     104            0 :                                      << "' Command list: " << vectorToString(commands, {';'}) << "."
     105            0 :                                      << __E__;
     106            0 :                         return 1;
     107              :                 }
     108            0 :         }
     109              :         else
     110              :         {
     111            0 :                 __COUT_INFO__ << "No FE Macro Name specified, here is the list of existing FE "
     112              :                                  "Macro Names corresponding to the specified Front-end UID '"
     113            0 :                               << argv[3] << "':" << __E__;
     114            0 :                 for(cmd = 0; cmd < commands.size(); ++cmd)
     115            0 :                         __COUT_INFO__ << "\t\t" << commands[cmd] << __E__;
     116              : 
     117            0 :                 return 0;
     118              :         }
     119              : 
     120            0 :         if(cmd >= commands.size())
     121              :         {
     122            0 :                 __COUT_ERR__ << "Illegal command index " << cmd << " vs " << commands.size()
     123            0 :                              << " count." << __E__;
     124            0 :                 return 1;
     125              :         }
     126              : 
     127              :         __COUTV__(commands[cmd]);
     128              : 
     129            0 :         uint32_t numberOfInputs = mm.getCommandInputCount(fes[fe], commands[cmd]);
     130              :         __COUTV__(numberOfInputs);
     131              : 
     132            0 :         uint32_t numberOfOutputs = mm.getCommandOutputCount(fes[fe], commands[cmd]);
     133              :         __COUTV__(numberOfOutputs);
     134              : 
     135            0 :         std::vector<std::string> inputs;
     136            0 :         if(argc != int(5 + numberOfInputs))
     137              :         {
     138            0 :                 __COUT_WARN__
     139              :                     << "Incorrect number of inputs provided for Front-end Macro Command name '"
     140            0 :                     << commands[cmd] << "' on FE UID '" << fes[fe] << "': " << argc - 5 << " vs "
     141            0 :                     << numberOfInputs << " expected." << __E__;
     142            0 :                 __COUT_INFO__ << "Will not run command." << __E__;
     143              : 
     144            0 :                 for(uint32_t i = 0; i < numberOfInputs; ++i)
     145              :                 {
     146            0 :                         std::string inputName = mm.getCommandInputName(fes[fe], commands[cmd], i);
     147            0 :                         __COUT_INFO__ << "\tExpected input #" << i + 1 << ": " << inputName << __E__;
     148            0 :                 }
     149            0 :                 return 0;
     150              :         }
     151              : 
     152              :         __COUTV__(vectorToString(inputs, {';'}));
     153            0 :         for(uint32_t i = 0; i < numberOfInputs; ++i)
     154              :         {
     155            0 :                 inputs.push_back(ots_mm_udp_interface::encodeURIComponent(argv[5 + i]));
     156            0 :                 std::string inputName = mm.getCommandInputName(fes[fe], commands[cmd], i);
     157            0 :                 __COUT_INFO__ << "\tInput #" << i << ": " << inputName << " = "
     158            0 :                               << ots_mm_udp_interface::decodeURIComponent(inputs.back()) << __E__;
     159            0 :         }
     160              : 
     161            0 :         __COUT_INFO__ << "Running command with these expected outputs..." << __E__;
     162            0 :         for(uint32_t i = 0; i < numberOfOutputs; ++i)
     163              :         {
     164            0 :                 std::string outputName = mm.getCommandOutputName(fes[fe], commands[cmd], i);
     165            0 :                 __COUT_INFO__ << "\tOutput #" << i << ": " << outputName << __E__;
     166            0 :         }
     167              : 
     168              :         std::string commandResult =
     169            0 :             mm.runCommand(fes[fe], commands[cmd], vectorToString(inputs, {';'}));
     170              : 
     171            0 :         std::vector<std::string> outputs = getVectorFromString(commandResult, {';'});
     172              : 
     173            0 :         if(numberOfOutputs != outputs.size())
     174              :         {
     175              :                 __COUTV__(commandResult);
     176            0 :                 __COUT_ERR__ << "Illegal response, mismatch in output arguments returned: "
     177            0 :                              << outputs.size() << " vs " << numberOfOutputs << " expected."
     178            0 :                              << __E__;
     179            0 :                 return 1;
     180              :         }
     181              : 
     182              :         __COUTV__(vectorToString(outputs, {';'}));
     183            0 :         for(uint32_t i = 0; i < numberOfOutputs; ++i)
     184              :         {
     185            0 :                 std::string outputName = mm.getCommandOutputName(fes[fe], commands[cmd], i);
     186              :                 __COUT__ << "\tOutput #" << i << ": " << outputName << " = "
     187              :                          << mm.decodeURIComponent(outputs[i]) << __E__;
     188            0 :         }
     189            0 :         __COUT_INFO__ << "Done." << __E__;
     190            0 :         return 0;
     191            0 : }
     192            0 : catch(const std::runtime_error& e)
     193              : {
     194            0 :         __COUT_ERR__ << "Error caught during test execution: \n" << e.what() << __E__;
     195            0 :         return 1;
     196            0 : }
        

Generated by: LCOV version 2.0-1