Skip to content

Commit 17d3588

Browse files
committed
fix(test): Fix uart test pin swapping
1 parent bcb63d4 commit 17d3588

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

tests/validation/uart/uart.ino

+16-18
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,33 @@ public:
6363
serial.end();
6464
}
6565

66+
void reset_buffers() {
67+
recv_msg = "";
68+
peeked_char = -1;
69+
}
70+
6671
void transmit_and_check_msg(const String &msg_append, bool perform_assert = true) {
72+
reset_buffers();
6773
delay(100);
6874
serial.print("Hello from Serial" + String(uart_num) + " " + msg_append);
6975
serial.flush();
7076
delay(100);
7177
if (perform_assert) {
7278
TEST_ASSERT_EQUAL_STRING(("Hello from Serial" + String(uart_num) + " " + msg_append).c_str(), recv_msg.c_str());
79+
log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str());
7380
}
7481
}
7582

7683
void onReceive() {
7784
char c;
78-
recv_msg = "";
7985
size_t available = serial.available();
80-
if (available != 0) {
86+
if (peeked_char == -1) {
8187
peeked_char = serial.peek();
8288
}
8389
while (available--) {
8490
c = (char)serial.read();
8591
recv_msg += c;
8692
}
87-
log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str());
8893
}
8994
};
9095

@@ -354,31 +359,24 @@ void change_pins_test(void) {
354359
esp_rom_gpio_connect_out_signal(config.default_rx_pin, SIG_GPIO_OUT_IDX, false, false);
355360
}
356361

357-
log_d("Swapping UART pins");
362+
log_d("Swapping UART pins and testing transmission");
358363

359364
if (TEST_UART_NUM == 1) {
360-
Serial1.setPins(NEW_RX1, NEW_TX1);
361-
TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(1));
362-
TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(1));
365+
UARTTestConfig& config = *uart_test_configs[0];
366+
config.serial.setPins(NEW_RX1, NEW_TX1);
367+
TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(config.uart_num));
368+
TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(config.uart_num));
369+
370+
uart_internal_loopback(config.uart_num, NEW_RX1);
371+
config.transmit_and_check_msg("using new pins");
363372
} else {
364373
for (int i = 0; i < TEST_UART_NUM; i++) {
365374
UARTTestConfig& config = *uart_test_configs[i];
366375
UARTTestConfig& next_uart = *uart_test_configs[(i + 1) % TEST_UART_NUM];
367376
config.serial.setPins(next_uart.default_rx_pin, next_uart.default_tx_pin);
368377
TEST_ASSERT_EQUAL(uart_get_RxPin(config.uart_num), next_uart.default_rx_pin);
369378
TEST_ASSERT_EQUAL(uart_get_TxPin(config.uart_num), next_uart.default_tx_pin);
370-
config.begin(115200);
371-
}
372-
}
373379

374-
log_d("Re-enabling UART loopback");
375-
376-
if (TEST_UART_NUM == 1) {
377-
uart_internal_loopback(1, NEW_RX1);
378-
} else {
379-
for (int i = 0; i < TEST_UART_NUM; i++) {
380-
UARTTestConfig& config = *uart_test_configs[i];
381-
UARTTestConfig& next_uart = *uart_test_configs[(i + 1) % TEST_UART_NUM];
382380
uart_internal_loopback(config.uart_num, next_uart.default_rx_pin);
383381
config.transmit_and_check_msg("using new pins");
384382
}

0 commit comments

Comments
 (0)