Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer driver test #1939

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions testing/drivertest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ MAINSRC += drivertest_block.c
endif

ifneq ($(CONFIG_RTC),)
ifneq ($(CONFIG_SIG_EVTHREAD),)
MAINSRC += drivertest_rtc.c
PROGNAME += cmocka_driver_rtc
endif
endif

ifneq ($(CONFIG_TIMER),)
MAINSRC += drivertest_timer.c
Expand Down
24 changes: 20 additions & 4 deletions testing/drivertest/drivertest_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>

#include <syslog.h>
#include <nuttx/timers/timer.h>

/****************************************************************************
Expand All @@ -48,8 +48,8 @@
#define TIMER_DEFAULT_DEVPATH "/dev/timer0"
#define TIMER_DEFAULT_INTERVAL 1000000
#define TIMER_DEFAULT_NSAMPLES 20
#define TIMER_DEFAULT_SIGNO 32
#define TIMER_DEFAULT_RANGE 1
#define TIMER_DEFAULT_SIGNO 31
#define TIMER_DEFAULT_RANGE 1000

#define OPTARG_TO_VALUE(value, type, base) \
do \
Expand Down Expand Up @@ -209,8 +209,10 @@ static void test_case_timer(FAR void **state)
int ret;
uint32_t range;
uint32_t tim;
uint32_t max_timeout;
struct sigaction act;
struct timer_notify_s notify;
struct timer_status_s timer_status;
FAR struct timer_state_s *timer_state;

timer_state = (FAR struct timer_state_s *)*state;
Expand Down Expand Up @@ -251,14 +253,28 @@ static void test_case_timer(FAR void **state)
ret = ioctl(fd, TCIOC_START, 0);
assert_return_code(ret, OK);

/* Get status */

ret = ioctl(fd, TCIOC_GETSTATUS, &timer_status);
assert_return_code(ret, OK);
assert_int_equal(timer_state->interval, timer_status.timeout);
assert_in_range(timer_status.timeleft,
0, timer_state->interval);

/* Get max timeout */

ret = ioctl(fd, TCIOC_MAXTIMEOUT, &max_timeout);
assert_return_code(ret, OK);
syslog(LOG_DEBUG, "max timeout:%ld\n", max_timeout);

/* Set the timer interval */

for (i = 0; i < timer_state->nsamples; i++)
{
tim = get_timestamp();
usleep(2 * timer_state->interval);
tim = get_timestamp() - tim;
range = timer_state->interval / 1000 - tim;
range = abs(timer_state->interval / 1000 - tim);
assert_in_range(range, 0, timer_state->range);
}

Expand Down
Loading