usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-execinfo.c
blobad9ac180e6a4a142f3b56fab576d1fc8b310701b
1 /* Test that execinfo.h defines stub functions.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Collin Funk <collin.funk1@gmail.com>, 2024. */
19 #include <config.h>
21 /* Specification. */
22 #include <execinfo.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "macros.h"
29 static void
30 test_backtrace (int pass)
32 void *buffer[10];
33 int max_size;
34 int size;
35 char **symbols;
37 max_size = (pass == 0 ? SIZEOF (buffer) : 1);
38 size = backtrace (buffer, max_size);
39 ASSERT (size >= 0 && size <= max_size);
41 /* Print the backtrace to a file descriptor. */
42 backtrace_symbols_fd (buffer, size, 1);
43 printf ("\n");
45 symbols = backtrace_symbols (buffer, size);
46 if (size > 0)
47 /* We have enough memory available. */
48 ASSERT (symbols != NULL);
50 /* Print the backtrace if possible. */
51 if (symbols != NULL)
53 for (int i = 0; i < size; ++i)
54 printf ("%s\n", symbols[i]);
55 free (symbols);
59 int
60 main (void)
62 printf ("Full stack trace:\n"); fflush (stdout);
63 test_backtrace (0);
64 printf ("\nTruncated stack trace:\n"); fflush (stdout);
65 test_backtrace (1);
67 return test_exit_status;