From 6d41e78bb3538d73656635f2bb2fb47790bdc4d0 Mon Sep 17 00:00:00 2001 From: Wiktor Kwiatkowski Date: Tue, 28 Jul 2026 14:04:09 +0200 Subject: [PATCH 1/2] test/mtest: Add syscfg option to delay test execution Define MTEST_START_DELAY [s] to pause before test cases begin. No delay by default. --- test/mtest/mtest/src/mtest.c | 3 +++ test/mtest/mtest/syscfg.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/mtest/mtest/src/mtest.c b/test/mtest/mtest/src/mtest.c index 3b6d3d82c5..2296c750d7 100644 --- a/test/mtest/mtest/src/mtest.c +++ b/test/mtest/mtest/src/mtest.c @@ -55,6 +55,9 @@ mtest_case_complete(void) void mtest_suite_init(const char *name) { + if (MYNEWT_VAL(MTEST_START_DELAY) > 0) { + os_time_delay(MYNEWT_VAL(MTEST_START_DELAY) * OS_TICKS_PER_SEC); + } printf("MTEST test=%s \n", MYNEWT_VAL(APP_NAME)); printf("MTEST bsp=%s \n", MYNEWT_VAL(BSP_NAME)); printf("MTEST core=%s\n\n", MYNEWT_VAL(REPO_HASH_APACHE_MYNEWT_CORE)); diff --git a/test/mtest/mtest/syscfg.yml b/test/mtest/mtest/syscfg.yml index 9d3c811a81..b1c22eab5c 100644 --- a/test/mtest/mtest/syscfg.yml +++ b/test/mtest/mtest/syscfg.yml @@ -18,3 +18,6 @@ # syscfg.defs: + MTEST_START_DELAY: + description: 'Time before test will be executed in seconds' + value: 0 From 1f6006788746f669fb96d2ab45c9b754ad38e506 Mon Sep 17 00:00:00 2001 From: Wiktor Kwiatkowski Date: Tue, 28 Jul 2026 15:26:22 +0200 Subject: [PATCH 2/2] 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_watchdog/src/watchdog_test_cases.c | 77 +++++++++++++++++++ test/mtest/mtest_watchdog/syscfg.yml | 21 +++++ 5 files changed, 229 insertions(+) create mode 100644 test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h create mode 100644 test/mtest/mtest_watchdog/pkg.yml create mode 100644 test/mtest/mtest_watchdog/src/main.c create mode 100644 test/mtest/mtest_watchdog/src/watchdog_test_cases.c create mode 100644 test/mtest/mtest_watchdog/syscfg.yml 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 0000000000..17720eb5f5 --- /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 0000000000..80a3aa502d --- /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 " +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 0000000000..74e23526b1 --- /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 0000000000..57426d77f4 --- /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 0000000000..088f8de494 --- /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