From b392099602c5c0e2fa77252ff587f59d8ec37f36 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 11 Dec 2023 22:38:17 +0700 Subject: [PATCH] soft_uart: demonstrate a problem with manual flush()ing This problem can only happen if the user is flush()ing the Rx buffer manually by calling osmo_soft_uart_flush_rx(). Let's demonstrate it in the unit test, so that we don't forget about it (add FIXME). Change-Id: Iad932a505d6fd98360f90510651501f8708ff5d2 --- tests/soft_uart/soft_uart_test.c | 20 ++++++++++++++++++++ tests/soft_uart/soft_uart_test.ok | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/tests/soft_uart/soft_uart_test.c b/tests/soft_uart/soft_uart_test.c index e9adb294e..0ea7fa8c5 100644 --- a/tests/soft_uart/soft_uart_test.c +++ b/tests/soft_uart/soft_uart_test.c @@ -226,6 +226,7 @@ static void test_rx(void) static void test_rx_flush(void) { + struct osmo_soft_uart_cfg cfg; struct osmo_soft_uart *suart; SUART_TEST_BEGIN; @@ -242,6 +243,25 @@ static void test_rx_flush(void) printf("calling osmo_soft_uart_flush_rx() while Rx enabled, but no data\n"); osmo_soft_uart_flush_rx(suart); + /* FIXME: this scenario demonstrates a problem that may occur when the user + * flushes the Rx buffer manually while the soft-UART state reflects flags + * of an incomplete symbol, for which we're waiting the stop bit. */ + printf("testing corner case: manual flushing during a parity error (8-E-1)\n"); + cfg = suart_test_default_cfg; + cfg.parity_mode = OSMO_SUART_PARITY_EVEN; + osmo_soft_uart_configure(suart, &cfg); + test_rx_exec(suart, "1111111" /* no data */ + "0 01010101 0 1" /* even parity, correct */ + "0 10101010 0 1" /* even parity, correct */ + "0 11111111 1" /* odd parity, incorrect, but stop bit is pending */ + "F" /* manual flush happens before receiving the stop bit */ + "1" /* finally, the stop bit is received */ + ); + /* test_rx_exec() @ 47: flush the Rx buffer + * suart_rx_cb(flags=02): aa 55 <--- this is wrong, should be flags=00 + * suart_rx_cb(flags=02): ff <--- this is expected due to odd parity */ + + osmo_soft_uart_free(suart); } diff --git a/tests/soft_uart/soft_uart_test.ok b/tests/soft_uart/soft_uart_test.ok index c42d0f516..baf3483a9 100644 --- a/tests/soft_uart/soft_uart_test.ok +++ b/tests/soft_uart/soft_uart_test.ok @@ -71,6 +71,10 @@ Executing test_rx_flush calling osmo_soft_uart_flush_rx() while Rx disabled enabling the receiver calling osmo_soft_uart_flush_rx() while Rx enabled, but no data +testing corner case: manual flushing during a parity error (8-E-1) +test_rx_exec() @ 47: flush the Rx buffer +suart_rx_cb(flags=02): aa 55 +suart_rx_cb(flags=02): ff Executing test_tx_rx ======== testing 8-N-1