Enlarge wait time for flushing serial buffer in Greentea test code

Original wait time is not enough for UART to flush out before deepsleep/reset on some targets.
pull/10657/head
ccli8 2018-07-23 11:42:20 +08:00 committed by Filip Jagodzinski
parent 84440531f1
commit 5190ec8048
3 changed files with 52 additions and 4 deletions

View File

@ -49,6 +49,22 @@
#define MSG_KEY_RESET_REASON "reason"
#define MSG_KEY_DEVICE_RESET "reset"
/* Flush serial buffer before deep sleep/reset
*
* Since deepsleep()/reset would shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
* 20ms here for safe.
*
* This should be replaced with a better function that checks if the
* hardware buffers are empty. However, such an API does not exist now,
* so we'll use the wait_ms() function for now.
*/
#define SERIAL_FLUSH_TIME_MS 20
typedef enum {
CMD_STATUS_CONTINUE,
CMD_STATUS_ERROR
@ -85,7 +101,7 @@ static cmd_status_t handle_command(const char *key, const char *value)
if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_NVIC) == 0) {
greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK);
wait_ms(10); // Wait for the serial buffers to flush.
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
NVIC_SystemReset();
TEST_ASSERT_MESSAGE(0, "NVIC_SystemReset did not reset the device as expected.");
return CMD_STATUS_ERROR;
@ -94,7 +110,7 @@ static cmd_status_t handle_command(const char *key, const char *value)
#if DEVICE_WATCHDOG
if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) {
greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK);
wait_ms(10); // Wait for the serial buffers to flush.
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS };
if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) {
TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error.");

View File

@ -41,6 +41,22 @@
#define MSG_KEY_START_CASE "start_case"
#define MSG_KEY_DEVICE_RESET "reset_on_case_teardown"
/* Flush serial buffer before deep sleep/reset
*
* Since deepsleep()/reset would shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
* 20ms here for safe.
*
* This should be replaced with a better function that checks if the
* hardware buffers are empty. However, such an API does not exist now,
* so we'll use the wait_ms() function for now.
*/
#define SERIAL_FLUSH_TIME_MS 20
int CASE_INDEX_START;
int CASE_INDEX_CURRENT;
@ -128,7 +144,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case * const source, const
}
greentea_send_kv(MSG_KEY_DEVICE_RESET, CASE_INDEX_START + CASE_INDEX_CURRENT);
utest_printf("The device will now restart.\n");
wait_ms(10); // Wait for the serial buffers to flush.
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
NVIC_SystemReset();
return status; // Reset is instant so this line won't be reached.
}

View File

@ -38,6 +38,22 @@
#define MSG_KEY_START_CASE "start_case"
#define MSG_KEY_DEVICE_RESET "dev_reset"
/* Flush serial buffer before deep sleep/reset
*
* Since deepsleep()/reset would shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
* 20ms here for safe.
*
* This should be replaced with a better function that checks if the
* hardware buffers are empty. However, such an API does not exist now,
* so we'll use the wait_ms() function for now.
*/
#define SERIAL_FLUSH_TIME_MS 20
using utest::v1::Case;
using utest::v1::Specification;
using utest::v1::Harness;
@ -149,7 +165,7 @@ void test_deepsleep_reset()
}
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (TIMEOUT_MS + TIMEOUT_DELTA_MS));
wait_ms(10); // Wait for the serial buffers to flush.
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
if (!sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
}