]> granicus.if.org Git - esp-idf/commitdiff
driver: Add uart and i2c UTs to check ticks_to_wait in some functions
authorKonstantin Kondrashov <konstantin@espressif.com>
Tue, 4 Jun 2019 04:17:55 +0000 (12:17 +0800)
committerKonstantinKondrashov <konstantin@espressif.com>
Fri, 14 Jun 2019 04:31:43 +0000 (12:31 +0800)
components/driver/test/test_uart.c

index da6ffd1ff92811f9ca015fddbc8154a8ce5cd15c..1f5882981075d7bf86339669dfbcfd49cc36dbaa 100644 (file)
@@ -29,6 +29,56 @@ static void uart_config(uint32_t baud_rate, bool use_ref_tick)
     uart_driver_install(UART_NUM1, BUF_SIZE * 2, BUF_SIZE * 2, 20, NULL, 0);
 }
 
+static volatile bool exit_flag;
+
+static void test_task(void *pvParameters)
+{
+    xSemaphoreHandle *sema = (xSemaphoreHandle *) pvParameters;
+    char* data = (char *) malloc(256);
+
+    while (exit_flag == false) {
+        uart_tx_chars(UART_NUM1, data, 256);
+        // The uart_wait_tx_done() function does not block anything if ticks_to_wait = 0.
+        uart_wait_tx_done(UART_NUM1, 0);
+    }
+
+    free(data);
+    xSemaphoreGive(*sema);
+    vTaskDelete(NULL);
+}
+
+static void test_task2(void *pvParameters)
+{
+    while (exit_flag == false) {
+        // This task obstruct a setting tx_done_sem semaphore in the UART interrupt.
+        // It leads to waiting the ticks_to_wait time in uart_wait_tx_done() function.
+        uart_disable_intr_mask(UART_NUM1, UART_TX_DONE_INT_ENA_M);
+    }
+    vTaskDelete(NULL);
+}
+
+TEST_CASE("test uart_wait_tx_done is not blocked when ticks_to_wait=0", "[uart]")
+{
+    uart_config(UART_BAUD_11520, false);
+
+    xSemaphoreHandle exit_sema = xSemaphoreCreateBinary();
+    exit_flag = false;
+
+    xTaskCreate(test_task,  "tsk1", 2048, &exit_sema, 5, NULL);
+    xTaskCreate(test_task2, "tsk2", 2048, NULL,       5, NULL);
+
+    printf("Waiting for 5 sec\n");
+    vTaskDelay(5000 / portTICK_PERIOD_MS);
+    exit_flag = true;
+
+    if (xSemaphoreTake(exit_sema, 1000 / portTICK_PERIOD_MS) == pdTRUE) {
+        vSemaphoreDelete(exit_sema);
+    } else {
+        TEST_FAIL_MESSAGE("uart_wait_tx_done is blocked");
+    }
+    TEST_ESP_OK(uart_driver_delete(UART_NUM1));
+}
+
 TEST_CASE("test uart get baud-rate","[uart]")
 {
     uint32_t baud_rate1 = 0;