Ignore:
Timestamp:
Jun 25, 2009 12:29:04 PM (15 years ago)
Author:
bennylp
Message:

Ticket #765: Bug with milliseconds time resolution in WinCE/Windows Mobile targets (thanks Johan Lantz for the report)

  • backported changes in #764
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.0/pjlib/src/pjlib-test/sleep.c

    r2394 r2805  
    5656static int simple_sleep_test(void) 
    5757{ 
    58     enum { COUNT = 5 }; 
     58    enum { COUNT = 10 }; 
    5959    int i; 
    6060    pj_status_t rc; 
     
    6363     
    6464    for (i=0; i<COUNT; ++i) { 
     65        pj_time_val tv; 
     66        pj_parsed_time pt; 
     67 
    6568        rc = pj_thread_sleep(1000); 
    6669        if (rc != PJ_SUCCESS) { 
     
    6871            return -10; 
    6972        } 
    70         PJ_LOG(3,(THIS_FILE, "...wake up..")); 
     73 
     74        rc = pj_gettimeofday(&tv); 
     75        if (rc != PJ_SUCCESS) { 
     76            app_perror("...error: pj_gettimeofday()", rc); 
     77            return -11; 
     78        } 
     79 
     80        pj_time_decode(&tv, &pt); 
     81 
     82        PJ_LOG(3,(THIS_FILE,  
     83                  "...%04d-%02d-%02d %02d:%02d:%02d.%03d", 
     84                  pt.year, pt.mon, pt.day, 
     85                  pt.hour, pt.min, pt.sec, pt.msec)); 
     86 
    7187    } 
    7288 
     
    7692static int sleep_duration_test(void) 
    7793{ 
    78     enum { MIS = 20, DURATION = 1000, DURATION2 = 500 }; 
     94    enum { MIS = 20}; 
     95    unsigned duration[] = { 2000, 1000, 500, 200, 100 }; 
     96    unsigned i; 
    7997    pj_status_t rc; 
    8098 
     
    82100 
    83101    /* Test pj_thread_sleep() and pj_gettimeofday() */ 
    84     { 
     102    for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) { 
    85103        pj_time_val start, stop; 
    86104        pj_uint32_t msec; 
     
    94112 
    95113        /* Sleep */ 
    96         rc = pj_thread_sleep(DURATION); 
     114        rc = pj_thread_sleep(duration[i]); 
    97115        if (rc != PJ_SUCCESS) { 
    98116            app_perror("...error: pj_thread_sleep()", rc); 
     
    110128 
    111129        /* Check if it's within range. */ 
    112         if (msec < DURATION * (100-MIS)/100 || 
    113             msec > DURATION * (100+MIS)/100) 
     130        if (msec < duration[i] * (100-MIS)/100 || 
     131            msec > duration[i] * (100+MIS)/100) 
    114132        { 
    115133            PJ_LOG(3,(THIS_FILE,  
    116134                      "...error: slept for %d ms instead of %d ms " 
    117135                      "(outside %d%% err window)", 
    118                       msec, DURATION, MIS)); 
     136                      msec, duration[i], MIS)); 
    119137            return -30; 
    120138        } 
     
    123141 
    124142    /* Test pj_thread_sleep() and pj_get_timestamp() and friends */ 
    125     { 
     143    for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) { 
    126144        pj_time_val t1, t2; 
    127145        pj_timestamp start, stop; 
     
    141159 
    142160        /* Sleep */ 
    143         rc = pj_thread_sleep(DURATION2); 
     161        rc = pj_thread_sleep(duration[i]); 
    144162        if (rc != PJ_SUCCESS) { 
    145163            app_perror("...error: pj_thread_sleep()", rc); 
     
    163181 
    164182        /* Check if it's within range. */ 
    165         if (msec < DURATION2 * (100-MIS)/100 || 
    166             msec > DURATION2 * (100+MIS)/100) 
     183        if (msec < duration[i] * (100-MIS)/100 || 
     184            msec > duration[i] * (100+MIS)/100) 
    167185        { 
    168186            PJ_LOG(3,(THIS_FILE,  
    169187                      "...error: slept for %d ms instead of %d ms " 
    170188                      "(outside %d%% err window)", 
    171                       msec, DURATION2, MIS)); 
     189                      msec, duration[i], MIS)); 
    172190            PJ_TIME_VAL_SUB(t2, t1); 
    173191            PJ_LOG(3,(THIS_FILE,  
Note: See TracChangeset for help on using the changeset viewer.