Changeset 386
- Timestamp:
- Apr 5, 2006 6:42:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/timestamp.c
r126 r386 47 47 48 48 #define THIS_FILE "timestamp" 49 50 static int timestamp_accuracy() 51 { 52 pj_timestamp freq, t1, t2; 53 pj_time_val tv1, tv2, tvtmp; 54 pj_uint32_t msec, tics; 55 pj_int64_t diff; 56 57 PJ_LOG(3,(THIS_FILE, "...testing frequency accuracy (pls wait)")); 58 59 pj_get_timestamp_freq(&freq); 60 61 /* Get the start time */ 62 pj_gettimeofday(&tvtmp); 63 do { 64 pj_gettimeofday(&tv1); 65 } while (PJ_TIME_VAL_EQ(tvtmp, tv1)); 66 pj_get_timestamp(&t1); 67 68 /* Sleep for 5 seconds */ 69 pj_thread_sleep(10000); 70 71 /* Get end time */ 72 pj_gettimeofday(&tvtmp); 73 do { 74 pj_gettimeofday(&tv2); 75 } while (PJ_TIME_VAL_EQ(tvtmp, tv2)); 76 pj_get_timestamp(&t2); 77 78 /* Get the elapsed time */ 79 PJ_TIME_VAL_SUB(tv2, tv1); 80 msec = PJ_TIME_VAL_MSEC(tv2); 81 82 /* Check that the frequency match the elapsed time */ 83 tics = (unsigned)(t2.u64 - t1.u64); 84 diff = tics - (msec * freq.u64 / 1000); 85 if (diff < 0) 86 diff = -diff; 87 88 /* Only allow 1 msec mismatch */ 89 if (diff > (pj_int64_t)(freq.u64 / 1000)) { 90 PJ_LOG(3,(THIS_FILE, "....error: timestamp drifted by %d usec after " 91 "%d msec", 92 (pj_uint32_t)(diff * 1000000 / freq.u64), 93 msec)); 94 return -2000; 95 96 /* Otherwise just print warning if timestamp drifted by >1 usec */ 97 } else if (diff > (pj_int64_t)(freq.u64 / 1000000)) { 98 PJ_LOG(3,(THIS_FILE, "....warning: timestamp drifted by %d usec after " 99 "%d msec", 100 (pj_uint32_t)(diff * 1000000 / freq.u64), 101 msec)); 102 } 103 104 return 0; 105 } 106 49 107 50 108 int timestamp_test(void) … … 147 205 return -1030; 148 206 } 207 208 /* Testing time/timestamp accuracy */ 209 rc = timestamp_accuracy(); 210 if (rc != 0) 211 return rc; 212 149 213 return 0; 150 214 }
Note: See TracChangeset
for help on using the changeset viewer.