xiaoxiang781216 commented on code in PR #3639:
URL: https://github.com/apache/nuttx-apps/pull/3639#discussion_r3615876047


##########
testing/drivers/drivertest/drivertest_watchdog.c:
##########
@@ -281,16 +305,224 @@ static void parse_commandline(FAR struct wdg_state_s 
*wdg_state, int argc,
     }
 }
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+
 /****************************************************************************
  * Name: capture_callback
  ****************************************************************************/
 
 static int capture_callback(int irq, FAR void *context, FAR void *arg)
 {
-  sem_post(&g_semaphore);
+  DEBUGASSERT(g_capture_test_state != NULL);
+  sem_post(&g_capture_test_state->semaphore);
+  return OK;
+}
+
+#endif /* CONFIG_BOARDCTL_RESET_CAUSE */
+
+#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
+
+struct watchdog_notifier_test_nb_s
+{
+  struct notifier_block nb;
+  FAR struct wdg_state_s *state;
+  int                   id;
+};
+
+static int watchdog_notifier_test_callback(FAR struct notifier_block *nb,
+                                            unsigned long action,
+                                            FAR void *data)
+{
+  FAR struct watchdog_notifier_test_nb_s *test_nb;
+  unsigned int index;
+
+  test_nb = container_of(nb, struct watchdog_notifier_test_nb_s, nb);
+  index = test_nb->state->notifier_calls;
+  if (index < 8)
+    {
+      test_nb->state->notifier_action[index] = action;
+      test_nb->state->notifier_data[index] = data;
+      test_nb->state->notifier_id[index] = test_nb->id;
+    }
+
+  test_nb->state->notifier_calls++;
+  return OK;
+}
+
+static unsigned long watchdog_notifier_test_expected_action(void)
+{
+#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
+  return WATCHDOG_KEEPALIVE_BY_ONESHOT;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
+  return WATCHDOG_KEEPALIVE_BY_TIMER;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
+  return WATCHDOG_KEEPALIVE_BY_WDOG;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WORKER)
+  return WATCHDOG_KEEPALIVE_BY_WORKER;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
+  return WATCHDOG_KEEPALIVE_BY_CAPTURE;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_IDLE)
+  return WATCHDOG_KEEPALIVE_BY_IDLE;
+#else
+#  error "An automonitor source must be selected"
+#endif
+}
+
+static void drivertest_watchdog_notifier(FAR void **state)
+{
+  FAR struct wdg_state_s *wdg_state = *state;
+
+  struct watchdog_notifier_test_nb_s low =
+  {
+    .nb =
+      {
+        .notifier_call = watchdog_notifier_test_callback,
+        .priority = 10
+      },
+    .state = wdg_state,
+    .id = 1
+  };
+
+  struct watchdog_notifier_test_nb_s high =
+  {
+    .nb =
+      {
+        .notifier_call = watchdog_notifier_test_callback,
+        .priority = 20
+      },
+    .state = wdg_state,
+    .id = 2
+  };
+
+  unsigned long expected_action;
+
+  expected_action = watchdog_notifier_test_expected_action();
+  wdg_state->notifier_calls = 0;
+
+  /* Registration is priority ordered, and duplicate registration of the
+   * same notifier must not result in a duplicate callback.
+   */
+
+  watchdog_notifier_chain_register(&low.nb);
+  watchdog_notifier_chain_register(&low.nb);
+  watchdog_notifier_chain_register(&high.nb);
+
+  watchdog_automonitor_timeout();
+
+  assert_int_equal(wdg_state->notifier_calls, 2);
+  assert_int_equal(wdg_state->notifier_id[0], high.id);
+  assert_int_equal(wdg_state->notifier_id[1], low.id);
+  assert_int_equal(wdg_state->notifier_action[0], expected_action);
+  assert_int_equal(wdg_state->notifier_action[1], expected_action);
+  assert_null(wdg_state->notifier_data[0]);
+  assert_null(wdg_state->notifier_data[1]);
+
+  /* Every timeout notification is delivered to all currently registered
+   * callbacks.
+   */
+
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 4);
+  assert_int_equal(wdg_state->notifier_id[2], high.id);
+  assert_int_equal(wdg_state->notifier_id[3], low.id);
+
+  /* Unregistering one callback removes only that callback. */
+
+  watchdog_notifier_chain_unregister(&high.nb);
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 5);
+  assert_int_equal(wdg_state->notifier_id[4], low.id);
+
+  watchdog_notifier_chain_unregister(&low.nb);
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 5);
+}
+
+struct watchdog_notifier_race_s
+{
+  struct watchdog_notifier_test_nb_s nb;
+  volatile bool stop;
+};
+
+static volatile unsigned int g_notifier_race_callbacks;

Review Comment:
   move to watchdog_notifier_race_s



