Home --> Documentations --> PJLIB Reference
This file provides implementation of timestamp_test()
Scope of the Test
This tests whether timestamp API works.
API tested:
This file is pjlib-test/timestamp.c
#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
PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.
|