Walker test code coverage report
Current view: top level - Main - Init.cpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 57 61 93.4 %
Date: 2022-09-21 18:57:21 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 79 174 45.4 %

           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 "WalkerConfig.hpp"
      20                 :            : #include "Exception.hpp"
      21                 :            : #include "Tags.hpp"
      22                 :            : #include "Keywords.hpp"
      23                 :            : #include "Init.hpp"
      24                 :            : 
      25                 :            : namespace tk {
      26                 :            : 
      27                 :         98 : 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         [ +  - ]:         98 :   if ( getcwd(cwd, sizeof(cwd)) != nullptr )
      36         [ +  - ]:        196 :     return std::string( cwd );
      37                 :            :   else
      38 [ -  - ][ -  - ]:          0 :     Throw( "Error from POSIX API's getcwd()" );
                 [ -  - ]
      39                 :            : }
      40                 :            : 
      41                 :         98 : 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                 :         98 :   current_time = time( nullptr );
      52                 :            : 
      53         [ -  + ]:         98 :   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                 :         98 :   c_time_string = ctime(&current_time);
      58                 :            : 
      59         [ -  + ]:         98 :   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         [ +  - ]:         98 :   std::string str( c_time_string );
      64 [ +  - ][ +  - ]:         98 :   str.erase( std::remove(str.begin(), str.end(), '\n'), str.end() );
      65                 :            : 
      66                 :        196 :   return str;
      67                 :            : }
      68                 :            : 
      69                 :         98 : 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         [ +  + ]:         98 :   if ( header == HeaderType::RNGTEST )
      77                 :          4 :     print.headerRNGTest();
      78         [ +  + ]:         94 :   else if ( header == HeaderType::UNITTEST )
      79                 :          1 :     print.headerUnitTest();
      80         [ +  - ]:         93 :   else if ( header == HeaderType::WALKER )
      81                 :         93 :     print.headerWalker();
      82                 :            :   else
      83 [ -  - ][ -  - ]:          0 :     Throw( "Header not available" );
                 [ -  - ]
      84                 :         98 : }
      85                 :            : 
      86                 :         98 : 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 [ +  - ][ +  - ]:         98 :   print.section( "Build environment" );
      96 [ +  - ][ +  - ]:         98 :   print.item( "Hostname", build_hostname() );
      97 [ +  - ][ +  - ]:         98 :   print.item( "Executable", executable );
      98 [ +  - ][ +  - ]:         98 :   print.item( "Version", walker_version() );
      99 [ +  - ][ +  - ]:         98 :   print.item( "CMake build type", build_type() );
     100                 :            : 
     101                 :            : #ifdef NDEBUG
     102                 :            :   print.item( "Asserts", "off (turn on: CMAKE_BUILD_TYPE=DEBUG)" );
     103                 :            : #else
     104 [ +  - ][ +  - ]:         98 :   print.item( "Asserts", "on (turn off: CMAKE_BUILD_TYPE=RELEASE)" );
     105                 :            : #endif
     106                 :            : 
     107 [ +  - ][ +  - ]:         98 :   print.item( "MPI C++ wrapper", mpi_compiler() );
     108 [ +  - ][ +  - ]:         98 :   print.item( "Underlying C++ compiler", compiler() );
     109 [ +  - ][ +  - ]:         98 :   print.item( "Build date", build_date() );
     110                 :         98 : }
     111                 :            : 
     112                 :         98 : void echoRunEnv( const Print& print, int argc, char** argv,
     113                 :            :                  bool verbose, bool quiescence, bool charestate, bool trace,
     114                 :            :                  const std::string& screen_log, const std::string& input_log )
     115                 :            : // *****************************************************************************
     116                 :            : //  Echo runtime environment
     117                 :            : //! \param[in] print Pretty printer
     118                 :            : //! \param[in] argc Number of command-line arguments to executable
     119                 :            : //! \param[in] argv C-style string array to command-line arguments to executable
     120                 :            : //! \param[in] verbose True for verbose screen-output
     121                 :            : //! \param[in] quiescence True if quiescence detection is enabled
     122                 :            : //! \param[in] charestate True if chare state collection is enabled
     123                 :            : //! \param[in] trace True if call and stack trace output is enabled
     124                 :            : //! \param[in] screen_log Screen output log file name
     125                 :            : //! \param[in] input_log Input log file name
     126                 :            : // *****************************************************************************
     127                 :            : {
     128 [ +  - ][ +  - ]:         98 :   print.section( "Run-time environment" );
     129                 :            : 
     130 [ +  - ][ +  - ]:         98 :   print.item( "Date, time", curtime() );
     131 [ +  - ][ +  - ]:         98 :   print.item( "Work directory", workdir() );
     132 [ +  - ][ +  - ]:         98 :   print.item( "Executable (relative to work dir)", argv[0] );
     133                 :            : 
     134 [ +  - ][ +  - ]:         98 :   print.item( "Command line arguments" );
     135         [ +  - ]:         98 :   print << '\'';
     136         [ +  - ]:         98 :   if (argc>1) {
     137         [ +  + ]:        427 :     for (auto i=1; i<argc-1; ++i) {
     138 [ +  - ][ +  - ]:        329 :       print << std::string( argv[i] ) + ' ';
                 [ +  - ]
     139                 :            :     }
     140 [ +  - ][ +  - ]:         98 :     print << std::string( argv[argc-1] );
     141                 :            :   }
     142                 :         98 :   print << "'\n";
     143                 :            : 
     144 [ +  - ][ +  - ]:         98 :   print.item( "Screen output, -" + *kw::verbose::alias(),
     145 [ +  - ][ +  - ]:         98 :               verbose ? "verbose" : "quiet" );
     146 [ +  - ][ +  - ]:         98 :   print.item( "Screen output log file, -" + *kw::screen::alias(), screen_log );
     147 [ +  - ][ +  - ]:         98 :   print.item( "Input log file", input_log );
     148         [ +  - ]:         98 :   print.item( "Number of processing elements",
     149 [ +  - ][ +  - ]:        196 :               std::to_string( CkNumPes() ) + " (" +
     150 [ +  - ][ +  - ]:        392 :               std::to_string( CkNumNodes() ) + 'x' +
                 [ +  - ]
     151 [ +  - ][ +  - ]:        392 :               std::to_string( CkNumPes()/CkNumNodes() ) + ')' );
                 [ +  - ]
     152 [ +  - ][ +  - ]:         98 :   print.item( "Quiescence detection, -" + *kw::quiescence::alias(),
     153 [ +  + ][ +  - ]:         98 :               quiescence ? "on" : "off" );
     154 [ +  - ][ +  - ]:         98 :   print.item( "Chare state output, -" + *kw::charestate::alias(),
     155 [ -  + ][ +  - ]:         98 :               charestate ? "on" : "off" );
     156 [ +  - ][ +  - ]:         98 :   print.item( "Call and stack trace, -" + *kw::trace::alias(),
     157 [ +  - ][ +  - ]:         98 :               trace ? "on" : "off" );
     158                 :         98 : }
     159                 :            : 
     160                 :            : } // tk::

Generated by: LCOV version 1.14