annotate tests/test-fprintf-posix2.c @ 40227:5207eb0dcd2a

tests: Avoid havoc with "gcc -fcheck-pointer-bounds". * tests/test-fprintf-posix2.c: Skip the test when -fcheck-pointer-bounds is in use. * tests/test-printf-posix2.c: Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 17:09:30 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible fprintf() function.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc.
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18927
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
40227
5207eb0dcd2a tests: Avoid havoc with "gcc -fcheck-pointer-bounds".
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
23 /* This test assumes getrlimit() and setrlimit().
5207eb0dcd2a tests: Avoid havoc with "gcc -fcheck-pointer-bounds".
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
24 With "gcc -fcheck-pointer-bounds -mmpx -static", it produces an
5207eb0dcd2a tests: Avoid havoc with "gcc -fcheck-pointer-bounds".
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
25 endless loop of "Saw a #BR!" messages. */
5207eb0dcd2a tests: Avoid havoc with "gcc -fcheck-pointer-bounds".
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
26 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT && !defined __CHKP__
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <sys/types.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <sys/time.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include <sys/resource.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include <string.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include <errno.h>
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 main (int argc, char *argv[])
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 struct rlimit limit;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 int arg;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int ret;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* Some printf implementations allocate temporary space with malloc. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 #ifdef RLIMIT_DATA
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 return 77;
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
47 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 10000000)
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
48 limit.rlim_max = 10000000;
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #ifdef RLIMIT_AS
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 if (getrlimit (RLIMIT_AS, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 return 77;
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
57 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 10000000)
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
58 limit.rlim_max = 10000000;
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 if (setrlimit (RLIMIT_AS, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* Some printf implementations allocate temporary space on the stack. */
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 #ifdef RLIMIT_STACK
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 return 77;
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
67 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 10000000)
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
68 limit.rlim_max = 10000000;
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 limit.rlim_cur = limit.rlim_max;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 #endif
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 arg = atoi (argv[1]);
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 switch (arg)
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 case 0:
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 {
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
79 void *memory = malloc (10000000);
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
80 if (memory == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
81 return 1;
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
82 memset (memory, 17, 10000000);
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9443
diff changeset
83 return 78;
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 case 1:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
86 ret = fprintf (stdout, "%.10000000f", 1.0);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
87 return !(ret == 10000002 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 case 2:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
89 ret = fprintf (stdout, "%.10000000f", -1.0);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
90 return !(ret == 10000003 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 case 3:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
92 ret = fprintf (stdout, "%.10000000e", 1.0);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
93 return !(ret >= 10000006 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 case 4:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
95 ret = fprintf (stdout, "%.10000000d", 1);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
96 return !(ret == 10000000 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 case 5:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
98 ret = fprintf (stdout, "%.10000000d", -1);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
99 return !(ret == 10000001 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 case 6:
18927
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
101 ret = fprintf (stdout, "%.10000000u", 1);
f45a6a56da4e printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
102 return !(ret == 10000000 || (ret < 0 && errno == ENOMEM));
9443
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 return 0;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 #else
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 int
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 main (int argc, char *argv[])
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 {
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 return 77;
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 }
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
1df2e8a2fa66 New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 #endif