You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2026/08/28 10:44:42 UTC
(mynewt-core) 02/02: mtest: Add watchdog test
This is an automated email from the ASF dual-hosted git repository.
sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 259aa4d35834accecfa67bde6ed4038927716099
Author: Wiktor Kwiatkowski <wi...@codecoup.pl>
AuthorDate: Tue Jul 28 15:26:22 2026 +0200
mtest: Add watchdog test
This test adds two main test cases. The first case verifies whether
periodically calling hal_watchdog_tickle prevents the watchdog from
firing. The second case verifies that starving the watchdog correctly
triggers a system reset.
---
.../include/mtest_watchdog/mtest_watchdog.h | 35 ++++++++++
test/mtest/mtest_watchdog/pkg.yml | 32 +++++++++
test/mtest/mtest_watchdog/src/main.c | 64 ++++++++++++++++++
.../mtest/mtest_watchdog/src/watchdog_test_cases.c | 77 ++++++++++++++++++++++
test/mtest/mtest_watchdog/syscfg.yml | 21 ++++++
5 files changed, 229 insertions(+)
diff --git a/test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h b/test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h
new file mode 100644
index 000000000..17720eb5f
--- /dev/null
+++ b/test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef MTEST_WATCHDOG_H
+#define MTEST_WATCHDOG_H
+#include "mtest/mtest.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+MTEST_CASE_DECL(watchdog_test_case_1);
+MTEST_CASE_DECL(watchdog_test_case_2);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/test/mtest/mtest_watchdog/pkg.yml b/test/mtest/mtest_watchdog/pkg.yml
new file mode 100644
index 000000000..80a3aa502
--- /dev/null
+++ b/test/mtest/mtest_watchdog/pkg.yml
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: test/mtest/mtest_watchdog
+pkg.type: app
+pkg.description: "Tests watchdog"
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/hw/hal"
+ - "@apache-mynewt-core/sys/console"
+ - "@apache-mynewt-core/sys/log"
+ - "@apache-mynewt-core/test/mtest/mtest"
diff --git a/test/mtest/mtest_watchdog/src/main.c b/test/mtest/mtest_watchdog/src/main.c
new file mode 100644
index 000000000..74e23526b
--- /dev/null
+++ b/test/mtest/mtest_watchdog/src/main.c
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os_time.h"
+#include "mtest_watchdog/mtest_watchdog.h"
+
+#define FIRST_BOOT_DONE 0xC001B007
+volatile int reset_count __attribute__((section(".noinit")));
+volatile int boot_status __attribute__((section(".noinit")));
+
+MTEST_INIT(watchdog_test)
+{
+ if (boot_status != FIRST_BOOT_DONE) {
+ reset_count = 0;
+ boot_status = FIRST_BOOT_DONE;
+ /* Readback required by STM32H723ZG to ensure data reaches DTCM */
+ (void)boot_status;
+ }
+}
+
+MTEST_SUITE(watchdog_test)
+{
+ MTEST_RUN_INIT(watchdog_test);
+ switch (reset_count) {
+ case 0:
+ watchdog_test_case_1();
+ /* fallthrough */
+ case 1:
+ watchdog_test_case_2();
+ break;
+ default:
+ boot_status = 0;
+ reset_count = 0;
+ }
+}
+
+int
+mynewt_main(int argc, char **argv)
+{
+ sysinit();
+
+ watchdog_test();
+
+ while (1) {
+ os_time_delay(OS_TICKS_PER_SEC);
+ }
+}
diff --git a/test/mtest/mtest_watchdog/src/watchdog_test_cases.c b/test/mtest/mtest_watchdog/src/watchdog_test_cases.c
new file mode 100644
index 000000000..57426d77f
--- /dev/null
+++ b/test/mtest/mtest_watchdog/src/watchdog_test_cases.c
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "mtest/mtest.h"
+#include "hal/hal_system.h"
+#include "hal/hal_watchdog.h"
+#include "mtest_watchdog/mtest_watchdog.h"
+#include "os/os_cputime.h"
+
+extern volatile int reset_count;
+
+MTEST_CASE(watchdog_test_case_1)
+{
+ uint32_t start;
+ uint32_t last_tickle;
+ uint32_t now;
+
+ enum hal_reset_reason reason = hal_reset_cause();
+ MTEST_CASE_ASSERT(reason != HAL_RESET_WATCHDOG, "WDOG tickle failed");
+
+ start = os_cputime_ticks_to_usecs(os_cputime_get32());
+ last_tickle = start;
+ while (1) {
+ now = os_cputime_ticks_to_usecs(os_cputime_get32());
+ if (now - last_tickle >= MYNEWT_VAL(WATCHDOG_INTERVAL) * 1000 / 4) {
+ hal_watchdog_tickle();
+ last_tickle = now;
+ }
+
+ if (now - start >= 2 * (MYNEWT_VAL(WATCHDOG_INTERVAL) * 1000)) {
+ break;
+ }
+ }
+}
+
+MTEST_CASE(watchdog_test_case_2)
+{
+ uint32_t start;
+ uint32_t now;
+ enum hal_reset_reason reason;
+
+ if (reset_count == 1) {
+ reason = hal_reset_cause();
+ MTEST_CASE_ASSERT(reason == HAL_RESET_WATCHDOG, "Expected WDOG reset");
+ return;
+ }
+
+ reset_count++;
+ /* Readback required by STM32H723ZG to ensure data reaches DTCM */
+ (void)reset_count;
+
+ printf("Starving WDOG...\n");
+ start = os_cputime_ticks_to_usecs(os_cputime_get32());
+ while (1) {
+ now = os_cputime_ticks_to_usecs(os_cputime_get32());
+
+ if (now - start > 2 * (MYNEWT_VAL(WATCHDOG_INTERVAL) * 1000)) {
+ MTEST_CASE_ASSERT(0, "WDOG failed to fire");
+ }
+ }
+}
diff --git a/test/mtest/mtest_watchdog/syscfg.yml b/test/mtest/mtest_watchdog/syscfg.yml
new file mode 100644
index 000000000..088f8de49
--- /dev/null
+++ b/test/mtest/mtest_watchdog/syscfg.yml
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.vals:
+ WATCHDOG_INTERVAL: 2000
+ SANITY_INTERVAL: 500