From: David van Moolenbroek Date: Fri, 11 Oct 2013 10:01:37 +0000 (+0200) Subject: test75: fix child run time check bug X-Git-Tag: v3.3.0~750 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/syslog.conf.5.html?a=commitdiff_plain;h=refs%2Fchanges%2F34%2F1034%2F2;p=minix.git test75: fix child run time check bug Change-Id: Ieb071f01bfd5a07093868e5dbfc7d941f435bf20 --- diff --git a/test/test75.c b/test/test75.c index 88c4c6d72..dd8b88629 100644 --- a/test/test75.c +++ b/test/test75.c @@ -24,7 +24,8 @@ em(1, #field " of " #rusage1 " doesn't equal to " \ #field " of " #rusage2); -static void spin() +static void +spin(void) { struct timeval start_time; struct timeval end_time; @@ -33,7 +34,7 @@ static void spin() e(1); exit(1); } - memset(&end_time, 0, sizeof(end_time)); + end_time = start_time; do { if ((++loop % 3000000000) == 0) { if (gettimeofday(&end_time, NULL) == -1) { @@ -74,8 +75,6 @@ main(int argc, char *argv[]) e(1); exit(1); } - CHECK_ZERO_FIELD(r_usage2, ru_utime.tv_sec); - CHECK_ZERO_FIELD(r_usage2, ru_utime.tv_usec); CHECK_NOT_ZERO_FIELD(r_usage2, ru_maxrss); CHECK_NOT_ZERO_FIELD(r_usage2, ru_ixrss); CHECK_NOT_ZERO_FIELD(r_usage2, ru_idrss); @@ -83,7 +82,20 @@ main(int argc, char *argv[]) CHECK_EQUAL_FIELD(r_usage1, r_usage2, ru_ixrss); CHECK_EQUAL_FIELD(r_usage1, r_usage2, ru_idrss); CHECK_EQUAL_FIELD(r_usage1, r_usage2, ru_isrss); - if ((child = fork()) != 0) { + if ((child = fork()) == 0) { + /* + * We cannot do this part of the test in the parent, since + * start() calls system() which spawns a child process. + */ + if (getrusage(RUSAGE_CHILDREN, &r_usage1) != 0) { + e(1); + exit(1); + } + CHECK_ZERO_FIELD(r_usage1, ru_utime.tv_sec); + CHECK_ZERO_FIELD(r_usage1, ru_utime.tv_usec); + spin(); + exit(0); + } else { if (child != waitpid(child, &status, 0)) { e(1); exit(1); @@ -104,9 +116,6 @@ main(int argc, char *argv[]) CHECK_EQUAL_FIELD(r_usage1, r_usage3, ru_ixrss); CHECK_EQUAL_FIELD(r_usage1, r_usage3, ru_idrss); CHECK_EQUAL_FIELD(r_usage1, r_usage3, ru_isrss); - } else { - spin(); - exit(0); } quit();