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
This commit is contained in:
Vadim Yanitskiy 2023-12-11 22:51:29 +07:00 committed by laforge
parent b392099602
commit d8070f57d7
2 changed files with 39 additions and 0 deletions

View File

@ -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();

View File

@ -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