LCOV - code coverage report
Current view: top level - conffwk/test/apps - config_time_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 84 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 19 0

            Line data    Source code
       1              : //
       2              : // DUNE DAQ modification notice:
       3              : // This file has been modified from the original ATLAS config source for the DUNE DAQ project.
       4              : // Fork baseline commit: 67a24e731 (2022-10-27).
       5              : // Renamed since fork: yes (from test/config_time_test.cpp to test/apps/config_time_test.cxx).
       6              : //
       7              : 
       8              : #include <stdlib.h>
       9              : #include <time.h>
      10              : #include <sys/resource.h>
      11              : 
      12              : #include <chrono>
      13              : #include <iostream>
      14              : #include <fstream>
      15              : #include <string>
      16              : 
      17              : #include "conffwk/Configuration.hpp"
      18              : #include "conffwk/ConfigObject.hpp"
      19              : #include "conffwk/Schema.hpp"
      20              : 
      21              : using namespace dunedaq::conffwk;
      22              : 
      23            0 : ERS_DECLARE_ISSUE(
      24              :   conffwk_time_test,
      25              :   BadCommandLine,
      26              :   "bad command line: " << reason,
      27              :   ((const char*)reason)
      28              : )
      29              : 
      30            0 : ERS_DECLARE_ISSUE(
      31              :   conffwk_time_test,
      32              :   ConfigException,
      33              :   "caught dunedaq::conffwk::Exception exception",
      34              : )
      35              : 
      36              : static void
      37            0 : no_param(const char * s)
      38              : {
      39            0 :   std::ostringstream text;
      40            0 :   text << "no parameter for " << s << " provided";
      41            0 :   ers::fatal(conffwk_time_test::BadCommandLine(ERS_HERE, text.str().c_str()));
      42            0 :   exit(EXIT_FAILURE);
      43            0 : }
      44              : 
      45              : template <class T>
      46              : void
      47            0 : stop_and_report(T& tp, const char * fname)
      48              : {
      49            0 :   std::cout << "TEST \"" << fname << "\" => " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now()-tp).count() / 1000. << " ms\n";
      50            0 : }
      51              : 
      52              : 
      53            0 : int main(int argc, char *argv[])
      54              : {
      55            0 :   const char * db_name = 0;
      56            0 :   bool verbose = false;
      57              : 
      58            0 :   for(int i = 1; i < argc; i++) {
      59            0 :     const char * cp = argv[i];
      60              : 
      61            0 :     if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
      62            0 :       std::cout << 
      63              :         "Usage: conffwk_time_test -d dbspec [-c | -C [class_name]] [-o | -O [object_id]] [-n]\n"
      64              :         "\n"
      65              :         "Options/Arguments:\n"
      66              :         "  -d | --database dbspec        database specification in format plugin-name:parameters\n"
      67              :         "  -v | --verbose                print details\n"
      68              :         "\n"
      69              :         "Description:\n"
      70              :         "  The utility reports results of time tests.\n"
      71            0 :         "  When no -c or -o options are provided, utility lists all classes.\n\n";
      72              :     }
      73            0 :     else if(!strcmp(cp, "-d") || !strcmp(cp, "--database")) {
      74            0 :       if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
      75              :     }
      76            0 :     else if(!strcmp(cp, "-v") || !strcmp(cp, "--verbose")) {
      77            0 :       verbose = true;
      78              :     }
      79              :   }
      80              : 
      81            0 :   if(!db_name) {
      82            0 :     ers::fatal(conffwk_time_test::BadCommandLine(ERS_HERE, "no database name given"));
      83            0 :     return (EXIT_FAILURE);
      84              :   }
      85              : 
      86            0 :   try {
      87              :   
      88              :     
      89              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      90              : 
      91            0 :     auto tp = std::chrono::steady_clock::now();
      92              : 
      93            0 :     Configuration conf(db_name);
      94              : 
      95            0 :     if(verbose) {
      96            0 :       std::cout << "load database \"" << conf.get_impl_spec() << '\"' << std::endl;
      97              :     }
      98              : 
      99            0 :     stop_and_report(tp, "loading database");
     100              : 
     101              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     102              : 
     103            0 :     tp = std::chrono::steady_clock::now();
     104              : 
     105            0 :     std::set<std::string> classes;
     106              : 
     107            0 :     for(fmap<fset>::const_iterator i = conf.superclasses().begin(); i != conf.superclasses().end(); ++i) {
     108            0 :       classes.insert(*i->first);
     109              :     }
     110              : 
     111            0 :     if(verbose) {
     112            0 :       std::cout << "The database schema has " << classes.size() << " class(es):\n";
     113              :     }
     114              : 
     115            0 :     for(std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
     116            0 :       const dunedaq::conffwk::class_t& d(conf.get_class_info(*i));
     117            0 :       if(verbose) {
     118            0 :         d.print(std::cout, "  ");
     119              :       }
     120              :     }
     121              : 
     122            0 :     stop_and_report(tp, "reading schema meta-information");
     123              : 
     124              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     125              : 
     126            0 :     tp = std::chrono::steady_clock::now();
     127              : 
     128            0 :     std::vector<ConfigObject> all_objects;
     129              : 
     130            0 :     for(std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
     131            0 :       std::vector<ConfigObject> objects;
     132            0 :       conf.get(*i, objects);
     133              : 
     134            0 :       unsigned int count = 0;
     135              : 
     136            0 :       for(std::vector<ConfigObject>::const_iterator j = objects.begin(); j != objects.end(); ++j) {
     137            0 :         if((*j).class_name() == *i) {
     138            0 :           count++;
     139            0 :           all_objects.push_back(*j);
     140              :         }
     141              :       }
     142              :       
     143            0 :       if(verbose) {
     144            0 :         std::cout << "Class " << *i << " has " << count << " objects (" << objects.size() << " with derived classes)\n";
     145              :       }
     146            0 :     }
     147              :     
     148            0 :     if(verbose) {
     149            0 :       std::cout << "Total number of objects: " << all_objects.size() << std::endl;
     150              :     }
     151              : 
     152            0 :     stop_and_report(tp, "reading names of objects");
     153              : 
     154              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     155              : 
     156            0 :     tp = std::chrono::steady_clock::now();
     157              : 
     158            0 :     std::set<std::string> files;
     159              :     
     160            0 :     for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     161            0 :       files.insert((*i).contained_in());
     162              :     }
     163              :     
     164            0 :     if(verbose) {
     165            0 :       std::cout << "There are " << files.size() << " data files:\n";
     166              :       
     167            0 :       for(std::set<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
     168            0 :         std::cout << " - \"" << *i << "\"\n";
     169              :       }
     170              :     }
     171              :     
     172            0 :     stop_and_report(tp, "reading names of files");
     173              : 
     174              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     175              :     
     176            0 :     tp = std::chrono::steady_clock::now();
     177              : 
     178            0 :     if(verbose) {
     179            0 :       std::cout << "Details of objects:\n";
     180              : 
     181            0 :       for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     182            0 :         (*i).print_ref(std::cout, conf, "  ");
     183              :       }
     184              :     }
     185              :     else {
     186            0 :       std::ofstream null("/dev/null", std::ios::out);
     187            0 :       for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     188            0 :         (*i).print_ref(null, conf);
     189              :       }
     190            0 :     }
     191              : 
     192            0 :     stop_and_report(tp, "reading all attributes and relationships");
     193              : 
     194              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     195              : 
     196            0 :     return 0;
     197            0 :   }
     198            0 :   catch (dunedaq::conffwk::Exception & ex) {
     199            0 :     ers::fatal(conffwk_time_test::ConfigException(ERS_HERE, ex));
     200            0 :   }
     201              : 
     202            0 :   return (EXIT_FAILURE);
     203              : }
        

Generated by: LCOV version 2.0-1