From 17d358870f9e020a59898c1038d364b1bf0db9c9 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:44:23 -0300 Subject: [PATCH] fix(test): Fix uart test pin swapping --- tests/validation/uart/uart.ino | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/validation/uart/uart.ino b/tests/validation/uart/uart.ino index 692768dc34f..0d98c3bf689 100644 --- a/tests/validation/uart/uart.ino +++ b/tests/validation/uart/uart.ino @@ -63,28 +63,33 @@ public: serial.end(); } + void reset_buffers() { + recv_msg = ""; + peeked_char = -1; + } + void transmit_and_check_msg(const String &msg_append, bool perform_assert = true) { + reset_buffers(); delay(100); serial.print("Hello from Serial" + String(uart_num) + " " + msg_append); serial.flush(); delay(100); if (perform_assert) { TEST_ASSERT_EQUAL_STRING(("Hello from Serial" + String(uart_num) + " " + msg_append).c_str(), recv_msg.c_str()); + log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str()); } } void onReceive() { char c; - recv_msg = ""; size_t available = serial.available(); - if (available != 0) { + if (peeked_char == -1) { peeked_char = serial.peek(); } while (available--) { c = (char)serial.read(); recv_msg += c; } - log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str()); } }; @@ -354,12 +359,16 @@ void change_pins_test(void) { esp_rom_gpio_connect_out_signal(config.default_rx_pin, SIG_GPIO_OUT_IDX, false, false); } - log_d("Swapping UART pins"); + log_d("Swapping UART pins and testing transmission"); if (TEST_UART_NUM == 1) { - Serial1.setPins(NEW_RX1, NEW_TX1); - TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(1)); - TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(1)); + UARTTestConfig& config = *uart_test_configs[0]; + config.serial.setPins(NEW_RX1, NEW_TX1); + TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(config.uart_num)); + TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(config.uart_num)); + + uart_internal_loopback(config.uart_num, NEW_RX1); + config.transmit_and_check_msg("using new pins"); } else { for (int i = 0; i < TEST_UART_NUM; i++) { UARTTestConfig& config = *uart_test_configs[i]; @@ -367,18 +376,7 @@ void change_pins_test(void) { config.serial.setPins(next_uart.default_rx_pin, next_uart.default_tx_pin); TEST_ASSERT_EQUAL(uart_get_RxPin(config.uart_num), next_uart.default_rx_pin); TEST_ASSERT_EQUAL(uart_get_TxPin(config.uart_num), next_uart.default_tx_pin); - config.begin(115200); - } - } - log_d("Re-enabling UART loopback"); - - if (TEST_UART_NUM == 1) { - uart_internal_loopback(1, NEW_RX1); - } else { - for (int i = 0; i < TEST_UART_NUM; i++) { - UARTTestConfig& config = *uart_test_configs[i]; - UARTTestConfig& next_uart = *uart_test_configs[(i + 1) % TEST_UART_NUM]; uart_internal_loopback(config.uart_num, next_uart.default_rx_pin); config.transmit_and_check_msg("using new pins"); }