mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Test: Watchdog: Update the test case teardown
Replace the thread used in the test case teardown with a Ticker to allow testing with the bare metal profile. This Ticker is used to prevent the watchdog from resetting the device during the final greentea communication.pull/12182/head
							parent
							
								
									de798c4f37
								
							
						
					
					
						commit
						5a0fafdc89
					
				| 
						 | 
				
			
			@ -73,18 +73,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();
 | 
			
		||||
| 
						 | 
				
			
			@ -172,8 +160,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.
 | 
			
		||||
| 
						 | 
				
			
			@ -260,10 +250,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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,18 +90,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)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +129,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -174,7 +164,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +201,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
 | 
			
		||||
| 
						 | 
				
			
			@ -255,7 +247,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -288,7 +281,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -323,10 +317,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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,18 +73,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);
 | 
			
		||||
| 
						 | 
				
			
			@ -168,8 +156,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.
 | 
			
		||||
| 
						 | 
				
			
			@ -256,10 +246,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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,17 +88,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)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -135,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -167,7 +158,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +193,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
 | 
			
		||||
| 
						 | 
				
			
			@ -242,7 +235,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +267,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.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -308,10 +303,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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue