Mercurial > gnulib
annotate tests/test-fprintf-posix2.c @ 19484:10eb9086bea0
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 01 Jan 2018 00:57:25 +0000 |
parents | 9759915b2aca |
children | b06060465f09 |
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. |
19484
10eb9086bea0
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
2 Copyright (C) 2007, 2009-2018 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 | 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 |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stdlib.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include <sys/types.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include <sys/time.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 #include <sys/resource.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #include <string.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 #include <errno.h> |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 int |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 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
|
34 { |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 struct rlimit limit; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 int arg; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 int ret; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 /* 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
|
40 /* 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
|
41 #ifdef RLIMIT_DATA |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 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
|
43 return 77; |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 return 77; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 #endif |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 /* 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
|
51 #ifdef RLIMIT_AS |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 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
|
53 return 77; |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 return 77; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 #endif |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 /* 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
|
61 #ifdef RLIMIT_STACK |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 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
|
63 return 77; |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 return 77; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 #endif |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 arg = atoi (argv[1]); |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 switch (arg) |
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 case 0: |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 { |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
76 void *memory = malloc (10000000); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9443
diff
changeset
|
77 if (memory == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9443
diff
changeset
|
78 return 1; |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
79 memset (memory, 17, 10000000); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9443
diff
changeset
|
80 return 78; |
9443
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 } |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 case 1: |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
83 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
|
84 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
|
85 case 2: |
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 == 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
|
88 case 3: |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
89 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
|
90 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
|
91 case 4: |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
92 ret = fprintf (stdout, "%.10000000d", 1); |
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
93 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
|
94 case 5: |
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 == 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
|
97 case 6: |
18927
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
98 ret = fprintf (stdout, "%.10000000u", 1); |
f45a6a56da4e
printf-posix tests: Avoid test failure with "gcc --coverage".
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
99 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
|
100 } |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 return 0; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 } |
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 #else |
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 int |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 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
|
108 { |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 return 77; |
1df2e8a2fa66
New tests for modules 'test-fprintf-posix' and 'test-printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 } |
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 #endif |