From f4cbdb5820098627244c36fd20bf1836e12c2a57 Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Mon, 17 Apr 2023 15:58:15 +0800 Subject: [PATCH 1/4] watchdog:test watchdog not depend on fs. Signed-off-by: yangguangcai --- testing/drivertest/Makefile | 6 ++ testing/drivertest/drivertest_watchdog.c | 130 ++++++++--------------- 2 files changed, 48 insertions(+), 88 deletions(-) diff --git a/testing/drivertest/Makefile b/testing/drivertest/Makefile index bc4a5ecf49..bd59f53d13 100644 --- a/testing/drivertest/Makefile +++ b/testing/drivertest/Makefile @@ -55,6 +55,12 @@ ifneq ($(CONFIG_SIG_EVTHREAD),) MAINSRC += drivertest_posix_timer.c PROGNAME += cmocka_posix_timer endif + +ifneq ($(CONFIG_WATCHDOG),) +ifneq ($(CONFIG_BOARDCTL_RESET_CAUSE),) +MAINSRC += drivertest_watchdog.c +PROGNAME += cmocka_driver_watchdog +endif endif ifneq ($(CONFIG_PWM),) diff --git a/testing/drivertest/drivertest_watchdog.c b/testing/drivertest/drivertest_watchdog.c index 8db0cf0785..0845174845 100644 --- a/testing/drivertest/drivertest_watchdog.c +++ b/testing/drivertest/drivertest_watchdog.c @@ -46,16 +46,18 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #define WDG_DEFAULT_DEV_PATH "/dev/watchdog0" -#define WDG_DEFAULT_INFO_PATH "/data/wdg_info" #define WDG_DEFAULT_PINGTIMER 5000 #define WDG_DEFAULT_PINGDELAY 500 #define WDG_DEFAULT_TIMEOUT 2000 +#define WDG_DEFAULT_TESTCASE 0 +#define WDG_COUNT_TESTCASE 4 #define OPTARG_TO_VALUE(value, type, base) \ do \ @@ -73,22 +75,13 @@ * Private Types ****************************************************************************/ -enum wdg_reset_cause_e -{ - WDG_RESET_CAUSE_NONE, - WDG_RESET_CAUSE_NO_KEEP_ALIVE, - WDG_RESET_CAUSE_CRITICAL_SECTION_BUSY_LOOP, - WDG_RESET_CAUSE_IRQ_BUSY_LOOP -}; - struct wdg_state_s { char devpath[PATH_MAX]; - char infopath[PATH_MAX]; uint32_t pingtime; uint32_t pingdelay; uint32_t timeout; - enum wdg_reset_cause_e reset_cause; + int test_case; }; /**************************************************************************** @@ -99,6 +92,8 @@ struct wdg_state_s * Private Functions ****************************************************************************/ +extern int board_reset_cause(FAR struct boardioc_reset_cause_s *cause); + /**************************************************************************** * Name: get_timestamp ****************************************************************************/ @@ -135,52 +130,6 @@ static uint32_t get_time_elaps(uint32_t prev_tick) return prev_tick; } -/**************************************************************************** - * Name: wdg_write_reset_cause - ****************************************************************************/ - -static void wdg_write_reset_cause(FAR struct wdg_state_s *state) -{ - int fd; - int ret; - ssize_t size; - - fd = open(state->infopath, O_WRONLY | O_CREAT, 0666); - assert_true(fd > 0); - - size = write(fd, &state->reset_cause, sizeof(state->reset_cause)); - assert_int_equal(size, sizeof(state->reset_cause)); - - ret = fsync(fd); - assert_return_code(ret, OK); - ret = close(fd); - assert_return_code(ret, OK); -} - -/**************************************************************************** - * Name: wdg_read_reset_cause - ****************************************************************************/ - -static void wdg_read_reset_cause(FAR struct wdg_state_s *state) -{ - int fd; - int ret; - ssize_t size; - - fd = open(state->infopath, O_RDONLY); - if (fd < 0) - { - state->reset_cause = WDG_RESET_CAUSE_NONE; - return; - } - - size = read(fd, &state->reset_cause, sizeof(state->reset_cause)); - assert_int_equal(size, sizeof(state->reset_cause)); - - ret = close(fd); - assert_return_code(ret, OK); -} - /**************************************************************************** * Name: wdg_init ****************************************************************************/ @@ -215,14 +164,14 @@ static int wdg_init(FAR struct wdg_state_s *state) static void show_usage(FAR const char *progname, FAR struct wdg_state_s *wdg_state, int exitcode) { - printf("Usage: %s -d -p -t " + printf("Usage: %s -d -r -t " "-l -o \n", progname); printf(" [-d devpath] selects the WATCHDOG device.\n" " Default: %s Current: %s\n", WDG_DEFAULT_DEV_PATH, wdg_state->devpath); - printf(" [-p infopath] selects the WATCHDOG reset cause path.\n" - " Default: %s Current: %s\n", WDG_DEFAULT_INFO_PATH, - wdg_state->infopath); + printf(" [-r test_case] selects the testcase.\n" + " Default: %d Current: %d\n", WDG_DEFAULT_TESTCASE, + wdg_state->test_case); printf(" [-t pingtime] Selects the time in milliseconds.\n" " Default: %d Current: %" PRIu32 "\n", WDG_DEFAULT_PINGTIMER, wdg_state->pingtime); @@ -247,7 +196,7 @@ static void parse_commandline(FAR struct wdg_state_s *wdg_state, int argc, int ch; int converted; - while ((ch = getopt(argc, argv, "d:p:t:l:o:h")) != ERROR) + while ((ch = getopt(argc, argv, "d:r:t:l:o:h")) != ERROR) { switch (ch) { @@ -258,6 +207,16 @@ static void parse_commandline(FAR struct wdg_state_s *wdg_state, int argc, case 'p': strlcpy(wdg_state->infopath, optarg, sizeof(wdg_state->infopath)); + case 'r': + OPTARG_TO_VALUE(converted, uint32_t, 10); + if (converted < WDG_DEFAULT_TESTCASE || + converted >= WDG_COUNT_TESTCASE) + { + printf("signal out of range: %d\n", converted); + show_usage(argv[0], wdg_state, EXIT_FAILURE); + } + + wdg_state->test_case = converted; break; case 't': @@ -315,18 +274,20 @@ static void test_case_wdog_01(FAR void **state) int ret; uint32_t start_ms; FAR struct wdg_state_s *wdg_state; + struct boardioc_reset_cause_s reset_cause; wdg_state = (FAR struct wdg_state_s *)*state; - wdg_read_reset_cause(wdg_state); - /* If it's not the first step, skip... */ - if (wdg_state->reset_cause != WDG_RESET_CAUSE_NONE) + if (wdg_state->test_case != 0) { return; } + board_reset_cause(&reset_cause); + assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_CHIPPOR); + dev_fd = wdg_init(wdg_state); /* Get the starting time */ @@ -347,11 +308,6 @@ static void test_case_wdog_01(FAR void **state) assert_return_code(ret, OK); } - /* write the reset cause */ - - wdg_state->reset_cause = WDG_RESET_CAUSE_NO_KEEP_ALIVE; - wdg_write_reset_cause(wdg_state); - /* Then stop pinging */ /* Sleep for the requested amount of time */ @@ -372,20 +328,19 @@ static void test_case_wdog_01(FAR void **state) static void test_case_wdog_02(FAR void **state) { FAR struct wdg_state_s *wdg_state; + struct boardioc_reset_cause_s reset_cause; wdg_state = (FAR struct wdg_state_s *)*state; - wdg_read_reset_cause(wdg_state); - - if (wdg_state->reset_cause != WDG_RESET_CAUSE_NO_KEEP_ALIVE) + if (wdg_state->test_case != 1) { return; } - wdg_init(wdg_state); + board_reset_cause(&reset_cause); + assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); - wdg_state->reset_cause = WDG_RESET_CAUSE_CRITICAL_SECTION_BUSY_LOOP; - wdg_write_reset_cause(wdg_state); + wdg_init(wdg_state); enter_critical_section(); @@ -418,20 +373,19 @@ static void test_case_wdog_03(FAR void **state) int ret; static struct wdog_s wdog; FAR struct wdg_state_s *wdg_state; + struct boardioc_reset_cause_s reset_cause; wdg_state = (FAR struct wdg_state_s *)*state; - wdg_read_reset_cause(wdg_state); - - if (wdg_state->reset_cause != WDG_RESET_CAUSE_CRITICAL_SECTION_BUSY_LOOP) + if (wdg_state->test_case != 2) { return; } - wdg_init(wdg_state); + board_reset_cause(&reset_cause); + assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); - wdg_state->reset_cause = WDG_RESET_CAUSE_IRQ_BUSY_LOOP; - wdg_write_reset_cause(wdg_state); + wdg_init(wdg_state); ret = wd_start(&wdog, 1, wdg_wdentry, (wdparm_t)0); assert_return_code(ret, OK); @@ -457,14 +411,14 @@ static void test_case_wdog_04(FAR void **state) int ret; uint32_t start_ms; FAR struct wdg_state_s *wdg_state; + struct boardioc_reset_cause_s reset_cause; wdg_state = (FAR struct wdg_state_s *)*state; - wdg_read_reset_cause(wdg_state); - assert_int_equal(wdg_state->reset_cause, WDG_RESET_CAUSE_IRQ_BUSY_LOOP); + assert_int_equal(wdg_state->test_case, 3); - ret = remove(wdg_state->infopath); - assert_return_code(ret, OK); + board_reset_cause(&reset_cause); + assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); dev_fd = wdg_init(wdg_state); @@ -508,10 +462,10 @@ int main(int argc, FAR char *argv[]) struct wdg_state_s wdg_state = { .devpath = WDG_DEFAULT_DEV_PATH, - .infopath = WDG_DEFAULT_INFO_PATH, .pingtime = WDG_DEFAULT_PINGTIMER, .pingdelay = WDG_DEFAULT_PINGDELAY, - .timeout = WDG_DEFAULT_TIMEOUT + .timeout = WDG_DEFAULT_TIMEOUT, + .test_case = WDG_DEFAULT_TESTCASE }; parse_commandline(&wdg_state, argc, argv); From 89e45cf340b24eda5fd278e90b04516d9b353952 Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Fri, 5 May 2023 11:11:40 +0800 Subject: [PATCH 2/4] test/watchdog:test interface getstatus. Signed-off-by: yangguangcai --- testing/drivertest/drivertest_watchdog.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/testing/drivertest/drivertest_watchdog.c b/testing/drivertest/drivertest_watchdog.c index 0845174845..8bfc04acb1 100644 --- a/testing/drivertest/drivertest_watchdog.c +++ b/testing/drivertest/drivertest_watchdog.c @@ -28,8 +28,6 @@ #include #include #include -#include - #include #include #include @@ -37,16 +35,14 @@ #include #include #include - #include #include #include #include #include - #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions @@ -57,6 +53,7 @@ #define WDG_DEFAULT_PINGDELAY 500 #define WDG_DEFAULT_TIMEOUT 2000 #define WDG_DEFAULT_TESTCASE 0 +#define WDG_DEFAULT_DEVIATION 20 #define WDG_COUNT_TESTCASE 4 #define OPTARG_TO_VALUE(value, type, base) \ @@ -92,8 +89,6 @@ struct wdg_state_s * Private Functions ****************************************************************************/ -extern int board_reset_cause(FAR struct boardioc_reset_cause_s *cause); - /**************************************************************************** * Name: get_timestamp ****************************************************************************/ @@ -411,6 +406,7 @@ static void test_case_wdog_04(FAR void **state) int ret; uint32_t start_ms; FAR struct wdg_state_s *wdg_state; + struct watchdog_status_s status; struct boardioc_reset_cause_s reset_cause; wdg_state = (FAR struct wdg_state_s *)*state; @@ -434,6 +430,16 @@ static void test_case_wdog_04(FAR void **state) usleep(wdg_state->pingdelay * 1000); + /* Get Status */ + + ret = ioctl(dev_fd, WDIOC_GETSTATUS, &status); + assert_return_code(ret, OK); + + assert_int_equal(status.timeout, wdg_state->timeout); + assert_in_range( + status.timeout - status.timeleft - wdg_state->pingdelay, + 0, WDG_DEFAULT_DEVIATION); + /* Then ping */ ret = ioctl(dev_fd, WDIOC_KEEPALIVE, 0); From 6b718ccc9b88e9f1b03d3a52770c1e76eff6914a Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Mon, 26 Jun 2023 18:27:22 +0800 Subject: [PATCH 3/4] test/watchdog:call board_ioctl from board_reset_cause. Signed-off-by: yangguangcai --- testing/drivertest/drivertest_watchdog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/drivertest/drivertest_watchdog.c b/testing/drivertest/drivertest_watchdog.c index 8bfc04acb1..e1b5bcb0da 100644 --- a/testing/drivertest/drivertest_watchdog.c +++ b/testing/drivertest/drivertest_watchdog.c @@ -280,7 +280,7 @@ static void test_case_wdog_01(FAR void **state) return; } - board_reset_cause(&reset_cause); + boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_CHIPPOR); dev_fd = wdg_init(wdg_state); @@ -332,7 +332,7 @@ static void test_case_wdog_02(FAR void **state) return; } - board_reset_cause(&reset_cause); + boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); wdg_init(wdg_state); @@ -377,7 +377,7 @@ static void test_case_wdog_03(FAR void **state) return; } - board_reset_cause(&reset_cause); + boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); wdg_init(wdg_state); @@ -413,7 +413,7 @@ static void test_case_wdog_04(FAR void **state) assert_int_equal(wdg_state->test_case, 3); - board_reset_cause(&reset_cause); + boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&reset_cause); assert_int_equal(reset_cause.cause, BOARDIOC_RESETCAUSE_SYS_RWDT); dev_fd = wdg_init(wdg_state); From c6a7046657efb67a3a537094e8145212046dba38 Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Fri, 7 Jul 2023 17:15:17 +0800 Subject: [PATCH 4/4] watchdog:input watchdog deviation. Signed-off-by: yangguangcai --- testing/drivertest/drivertest_watchdog.c | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/testing/drivertest/drivertest_watchdog.c b/testing/drivertest/drivertest_watchdog.c index e1b5bcb0da..1bd44b3f22 100644 --- a/testing/drivertest/drivertest_watchdog.c +++ b/testing/drivertest/drivertest_watchdog.c @@ -78,6 +78,7 @@ struct wdg_state_s uint32_t pingtime; uint32_t pingdelay; uint32_t timeout; + uint32_t deviation; int test_case; }; @@ -160,7 +161,7 @@ static void show_usage(FAR const char *progname, FAR struct wdg_state_s *wdg_state, int exitcode) { printf("Usage: %s -d -r -t " - "-l -o \n", progname); + "-l -o -a \n", progname); printf(" [-d devpath] selects the WATCHDOG device.\n" " Default: %s Current: %s\n", WDG_DEFAULT_DEV_PATH, wdg_state->devpath); @@ -176,6 +177,9 @@ static void show_usage(FAR const char *progname, printf(" [-o timeout] Time in milliseconds that the testcase will\n" " Default: %d Current: %" PRIu32 "\n", WDG_DEFAULT_TIMEOUT, wdg_state->timeout); + printf(" [-a deviation] Watchdog getstatus precision.\n" + " Default: %d Current: %" PRIu32 "\n", + WDG_DEFAULT_DEVIATION, wdg_state->deviation); printf(" [-h] = Shows this message and exits\n"); exit(exitcode); @@ -191,7 +195,7 @@ static void parse_commandline(FAR struct wdg_state_s *wdg_state, int argc, int ch; int converted; - while ((ch = getopt(argc, argv, "d:r:t:l:o:h")) != ERROR) + while ((ch = getopt(argc, argv, "d:r:t:l:o:a:h")) != ERROR) { switch (ch) { @@ -240,13 +244,24 @@ static void parse_commandline(FAR struct wdg_state_s *wdg_state, int argc, OPTARG_TO_VALUE(converted, uint32_t, 10); if (converted < 1 || converted > INT_MAX) { - printf("signal out of range: %d", converted); + printf("signal out of range: %d\n", converted); show_usage(argv[0], wdg_state, EXIT_FAILURE); } wdg_state->timeout = (uint32_t)converted; break; + case 'a': + OPTARG_TO_VALUE(converted, uint32_t, 10); + if (converted < 1 || converted > INT_MAX) + { + printf("signal out of range: %d\n", converted); + show_usage(argv[0], wdg_state, EXIT_FAILURE); + } + + wdg_state->deviation = (uint32_t)converted; + break; + case '?': printf("Unsupported option: %s\n", optarg); show_usage(argv[0], wdg_state, EXIT_FAILURE); @@ -437,8 +452,9 @@ static void test_case_wdog_04(FAR void **state) assert_int_equal(status.timeout, wdg_state->timeout); assert_in_range( - status.timeout - status.timeleft - wdg_state->pingdelay, - 0, WDG_DEFAULT_DEVIATION); + status.timeout - status.timeleft, + wdg_state->pingdelay - wdg_state->deviation, + wdg_state->pingdelay + wdg_state->deviation); /* Then ping */ @@ -471,7 +487,8 @@ int main(int argc, FAR char *argv[]) .pingtime = WDG_DEFAULT_PINGTIMER, .pingdelay = WDG_DEFAULT_PINGDELAY, .timeout = WDG_DEFAULT_TIMEOUT, - .test_case = WDG_DEFAULT_TESTCASE + .test_case = WDG_DEFAULT_TESTCASE, + .deviation = WDG_DEFAULT_DEVIATION }; parse_commandline(&wdg_state, argc, argv);