1 /* Test 75 - getrusage functionality test.
4 #include <sys/resource.h>
14 #define CHECK_ZERO_FIELD(rusage, field) \
15 if (rusage.field != 0) \
16 em(1, #field " must be zero");
18 #define CHECK_NOT_ZERO_FIELD(rusage, field) \
19 if (rusage.field == 0) \
20 em(1, #field " can't be zero");
22 #define CHECK_EQUAL_FIELD(rusage1, rusage2, field) \
23 if (rusage1.field != rusage2.field) \
24 em(1, #field " of " #rusage1 " doesn't equal to " \
25 #field " of " #rusage2);
30 struct timeval start_time
;
31 struct timeval end_time
;
32 unsigned int loop
= 0;
33 if (gettimeofday(&start_time
, NULL
) == -1) {
37 end_time
= start_time
;
39 if ((++loop
% 3000000000) == 0) {
40 if (gettimeofday(&end_time
, NULL
) == -1) {
45 } while (start_time
.tv_sec
+ 10 > end_time
.tv_sec
);
49 main(int argc
, char *argv
[])
51 struct rusage r_usage1
;
52 struct rusage r_usage2
;
53 struct rusage r_usage3
;
57 if ((getrusage(RUSAGE_SELF
+ 1, &r_usage1
) != -1 || errno
!= EINVAL
) ||
58 (getrusage(RUSAGE_CHILDREN
- 1, &r_usage1
) != -1 ||
59 errno
!= EINVAL
) || (getrusage(RUSAGE_SELF
, NULL
) != -1 ||
65 if (getrusage(RUSAGE_SELF
, &r_usage1
) != 0) {
69 CHECK_NOT_ZERO_FIELD(r_usage1
, ru_utime
.tv_sec
);
70 CHECK_NOT_ZERO_FIELD(r_usage1
, ru_maxrss
);
71 CHECK_NOT_ZERO_FIELD(r_usage1
, ru_ixrss
);
72 CHECK_NOT_ZERO_FIELD(r_usage1
, ru_idrss
);
73 CHECK_NOT_ZERO_FIELD(r_usage1
, ru_isrss
);
74 if (getrusage(RUSAGE_CHILDREN
, &r_usage2
) != 0) {
78 CHECK_NOT_ZERO_FIELD(r_usage2
, ru_maxrss
);
79 CHECK_NOT_ZERO_FIELD(r_usage2
, ru_ixrss
);
80 CHECK_NOT_ZERO_FIELD(r_usage2
, ru_idrss
);
81 CHECK_NOT_ZERO_FIELD(r_usage2
, ru_isrss
);
82 CHECK_EQUAL_FIELD(r_usage1
, r_usage2
, ru_ixrss
);
83 CHECK_EQUAL_FIELD(r_usage1
, r_usage2
, ru_idrss
);
84 CHECK_EQUAL_FIELD(r_usage1
, r_usage2
, ru_isrss
);
85 if ((child
= fork()) == 0) {
87 * We cannot do this part of the test in the parent, since
88 * start() calls system() which spawns a child process.
90 if (getrusage(RUSAGE_CHILDREN
, &r_usage1
) != 0) {
94 CHECK_ZERO_FIELD(r_usage1
, ru_utime
.tv_sec
);
95 CHECK_ZERO_FIELD(r_usage1
, ru_utime
.tv_usec
);
99 if (child
!= waitpid(child
, &status
, 0)) {
103 if (WEXITSTATUS(status
) != 0) {
107 if (getrusage(RUSAGE_CHILDREN
, &r_usage3
) != 0) {
111 CHECK_NOT_ZERO_FIELD(r_usage3
, ru_utime
.tv_sec
);
112 CHECK_NOT_ZERO_FIELD(r_usage3
, ru_maxrss
);
113 CHECK_NOT_ZERO_FIELD(r_usage3
, ru_ixrss
);
114 CHECK_NOT_ZERO_FIELD(r_usage3
, ru_idrss
);
115 CHECK_NOT_ZERO_FIELD(r_usage3
, ru_isrss
);
116 CHECK_EQUAL_FIELD(r_usage1
, r_usage3
, ru_ixrss
);
117 CHECK_EQUAL_FIELD(r_usage1
, r_usage3
, ru_idrss
);
118 CHECK_EQUAL_FIELD(r_usage1
, r_usage3
, ru_isrss
);