On 16 January 2015 at 12:05, Ola Liljedahl <[email protected]> wrote:

> Use nanosleep instead of the deprecated usleep. Define POSIX version to be
> able
> to use rand_r. (https://bugs.linaro.org/show_bug.cgi?id=1048)
>
> Signed-off-by: Ola Liljedahl <[email protected]>
> ---
> (This document/code contribution attached is provided under the terms of
> agreement LES-LTM-21309)
>
>  test/validation/odp_timer.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c
> index 5ba1b84..ce5dcaf 100644
> --- a/test/validation/odp_timer.c
> +++ b/test/validation/odp_timer.c
> @@ -8,7 +8,10 @@
>   * @file
>   */
>
> +/* For rand_r and nanosleep */
> +#define _POSIX_C_SOURCE 200112L
>  #include <assert.h>
> +#include <time.h>
>  #include <unistd.h>
>  #include <odp.h>
>  #include "odp_cunit_common.h"
> @@ -210,8 +213,11 @@ static void *worker_entrypoint(void *arg)
>                         /* Save expected expiration tick */
>                         tt[i].tick = cur_tick + tck;
>                 }
> -               if (usleep(1000/*1ms*/) < 0)
> -                       perror("usleep"), abort();
> +               struct timespec ts;
> +               ts.tv_sec = 0;
> +               ts.tv_nsec = 1000000; /* 1ms */
> +               if (nanosleep(&ts, NULL) < 0)
> +                       perror("nanosleep"), abort();
>

perror will not get passed though the test logging framework

For abort there are two better options
Abort will kill the test harness where any of the CUnit fatal macros
<http://cunit.sourceforge.net/doc/writing_tests.html#assertions> will allow
the frame work to recover and run the next test in a new process.
Although in this case we want to try to stay within CUnits framework, the
above logging and abort behaviour is available via LOG_ABORT is a good way
for a test to abort, it will log via the test ODP test framework before
aborting



>         }
>
>         /* Cancel and free all timers */
> @@ -238,7 +244,11 @@ static void *worker_entrypoint(void *arg)
>
>         /* Delay some more to ensure timeouts for expired timers can be
>          * received */
> -       usleep(1000/*1ms*/);
> +       struct timespec ts;
> +       ts.tv_sec = 0;
> +       ts.tv_nsec = 1000000; /* 1ms */
> +       if (nanosleep(&ts, NULL) < 0)
> +               perror("nanosleep"), abort();
>         while (nstale != 0) {
>                 odp_buffer_t buf = odp_queue_deq(queue);
>                 if (buf != ODP_BUFFER_INVALID) {
> --
> 1.9.1
>
>
> _______________________________________________
> lng-odp mailing list
> [email protected]
> http://lists.linaro.org/mailman/listinfo/lng-odp
>



-- 
*Mike Holmes*
Linaro  Sr Technical Manager
LNG - ODP
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to