Add clock test, and fix ucore_clock.h header
This commit is contained in:
@@ -84,7 +84,7 @@ void ucore_settable_clock_init(struct ucore_settable_clock *clock);
|
|||||||
/**
|
/**
|
||||||
* Set the new timeval this clock will return
|
* Set the new timeval this clock will return
|
||||||
**/
|
**/
|
||||||
void ucore_cached_clock_set_tv(struct ucore_settable_clock *clock,
|
void ucore_settable_clock_set_tv(struct ucore_settable_clock *clock,
|
||||||
const struct timeval *tv);
|
const struct timeval *tv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +92,7 @@ void ucore_cached_clock_set_tv(struct ucore_settable_clock *clock,
|
|||||||
* Convenience function that takes seconds/microseconds as arguments
|
* Convenience function that takes seconds/microseconds as arguments
|
||||||
* instead of a struct timeval.
|
* instead of a struct timeval.
|
||||||
**/
|
**/
|
||||||
void ucore_cached_clock_set(struct ucore_settable_clock *clock,
|
void ucore_settable_clock_set(struct ucore_settable_clock *clock,
|
||||||
time_t secs, suseconds_t usecs);
|
time_t secs, suseconds_t usecs);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
#include <check.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ucore/ucore_clock.h>
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST (test_settable_clock)
|
||||||
|
struct ucore_settable_clock my_clock;
|
||||||
|
struct timeval tv;
|
||||||
|
struct timeval tv_tmp;
|
||||||
|
|
||||||
|
ucore_settable_clock_init(&my_clock);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv);
|
||||||
|
|
||||||
|
fail_if(tv.tv_sec != 0);
|
||||||
|
fail_if(tv.tv_usec != 0);
|
||||||
|
|
||||||
|
ucore_settable_clock_set(&my_clock, 10001, 1002);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv);
|
||||||
|
|
||||||
|
fail_if(tv.tv_sec != 10001);
|
||||||
|
fail_if(tv.tv_usec != 1002);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv);
|
||||||
|
|
||||||
|
tv_tmp.tv_sec = 123456789;
|
||||||
|
tv_tmp.tv_usec = 44;
|
||||||
|
|
||||||
|
ucore_settable_clock_set_tv(&my_clock, &tv_tmp);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv);
|
||||||
|
|
||||||
|
fail_if(tv.tv_sec != 123456789);
|
||||||
|
fail_if(tv.tv_usec != 44);
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_cached_clock)
|
||||||
|
struct ucore_cached_clock my_clock;
|
||||||
|
struct timeval tv1,tv2;
|
||||||
|
|
||||||
|
ucore_cached_clock_init(&my_clock, &ucore_timeofday_clock);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv1);
|
||||||
|
|
||||||
|
fail_if(tv1.tv_sec == 0);
|
||||||
|
fail_if(tv1.tv_usec == 0);
|
||||||
|
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv1);
|
||||||
|
usleep(100);
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv2);
|
||||||
|
|
||||||
|
fail_if(timercmp(&tv1, &tv2, !=));
|
||||||
|
|
||||||
|
usleep(100);
|
||||||
|
ucore_cached_clock_update(&my_clock);
|
||||||
|
my_clock.clock.now(&my_clock.clock, &tv1);
|
||||||
|
|
||||||
|
fail_if(!timercmp(&tv1, &tv2, !=));
|
||||||
|
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
Suite *clock_suite(void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create("clock");
|
||||||
|
TCase *tc = tcase_create("clock tests");
|
||||||
|
|
||||||
|
tcase_add_test(tc, test_settable_clock);
|
||||||
|
tcase_add_test(tc, test_cached_clock);
|
||||||
|
|
||||||
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
+3
-1
@@ -15,6 +15,7 @@ extern Suite *pack_suite(void);
|
|||||||
extern Suite *logging_suite(void);
|
extern Suite *logging_suite(void);
|
||||||
extern Suite *threadqueue_suite(void);
|
extern Suite *threadqueue_suite(void);
|
||||||
extern Suite *buffer_suite(void);
|
extern Suite *buffer_suite(void);
|
||||||
|
extern Suite *clock_suite(void);
|
||||||
|
|
||||||
static suite_func suites[] = {
|
static suite_func suites[] = {
|
||||||
bitvec_suite,
|
bitvec_suite,
|
||||||
@@ -25,7 +26,8 @@ static suite_func suites[] = {
|
|||||||
pack_suite,
|
pack_suite,
|
||||||
logging_suite,
|
logging_suite,
|
||||||
threadqueue_suite,
|
threadqueue_suite,
|
||||||
buffer_suite
|
buffer_suite,
|
||||||
|
clock_suite,
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Reference in New Issue
Block a user