You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/28 05:45:39 UTC
(nuttx-apps) branch master updated: test timer:change deviation to be pass as parameter.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new fb37ef367 test timer:change deviation to be pass as parameter.
fb37ef367 is described below
commit fb37ef36713b0aadc507cd08db4b4eef1ad7a007
Author: yangguangcai <ya...@xiaomi.com>
AuthorDate: Fri Mar 15 16:15:46 2024 +0800
test timer:change deviation to be pass as parameter.
Signed-off-by: yangguangcai <ya...@xiaomi.com>
---
testing/drivertest/drivertest_posix_timer.c | 45 +++++++++++++++++------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/testing/drivertest/drivertest_posix_timer.c b/testing/drivertest/drivertest_posix_timer.c
index dbe9eca59..5ab5ac02f 100644
--- a/testing/drivertest/drivertest_posix_timer.c
+++ b/testing/drivertest/drivertest_posix_timer.c
@@ -37,7 +37,6 @@
#define RTC_DEFAULT_DEVIATION 10
#define DEFAULT_TIME_OUT 2
#define SLEEPSECONDS 10
-#define COMEINCALLBACK 0
#define OPTARG_TO_VALUE(value, type, base) \
do \
@@ -58,12 +57,8 @@
struct posix_timer_state_s
{
struct itimerspec it;
-};
-
-struct sigev_para_s
-{
- int tim;
- int interval;
+ uint32_t tim;
+ uint32_t deviation;
};
/****************************************************************************
@@ -80,8 +75,9 @@ struct sigev_para_s
static void show_usage(FAR const char *progname, int exitcode)
{
- printf("Usage: %s"
- " -s <timeout seconds>\n",
+ printf("Usage: %s\n"
+ " -s <timeout seconds>\n"
+ " -a <timeout deviation>\n",
progname);
exit(exitcode);
@@ -98,7 +94,7 @@ static void parse_commandline(
int ch;
int converted;
- while ((ch = getopt(argc, argv, "s:")) != ERROR)
+ while ((ch = getopt(argc, argv, "s:a:")) != ERROR)
{
switch (ch)
{
@@ -114,6 +110,17 @@ static void parse_commandline(
posix_timer_state->it.it_interval.tv_sec = (uint32_t)converted;
break;
+ case 'a':
+ OPTARG_TO_VALUE(converted, uint32_t, 10);
+ if (converted < 0 || converted > INT_MAX)
+ {
+ printf("deviation out of range: %d\n", converted);
+ show_usage(argv[0], EXIT_FAILURE);
+ }
+
+ posix_timer_state->deviation = (uint32_t)converted;
+ break;
+
case '?':
printf("Unsupported option: %s\n", optarg);
show_usage(argv[0], EXIT_FAILURE);
@@ -141,11 +148,14 @@ static uint32_t get_timestamp(void)
static void posix_timer_callback(union sigval arg)
{
- FAR struct sigev_para_s *sigev_para = (struct sigev_para_s *)arg.sival_ptr;
+ FAR struct posix_timer_state_s *sigev_para =
+ (FAR struct posix_timer_state_s *)arg.sival_ptr;
int range = get_timestamp() - (*sigev_para).tim;
+
assert_in_range(range,
- (*sigev_para).interval * 1000 - RTC_DEFAULT_DEVIATION,
- (*sigev_para).interval * 1000 + RTC_DEFAULT_DEVIATION);
+ sigev_para->it.it_interval.tv_sec * 1000 - sigev_para->deviation,
+ sigev_para->it.it_interval.tv_sec * 1000 + sigev_para->deviation);
+
syslog(LOG_DEBUG, "callback trigger!!!\n");
(*sigev_para).tim = get_timestamp();
}
@@ -159,7 +169,6 @@ static void test_case_posix_timer(FAR void **state)
int ret;
timer_t timerid;
struct sigevent event;
- struct sigev_para_s sigev_para;
FAR struct posix_timer_state_s *posix_timer_state;
struct itimerspec it;
@@ -170,7 +179,7 @@ static void test_case_posix_timer(FAR void **state)
event.sigev_notify = SIGEV_THREAD;
event.sigev_notify_function = posix_timer_callback;
event.sigev_notify_attributes = NULL;
- event.sigev_value.sival_ptr = (struct sigev_para_s *)&sigev_para;
+ event.sigev_value.sival_ptr = posix_timer_state;
/* Create the timer */
@@ -182,8 +191,7 @@ static void test_case_posix_timer(FAR void **state)
ret = timer_settime(timerid, 0, &(posix_timer_state->it), NULL);
assert_return_code(ret, OK);
- sigev_para.interval = posix_timer_state->it.it_interval.tv_sec;
- sigev_para.tim = get_timestamp();
+ posix_timer_state->tim = get_timestamp();
/* Get the timer status */
@@ -209,7 +217,8 @@ int main(int argc, FAR char *argv[])
.it.it_value.tv_sec = DEFAULT_TIME_OUT,
.it.it_value.tv_nsec = 0,
.it.it_interval.tv_sec = DEFAULT_TIME_OUT,
- .it.it_interval.tv_nsec = 0
+ .it.it_interval.tv_nsec = 0,
+ .deviation = RTC_DEFAULT_DEVIATION
};
const struct CMUnitTest tests[] =