|
Packit |
6c4009 |
/* Main function for test programs.
|
|
Packit |
6c4009 |
Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This file should be included from test cases. It will define a
|
|
Packit |
6c4009 |
main function which provides the test wrapper.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
It assumes that the test case defines a function
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int do_test (void);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
and arranges for that function being called under the test wrapper.
|
|
Packit |
6c4009 |
The do_test function should return 0 to indicate a passing test, 1
|
|
Packit |
6c4009 |
to indicate a failing test, or 77 to indicate an unsupported test.
|
|
Packit |
6c4009 |
Other result values could be used to indicate a failing test, but
|
|
Packit |
6c4009 |
the result of the expression is passed to exit and exit only
|
|
Packit |
6c4009 |
returns the lower 8 bits of its input. A non-zero return with some
|
|
Packit |
6c4009 |
values could cause a test to incorrectly be considered passing when
|
|
Packit |
6c4009 |
it really failed. For this reason, the function should always
|
|
Packit |
6c4009 |
return 0 (EXIT_SUCCESS), 1 (EXIT_FAILURE), or 77
|
|
Packit |
6c4009 |
(EXIT_UNSUPPORTED).
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The test function may print out diagnostic or warning messages as well
|
|
Packit |
6c4009 |
as messages about failures. These messages should be printed to stdout
|
|
Packit |
6c4009 |
and not stderr so that the output is properly ordered with respect to
|
|
Packit |
6c4009 |
the rest of the glibc testsuite run output.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Several preprocessors macros can be defined before including this
|
|
Packit |
6c4009 |
file.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The name of the do_test function can be changed with the
|
|
Packit |
6c4009 |
TEST_FUNCTION macro. It must expand to the desired function name.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If the test case needs access to command line parameters, it must
|
|
Packit |
6c4009 |
define the TEST_FUNCTION_ARGV macro with the name of the test
|
|
Packit |
6c4009 |
function. It must have the following type:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int TEST_FUNCTION_ARGV (int argc, char **argv);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This overrides the do_test default function and is incompatible
|
|
Packit |
6c4009 |
with the TEST_FUNCTION macro.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If PREPARE is defined, it must expand to the name of a function of
|
|
Packit |
6c4009 |
the type
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void PREPARE (int argc, char **);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This function will be called early, after parsing the command line,
|
|
Packit |
6c4009 |
but before running the test, in the parent process which acts as
|
|
Packit |
6c4009 |
the test supervisor.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If CLEANUP_HANDLER is defined, it must expand to the name of a
|
|
Packit |
6c4009 |
function of the type
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void CLEANUP_HANDLER (void);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This function will be called from the timeout (SIGALRM) signal
|
|
Packit |
6c4009 |
handler.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If EXPECTED_SIGNAL is defined, it must expanded to a constant which
|
|
Packit |
6c4009 |
denotes the expected signal number.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If EXPECTED_STATUS is defined, it must expand to the expected exit
|
|
Packit |
6c4009 |
status.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If TIMEOUT is defined, it must be positive constant. It overrides
|
|
Packit |
6c4009 |
the default test timeout and is measured in seconds.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If TEST_NO_MALLOPT is defined, the test wrapper will not call
|
|
Packit |
6c4009 |
mallopt.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Custom command line handling can be implemented by defining the
|
|
Packit |
6c4009 |
CMDLINE_OPTION macro (after including the <getopt.h> header; this
|
|
Packit |
6c4009 |
requires _GNU_SOURCE to be defined). This macro must expand to a
|
|
Packit |
6c4009 |
to a comma-separated list of braced initializers for struct option
|
|
Packit |
6c4009 |
from <getopt.h>, with a trailing comma. CMDLINE_PROCESS can be
|
|
Packit |
6c4009 |
defined as the name of a function which is called to process these
|
|
Packit |
6c4009 |
options. The function is passed the option character/number and
|
|
Packit |
6c4009 |
has this type:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void CMDLINE_PROCESS (int);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If the program also to process custom default short command line
|
|
Packit |
6c4009 |
argument (similar to getopt) it must define CMDLINE_OPTSTRING
|
|
Packit |
6c4009 |
with the expected options (for instance "vb").
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
main (int argc, char **argv)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct test_config test_config;
|
|
Packit |
6c4009 |
memset (&test_config, 0, sizeof (test_config));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef PREPARE
|
|
Packit |
6c4009 |
test_config.prepare_function = (PREPARE);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined (TEST_FUNCTION) && defined (TEST_FUNCTON_ARGV)
|
|
Packit |
6c4009 |
# error TEST_FUNCTION and TEST_FUNCTION_ARGV cannot be defined at the same time
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#if defined (TEST_FUNCTION)
|
|
Packit |
6c4009 |
test_config.test_function = TEST_FUNCTION;
|
|
Packit |
6c4009 |
#elif defined (TEST_FUNCTION_ARGV)
|
|
Packit |
6c4009 |
test_config.test_function_argv = TEST_FUNCTION_ARGV;
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
test_config.test_function = do_test;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef CLEANUP_HANDLER
|
|
Packit |
6c4009 |
test_config.cleanup_function = CLEANUP_HANDLER;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef EXPECTED_SIGNAL
|
|
Packit |
6c4009 |
test_config.expected_signal = (EXPECTED_SIGNAL);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef EXPECTED_STATUS
|
|
Packit |
6c4009 |
test_config.expected_status = (EXPECTED_STATUS);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef TEST_NO_MALLOPT
|
|
Packit |
6c4009 |
test_config.no_mallopt = 1;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef TEST_NO_SETVBUF
|
|
Packit |
6c4009 |
test_config.no_setvbuf = 1;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef TIMEOUT
|
|
Packit |
6c4009 |
test_config.timeout = TIMEOUT;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef CMDLINE_OPTIONS
|
|
Packit |
6c4009 |
struct option options[] =
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
CMDLINE_OPTIONS
|
|
Packit |
6c4009 |
TEST_DEFAULT_OPTIONS
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
test_config.options = &options;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#ifdef CMDLINE_PROCESS
|
|
Packit |
6c4009 |
test_config.cmdline_function = CMDLINE_PROCESS;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#ifdef CMDLINE_OPTSTRING
|
|
Packit |
6c4009 |
test_config.optstring = "+" CMDLINE_OPTSTRING;
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
test_config.optstring = "+";
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return support_test_main (argc, argv, &test_config);
|
|
Packit |
6c4009 |
}
|