update NEWS.stable
[gnulib.git] / tests / test-get-rusage-data.c
1 /* Test of getter for RLIMIT_DATA.
2    Copyright (C) 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program 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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #include <config.h>
18
19 #include "resource-ext.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "macros.h"
25
26 int
27 main ()
28 {
29   uintptr_t value1, value2, value3;
30
31   value1 = get_rusage_data ();
32
33   malloc (0x88);
34
35   value2 = get_rusage_data ();
36
37   malloc (0x281237);
38
39   value3 = get_rusage_data ();
40
41   if (value1 == 0 && value2 == 0 && value3 == 0)
42     {
43       fprintf (stderr, "Skipping test: no way to determine data segment size\n");
44       return 77;
45     }
46   else
47     {
48       /* The data segment size is positive, except possibly at the beginning.  */
49       ASSERT (value2 > 0);
50
51       /* Allocating memory should not decrease the data segment size.  */
52       ASSERT (value2 >= value1);
53       ASSERT (value3 >= value2);
54
55 #if !((defined __APPLE__ && defined __MACH__) || defined __OpenBSD__ || (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__)
56       /* Allocating 2.5 MB of memory should increase the data segment size.  */
57       ASSERT (value3 > value1);
58 #endif
59
60       return 0;
61     }
62 }