##########
testing/drivers/drivertest/drivertest_watchdog.c:
##########
@@ -281,16 +305,224 @@ static void parse_commandline(FAR struct wdg_state_s 
*wdg_state, int argc,
     }
 }
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+
 /****************************************************************************
  * Name: capture_callback
  ****************************************************************************/
 
 static int capture_callback(int irq, FAR void *context, FAR void *arg)
 {
-  sem_post(&g_semaphore);
+  DEBUGASSERT(g_capture_test_state != NULL);
+  sem_post(&g_capture_test_state->semaphore);
+  return OK;
+}
+
+#endif /* CONFIG_BOARDCTL_RESET_CAUSE */
+
+#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
+
+struct watchdog_notifier_test_nb_s

Review Comment:
   move the struct to private type section



##########
testing/drivers/drivertest/drivertest_watchdog.c:
##########
@@ -281,16 +305,224 @@ static void parse_commandline(FAR struct wdg_state_s 
*wdg_state, int argc,
     }
 }
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+
 /****************************************************************************
  * Name: capture_callback
  ****************************************************************************/
 
 static int capture_callback(int irq, FAR void *context, FAR void *arg)
 {
-  sem_post(&g_semaphore);
+  DEBUGASSERT(g_capture_test_state != NULL);
+  sem_post(&g_capture_test_state->semaphore);
+  return OK;
+}
+
+#endif /* CONFIG_BOARDCTL_RESET_CAUSE */
+
+#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
+
+struct watchdog_notifier_test_nb_s
+{
+  struct notifier_block nb;
+  FAR struct wdg_state_s *state;
+  int                   id;
+};
+
+static int watchdog_notifier_test_callback(FAR struct notifier_block *nb,
+                                            unsigned long action,
+                                            FAR void *data)
+{
+  FAR struct watchdog_notifier_test_nb_s *test_nb;
+  unsigned int index;
+
+  test_nb = container_of(nb, struct watchdog_notifier_test_nb_s, nb);
+  index = test_nb->state->notifier_calls;
+  if (index < 8)
+    {
+      test_nb->state->notifier_action[index] = action;
+      test_nb->state->notifier_data[index] = data;
+      test_nb->state->notifier_id[index] = test_nb->id;
+    }
+
+  test_nb->state->notifier_calls++;
+  return OK;
+}
+
+static unsigned long watchdog_notifier_test_expected_action(void)
+{
+#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
+  return WATCHDOG_KEEPALIVE_BY_ONESHOT;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
+  return WATCHDOG_KEEPALIVE_BY_TIMER;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
+  return WATCHDOG_KEEPALIVE_BY_WDOG;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WORKER)
+  return WATCHDOG_KEEPALIVE_BY_WORKER;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
+  return WATCHDOG_KEEPALIVE_BY_CAPTURE;
+#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_IDLE)
+  return WATCHDOG_KEEPALIVE_BY_IDLE;
+#else
+#  error "An automonitor source must be selected"
+#endif
+}
+
+static void drivertest_watchdog_notifier(FAR void **state)
+{
+  FAR struct wdg_state_s *wdg_state = *state;
+
+  struct watchdog_notifier_test_nb_s low =
+  {
+    .nb =
+      {
+        .notifier_call = watchdog_notifier_test_callback,
+        .priority = 10
+      },
+    .state = wdg_state,
+    .id = 1
+  };
+
+  struct watchdog_notifier_test_nb_s high =
+  {
+    .nb =
+      {
+        .notifier_call = watchdog_notifier_test_callback,
+        .priority = 20
+      },
+    .state = wdg_state,
+    .id = 2
+  };
+
+  unsigned long expected_action;
+
+  expected_action = watchdog_notifier_test_expected_action();
+  wdg_state->notifier_calls = 0;
+
+  /* Registration is priority ordered, and duplicate registration of the
+   * same notifier must not result in a duplicate callback.
+   */
+
+  watchdog_notifier_chain_register(&low.nb);
+  watchdog_notifier_chain_register(&low.nb);
+  watchdog_notifier_chain_register(&high.nb);
+
+  watchdog_automonitor_timeout();
+
+  assert_int_equal(wdg_state->notifier_calls, 2);
+  assert_int_equal(wdg_state->notifier_id[0], high.id);
+  assert_int_equal(wdg_state->notifier_id[1], low.id);
+  assert_int_equal(wdg_state->notifier_action[0], expected_action);
+  assert_int_equal(wdg_state->notifier_action[1], expected_action);
+  assert_null(wdg_state->notifier_data[0]);
+  assert_null(wdg_state->notifier_data[1]);
+
+  /* Every timeout notification is delivered to all currently registered
+   * callbacks.
+   */
+
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 4);
+  assert_int_equal(wdg_state->notifier_id[2], high.id);
+  assert_int_equal(wdg_state->notifier_id[3], low.id);
+
+  /* Unregistering one callback removes only that callback. */
+
+  watchdog_notifier_chain_unregister(&high.nb);
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 5);
+  assert_int_equal(wdg_state->notifier_id[4], low.id);
+
+  watchdog_notifier_chain_unregister(&low.nb);
+  watchdog_automonitor_timeout();
+  assert_int_equal(wdg_state->notifier_calls, 5);
+}
+
+struct watchdog_notifier_race_s

Review Comment:
   move the struct to private type section



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to