Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Control/UnitTestConfig.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.,
7 : : 2022-2025 J. Bakosi
8 : : All rights reserved. See the LICENSE file for details.
9 : : \brief UnitTest's command line
10 : : */
11 : : // *****************************************************************************
12 : : #pragma once
13 : :
14 : : #include <getopt.h>
15 : :
16 : : #include "NoWarning/charm++.hpp"
17 : :
18 : : #include "XystConfig.hpp"
19 : : #include "Exception.hpp"
20 : : #include "Print.hpp"
21 : : #include "TaggedTuple.hpp"
22 : : #include "PrintTaggedTupleDeep.hpp"
23 : : #include "Writer.hpp"
24 : :
25 : : namespace tag {
26 : 2 : DEFTAG( group );
27 : 2 : DEFTAG( quiescence );
28 : : } // tag::
29 : :
30 : : namespace unittest {
31 : : //! UnitTest control facilitating user input to internal data transfer
32 : : namespace ctr {
33 : :
34 : : //! Member data for tagged tuple
35 : : using ConfigMembers = brigand::list<
36 : : tag::group, std::string // groups to test
37 : : , tag::quiescence, bool // enable quiescence detection
38 : : >;
39 : :
40 : : //! Config is a TaggedTuple specialized to MeshConv
41 : : class Config : public tk::TaggedTuple< ConfigMembers > {
42 : :
43 : : public:
44 : : //! Parse unittest command line
45 : 4 : void cmdline( int argc, char** argv ) {
46 : 4 : tk::Print print;
47 : :
48 : : // Process command line arguments
49 : : int c;
50 [ + + ]: 6 : while ((c = getopt( argc, argv, "h?g:qv" )) != -1) {
51 [ + + ][ + + ]: 4 : switch (c) {
52 : 1 : case '?':
53 : : case 'h':
54 : : default:
55 [ + - ]: 1 : help( argv );
56 [ - - ]: 1 : CkExit();
57 : 0 : break;
58 : 1 : case 'g':
59 [ + - ]: 1 : get< tag::group >() = optarg;
60 : 1 : break;
61 : 1 : case 'q':
62 : 1 : get< tag::quiescence >() = true;
63 : 1 : break;
64 : 1 : case 'v':
65 [ + - ]: 1 : print << '\n';
66 [ + - ][ + - ]: 1 : print.version( tk::unittest_executable(), tk::git_commit() );
[ + - ]
67 [ - - ]: 1 : CkExit();
68 : 0 : break;
69 : : }
70 : : }
71 : :
72 [ - + ]: 2 : if (optind != argc) {
73 [ - - ]: 0 : print << "\nA non-option was supplied";
74 [ - - ]: 0 : help( argv );
75 [ - - ]: 0 : CkExit( EXIT_FAILURE );
76 : : }
77 : :
78 : : // Output state to file
79 [ + - ][ + - ]: 2 : auto logfilename = tk::unittest_executable() + "_cmdline.log";
80 [ + - ]: 4 : tk::Writer log( logfilename );
81 [ + - ]: 2 : tk::print( log.stream(), *this );
82 : 2 : }
83 : :
84 : : //! Print help
85 : 1 : void help( char** argv ) {
86 : 1 : tk::Print() <<
87 : : "\nUsage: " << argv[0] << " [OPTION]...\n"
88 : : "\n"
89 : : " -h, -? Print out this help\n"
90 : : " -g <group> Select test-group to run\n"
91 : : " -q Enable quiescence detection\n"
92 : : " -v Print revision information\n"
93 [ + - ][ + - ]: 1 : "\n";
[ + - ]
94 : 1 : }
95 : :
96 : : /** @name Pack/Unpack: Serialize Config object for Charm++ */
97 : : ///@{
98 : : //! \brief Pack/Unpack serialize member function
99 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
100 : : void pup( PUP::er& p ) { tk::TaggedTuple< ConfigMembers >::pup(p); }
101 : : //! \brief Pack/Unpack serialize operator|
102 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
103 : : //! \param[in,out] c Config object reference
104 : : friend void operator|( PUP::er& p, Config& c ) { c.pup(p); }
105 : : //@}
106 : : };
107 : :
108 : :
109 : : } // ctr::
110 : : } // unittest::
|