Skip to content

Update watchdog tests to run with bare metal profile #12182

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 2 commits into from
Jan 3, 2020
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
28 changes: 4 additions & 24 deletions TESTS/mbed_drivers/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !defined(MBED_CONF_RTOS_PRESENT)
#error [NOT_SUPPORTED] Watchdog test cases require a RTOS to run.
#else

#if !DEVICE_WATCHDOG
#error [NOT_SUPPORTED] Watchdog not supported for this target
#else
Expand Down Expand Up @@ -73,18 +68,6 @@ using utest::v1::Harness;

using namespace mbed;

Thread wdg_kicking_thread(osPriorityNormal, 768);
Semaphore kick_wdg_during_test_teardown(0, 1);

void wdg_kicking_thread_fun()
{
kick_wdg_during_test_teardown.wait();
while (true) {
hal_watchdog_kick();
wait_ms(20);
}
}

void test_max_timeout_is_valid()
{
Watchdog &watchdog = Watchdog::get_instance();
Expand Down Expand Up @@ -172,8 +155,10 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
if (CASE_IGNORED) {
return utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
}
// Unlock kicking the watchdog during teardown.
kick_wdg_during_test_teardown.release();
// Start kicking the watchdog during teardown.
hal_watchdog_kick();
Ticker wdg_kicking_ticker;
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
if (failed) {
/* Return immediately and skip the device reset, if the test case failed.
Expand Down Expand Up @@ -260,10 +245,6 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
return utest::v1::STATUS_ABORT;
}

// The thread is started here, but feeding the watchdog will start
// when the semaphore is released during a test case teardown.
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));

utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
return CASE_INDEX_START;
}
Expand All @@ -289,4 +270,3 @@ int main()
}

#endif // !DEVICE_WATCHDOG
#endif // !defined(MBED_CONG_RTOS_PRESENT)
37 changes: 11 additions & 26 deletions TESTS/mbed_drivers/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(MBED_CONF_RTOS_PRESENT)
#error [NOT_SUPPORTED] Watchdog reset test cases require a RTOS to run.
#else

#if !DEVICE_WATCHDOG
#error [NOT_SUPPORTED] Watchdog not supported for this target
#else
Expand Down Expand Up @@ -90,18 +86,7 @@ struct testcase_data {

testcase_data current_case;

Thread wdg_kicking_thread(osPriorityNormal, 768);
Semaphore kick_wdg_during_test_teardown(0, 1);

void wdg_kicking_thread_fun()
{
kick_wdg_during_test_teardown.acquire();
Watchdog &watchdog = Watchdog::get_instance();
while (true) {
watchdog.kick();
wait_us(20000);
}
}
Ticker wdg_kicking_ticker;

bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
{
Expand Down Expand Up @@ -140,7 +125,8 @@ void test_simple_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -174,7 +160,8 @@ void test_sleep_reset()

// Watchdog reset should have occurred during the sleep above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -210,7 +197,8 @@ void test_deepsleep_reset()

// Watchdog reset should have occurred during the deepsleep above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}
#endif
Expand Down Expand Up @@ -255,7 +243,8 @@ void test_restart_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -288,7 +277,8 @@ void test_kick_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -323,10 +313,6 @@ int testsuite_setup(const size_t number_of_cases)
return utest::v1::STATUS_ABORT;
}

// The thread is started here, but feeding the watchdog will start
// when the semaphore is released during a test case teardown.
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));

utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases,
current_case.start_index);
return current_case.start_index;
Expand All @@ -352,4 +338,3 @@ int main()
return !Harness::run(specification);
}
#endif // !DEVICE_WATCHDOG
#endif // !defined(MBED_CONF_RTOS_PRESENT)
29 changes: 5 additions & 24 deletions TESTS/mbed_hal/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(MBED_CONF_RTOS_PRESENT)
#error [NOT_SUPPORTED] Watchdog test cases require a RTOS to run.
#else

#if !DEVICE_WATCHDOG
#error [NOT_SUPPORTED] Watchdog not supported for this target
#else
Expand Down Expand Up @@ -73,18 +69,6 @@ using utest::v1::Harness;

const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };

Thread wdg_kicking_thread(osPriorityNormal, 768);
Semaphore kick_wdg_during_test_teardown(0, 1);

void wdg_kicking_thread_fun()
{
kick_wdg_during_test_teardown.wait();
while (true) {
hal_watchdog_kick();
wait_ms(20);
}
}

void test_max_timeout_is_valid()
{
TEST_ASSERT(hal_watchdog_get_platform_features().max_timeout > 1UL);
Expand Down Expand Up @@ -168,8 +152,10 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
if (CASE_IGNORED) {
return utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
}
// Unlock kicking the watchdog during teardown.
kick_wdg_during_test_teardown.release();
// Start kicking the watchdog during teardown.
hal_watchdog_kick();
Ticker wdg_kicking_ticker;
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
if (failed) {
/* Return immediately and skip the device reset, if the test case failed.
Expand Down Expand Up @@ -256,10 +242,6 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
return utest::v1::STATUS_ABORT;
}

// The thread is started here, but feeding the watchdog will start
// when the semaphore is released during a test case teardown.
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));

utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
return CASE_INDEX_START;
}
Expand Down Expand Up @@ -288,5 +270,4 @@ int main()
return !Harness::run(specification);
}

#endif // !DEVICE_WATCHDOG
#endif // !defined(MBED_CONF_RTOS_PRESENT)
#endif // !DEVICE_WATCHDOG
36 changes: 11 additions & 25 deletions TESTS/mbed_hal/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !MBED_CONF_RTOS_PRESENT
#error [NOT_SUPPORTED] Watchdog reset test cases require a RTOS to run.
#else

#if !DEVICE_WATCHDOG
#error [NOT_SUPPORTED] Watchdog not supported for this target
#else
Expand Down Expand Up @@ -88,17 +84,7 @@ struct testcase_data {

testcase_data current_case;

Thread wdg_kicking_thread(osPriorityNormal, 768);
Semaphore kick_wdg_during_test_teardown(0, 1);

void wdg_kicking_thread_fun()
{
kick_wdg_during_test_teardown.acquire();
while (true) {
hal_watchdog_kick();
wait_us(20000);
}
}
Ticker wdg_kicking_ticker;

bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
{
Expand Down Expand Up @@ -135,7 +121,8 @@ void test_simple_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -167,7 +154,8 @@ void test_sleep_reset()

// Watchdog reset should have occurred during the sleep above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -201,7 +189,8 @@ void test_deepsleep_reset()

// Watchdog reset should have occurred during the deepsleep above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}
#endif
Expand Down Expand Up @@ -242,7 +231,8 @@ void test_restart_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -273,7 +263,8 @@ void test_kick_reset()

// Watchdog reset should have occurred during a wait above.

kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
hal_watchdog_kick();
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
}

Expand Down Expand Up @@ -308,10 +299,6 @@ int testsuite_setup(const size_t number_of_cases)
return utest::v1::STATUS_ABORT;
}

// The thread is started here, but feeding the watchdog will start
// when the semaphore is released during a test case teardown.
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));

utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases,
current_case.start_index);
return current_case.start_index;
Expand All @@ -338,4 +325,3 @@ int main()
}

#endif // !DEVICE_WATCHDOG
#endif // !MBED_CONF_RTOS_PRESENT