Add tests
This commit is contained in:
parent
efd30c098d
commit
fd28d9815a
@ -1,18 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "CUnit/Basic.h"
|
||||
#include "timer_utils.h"
|
||||
#include "time_scales.h"
|
||||
|
||||
int init_suite1(void)
|
||||
{
|
||||
printf("init_suit1()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clean_suite1(void)
|
||||
{
|
||||
printf("clean_suit1()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -43,13 +43,51 @@ void test_add_time_3(void)
|
||||
{
|
||||
struct itimerspec test_time = {
|
||||
.it_value = {
|
||||
.tv_nsec = 999999999,
|
||||
.tv_nsec = 999999111,
|
||||
.tv_sec = 0}};
|
||||
tmr_add_ns_to_current_time(&test_time, 1000);
|
||||
CU_ASSERT(test_time.it_value.tv_sec == 1);
|
||||
CU_ASSERT(test_time.it_value.tv_nsec == 999);
|
||||
CU_ASSERT(test_time.it_value.tv_nsec == 111);
|
||||
}
|
||||
|
||||
void test_add_time_4(void)
|
||||
{
|
||||
const uint32_t start = 999999990;
|
||||
struct itimerspec time = {
|
||||
.it_value = {
|
||||
.tv_nsec = start,
|
||||
.tv_sec = 0}};
|
||||
|
||||
for (uint32_t i = start; i < 999999999; i++)
|
||||
{
|
||||
tmr_add_ns_to_current_time(&time, 1);
|
||||
printf("%u:\t", i);
|
||||
printf("%u,%u\n", time.it_value.tv_sec, time.it_value.tv_nsec);
|
||||
CU_ASSERT(time.it_value.tv_nsec == i + 1);
|
||||
}
|
||||
|
||||
tmr_add_ns_to_current_time(&time, 1);
|
||||
printf("1000000000:\t");
|
||||
printf("%u,%u\n", time.it_value.tv_sec, time.it_value.tv_nsec);
|
||||
CU_ASSERT(time.it_value.tv_nsec == 0);
|
||||
CU_ASSERT(time.it_value.tv_sec == 1);
|
||||
}
|
||||
|
||||
void test_big_number(void)
|
||||
{
|
||||
struct itimerspec time = {
|
||||
.it_value = {
|
||||
.tv_nsec = 999999999,
|
||||
.tv_sec = 0,
|
||||
},
|
||||
};
|
||||
|
||||
tmr_add_ns_to_current_time(&time, 1*SEC);
|
||||
CU_ASSERT(time.it_value.tv_nsec == 999999999);
|
||||
CU_ASSERT(time.it_value.tv_sec == 1);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
CU_pSuite pSuite = NULL;
|
||||
@ -64,14 +102,11 @@ int main()
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
if ((NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_1)) ||
|
||||
(NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_2))||
|
||||
(NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_3))||
|
||||
(NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_2)))
|
||||
{
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_1);
|
||||
CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_2);
|
||||
CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_3);
|
||||
CU_add_test(pSuite, "test adding time in loop", test_add_time_4);
|
||||
CU_add_test(pSuite, "test adding big numbers", test_big_number);
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
|
Loading…
Reference in New Issue
Block a user