tests: net: buf: Better clone coverage

This commit ensures that user data get copied when cloning a buffer.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This commit is contained in:
Reto Schneider 2024-03-25 13:49:17 +01:00 committed by Maureen Helm
parent da676d2e01
commit 3aba7d5bc6

View file

@ -464,6 +464,25 @@ ZTEST(net_buf_tests, test_net_buf_clone_reference_counted_zero_sized_buffer)
zassert_not_null(clone, "Failed to clone zero sized buffer");
net_buf_unref(buf);
}
ZTEST(net_buf_tests, test_net_buf_clone_user_data)
{
struct net_buf *original, *clone;
uint32_t *buf_user_data, *clone_user_data;
/* Requesting size 1 because all we are interested in are the user data */
original = net_buf_alloc_len(&bufs_pool, 1, K_NO_WAIT);
zassert_not_null(original, "Failed to get buffer");
buf_user_data = net_buf_user_data(original);
*buf_user_data = 0xAABBCCDD;
clone = net_buf_clone(original, K_NO_WAIT);
zassert_not_null(clone, "Failed to get clone buffer");
clone_user_data = net_buf_user_data(clone);
zexpect_equal(*clone_user_data, 0xAABBCCDD, "User data copy is invalid");
net_buf_unref(original);
net_buf_unref(clone);
}