Skip to content

Commit cf19d7e

Browse files
nordic-krchcarlescufi
authored andcommitted
tests: lib: spsc_pbuf: Add test for getting maximum utilization
Add test for CONFIG_SPSC_PBUF_UTILIZATION option. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 1986591 commit cf19d7e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/lib/spsc_pbuf/src/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,48 @@ ZTEST(test_spsc_pbuf, test_largest_alloc)
366366
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN - 1, 0, 1, 12);
367367
}
368368

369+
ZTEST(test_spsc_pbuf, test_utilization)
370+
{
371+
static uint8_t buffer[64] __aligned(MAX(CONFIG_SPSC_PBUF_CACHE_LINE, 4));
372+
struct spsc_pbuf *pb;
373+
uint32_t capacity;
374+
uint16_t len1, len2, len3;
375+
int u;
376+
377+
pb = spsc_pbuf_init(buffer, sizeof(buffer), 0);
378+
379+
if (!IS_ENABLED(CONFIG_SPSC_PBUF_UTILIZATION)) {
380+
zassert_equal(spsc_pbuf_get_utilization(pb), -ENOTSUP, NULL);
381+
return;
382+
}
383+
capacity = spsc_pbuf_capacity(pb);
384+
385+
len1 = 10;
386+
PACKET_WRITE(pb, len1, len1, 0, len1);
387+
u = spsc_pbuf_get_utilization(pb);
388+
zassert_equal(u, 0, NULL);
389+
390+
PACKET_CONSUME(pb, len1, 0);
391+
u = spsc_pbuf_get_utilization(pb);
392+
zassert_equal(u, ROUND_UP(len1, sizeof(uint32_t)) + sizeof(uint32_t), NULL);
393+
394+
len2 = 11;
395+
PACKET_WRITE(pb, len2, len2, 1, len2);
396+
PACKET_CONSUME(pb, len2, 1);
397+
u = spsc_pbuf_get_utilization(pb);
398+
zassert_equal(u, ROUND_UP(len2, sizeof(uint32_t)) + sizeof(uint32_t), NULL);
399+
400+
len3 = capacity - ROUND_UP(len1, sizeof(uint32_t)) - ROUND_UP(len2, sizeof(uint32_t))
401+
- 3 * sizeof(uint32_t) + sizeof(uint32_t);
402+
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN, len3, 2, len3);
403+
PACKET_CONSUME(pb, len3, 2);
404+
405+
u = spsc_pbuf_get_utilization(pb);
406+
int exp_u = ROUND_UP(len3, sizeof(uint32_t)) + sizeof(uint32_t);
407+
408+
zassert_equal(u, exp_u, NULL);
409+
}
410+
369411
struct stress_data {
370412
struct spsc_pbuf *pbuf;
371413
uint32_t capacity;

tests/lib/spsc_pbuf/testcase.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ tests:
2121
extra_configs:
2222
- CONFIG_SPSC_PBUF_CACHE_NEVER=y
2323

24+
lib.spsc_pbuf_utilization:
25+
integration_platforms:
26+
- native_posix
27+
# Exclude platform which does not link with cache functions
28+
platform_exclude: ast1030_evb
29+
extra_configs:
30+
- CONFIG_SPSC_PBUF_UTILIZATION=y
31+
2432
lib.spsc_pbuf_stress:
2533
platform_allow: qemu_x86
2634
extra_configs:

0 commit comments

Comments
 (0)