test/testsem.c
changeset 5106 d547877e355e
parent 1895 c121d94672cb
child 5535 96594ac5fd1a
     1.1 --- a/test/testsem.c	Thu Jan 27 00:19:46 2011 -0800
     1.2 +++ b/test/testsem.c	Thu Jan 27 00:34:12 2011 -0800
     1.3 @@ -39,6 +39,29 @@
     1.4      alive = 0;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +TestWaitTimeout(void)
     1.9 +{
    1.10 +    Uint32 start_ticks;
    1.11 +    Uint32 end_ticks;
    1.12 +    Uint32 duration;
    1.13 +
    1.14 +    sem = SDL_CreateSemaphore(0);
    1.15 +    printf("Waiting 2 seconds on semaphore\n");
    1.16 +
    1.17 +    start_ticks = SDL_GetTicks();
    1.18 +    SDL_SemWaitTimeout(sem, 2000);
    1.19 +    end_ticks = SDL_GetTicks();
    1.20 +
    1.21 +    duration = end_ticks - start_ticks;
    1.22 +
    1.23 +    /* Accept a little offset in the effective wait */
    1.24 +    if (duration > 1900 && duration < 2050)
    1.25 +        printf("Wait done.\n");
    1.26 +    else
    1.27 +        fprintf(stderr, "Wait took %d milliseconds\n", duration);
    1.28 +}
    1.29 +
    1.30  int
    1.31  main(int argc, char **argv)
    1.32  {
    1.33 @@ -81,6 +104,9 @@
    1.34      printf("Finished waiting for threads\n");
    1.35  
    1.36      SDL_DestroySemaphore(sem);
    1.37 +
    1.38 +    TestWaitTimeout();
    1.39 +
    1.40      SDL_Quit();
    1.41      return (0);
    1.42  }