| 1 | /* Test of getter for RLIMIT_AS. |
| 2 | Copyright (C) 2011-2020 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 <https://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 | void *memchunk1; |
| 27 | void *memchunk2; |
| 28 | |
| 29 | int |
| 30 | main () |
| 31 | { |
| 32 | uintptr_t value1, value2, value3; |
| 33 | |
| 34 | value1 = get_rusage_as (); |
| 35 | |
| 36 | memchunk1 = malloc (0x88); |
| 37 | |
| 38 | value2 = get_rusage_as (); |
| 39 | |
| 40 | memchunk2 = malloc (0x281237); |
| 41 | |
| 42 | value3 = get_rusage_as (); |
| 43 | |
| 44 | if (value1 == 0 && value2 == 0 && value3 == 0) |
| 45 | { |
| 46 | fprintf (stderr, "Skipping test: no way to determine address space size\n"); |
| 47 | return 77; |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | /* The address space size is positive. */ |
| 52 | ASSERT (value1 > 0); |
| 53 | |
| 54 | /* Allocating memory should not decrease the address space size. */ |
| 55 | ASSERT (value2 >= value1); |
| 56 | ASSERT (value3 >= value2); |
| 57 | |
| 58 | /* Allocating 2.5 MB of memory should increase the address space size. */ |
| 59 | ASSERT (value3 > value1); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | } |