Skip to content

Commit 2d0f7c9

Browse files
nordic-baminordic-piks
authored andcommitted
tests: drivers: uart: Extend UART latency test with different baudrates
Test with 9600, 115200 and 921600. Signed-off-by: Bartosz Miller <[email protected]>
1 parent 45496f2 commit 2d0f7c9

File tree

4 files changed

+95
-36
lines changed

4 files changed

+95
-36
lines changed

tests/drivers/uart/uart_latency/src/async.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void enable_uart_rx(uart_test_data *test_data)
4747
zassert_equal(err, 0, "Unexpected error when enabling UART RX: %d");
4848
}
4949

50-
static void test_uart_latency(size_t buffer_size)
50+
static void test_uart_latency(size_t buffer_size, uint32_t baudrate)
5151
{
5252
int err;
5353
uint32_t tst_timer_value;
@@ -64,10 +64,12 @@ static void test_uart_latency(size_t buffer_size)
6464
zassert_true(buffer_size <= MAX_BUFFER_SIZE,
6565
"Given buffer size is to big, allowed max %u bytes\n", MAX_BUFFER_SIZE);
6666

67-
TC_PRINT("UART TX latency in ASYNC mode test with buffer size: %u bytes\n", buffer_size);
67+
TC_PRINT("UART TX latency in ASYNC mode test with buffer size: %u bytes and baudrate: %u\n",
68+
buffer_size, baudrate);
6869
set_test_pattern(&test_data);
6970
err = uart_config_get(uart_dev, &test_uart_config);
7071
zassert_equal(err, 0, "Failed to get uart config");
72+
test_uart_config.baudrate = baudrate;
7173
err = uart_configure(uart_dev, &test_uart_config);
7274
zassert_equal(err, 0, "UART configuration failed");
7375
err = uart_callback_set(uart_dev, async_uart_callback, NULL);
@@ -100,7 +102,7 @@ static void test_uart_latency(size_t buffer_size)
100102
theoretical_transmission_time_us);
101103
TC_PRINT("Measured transmission time (for %u bytes) [us]: %llu\n", buffer_size,
102104
timer_value_us);
103-
TC_PRINT("Measured - claculated time delta (for %d bytes) [us]: %llu\n", buffer_size,
105+
TC_PRINT("Measured - claculated time delta (for %d bytes) [us]: %lld\n", buffer_size,
104106
timer_value_us - theoretical_transmission_time_us);
105107
TC_PRINT("Maximal allowed transmission time [us]: %u\n",
106108
maximal_allowed_transmission_time_us);
@@ -109,12 +111,28 @@ static void test_uart_latency(size_t buffer_size)
109111
"Measured call latency is over the specified limit");
110112
}
111113

112-
ZTEST(uart_latency, test_uart_latency_in_async_mode)
114+
ZTEST(uart_latency, test_uart_latency_in_async_mode_baud_9k6)
113115
{
114-
test_uart_latency(1);
115-
test_uart_latency(128);
116-
test_uart_latency(1024);
117-
test_uart_latency(3000);
116+
test_uart_latency(10, UART_BAUD_9k6);
117+
test_uart_latency(128, UART_BAUD_9k6);
118+
test_uart_latency(1024, UART_BAUD_9k6);
119+
test_uart_latency(3000, UART_BAUD_9k6);
120+
}
121+
122+
ZTEST(uart_latency, test_uart_latency_in_async_mode_baud_115k2)
123+
{
124+
test_uart_latency(10, UART_BAUD_115k2);
125+
test_uart_latency(128, UART_BAUD_115k2);
126+
test_uart_latency(1024, UART_BAUD_115k2);
127+
test_uart_latency(3000, UART_BAUD_115k2);
128+
}
129+
130+
ZTEST(uart_latency, test_uart_latency_in_async_mode_baud_921k6)
131+
{
132+
test_uart_latency(10, UART_BAUD_921k6);
133+
test_uart_latency(128, UART_BAUD_921k6);
134+
test_uart_latency(1024, UART_BAUD_921k6);
135+
test_uart_latency(3000, UART_BAUD_921k6);
118136
}
119137

120138
void *test_setup(void)

tests/drivers/uart/uart_latency/src/common.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
#include <zephyr/drivers/counter.h>
1212
#include <zephyr/drivers/uart.h>
1313

14-
#define UART_TIMEOUT_US 1000000
15-
#define REQUEST_SERVING_WAIT_TIME_US 10000
14+
#define UART_TIMEOUT_US 5000000
1615
#define MAX_BUFFER_SIZE 4096
1716
#define TEST_TIMER_COUNT_TIME_LIMIT_MS 500
18-
#define MAX_TOLERANCE 2.0
17+
#define MAX_TOLERANCE 2.0
18+
19+
#define UART_BAUD_9k6 9600
20+
#define UART_BAUD_115k2 115200
21+
#define UART_BAUD_921k6 921600
1922

2023
#if DT_NODE_EXISTS(DT_NODELABEL(dut))
2124
#define UART_NODE DT_NODELABEL(dut)

tests/drivers/uart/uart_latency/src/int_driven.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extern uint8_t rx_test_buffer[MAX_BUFFER_SIZE];
1616
static uint32_t tx_byte_offset;
1717
static uint32_t rx_byte_offset;
1818

19-
K_SEM_DEFINE(uart_transmission_done_sem, 0, 1);
19+
K_SEM_DEFINE(uart_tx_done_sem, 0, 1);
20+
K_SEM_DEFINE(uart_rx_done_sem, 0, 1);
2021

2122
void uart_tx_interrupt_service(const struct device *dev, uint8_t *test_pattern, size_t buffer_size,
2223
uint32_t *tx_byte_offset)
@@ -29,8 +30,8 @@ void uart_tx_interrupt_service(const struct device *dev, uint8_t *test_pattern,
2930
*tx_byte_offset += bytes_sent;
3031
} else {
3132
*tx_byte_offset = 0;
33+
k_sem_give(&uart_tx_done_sem);
3234
uart_irq_tx_disable(dev);
33-
k_sem_give(&uart_transmission_done_sem);
3435
}
3536
}
3637

@@ -44,6 +45,11 @@ void uart_rx_interrupt_service(const struct device *dev, uint8_t *receive_buffer
4445
uart_fifo_read(dev, receive_buffer_pointer + *rx_byte_offset, buffer_size);
4546
*rx_byte_offset += rx_data_length;
4647
} while (rx_data_length);
48+
if (*rx_byte_offset >= buffer_size) {
49+
*rx_byte_offset = 0;
50+
k_sem_give(&uart_rx_done_sem);
51+
uart_irq_rx_disable(uart_dev);
52+
}
4753
}
4854

4955
void uart_isr_handler(const struct device *dev, void *user_data)
@@ -63,7 +69,7 @@ void uart_isr_handler(const struct device *dev, void *user_data)
6369
}
6470
}
6571

66-
static void test_uart_latency(size_t buffer_size)
72+
static void test_uart_latency(size_t buffer_size, uint32_t baudrate)
6773
{
6874
int err;
6975
uint32_t tst_timer_value;
@@ -82,17 +88,20 @@ static void test_uart_latency(size_t buffer_size)
8288
rx_byte_offset = 0;
8389

8490
zassert_true(buffer_size <= MAX_BUFFER_SIZE,
85-
"Given buffer size is to big, allowed max %u bytes\n", MAX_BUFFER_SIZE);
91+
"Given buffer size is to big, allowed max %u bytes and baudrate: %u\n",
92+
MAX_BUFFER_SIZE);
8693

87-
TC_PRINT("UART TX latency in INTERRUPT mode test with buffer size: %u bytes\n",
88-
buffer_size);
94+
TC_PRINT("UART TX latency in INTERRUPT mode test with buffer size: %u bytes and baudrate: "
95+
"%u\n",
96+
buffer_size, baudrate);
8997

9098
set_test_pattern(&test_data);
9199
configure_test_timer(tst_timer_dev, TEST_TIMER_COUNT_TIME_LIMIT_MS);
92100
counter_reset(tst_timer_dev);
93101

94102
err = uart_config_get(uart_dev, &test_uart_config);
95103
zassert_equal(err, 0, "Failed to get uart config");
104+
test_uart_config.baudrate = baudrate;
96105
err = uart_configure(uart_dev, &test_uart_config);
97106
zassert_equal(err, 0, "UART configuration failed");
98107
err = uart_irq_callback_set(uart_dev, uart_isr_handler);
@@ -110,23 +119,24 @@ static void test_uart_latency(size_t buffer_size)
110119

111120
dk_set_led_on(DK_LED1);
112121
counter_start(tst_timer_dev);
113-
zassert_equal(k_sem_take(&uart_transmission_done_sem, K_MSEC(TX_TIMEOUT_MS)), 0);
122+
while (k_sem_take(&uart_tx_done_sem, K_NO_WAIT) != 0) {
123+
};
114124
counter_get_value(tst_timer_dev, &tst_timer_value);
115125
counter_stop(tst_timer_dev);
116126
dk_set_led_off(DK_LED1);
117127
timer_value_us = counter_ticks_to_us(tst_timer_dev, tst_timer_value);
118128

119-
uart_irq_tx_disable(uart_dev);
120-
uart_irq_rx_disable(uart_dev);
121-
uart_irq_err_disable(uart_dev);
129+
while (k_sem_take(&uart_rx_done_sem, K_NO_WAIT) != 0) {
130+
};
122131

132+
uart_irq_err_disable(uart_dev);
123133
check_transmitted_data(&test_data);
124134

125135
TC_PRINT("Calculated transmission time (for %u bytes) [us]: %u\n", buffer_size,
126136
theoretical_transmission_time_us);
127137
TC_PRINT("Measured transmission time (for %u bytes) [us]: %llu\n", buffer_size,
128138
timer_value_us);
129-
TC_PRINT("Measured - claculated time delta (for %u bytes) [us]: %llu\n", buffer_size,
139+
TC_PRINT("Measured - claculated time delta (for %u bytes) [us]: %lld\n", buffer_size,
130140
timer_value_us - theoretical_transmission_time_us);
131141
TC_PRINT("Maximal allowed transmission time [us]: %u\n",
132142
maximal_allowed_transmission_time_us);
@@ -135,12 +145,20 @@ static void test_uart_latency(size_t buffer_size)
135145
"Measured call latency is over the specified limit");
136146
}
137147

138-
ZTEST(uart_latency, test_uart_latency_in_interrupt_mode)
148+
ZTEST(uart_latency, test_uart_latency_in_interrupt_mode_baud_9k6)
149+
{
150+
test_uart_latency(10, UART_BAUD_9k6);
151+
test_uart_latency(128, UART_BAUD_9k6);
152+
test_uart_latency(1024, UART_BAUD_9k6);
153+
test_uart_latency(3000, UART_BAUD_9k6);
154+
}
155+
156+
ZTEST(uart_latency, test_uart_latency_in_interrupt_mode_baud_115k2)
139157
{
140-
test_uart_latency(1);
141-
test_uart_latency(128);
142-
test_uart_latency(1024);
143-
test_uart_latency(3000);
158+
test_uart_latency(10, UART_BAUD_115k2);
159+
test_uart_latency(128, UART_BAUD_115k2);
160+
test_uart_latency(1024, UART_BAUD_115k2);
161+
test_uart_latency(3000, UART_BAUD_115k2);
144162
}
145163

146164
void *test_setup(void)

tests/drivers/uart/uart_latency/src/polling.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern const struct device *const tst_timer_dev;
1111
extern uint8_t tx_test_buffer[MAX_BUFFER_SIZE];
1212
extern uint8_t rx_test_buffer[MAX_BUFFER_SIZE];
1313

14-
static void test_uart_latency(size_t buffer_size)
14+
static void test_uart_latency(size_t buffer_size, uint32_t baudrate)
1515
{
1616
int err;
1717
uint32_t tst_timer_value;
@@ -27,12 +27,16 @@ static void test_uart_latency(size_t buffer_size)
2727
test_data.buffer_size = buffer_size;
2828

2929
zassert_true(buffer_size <= MAX_BUFFER_SIZE,
30-
"Given buffer size is to big, allowed max %u bytes\n", MAX_BUFFER_SIZE);
30+
"Given buffer size is to big, allowed max %u bytes", MAX_BUFFER_SIZE);
31+
32+
TC_PRINT("UART TX latency in POLLING mode test with buffer size: %u bytes and baudrate: "
33+
"%u\n",
34+
buffer_size, baudrate);
3135

32-
TC_PRINT("UART TX latency in POLLING mode test with buffer size: %u bytes\n", buffer_size);
3336
set_test_pattern(&test_data);
3437
err = uart_config_get(uart_dev, &test_uart_config);
3538
zassert_equal(err, 0, "Failed to get uart config");
39+
test_uart_config.baudrate = baudrate;
3640
err = uart_configure(uart_dev, &test_uart_config);
3741
zassert_equal(err, 0, "UART configuration failed");
3842

@@ -62,7 +66,7 @@ static void test_uart_latency(size_t buffer_size)
6266
theoretical_transmission_time_us);
6367
TC_PRINT("Measured transmission time (for %u bytes) [us]: %llu\n", buffer_size,
6468
timer_value_us);
65-
TC_PRINT("Measured - claculated time delta (for %u bytes) [us]: %llu\n", buffer_size,
69+
TC_PRINT("Measured - claculated time delta (for %u bytes) [us]: %lld\n", buffer_size,
6670
timer_value_us - theoretical_transmission_time_us);
6771
TC_PRINT("Maximal allowed transmission time [us]: %u\n",
6872
maximal_allowed_transmission_time_us);
@@ -71,12 +75,28 @@ static void test_uart_latency(size_t buffer_size)
7175
"Measured call latency is over the specified limit");
7276
}
7377

74-
ZTEST(uart_latency, test_uart_latency_in_polling_mode)
78+
ZTEST(uart_latency, test_uart_latency_in_polling_mode_baud_9k6)
79+
{
80+
test_uart_latency(10, UART_BAUD_9k6);
81+
test_uart_latency(128, UART_BAUD_9k6);
82+
test_uart_latency(1024, UART_BAUD_9k6);
83+
test_uart_latency(3000, UART_BAUD_9k6);
84+
}
85+
86+
ZTEST(uart_latency, test_uart_latency_in_polling_mode_baud_115k2)
87+
{
88+
test_uart_latency(10, UART_BAUD_115k2);
89+
test_uart_latency(128, UART_BAUD_115k2);
90+
test_uart_latency(1024, UART_BAUD_115k2);
91+
test_uart_latency(3000, UART_BAUD_115k2);
92+
}
93+
94+
ZTEST(uart_latency, test_uart_latency_in_polling_mode_baud_921k6)
7595
{
76-
test_uart_latency(1);
77-
test_uart_latency(128);
78-
test_uart_latency(1024);
79-
test_uart_latency(3000);
96+
test_uart_latency(10, UART_BAUD_921k6);
97+
test_uart_latency(128, UART_BAUD_921k6);
98+
test_uart_latency(1024, UART_BAUD_921k6);
99+
test_uart_latency(3000, UART_BAUD_921k6);
80100
}
81101

82102
void *test_setup(void)

0 commit comments

Comments
 (0)