This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: rt/tst-cpuclock*.c: minor cleanups


On 2/6/2012 6:51 AM, Thomas Schwinge wrote:
> Hi!
> 
> 2012-02-06  Thomas Schwinge  <thomas@codesourcery.com>
> 
> 	* rt/tst-cpuclock1.c: Add a few comments, and error checking for
> 	nanosleep invocations.
> 	* rt/tst-cpuclock2.c: Print the values as intended.
> 
> Index: rt/tst-cpuclock1.c
> ===================================================================
> --- rt/tst-cpuclock1.c	(revision 355696)
> +++ rt/tst-cpuclock1.c	(working copy)
> @@ -1,5 +1,5 @@
>  /* Test program for process CPU clocks.
> -   Copyright (C) 2004 Free Software Foundation, Inc.
> +   Copyright (C) 2004, 2012 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
>     The GNU C Library is free software; you can redistribute it and/or
> @@ -131,11 +131,18 @@
>        result = 1;
>        goto done;
>      }
> +  /* Should be close to 0.0.  */
>    printf ("live PID %d before sleep => %lu.%.9lu\n",
>  	  child, before.tv_sec, before.tv_nsec);
>  
>    struct timespec sleeptime = { .tv_nsec = 500000000 };
> -  nanosleep (&sleeptime, NULL);
> +  e = nanosleep (&sleeptime, NULL);
> +  if (e != 0)
> +    {
> +      perror ("nanosleep");
> +      result = 1;
> +      goto done;
> +    }
>  
>    if (clock_gettime (child_clock, &after) < 0)
>      {
> @@ -144,6 +151,7 @@
>        result = 1;
>        goto done;
>      }
> +  /* Should be close to 0.5.  */
>    printf ("live PID %d after sleep => %lu.%.9lu\n",
>  	  child, after.tv_sec, after.tv_nsec);
>  
> @@ -214,7 +222,13 @@
>    /* Wait long enough to let the child finish dying.  */
>  
>    sleeptime.tv_nsec = 200000000;
> -  nanosleep (&sleeptime, NULL);
> +  e = nanosleep (&sleeptime, NULL);
> +  if (e != 0)
> +    {
> +      perror ("nanosleep");
> +      result = 1;
> +      goto done;
> +    }
>  
>    struct timespec dead;
>    if (clock_gettime (child_clock, &dead) < 0)
> @@ -224,6 +238,7 @@
>        result = 1;
>        goto done;
>      }
> +  /* Should be close to 0.6.  */
>    printf ("dead PID %d => %lu.%.9lu\n",
>  	  child, dead.tv_sec, dead.tv_nsec);
>  
> Index: rt/tst-cpuclock2.c
> ===================================================================
> --- rt/tst-cpuclock2.c	(revision 355696)
> +++ rt/tst-cpuclock2.c	(working copy)
> @@ -1,5 +1,5 @@
>  /* Test program for process and thread CPU clocks.
> -   Copyright (C) 2005 Free Software Foundation, Inc.
> +   Copyright (C) 2005, 2012 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
>     The GNU C Library is free software; you can redistribute it and/or
> @@ -229,7 +229,7 @@
>    if (clock_gettime (process_clock, &process_before) < 0)
>      {
>        printf ("clock_gettime on process clock %lx => %s\n",
> -	      (unsigned long int) th_clock, strerror (errno));
> +	      (unsigned long int) process_clock, strerror (errno));
>        return 1;
>      }
>  
> @@ -247,7 +247,7 @@
>    if (clock_gettime (my_thread_clock, &me_before) < 0)
>      {
>        printf ("clock_gettime on live thread clock %lx => %s\n",

This error message still isn't correct.

The text should read "on self thread clock" since the live thread clock is th_clock.

> -	      (unsigned long int) th_clock, strerror (errno));
> +	      (unsigned long int) my_thread_clock, strerror (errno));
>        return 1;
>      }
>    printf ("self thread before sleep => %lu.%.9lu\n",
> @@ -268,14 +268,14 @@
>    if (clock_gettime (process_clock, &process_after) < 0)
>      {
>        printf ("clock_gettime on process clock %lx => %s\n",
> -	      (unsigned long int) th_clock, strerror (errno));
> +	      (unsigned long int) process_clock, strerror (errno));
>        return 1;
>      }
>  
>    if (clock_gettime (my_thread_clock, &me_after) < 0)
>      {
>        printf ("clock_gettime on live thread clock %lx => %s\n",

Same here, "on self thread clock"

> -	      (unsigned long int) th_clock, strerror (errno));
> +	      (unsigned long int) my_thread_clock, strerror (errno));
>        return 1;
>      }
>    printf ("self thread after sleep => %lu.%.9lu\n",

The test tst-cpuclock2.c also uses nanosleep and clock_nanosleep,
is there any reason not to adjust those calls also to check for
failure?

Cheers,
Carlos.
-- 
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos@codesourcery.com
+1 (613) 963 1026


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]