2008-05-19 19:31:59 +04:00
|
|
|
#include <string.h>
|
2008-05-20 16:26:37 +04:00
|
|
|
#include <unistd.h>
|
2008-05-19 19:31:59 +04:00
|
|
|
|
|
|
|
#include "support.h"
|
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
#include "csync_time.h"
|
2008-05-20 14:08:22 +04:00
|
|
|
#include "std/c_time.h"
|
2008-05-19 19:31:59 +04:00
|
|
|
|
|
|
|
START_TEST (check_c_tspecdiff)
|
|
|
|
{
|
|
|
|
struct timespec start, finish, diff;
|
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
csync_gettime(&finish);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
|
|
|
diff = c_tspecdiff(finish, start);
|
|
|
|
|
|
|
|
fail_unless(diff.tv_sec == 0, NULL);
|
2012-02-04 16:24:56 +04:00
|
|
|
fail_unless(diff.tv_nsec >= 0, NULL);
|
2008-05-19 19:31:59 +04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2008-05-20 16:26:37 +04:00
|
|
|
START_TEST (check_c_tspecdiff_five)
|
|
|
|
{
|
|
|
|
struct timespec start, finish, diff;
|
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&start);
|
2008-05-20 16:26:37 +04:00
|
|
|
sleep(5);
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&finish);
|
2008-05-20 16:26:37 +04:00
|
|
|
|
|
|
|
diff = c_tspecdiff(finish, start);
|
|
|
|
|
|
|
|
fail_unless(diff.tv_sec == 5, NULL);
|
|
|
|
fail_unless(diff.tv_nsec > 0, NULL);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2008-05-19 19:31:59 +04:00
|
|
|
START_TEST (check_c_secdiff)
|
|
|
|
{
|
|
|
|
struct timespec start, finish;
|
|
|
|
double diff;
|
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
csync_gettime(&finish);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
|
|
|
diff = c_secdiff(finish, start);
|
|
|
|
|
2012-02-04 16:24:56 +04:00
|
|
|
fail_unless(diff >= 0.00 && diff < 1.00, "diff is %.2f", diff);
|
2008-05-20 16:26:37 +04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST (check_c_secdiff_three)
|
|
|
|
{
|
|
|
|
struct timespec start, finish;
|
|
|
|
double diff;
|
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&start);
|
2008-05-20 16:26:37 +04:00
|
|
|
sleep(3);
|
2012-02-04 16:24:53 +04:00
|
|
|
csync_gettime(&finish);
|
2008-05-20 16:26:37 +04:00
|
|
|
|
|
|
|
diff = c_secdiff(finish, start);
|
|
|
|
|
|
|
|
fail_unless(diff > 3.00 && diff < 4.00, "diff is %.2f", diff);
|
2008-05-19 19:31:59 +04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
static Suite *make_std_c_suite(void) {
|
|
|
|
Suite *s = suite_create("std:path:c_basename");
|
|
|
|
|
|
|
|
create_case(s, "check_c_tspecdiff", check_c_tspecdiff);
|
2008-05-20 16:26:37 +04:00
|
|
|
create_case(s, "check_c_tspecdiff_five", check_c_tspecdiff_five);
|
2008-05-19 19:31:59 +04:00
|
|
|
create_case(s, "check_c_secdiff", check_c_secdiff);
|
2008-05-20 16:26:37 +04:00
|
|
|
create_case(s, "check_c_secdiff_three", check_c_secdiff_three);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
Suite *s = NULL;
|
|
|
|
SRunner *sr = NULL;
|
|
|
|
struct argument_s arguments;
|
|
|
|
int nf;
|
|
|
|
|
|
|
|
ZERO_STRUCT(arguments);
|
|
|
|
|
|
|
|
cmdline_parse(argc, argv, &arguments);
|
|
|
|
|
|
|
|
s = make_std_c_suite();
|
|
|
|
|
|
|
|
sr = srunner_create(s);
|
|
|
|
if (arguments.nofork) {
|
|
|
|
srunner_set_fork_status(sr, CK_NOFORK);
|
|
|
|
}
|
|
|
|
srunner_run_all(sr, CK_VERBOSE);
|
|
|
|
nf = srunner_ntests_failed(sr);
|
|
|
|
srunner_free(sr);
|
|
|
|
|
|
|
|
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|