Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/mtest/mtest/src/mtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions test/mtest/mtest/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
#

syscfg.defs:
MTEST_START_DELAY:
description: 'Time before test will be executed in seconds'
value: 0
35 changes: 35 additions & 0 deletions test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions test/mtest/mtest_watchdog/pkg.yml
Original file line number Diff line number Diff line change
@@ -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 <dev@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"
64 changes: 64 additions & 0 deletions test/mtest/mtest_watchdog/src/main.c
Original file line number Diff line number Diff line change
@@ -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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while those functions should never return I'd still add break for sake of coding style

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (now - start >= 2 * (MYNEWT_VAL(WATCHDOG_INTERVAL) * 1000)) {
break;
}

watchdog_test_case_1(); actually does return when the time counter is at least 2x WATCHDOG_INTERVAL.
Adding a break statement would break the test flow, and watchdog_test_case_2(); would never execute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the switch statement to something like this:

if (reset_count == 0) { 
        watchdog_test_case_1();
        watchdog_test_case_2();
    } else if (reset_count == 1) {
        watchdog_test_case_2();
    } else {
        boot_status = 0;
        reset_count = 0;
    } 

It will work the same but will get rid of the fallthrough in the switch statement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch is fine, but comment if fall-through is on purpose

/* 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);
}
}
77 changes: 77 additions & 0 deletions test/mtest/mtest_watchdog/src/watchdog_test_cases.c
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
21 changes: 21 additions & 0 deletions test/mtest/mtest_watchdog/syscfg.yml
Original file line number Diff line number Diff line change
@@ -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
Loading