|
HOME
SIP/media Features
High Performance SIP
Small Footprint SIP
Symbian Port
FAQ
Documentation
Licensing
Download
Development (Trac)
Projects using pjsip
Mailing List
Open Source Links
About: PJLIB, PJLIB-UTIL, PJSIP, and PJMEDIA are created by: Benny Prijono <bennylp pjsip.org>
|
|
Home --> Documentations --> PJLIB Reference
This file provides implementation of sleep_test().
This tests:
API tested:
This file is pjlib-test/sleep.c
#include "test.h"
#if INCLUDE_SLEEP_TEST
#include <pjlib.h>
#define THIS_FILE "sleep_test"
static int simple_sleep_test(void)
{
enum { COUNT = 10 };
int i;
pj_status_t rc;
PJ_LOG(3,(THIS_FILE, "..will write messages every 1 second:"));
for (i=0; i<COUNT; ++i) {
pj_time_val tv;
pj_parsed_time pt;
rc = pj_thread_sleep(1000);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_thread_sleep()", rc);
return -10;
}
rc = pj_gettimeofday(&tv);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_gettimeofday()", rc);
return -11;
}
pj_time_decode(&tv, &pt);
PJ_LOG(3,(THIS_FILE,
"...%04d-%02d-%02d %02d:%02d:%02d.%03d",
pt.year, pt.mon, pt.day,
pt.hour, pt.min, pt.sec, pt.msec));
}
return 0;
}
static int sleep_duration_test(void)
{
enum { MIS = 20};
unsigned duration[] = { 2000, 1000, 500, 200, 100 };
unsigned i;
pj_status_t rc;
PJ_LOG(3,(THIS_FILE, "..running sleep duration test"));
for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val start, stop;
pj_uint32_t msec;
rc = pj_gettimeofday(&start);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_gettimeofday()", rc);
return -10;
}
rc = pj_thread_sleep(duration[i]);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_thread_sleep()", rc);
return -20;
}
rc = pj_gettimeofday(&stop);
PJ_TIME_VAL_SUB(stop, start);
msec = PJ_TIME_VAL_MSEC(stop);
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
return -30;
}
}
for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val t1, t2;
pj_timestamp start, stop;
pj_uint32_t msec;
pj_thread_sleep(0);
rc = pj_get_timestamp(&start);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_get_timestamp()", rc);
return -60;
}
pj_gettimeofday(&t1);
rc = pj_thread_sleep(duration[i]);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_thread_sleep()", rc);
return -70;
}
pj_get_timestamp(&stop);
pj_gettimeofday(&t2);
if (PJ_TIME_VAL_LT(t2, t1)) {
PJ_LOG(3,(THIS_FILE, "...error: t2 is less than t1!!"));
return -75;
}
msec = pj_elapsed_msec(&start, &stop);
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
PJ_TIME_VAL_SUB(t2, t1);
PJ_LOG(3,(THIS_FILE,
"...info: gettimeofday() reported duration is "
"%d msec",
PJ_TIME_VAL_MSEC(t2)));
return -76;
}
}
return 0;
}
int sleep_test()
{
int rc;
rc = simple_sleep_test();
if (rc != PJ_SUCCESS)
return rc;
rc = sleep_duration_test();
if (rc != PJ_SUCCESS)
return rc;
return 0;
}
#else
int dummy_sleep_test;
#endif
PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.
|
|