-
Notifications
You must be signed in to change notification settings - Fork 382
mtest: Add watchdog test #3719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
mtest: Add watchdog test #3719
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
35
test/mtest/mtest_watchdog/include/mtest_watchdog/mtest_watchdog.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| /* 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mynewt-core/test/mtest/mtest_watchdog/src/watchdog_test_cases.c
Lines 46 to 48 in 2705534
watchdog_test_case_1();actually does return when the time counter is at least 2xWATCHDOG_INTERVAL.Adding a
breakstatement would break the test flow, andwatchdog_test_case_2();would never execute.There was a problem hiding this comment.
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:
It will work the same but will get rid of the fallthrough in the switch statement.
There was a problem hiding this comment.
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