Skip to content

Commit

Permalink
fix(test): Fix uart test pin swapping
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz committed Nov 13, 2024
1 parent bcb63d4 commit 17d3588
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions tests/validation/uart/uart.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};

Expand Down Expand Up @@ -354,31 +359,24 @@ 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];
UARTTestConfig& next_uart = *uart_test_configs[(i + 1) % TEST_UART_NUM];
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");
}
Expand Down

0 comments on commit 17d3588

Please sign in to comment.