66
77#include <time.h>
88#include <pthread.h>
9- #include <errno.h>
10- #include <tc_util.h>
9+ #include <ztest.h>
1110
1211#define SECS_TO_SLEEP 2
1312#define DURATION_SECS 1
@@ -19,13 +18,13 @@ static int exp_count;
1918
2019void handler (union sigval val )
2120{
22- TC_PRINT ("Handler Signal value :%d for %d times\n" , val .sival_int ,
21+ printk ("Handler Signal value :%d for %d times\n" , val .sival_int ,
2322 ++ exp_count );
2423}
2524
26- void main (void )
25+ void test_timer (void )
2726{
28- int ret , status = TC_FAIL ;
27+ int ret ;
2928 struct sigevent sig ;
3029 timer_t timerid ;
3130 struct itimerspec value , ovalue ;
@@ -36,31 +35,27 @@ void main(void)
3635 sig .sigev_notify_function = handler ;
3736 sig .sigev_value .sival_int = 20 ;
3837 sig .sigev_notify_attributes = NULL ;
39- TC_START ("POSIX timer test\n" );
38+
39+ printk ("POSIX timer test\n" );
4040 ret = timer_create (CLOCK_MONOTONIC , & sig , & timerid );
4141
42- if (ret == 0 ) {
43- value .it_value .tv_sec = DURATION_SECS ;
44- value .it_value .tv_nsec = DURATION_NSECS ;
45- value .it_interval .tv_sec = PERIOD_SECS ;
46- value .it_interval .tv_nsec = PERIOD_NSECS ;
47- ret = timer_settime (timerid , 0 , & value , & ovalue );
48- clock_gettime (CLOCK_MONOTONIC , & ts );
49-
50- if (ret == 0 ) {
51- sleep (SECS_TO_SLEEP );
52- } else {
53- TC_PRINT ("posix timer failed to start, error %d\n" ,
54- errno );
55- goto test_end ;
56- }
57-
58- clock_gettime (CLOCK_MONOTONIC , & te );
59- timer_delete (timerid );
60- } else {
61- TC_ERROR ("POSIX timer create failed with %d\n" , errno );
62- goto test_end ;
63- }
42+ /*TESTPOINT: Check if timer is created successfully*/
43+ zassert_false (ret , "POSIX timer create failed\n" );
44+
45+ value .it_value .tv_sec = DURATION_SECS ;
46+ value .it_value .tv_nsec = DURATION_NSECS ;
47+ value .it_interval .tv_sec = PERIOD_SECS ;
48+ value .it_interval .tv_nsec = PERIOD_NSECS ;
49+ ret = timer_settime (timerid , 0 , & value , & ovalue );
50+ clock_gettime (CLOCK_MONOTONIC , & ts );
51+
52+ /*TESTPOINT: Check if timer has started successfully*/
53+ zassert_false (ret , "POSIX timer failed to start\n" );
54+
55+ sleep (SECS_TO_SLEEP );
56+
57+ clock_gettime (CLOCK_MONOTONIC , & te );
58+ timer_delete (timerid );
6459
6560 if (te .tv_nsec >= ts .tv_nsec ) {
6661 secs_elapsed = te .tv_sec - ts .tv_sec ;
@@ -75,8 +70,14 @@ void main(void)
7570 (value .it_interval .tv_sec * NSEC_PER_SEC +
7671 value .it_interval .tv_nsec )) / NSEC_PER_SEC ;
7772
78- status = (total_secs_timer == secs_elapsed ) ? TC_PASS : TC_FAIL ;
73+ /*TESTPOINT: Check if POSIX timer test passed*/
74+ zassert_equal (total_secs_timer , secs_elapsed ,
75+ "POSIX timer test has failed\n" );
76+ }
7977
80- test_end :
81- TC_END_REPORT (status );
78+ void test_main (void )
79+ {
80+ ztest_test_suite (test_posix_timer ,
81+ ztest_unit_test (test_timer ));
82+ ztest_run_test_suite (test_posix_timer );
8283}
0 commit comments