/* $Id$ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "test.h" /** * \page page_pjlib_sleep_test Test: Sleep, Time, and Timestamp * * This file provides implementation of \b sleep_test(). * * \section sleep_test_sec Scope of the Test * * This tests: * - whether pj_thread_sleep() works. * - whether pj_gettimeofday() works. * - whether pj_get_timestamp() and friends works. * * API tested: * - pj_thread_sleep() * - pj_gettimeofday() * - PJ_TIME_VAL_SUB() * - PJ_TIME_VAL_LTE() * - pj_get_timestamp() * - pj_get_timestamp_freq() (implicitly) * - pj_elapsed_time() * - pj_elapsed_usec() * * * This file is pjlib-test/sleep.c * * \include pjlib-test/sleep.c */ #if INCLUDE_SLEEP_TEST #include #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 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; } } /* Test pj_thread_sleep() and pj_get_timestamp() and friends */ for (i=0; i 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; } } /* All done. */ 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 /* To prevent warning about "translation unit is empty" * when this test is disabled. */ int dummy_sleep_test; #endif /* INCLUDE_SLEEP_TEST */