This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <stdio.h>
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <errno.h>
27
28 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT
29 # include <sys/types.h>
30 # include <sys/time.h>
31 # include <sys/resource.h>
32 #endif
33
34 #include "qemu.h"
35 #include "resource-ext.h"
36
37
38
39
40 #define NUM_ROUNDS 1000
41
42
43 #define MAX_ALLOC_ROUND 10000
44
45
46
47
48 #define MAX_ALLOC_TOTAL (NUM_ROUNDS * MAX_ALLOC_ROUND)
49
50 int
51 main (int argc, char *argv[])
52 {
53 uintptr_t initial_rusage_as;
54 int arg;
55 int result;
56
57 if (is_running_under_qemu_user ())
58 {
59 fprintf (stderr, "Skipping test: cannot trust address space size when running under QEMU\n");
60 return 79;
61 }
62
63
64
65
66 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT && defined RLIMIT_DATA
67 {
68 struct rlimit limit;
69
70 if (getrlimit (RLIMIT_DATA, &limit) >= 0)
71 {
72 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > MAX_ALLOC_TOTAL)
73 limit.rlim_max = MAX_ALLOC_TOTAL;
74 limit.rlim_cur = limit.rlim_max;
75 (void) setrlimit (RLIMIT_DATA, &limit);
76 }
77 }
78 #endif
79
80
81
82 initial_rusage_as = get_rusage_as ();
83 #if !defined _AIX
84 if (initial_rusage_as == 0)
85 return 77;
86 #endif
87
88 arg = atoi (argv[1]);
89 if (arg == 0)
90 {
91 void *memory = malloc (MAX_ALLOC_TOTAL);
92 if (memory == NULL)
93 return 1;
94 memset (memory, 17, MAX_ALLOC_TOTAL);
95 result = 80;
96 }
97 else
98 {
99
100
101 int repeat;
102
103 for (repeat = 0; repeat < NUM_ROUNDS; repeat++)
104 {
105
106
107 if (dprintf (STDOUT_FILENO, "%011000d\n", 17) == -1
108 && errno == ENOMEM)
109 return 1;
110 }
111
112 result = 0;
113 }
114
115 if (get_rusage_as () > initial_rusage_as + MAX_ALLOC_TOTAL)
116 return 1;
117
118 return result;
119 }