Quinoa all test code coverage report
Current view: top level - Control/RNGTest/CmdLine - Parser.cpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 24 40 60.0 %
Date: 2021-11-11 18:25:50 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 150 16.7 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Control/RNGTest/CmdLine/Parser.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     RNGTest's command line parser
       9                 :            :   \details   This file defines the command-line argument parser for the random
      10                 :            :     number generator test suite, RNGTest.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : 
      14                 :            : #include "NoWarning/pegtl.hpp"
      15                 :            : #include "NoWarning/charm.hpp"
      16                 :            : 
      17                 :            : #include "QuinoaConfig.hpp"
      18                 :            : #include "Exception.hpp"
      19                 :            : #include "Print.hpp"
      20                 :            : #include "Keywords.hpp"
      21                 :            : #include "RNGTest/Types.hpp"
      22                 :            : #include "RNGTest/CmdLine/Parser.hpp"
      23                 :            : #include "RNGTest/CmdLine/Grammar.hpp"
      24                 :            : #include "RNGTest/CmdLine/CmdLine.hpp"
      25                 :            : #include "RNGTest/InputDeck/InputDeck.hpp"
      26                 :            : 
      27                 :            : namespace tk {
      28                 :            : namespace grm {
      29                 :            : 
      30                 :            : tk::Print g_print;
      31                 :            : 
      32                 :            : } // grm::
      33                 :            : } // tk::
      34                 :            : 
      35                 :            : namespace rngtest {
      36                 :            : 
      37                 :            : extern ctr::InputDeck g_inputdeck;
      38                 :            : 
      39                 :            : } // rngtest::
      40                 :            : 
      41                 :            : using rngtest::CmdLineParser;
      42                 :            : 
      43                 :          4 : CmdLineParser::CmdLineParser( int argc,
      44                 :            :                               char** argv,
      45                 :            :                               const tk::Print& print,
      46                 :          4 :                               ctr::CmdLine& cmdline ) :
      47                 :          4 :   StringParser( argc, argv )
      48                 :            : // *****************************************************************************
      49                 :            : //  Contructor: parse the command line for RNGTest
      50                 :            : //! \param[in] argc Number of C-style character arrays in argv
      51                 :            : //! \param[in] argv C-style character array of character arrays
      52                 :            : //! \param[in] print Pretty printer
      53                 :            : //! \param[in,out] cmdline Command-line stack where data is stored from parsing
      54                 :            : // *****************************************************************************
      55                 :            : {
      56                 :            :   // Create CmdLine (a tagged tuple) to store parsed input
      57 [ +  - ][ +  - ]:          8 :   ctr::CmdLine cmd( g_inputdeck.get< tag::cmd, tag::ctrinfo >() );
      58                 :            : 
      59                 :            :   // Reset parser's output stream to that of print's. This is so that mild
      60                 :            :   // warnings emitted during parsing can be output using the pretty printer.
      61                 :            :   // Usually, errors and warnings are simply accumulated during parsing and
      62                 :            :   // printed during diagnostics after the parser has finished. However, in some
      63                 :            :   // special cases we can provide a more user-friendly message right during
      64                 :            :   // parsing since there is more information available to construct a more
      65                 :            :   // sensible message. This is done in e.g., tk::grm::store_option. Resetting
      66                 :            :   // the global g_print, to that of passed in as the constructor argument allows
      67                 :            :   // not to have to create a new pretty printer, but use the existing one.
      68 [ +  - ][ +  - ]:          4 :   tk::grm::g_print.reset( print.save() );
      69                 :            : 
      70                 :            :   // Parse command line string by populating the underlying tagged tuple:
      71         [ +  - ]:          8 :   tao::pegtl::memory_input<> in( m_string, "command line" );
      72         [ +  - ]:          4 :   tao::pegtl::parse< cmd::read_string, tk::grm::action >( in, cmd );
      73                 :            : 
      74                 :            :   // Echo errors and warnings accumulated during parsing
      75         [ +  - ]:          4 :   diagnostics( print, cmd.get< tag::error >() );
      76                 :            : 
      77                 :            :   // Strip command line (and its underlying tagged tuple) from PEGTL instruments
      78                 :            :   // and transfer it out
      79                 :          4 :   cmdline = std::move( cmd );
      80                 :            : 
      81                 :            :   // If we got here, parser succeeded
      82 [ +  - ][ +  - ]:          4 :   print.item( "Parsed command line", "success" );
      83                 :            : 
      84                 :            :   // Print out help on all command-line arguments if the executable was invoked
      85                 :            :   // without arguments or the help was requested
      86                 :          4 :   const auto helpcmd = cmdline.get< tag::help >();
      87 [ +  - ][ -  + ]:          4 :   if (argc == 1 || helpcmd) {
      88 [ -  - ][ -  - ]:          0 :     print.help< tk::QUIET >( tk::rngtest_executable(),
         [ -  - ][ -  - ]
      89                 :          0 :                              cmdline.get< tag::cmdinfo >(),
      90                 :            :                              "Command-line Parameters:", "-" );
      91 [ -  - ][ -  - ]:          0 :     print.mandatory< tk::QUIET >( "The '--" + kw::control().string() +
         [ -  - ][ -  - ]
      92                 :            :                                   " <filename>' argument is mandatory." );
      93 [ -  - ][ -  - ]:          0 :     print.usage< tk::QUIET >(
      94         [ -  - ]:          0 :       tk::rngtest_executable(),
      95 [ -  - ][ -  - ]:          0 :       "charmrun +p4 " + tk::rngtest_executable() + " -" +
         [ -  - ][ -  - ]
                 [ -  - ]
      96 [ -  - ][ -  - ]:          0 :         *kw::verbose().alias() + " -" + *kw::control().alias() + " allmkl.q",
         [ -  - ][ -  - ]
      97                 :            :       "will execute the statistical tests configured in the control file "
      98                 :            :       "'allmkl.q' on 4 CPUs producing verbose screen output" );
      99                 :            :   }
     100                 :            : 
     101                 :            :   // Print out help on all control file keywords if they were requested
     102                 :          4 :   const auto helpctr = cmdline.get< tag::helpctr >();
     103         [ -  + ]:          4 :   if (helpctr)
     104 [ -  - ][ -  - ]:          0 :     print.help< tk::QUIET >( tk::rngtest_executable(),
         [ -  - ][ -  - ]
     105                 :          0 :                              cmdline.get< tag::ctrinfo >(),
     106                 :            :                              "Control File Keywords:" );
     107                 :            : 
     108                 :            :   // Print out verbose help for a single keyword if requested
     109         [ +  - ]:          8 :   const auto helpkw = cmdline.get< tag::helpkw >();
     110         [ -  + ]:          4 :   if (!helpkw.keyword.empty())
     111 [ -  - ][ -  - ]:          0 :     print.helpkw< tk::QUIET >( tk::rngtest_executable(), helpkw );
     112                 :            : 
     113                 :            :   // Print out version information if it was requested
     114                 :          4 :   const auto version = cmdline.get< tag::version >();
     115         [ -  + ]:          4 :   if (version)
     116 [ -  - ][ -  - ]:          0 :     print.version< tk::QUIET >( tk::rngtest_executable(),
     117         [ -  - ]:          0 :                                 tk::quinoa_version(),
     118         [ -  - ]:          0 :                                 tk::git_commit(),
     119         [ -  - ]:          0 :                                 tk::copyright() );
     120                 :            : 
     121                 :            :   // Print out license information if it was requested
     122                 :          4 :   const auto license = cmdline.get< tag::license >();
     123         [ -  + ]:          4 :   if (license)
     124 [ -  - ][ -  - ]:          0 :     print.license< tk::QUIET >( tk::rngtest_executable(), tk::license() );
                 [ -  - ]
     125                 :            : 
     126                 :            :   // Immediately exit if any help was output or was called without any argument
     127                 :            :   // or version or license info was requested with zero exit code
     128 [ +  - ][ +  - ]:          4 :   if (argc == 1 || helpcmd || helpctr || !helpkw.keyword.empty() || version ||
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
                 [ -  + ]
     129                 :            :       license)
     130                 :            :   {
     131         [ -  - ]:          0 :     CkExit();
     132                 :            :   }
     133                 :            : 
     134                 :            :   // Make sure mandatory arguments are set
     135         [ +  - ]:          8 :   auto alias = kw::control().alias();
     136 [ -  + ][ -  - ]:          4 :   ErrChk( !(cmdline.get< tag::io, tag::control >().empty()),
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     137                 :            :           "Mandatory control file not specified. "
     138                 :            :           "Use '--" + kw::control().string() + " <filename>'" +
     139                 :            :           ( alias ? " or '-" + *alias + " <filename>'" : "" ) + '.' );
     140                 :          4 : }

Generated by: LCOV version 1.14