Blame support/test-driver.c

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