1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* libstatgrab
* https://libstatgrab.org
* Copyright (C) 2003-2004 Peter Saunders
* Copyright (C) 2003-2019 Tim Bishop
* Copyright (C) 2003-2013 Adam Sampson
* Copyright (C) 2012-2019 Jens Rehsack
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <tools.h>
#include <testlib.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(WITH_LIBLOG4CPLUS)
#include <log4cplus/clogger.h>
#endif
#define NLOOPS 1
struct opt_def opt_def[] = {
#define OPT_HLP 0
{ 'h', opt_flag, { 0 } }, /* help */
#define OPT_LIST 1
{ 'l', opt_flag, { 0 } }, /* list */
#define OPT_RUN 2
{ 'r', opt_str, { 0 } }, /* run */
#define OPT_NLOOPS 3
{ 'n', opt_unsigned, { NLOOPS } }, /* num-loops */
{ 0, opt_flag, { 0 } }
};
void
help(char *prgname) {
printf( "%s -h|-l|-r <test list> [options]\n"
"\t-h\tshow help\n"
"\t-l\tlist available test functions\n"
"\t-r\trun specified list of test calls (comma separated list\n"
"\t\tof test functions from the list showed by -l)\n"
"\t-n\tnumber of loops to run (must be greater or equal to 1)\n", prgname );
}
#ifdef HAVE_LOG4CPLUS_INITIALIZE
static void *l4cplus_initializer;
static void
cleanup_logging(void)
{
log4cplus_deinitialize(l4cplus_initializer);
}
#endif
int
main(int argc, char **argv) {
#ifdef HAVE_LOG4CPLUS_INITIALIZE
l4cplus_initializer = log4cplus_initialize();
atexit((void (*)(void))cleanup_logging);
#endif
sg_log_init("libstatgrab-test", "SGTEST_LOG_PROPERTIES", argc ? argv[0] : NULL);
sg_init(1);
if( 0 != get_params( opt_def, argc, argv ) ) {
help(argv[0]);
return 1;
}
if( opt_def[OPT_HLP].optarg.b ) {
help(argv[0]);
return 0;
}
else if( opt_def[OPT_LIST].optarg.b ) {
print_testable_functions(0);
return 0;
}
else if( opt_def[OPT_RUN].optarg.str ) {
size_t *test_routines = NULL;
size_t entries = funcnames_to_indices(opt_def[OPT_RUN].optarg.str, &test_routines, 0);
int errors = 0;
if( 0 == entries ) {
die( ESRCH, "no functions to test" );
return 255;
}
while( opt_def[OPT_NLOOPS].optarg.u-- > 0 ) {
size_t func_rel_idx;
for( func_rel_idx = 0; func_rel_idx < entries; ++func_rel_idx ) {
mark_func(test_routines[func_rel_idx]);
if( !run_func( test_routines[func_rel_idx], 0 ) ) {
done_func(test_routines[func_rel_idx], 0);
++errors;
}
else {
done_func(test_routines[func_rel_idx], 1);
}
}
}
(void)report_testable_functions(0);
free(test_routines);
return errors;
}
help(argv[0]);
return 1;
}
|