#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_LOG(3,(THIS_FILE,
"..will write messages every 1 second:"));
for (i=0; i<COUNT; ++i) {
app_perror("...error: pj_thread_sleep()", rc);
return -10;
}
app_perror("...error: pj_gettimeofday()", rc);
return -11;
}
"...%04d-%02d-%02d %02d:%02d:%02d.%03d",
}
return 0;
}
static int sleep_duration_test(void)
{
enum { MIS = 20};
unsigned duration[] = { 2000, 1000, 500, 200, 100 };
unsigned i;
PJ_LOG(3,(THIS_FILE,
"..running sleep duration test"));
app_perror("...error: pj_gettimeofday()", rc);
return -10;
}
app_perror("...error: pj_thread_sleep()", rc);
return -20;
}
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
return -30;
}
}
app_perror("...error: pj_get_timestamp()", rc);
return -60;
}
app_perror("...error: pj_thread_sleep()", rc);
return -70;
}
PJ_LOG(3,(THIS_FILE,
"...error: t2 is less than t1!!"));
return -75;
}
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
"...info: gettimeofday() reported duration is "
"%d msec",
return -76;
}
}
return 0;
}
int sleep_test()
{
int rc;
rc = simple_sleep_test();
return rc;
rc = sleep_duration_test();
return rc;
return 0;
}
#else
int dummy_sleep_test;
#endif
int pj_status_t
Definition: types.h:68
#define PJ_ARRAY_SIZE(a)
Definition: types.h:281
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_uint32_t pj_elapsed_msec(const pj_timestamp *start, const pj_timestamp *stop)
pj_status_t pj_get_timestamp(pj_timestamp *ts)
pj_status_t pj_gettimeofday(pj_time_val *tv)
#define PJ_TIME_VAL_LT(t1, t2)
Definition: types.h:463
#define PJ_TIME_VAL_MSEC(t)
Definition: types.h:421
pj_status_t pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
#define PJ_TIME_VAL_SUB(t1, t2)
Definition: types.h:498
int sec
Definition: types.h:531
int hour
Definition: types.h:537
int year
Definition: types.h:528
int msec
Definition: types.h:540
int min
Definition: types.h:534
int day
Definition: types.h:520
int mon
Definition: types.h:523