From d8070f57d7f66be4aea572ba540e4425d1859170 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 11 Dec 2023 22:51:29 +0700 Subject: [PATCH] soft_uart: demonstrate a problem with inefficient polling As outlined in the test case, we pull a total of 50 bits from the transmitter in two rounds, pulling 25 bits at a time. In the default 8-N-1 configuration, 50 bits should ideally comprise 5 characters. However, as observed, only a total of 4 characters are retrieved from the application, leaving the remaining 10 bits (5 + 5) unused. Change-Id: Ic2539681a4adf6c1822e0bc256e4c829813d0e21 --- tests/soft_uart/soft_uart_test.c | 33 +++++++++++++++++++++++++++++++ tests/soft_uart/soft_uart_test.ok | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/tests/soft_uart/soft_uart_test.c b/tests/soft_uart/soft_uart_test.c index 0ea7fa8c5..7280bdcd1 100644 --- a/tests/soft_uart/soft_uart_test.c +++ b/tests/soft_uart/soft_uart_test.c @@ -604,6 +604,37 @@ static void test_flow_control_rts_cts(void) osmo_soft_uart_free(suart); } +static void test_tx_pull(void) +{ + struct osmo_soft_uart *suart; + ubit_t tx_buf[25 * 2]; + int rc; + + SUART_TEST_BEGIN; + + g_tx_cb_cfg.data = (void *)"\x42\x42\x42\x42\x42"; + g_tx_cb_cfg.data_len = 5; + + suart = osmo_soft_uart_alloc(NULL, __func__, &suart_test_default_cfg); + OSMO_ASSERT(suart != NULL); + + osmo_soft_uart_set_tx(suart, true); + + printf("pulling 25 bits (first time) out of the transmitter\n"); + rc = osmo_soft_uart_tx_ubits(suart, &tx_buf[0], sizeof(tx_buf) / 2); + OSMO_ASSERT(rc == 25); + + printf("pulling 25 bits (second time) out of the transmitter\n"); + rc = osmo_soft_uart_tx_ubits(suart, &tx_buf[25], sizeof(tx_buf) / 2); + OSMO_ASSERT(rc == 25); + + /* FIXME: we pull total 25 + 25 == 50 bits out of the transmitter, which is enough + * to fit 5 characters (assuming 8-N-1). However, the current impelementation would + * pull only 2 + 2 == characters total, wasting 5 + 5 == 10 bits for padding. */ + + osmo_soft_uart_free(suart); +} + int main(int argc, char **argv) { test_rx(); @@ -616,6 +647,8 @@ int main(int argc, char **argv) test_tx_rx_pull_n(4); test_tx_rx_pull_n(8); + test_tx_pull(); + /* test flow control */ test_modem_status(); test_flow_control_dtr_dsr(); diff --git a/tests/soft_uart/soft_uart_test.ok b/tests/soft_uart/soft_uart_test.ok index baf3483a9..dcd7ceb4f 100644 --- a/tests/soft_uart/soft_uart_test.ok +++ b/tests/soft_uart/soft_uart_test.ok @@ -220,6 +220,12 @@ suart_tx_cb(len=1/1): 55 ======== feeding 32 bits into the receiver suart_rx_cb(flags=00): 55 55 +Executing test_tx_pull +pulling 25 bits (first time) out of the transmitter +suart_tx_cb(len=2/2): 42 42 +pulling 25 bits (second time) out of the transmitter +suart_tx_cb(len=2/2): 42 42 + Executing test_modem_status initial status=0x00000000 de-asserting DCD, which was not asserted