Mark mtrace tests UNSUPPORTED if bug-ga2.mtrace or tst-leaks2.mtrace are missing
[glibc.git] / malloc / tst-mcheck.c
blob85bb41acb46bdb5b8d76299ae4c05ed6efdfeaa8
1 /* Copyright (C) 2005-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
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 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <libc-diag.h>
24 static int errors = 0;
26 static void
27 merror (const char *msg)
29 ++errors;
30 printf ("Error: %s\n", msg);
33 static int
34 do_test (void)
36 void *p, *q;
38 errno = 0;
40 DIAG_PUSH_NEEDS_COMMENT;
41 #if __GNUC_PREREQ (7, 0)
42 /* GCC 7 warns about too-large allocations; here we want to test
43 that they fail. */
44 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
45 #endif
46 p = malloc (-1);
47 DIAG_POP_NEEDS_COMMENT;
49 if (p != NULL)
50 merror ("malloc (-1) succeeded.");
51 else if (errno != ENOMEM)
52 merror ("errno is not set correctly.");
54 p = malloc (10);
55 if (p == NULL)
56 merror ("malloc (10) failed.");
58 p = realloc (p, 0);
59 if (p != NULL)
60 merror ("realloc (p, 0) failed.");
62 p = malloc (0);
63 if (p == NULL)
64 merror ("malloc (0) failed.");
66 p = realloc (p, 0);
67 if (p != NULL)
68 merror ("realloc (p, 0) failed.");
70 q = malloc (256);
71 if (q == NULL)
72 merror ("malloc (256) failed.");
74 p = malloc (512);
75 if (p == NULL)
76 merror ("malloc (512) failed.");
78 DIAG_PUSH_NEEDS_COMMENT;
79 #if __GNUC_PREREQ (7, 0)
80 /* GCC 7 warns about too-large allocations; here we want to test
81 that they fail. */
82 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
83 #endif
84 if (realloc (p, -256) != NULL)
85 merror ("realloc (p, -256) succeeded.");
86 else if (errno != ENOMEM)
87 merror ("errno is not set correctly.");
88 DIAG_POP_NEEDS_COMMENT;
90 free (p);
92 p = malloc (512);
93 if (p == NULL)
94 merror ("malloc (512) failed.");
96 DIAG_PUSH_NEEDS_COMMENT;
97 #if __GNUC_PREREQ (7, 0)
98 /* GCC 7 warns about too-large allocations; here we want to test
99 that they fail. */
100 DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
101 #endif
102 if (realloc (p, -1) != NULL)
103 merror ("realloc (p, -1) succeeded.");
104 else if (errno != ENOMEM)
105 merror ("errno is not set correctly.");
106 DIAG_POP_NEEDS_COMMENT;
108 free (p);
109 free (q);
111 return errors != 0;
114 #define TEST_FUNCTION do_test ()
115 #include "../test-skeleton.c"