S390: Move utf8-utf32-z9.c to multiarch folder and use s390_libc_ifunc_expr macro.
[glibc.git] / support / test-driver.c
blob482066dbeb326bb2b6518649128017e8be3b36e9
1 /* Main function for test programs.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* This file should be included from test cases. It will define a
20 main function which provides the test wrapper.
22 It assumes that the test case defines a function
24 int do_test (void);
26 and arranges for that function being called under the test wrapper.
27 The do_test function should return 0 to indicate a passing test, 1
28 to indicate a failing test, or 77 to indicate an unsupported test.
29 Other result values could be used to indicate a failing test, but
30 the result of the expression is passed to exit and exit only
31 returns the lower 8 bits of its input. A non-zero return with some
32 values could cause a test to incorrectly be considered passing when
33 it really failed. For this reason, the function should always
34 return 0 (EXIT_SUCCESS), 1 (EXIT_FAILURE), or 77
35 (EXIT_UNSUPPORTED).
37 The test function may print out diagnostic or warning messages as well
38 as messages about failures. These messages should be printed to stdout
39 and not stderr so that the output is properly ordered with respect to
40 the rest of the glibc testsuite run output.
42 Several preprocessors macros can be defined before including this
43 file.
45 The name of the do_test function can be changed with the
46 TEST_FUNCTION macro. It must expand to the desired function name.
48 If the test case needs access to command line parameters, it must
49 define the TEST_FUNCTION_ARGV macro with the name of the test
50 function. It must have the following type:
52 int TEST_FUNCTION_ARGV (int argc, char **argv);
54 This overrides the do_test default function and is incompatible
55 with the TEST_FUNCTION macro.
57 If PREPARE is defined, it must expand to the name of a function of
58 the type
60 void PREPARE (int argc, char **);
62 This function will be called early, after parsing the command line,
63 but before running the test, in the parent process which acts as
64 the test supervisor.
66 If CLEANUP_HANDLER is defined, it must expand to the name of a
67 function of the type
69 void CLEANUP_HANDLER (void);
71 This function will be called from the timeout (SIGALRM) signal
72 handler.
74 If EXPECTED_SIGNAL is defined, it must expanded to a constant which
75 denotes the expected signal number.
77 If EXPECTED_STATUS is defined, it must expand to the expected exit
78 status.
80 If TIMEOUT is defined, it must be positive constant. It overrides
81 the default test timeout and is measured in seconds.
83 If TEST_NO_MALLOPT is defined, the test wrapper will not call
84 mallopt.
86 Custom command line handling can be implemented by defining the
87 CMDLINE_OPTION macro (after including the <getopt.h> header; this
88 requires _GNU_SOURCE to be defined). This macro must expand to a
89 to a comma-separated list of braced initializers for struct option
90 from <getopt.h>, with a trailing comma. CMDLINE_PROCESS can be
91 defined as the name of a function which is called to process these
92 options. The function is passed the option character/number and
93 has this type:
95 void CMDLINE_PROCESS (int);
98 #include <support/test-driver.h>
100 #include <string.h>
103 main (int argc, char **argv)
105 struct test_config test_config;
106 memset (&test_config, 0, sizeof (test_config));
108 #ifdef PREPARE
109 test_config.prepare_function = (PREPARE);
110 #endif
112 #if defined (TEST_FUNCTION) && defined (TEST_FUNCTON_ARGV)
113 # error TEST_FUNCTION and TEST_FUNCTION_ARGV cannot be defined at the same time
114 #endif
115 #if defined (TEST_FUNCTION)
116 test_config.test_function = TEST_FUNCTION;
117 #elif defined (TEST_FUNCTION_ARGV)
118 test_config.test_function_argv = TEST_FUNCTION_ARGV;
119 #else
120 test_config.test_function = do_test;
121 #endif
123 #ifdef CLEANUP_HANDLER
124 test_config.cleanup_function = CLEANUP_HANDLER;
125 #endif
127 #ifdef EXPECTED_SIGNAL
128 test_config.expected_signal = (EXPECTED_SIGNAL);
129 #endif
131 #ifdef EXPECTED_STATUS
132 test_config.expected_status = (EXPECTED_STATUS);
133 #endif
135 #ifdef TEST_NO_MALLOPT
136 test_config.no_mallopt = 1;
137 #endif
139 #ifdef TIMEOUT
140 test_config.timeout = TIMEOUT;
141 #endif
143 #ifdef CMDLINE_OPTIONS
144 struct option options[] =
146 CMDLINE_OPTIONS
147 TEST_DEFAULT_OPTIONS
149 test_config.options = &options;
150 #endif
151 #ifdef CMDLINE_PROCESS
152 test_config.cmdline_function = CMDLINE_PROCESS;
153 #endif
155 return support_test_main (argc, argv, &test_config);