This tests whether timestamp API works.
#include "test.h"
#if INCLUDE_TIMESTAMP_TEST
#define THIS_FILE "timestamp"
static int timestamp_accuracy()
{
pj_int64_t msec, tics;
pj_int64_t diff;
PJ_LOG(3,(THIS_FILE,
"...testing frequency accuracy (pls wait)"));
do {
do {
tics = t2.u64 - t1.u64;
diff = tics - (msec * freq.u64 / 1000);
if (diff < 0)
diff = -diff;
if (diff > (pj_int64_t)(freq.u64 / 1000)) {
PJ_LOG(3,(THIS_FILE,
"....error: timestamp drifted by %d usec after "
"%d msec",
msec));
return -2000;
} else if (diff > (pj_int64_t)(freq.u64 / 1000000)) {
PJ_LOG(3,(THIS_FILE,
"....warning: timestamp drifted by %d usec after "
"%d msec",
msec));
} else {
PJ_LOG(3,(THIS_FILE,
"....good. Timestamp is accurate down to"
" nearest usec."));
}
return 0;
}
int timestamp_test(void)
{
enum { CONSECUTIVE_LOOP = 100 };
volatile unsigned i;
unsigned elapsed;
PJ_LOG(3,(THIS_FILE,
"...Testing timestamp (high res time)"));
app_perror("...ERROR: get timestamp freq", rc);
return -1000;
}
PJ_LOG(3,(THIS_FILE,
"....frequency: hiword=%lu loword=%lu",
PJ_LOG(3,(THIS_FILE,
"...checking if time can run backwards (pls wait).."));
app_perror("...ERROR: pj_get_timestamp", rc);
return -1001;
}
app_perror("...ERROR: pj_gettimeofday", rc);
return -1002;
}
for (i=0; i<CONSECUTIVE_LOOP; ++i) {
app_perror("...ERROR: pj_get_timestamp", rc);
return -1003;
}
app_perror("...ERROR: pj_gettimeofday", rc);
return -1004;
}
{
PJ_LOG(3,(THIS_FILE,
"...ERROR: timestamp run backwards!"));
return -1005;
}
PJ_LOG(3,(THIS_FILE,
"...ERROR: time run backwards!"));
return -1006;
}
}
PJ_LOG(3,(THIS_FILE,
"....testing simple 1000000 loop"));
app_perror("....error: cat't get timestamp", rc);
return -1010;
}
for (i=0; i<1000000; ++i) {
null_func();
}
PJ_LOG(3,(THIS_FILE,
"....elapsed: %u usec", (
unsigned)elapsed));
if (elapsed < 1 || elapsed > 1000000) {
PJ_LOG(3,(THIS_FILE,
"....error: elapsed time outside window (%u, "
"t1.u32.hi=%u, t1.u32.lo=%u, "
"t2.u32.hi=%u, t2.u32.lo=%u)",
elapsed,
return -1030;
}
rc = timestamp_accuracy();
if (rc != 0)
return rc;
return 0;
}
#else
int dummy_timestamp_test;
#endif
int pj_status_t
Definition: types.h:68
unsigned int pj_uint32_t
Definition: types.h:43
@ PJ_SUCCESS
Definition: types.h:93
#define PJ_LOG(level, arg)
Definition: log.h:106
pj_status_t pj_thread_sleep(unsigned msec)
pj_status_t pj_get_timestamp_freq(pj_timestamp *freq)
pj_status_t pj_get_timestamp(pj_timestamp *ts)
pj_uint32_t pj_elapsed_usec(const pj_timestamp *start, const pj_timestamp *stop)
pj_status_t pj_gettimeofday(pj_time_val *tv)
#define PJ_TIME_VAL_LT(t1, t2)
Definition: types.h:463
#define PJ_TIME_VAL_EQ(t1, t2)
Definition: types.h:431
#define PJ_TIME_VAL_MSEC(t)
Definition: types.h:421
#define PJ_TIME_VAL_SUB(t1, t2)
Definition: types.h:498
pj_uint32_t lo
Definition: types.h:142
pj_uint32_t hi
Definition: types.h:141
struct pj_timestamp::@9 u32