Quinoa all test code coverage report
Current view: top level - Main - Init.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 56 61 91.8 %
Date: 2024-04-29 14:42:33 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 94 260 36.2 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Main/Init.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Common initialization routines for main() functions for multiple
       9                 :            :      exectuables
      10                 :            :   \details   Common initialization routines for main() functions for multiple
      11                 :            :      exectuables. The functions in this file are used by multiple execitables
      12                 :            :      to ensure code-reuse and a uniform screen-output.
      13                 :            : */
      14                 :            : // *****************************************************************************
      15                 :            : 
      16                 :            : #include <ctime>
      17                 :            : #include <unistd.h>
      18                 :            : 
      19                 :            : #include "QuinoaConfig.hpp"
      20                 :            : #include "Exception.hpp"
      21                 :            : #include "Tags.hpp"
      22                 :            : #include "Keywords.hpp"
      23                 :            : #include "Init.hpp"
      24                 :            : 
      25                 :            : namespace tk {
      26                 :            : 
      27                 :        214 : static std::string workdir()
      28                 :            : // *****************************************************************************
      29                 :            : // Wrapper for POSIX API's getcwd() from unistd.h
      30                 :            : //! \return A stirng containing the current working directory
      31                 :            : // *****************************************************************************
      32                 :            : {
      33                 :            :   char cwd[1024];
      34                 :            : 
      35         [ +  - ]:        214 :   if ( getcwd(cwd, sizeof(cwd)) != nullptr )
      36                 :        214 :     return std::string( cwd );
      37                 :            :   else
      38 [ -  - ][ -  - ]:          0 :     Throw( "Error from POSIX API's getcwd()" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      39                 :            : }
      40                 :            : 
      41                 :        214 : std::string curtime()
      42                 :            : // *****************************************************************************
      43                 :            : //  Wrapper for the standard C library's gettimeofday() from
      44                 :            : //! \return A stirng containing the current date and time
      45                 :            : // *****************************************************************************
      46                 :            : {
      47                 :            :   time_t current_time;
      48                 :            :   char* c_time_string;
      49                 :            : 
      50                 :            :   // Obtain current time as seconds elapsed since the Epoch
      51                 :        214 :   current_time = time( nullptr );
      52                 :            : 
      53         [ -  + ]:        214 :   if (current_time == static_cast<time_t>(-1))
      54 [ -  - ][ -  - ]:          0 :     Throw( "Failure to compute the current time" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      55                 :            : 
      56                 :            :   // Convert to local time format
      57                 :        214 :   c_time_string = ctime(&current_time);
      58                 :            : 
      59         [ -  + ]:        214 :   if (c_time_string == nullptr)
      60 [ -  - ][ -  - ]:          0 :     Throw( "Failure to convert the current time" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      61                 :            : 
      62                 :            :   // Convert to std::string and remove trailing newline
      63                 :        214 :   std::string str( c_time_string );
      64 [ +  - ][ -  - ]:        214 :   str.erase( std::remove(str.begin(), str.end(), '\n'), str.end() );
      65                 :            : 
      66                 :        214 :   return str;
      67                 :            : }
      68                 :            : 
      69                 :        214 : void echoHeader( const Print& print, HeaderType header )
      70                 :            : // *****************************************************************************
      71                 :            : //  Echo program header
      72                 :            : //! \param[in] print Pretty printer
      73                 :            : //! \param[in] header Header type enum indicating which header to print
      74                 :            : // *****************************************************************************
      75                 :            : {
      76         [ +  + ]:        214 :   if ( header == HeaderType::INCITER )
      77                 :        195 :     print.headerInciter();
      78         [ +  + ]:         19 :   else if ( header == HeaderType::UNITTEST )
      79                 :          1 :     print.headerUnitTest();
      80         [ +  - ]:         18 :   else if ( header == HeaderType::MESHCONV )
      81                 :         18 :     print.headerMeshConv();
      82                 :            :   else
      83 [ -  - ][ -  - ]:          0 :     Throw( "Header not available" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      84                 :        214 : }
      85                 :            : 
      86                 :        214 : void echoBuildEnv( const Print& print, const std::string& executable )
      87                 :            : // *****************************************************************************
      88                 :            : //  Echo build environment
      89                 :            : //! \details Echo information read from build_dir/Base/Config.h filled by
      90                 :            : //!    CMake based on src/Main/Config.h.in.
      91                 :            : //! \param[in] print Pretty printer
      92                 :            : //! \param[in] executable Name of the executable
      93                 :            : // *****************************************************************************
      94                 :            : {
      95 [ +  - ][ +  - ]:        214 :   print.section( "Build environment" );
      96 [ +  - ][ +  - ]:        428 :   print.item( "Hostname", build_hostname() );
                 [ -  + ]
      97 [ +  - ][ +  - ]:        214 :   print.item( "Executable", executable );
      98                 :            :   //print.item( "Version", quinoa_version() );  // needs manual upkeep
      99                 :        214 :   auto sha1 = git_commit();
     100         [ -  + ]:        214 :   if (sha1.find("NOTFOUND") == std::string::npos)
     101 [ -  - ][ -  - ]:          0 :     print.item( "Revision SHA1", sha1 );
     102 [ +  - ][ +  - ]:        428 :   print.item( "CMake build type", build_type() );
         [ +  - ][ -  + ]
     103                 :            : 
     104                 :            : #ifdef NDEBUG
     105 [ +  - ][ +  - ]:        214 :   print.item( "Asserts", "off (turn on: CMAKE_BUILD_TYPE=DEBUG)" );
     106                 :            : #else
     107                 :            :   print.item( "Asserts", "on (turn off: CMAKE_BUILD_TYPE=RELEASE)" );
     108                 :            : #endif
     109                 :            : 
     110 [ +  - ][ +  - ]:        428 :   print.item( "MPI C++ wrapper", mpi_compiler() );
         [ +  - ][ -  + ]
     111 [ +  - ][ +  - ]:        428 :   print.item( "Underlying C++ compiler", compiler() );
         [ +  - ][ -  + ]
     112 [ +  - ][ +  - ]:        642 :   print.item( "Build date", build_date() );
         [ +  - ][ +  - ]
         [ -  + ][ -  - ]
     113                 :        214 : }
     114                 :            : 
     115                 :        214 : void echoRunEnv( const Print& print, int argc, char** argv,
     116                 :            :                  bool verbose, bool quiescence, bool charestate, bool trace,
     117                 :            :                  const std::string& screen_log, const std::string& input_log )
     118                 :            : // *****************************************************************************
     119                 :            : //  Echo runtime environment
     120                 :            : //! \param[in] print Pretty printer
     121                 :            : //! \param[in] argc Number of command-line arguments to executable
     122                 :            : //! \param[in] argv C-style string array to command-line arguments to executable
     123                 :            : //! \param[in] verbose True for verbose screen-output
     124                 :            : //! \param[in] quiescence True if quiescence detection is enabled
     125                 :            : //! \param[in] charestate True if chare state collection is enabled
     126                 :            : //! \param[in] trace True if call and stack trace output is enabled
     127                 :            : //! \param[in] screen_log Screen output log file name
     128                 :            : //! \param[in] input_log Input log file name
     129                 :            : // *****************************************************************************
     130                 :            : {
     131 [ +  - ][ +  - ]:        214 :   print.section( "Run-time environment" );
     132                 :            : 
     133 [ +  - ][ +  - ]:        428 :   print.item( "Date, time", curtime() );
                 [ +  - ]
     134 [ +  - ][ +  - ]:        428 :   print.item( "Work directory", workdir() );
                 [ +  - ]
     135 [ +  - ][ +  - ]:        214 :   print.item( "Executable (relative to work dir)", argv[0] );
     136                 :            : 
     137 [ +  - ][ +  - ]:        428 :   print.item( "Command line arguments" );
     138                 :            :   print << '\'';
     139         [ +  - ]:        214 :   if (argc>1) {
     140         [ +  + ]:       1484 :     for (auto i=1; i<argc-1; ++i) {
     141 [ +  - ][ +  - ]:       2540 :       print << std::string( argv[i] ) + ' ';
         [ -  + ][ -  - ]
     142                 :            :     }
     143         [ +  - ]:        428 :     print << std::string( argv[argc-1] );
     144                 :            :   }
     145                 :            :   print << "'\n";
     146                 :            : 
     147 [ +  - ][ +  - ]:        428 :   print.item( "Screen output, -" + *kw::verbose::alias(),
         [ +  - ][ -  - ]
     148         [ -  + ]:        214 :               verbose ? "verbose" : "quiet" );
     149 [ +  - ][ +  - ]:        428 :   print.item( "Screen output log file, -" + *kw::screen::alias(), screen_log );
         [ +  - ][ -  - ]
     150 [ +  - ][ +  - ]:        428 :   print.item( "Input log file", input_log );
     151 [ +  - ][ +  - ]:        428 :   print.item( "Number of processing elements",
                 [ -  + ]
     152 [ +  - ][ +  - ]:        428 :               std::to_string( CkNumPes() ) + " (" +
         [ -  + ][ -  + ]
         [ -  + ][ -  - ]
         [ -  - ][ -  - ]
     153 [ +  - ][ +  - ]:        856 :               std::to_string( CkNumNodes() ) + 'x' +
         [ +  - ][ -  + ]
         [ -  + ][ -  + ]
         [ -  - ][ -  - ]
                 [ -  - ]
     154 [ +  - ][ -  + ]:        428 :               std::to_string( CkNumPes()/CkNumNodes() ) + ')' );
                 [ -  - ]
     155 [ +  - ][ +  - ]:        428 :   print.item( "Quiescence detection, -" + *kw::quiescence::alias(),
         [ +  - ][ -  - ]
     156         [ +  + ]:        262 :               quiescence ? "on" : "off" );
     157 [ +  - ][ +  - ]:        428 :   print.item( "Chare state output, -" + *kw::charestate::alias(),
         [ +  - ][ -  - ]
     158         [ +  + ]:        427 :               charestate ? "on" : "off" );
     159 [ +  - ][ +  - ]:        428 :   print.item( "Call and stack trace, -" + *kw::trace::alias(),
         [ +  - ][ -  - ]
     160         [ -  + ]:        214 :               trace ? "on" : "off" );
     161                 :        214 : }
     162                 :            : 
     163                 :            : } // tk::

Generated by: LCOV version 1.14