Lines Matching +full:data +full:- +full:bits

1 /* main.c - Application main entry point */
6 * SPDX-License-Identifier: Apache-2.0
77 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in buf_destroy()
86 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in fixed_destroy()
95 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in var_destroy()
136 for (i = 0; i < bufs_pool.buf_count - 1; i++) { in ZTEST()
137 frag->frags = net_buf_alloc_len(&bufs_pool, 74, K_NO_WAIT); in ZTEST()
138 zassert_not_null(frag->frags, "Failed to get fragment"); in ZTEST()
139 frag = frag->frags; in ZTEST()
187 for (i = 0; i < bufs_pool.buf_count - 1; i++) { in ZTEST()
188 frag->frags = net_buf_alloc_len(&bufs_pool, 74, K_NO_WAIT); in ZTEST()
189 zassert_not_null(frag->frags, "Failed to get fragment"); in ZTEST()
190 frag = frag->frags; in ZTEST()
212 struct net_buf *frags[bufs_pool.buf_count - 1]; in ZTEST()
218 /* Create a buf that does not have any data to store, it just in ZTEST()
223 zassert_equal(buf->size, 0, "Invalid buffer size"); in ZTEST()
226 for (i = 0; i < bufs_pool.buf_count - 2; i++) { in ZTEST()
237 frag = buf->frags; in ZTEST()
241 frag = frag->frags; in ZTEST()
245 zassert_equal(i, bufs_pool.buf_count - 1, "Incorrect fragment count"); in ZTEST()
249 frag = buf->frags; in ZTEST()
251 struct net_buf *next = frag->frags; in ZTEST()
264 frag = buf->frags; in ZTEST()
266 frag = frag->frags; in ZTEST()
275 while (buf->frags) { in ZTEST()
276 struct net_buf *frag2 = buf->frags; in ZTEST()
284 zassert_equal(destroy_called, bufs_pool.buf_count - 1, in ZTEST()
290 for (i = 0; i < bufs_pool.buf_count - 4; i++) { in ZTEST()
301 net_buf_frag_insert(buf->frags->frags, frag); in ZTEST()
304 frag = buf->frags; in ZTEST()
306 frag = frag->frags; in ZTEST()
310 zassert_equal(i, bufs_pool.buf_count - 1, "Incorrect fragment count"); in ZTEST()
341 /* First add some application data */ in ZTEST()
349 ipv6 = (struct ipv6_hdr *)(frag->data - net_buf_headroom(frag)); in ZTEST()
374 * Note that with IEEE 802.15.4 we typically cannot have zero-copy in ZTEST()
378 #define LL_HEADERS (127 - 81) in ZTEST()
379 for (i = 0; i < bufs_pool.buf_count - 2; i++) { in ZTEST()
393 /* First add some application data */ in ZTEST()
395 for (i = 0; i < bufs_pool.buf_count - 2; i++) { in ZTEST()
399 occupied += frags[i]->len; in ZTEST()
402 ipv6 = (struct ipv6_hdr *)(frags[i]->data - net_buf_headroom(frags[i])); in ZTEST()
423 zassert_equal(buf->data, clone->data, "Incorrect clone data pointer"); in ZTEST()
434 const uint8_t data[3] = {0x11, 0x22, 0x33}; in ZTEST() local
441 net_buf_add_mem(buf, data, sizeof(data)); in ZTEST()
445 zassert_not_equal(buf->data, clone->data, in ZTEST()
447 zassert_mem_equal(clone->data, data, sizeof(data)); in ZTEST()
455 /* Regression test: Zero sized buffers must be copy-able, not trigger a NULL pointer dereference */
474 /* Requesting size 1 because all we are interested in are the user data */ in ZTEST()
483 zexpect_equal(*clone_user_data, 0xAABBCCDD, "User data copy is invalid"); in ZTEST()
498 /* Verify buffer's size and len - even though we requested less bytes we in ZTEST()
501 zassert_equal(buf->size, FIXED_BUFFER_SIZE, "Invalid fixed buffer size"); in ZTEST()
502 zassert_equal(buf->len, 0, "Invalid fixed buffer length"); in ZTEST()
523 zassert_equal(buf3->data, buf2->data, "Cloned data doesn't match"); in ZTEST()
560 "Invalid 16 bits byte order"); in ZTEST()
568 sizeof(le16), "Invalid 16 bits byte order"); in ZTEST()
570 sizeof(be16), "Invalid 16 bits byte order"); in ZTEST()
579 "Invalid 24 bits byte order"); in ZTEST()
587 sizeof(le24), "Invalid 24 bits byte order"); in ZTEST()
589 sizeof(be24), "Invalid 24 bits byte order"); in ZTEST()
598 "Invalid 32 bits byte order"); in ZTEST()
606 sizeof(le32), "Invalid 32 bits byte order"); in ZTEST()
608 sizeof(be32), "Invalid 32 bits byte order"); in ZTEST()
616 zassert_equal(u64, net_buf_pull_be40(buf), "Invalid 40 bits byte order"); in ZTEST()
624 "Invalid 40 bits byte order"); in ZTEST()
626 "Invalid 40 bits byte order"); in ZTEST()
635 "Invalid 48 bits byte order"); in ZTEST()
643 sizeof(le48), "Invalid 48 bits byte order"); in ZTEST()
645 sizeof(be48), "Invalid 48 bits byte order"); in ZTEST()
654 "Invalid 64 bits byte order"); in ZTEST()
662 sizeof(le64), "Invalid 64 bits byte order"); in ZTEST()
664 sizeof(be64), "Invalid 64 bits byte order"); in ZTEST()
675 "Invalid 16 bits byte order"); in ZTEST()
684 sizeof(le16), "Invalid 16 bits byte order"); in ZTEST()
686 sizeof(be16), "Invalid 16 bits byte order"); in ZTEST()
696 "Invalid 24 bits byte order"); in ZTEST()
705 sizeof(le24), "Invalid 24 bits byte order"); in ZTEST()
707 sizeof(be24), "Invalid 24 bits byte order"); in ZTEST()
717 "Invalid 32 bits byte order"); in ZTEST()
726 sizeof(le32), "Invalid 32 bits byte order"); in ZTEST()
728 sizeof(be32), "Invalid 32 bits byte order"); in ZTEST()
737 zassert_equal(u64, net_buf_remove_be40(buf), "Invalid 40 bits byte order"); in ZTEST()
746 "Invalid 40 bits byte order"); in ZTEST()
748 "Invalid 40 bits byte order"); in ZTEST()
758 "Invalid 48 bits byte order"); in ZTEST()
767 sizeof(le48), "Invalid 48 bits byte order"); in ZTEST()
769 sizeof(be48), "Invalid 48 bits byte order"); in ZTEST()
779 "Invalid 64 bits byte order"); in ZTEST()
788 sizeof(le64), "Invalid 64 bits byte order"); in ZTEST()
790 sizeof(be64), "Invalid 64 bits byte order"); in ZTEST()
805 zassert_equal(USER_DATA_FIXED, buf->user_data_size, in ZTEST()
816 zassert_equal(USER_DATA_HEAP, buf->user_data_size, in ZTEST()
827 zassert_equal(USER_DATA_VAR, buf->user_data_size, in ZTEST()
843 /* Happy case: Size of user data in destination buf is bigger than the source buf one */ in ZTEST()
852 /* Error case: User data size of destination buffer is too small */ in ZTEST()
854 "User data size in destination buffer too small"); in ZTEST()
860 "No-op is tolerated"); in ZTEST()
861 zassert_equal(*src_user_data, 0xAABBCCDD, "User data remains the same"); in ZTEST()
873 uint8_t data[FIXED_BUFFER_SIZE * 2]; in ZTEST() local
875 /* Fill data buffer */ in ZTEST()
876 for (int i = 0; i < sizeof(data); ++i) { in ZTEST()
877 data[i] = (uint8_t)i; in ZTEST()
884 written = net_buf_append_bytes(buf, buf->size, data, K_NO_WAIT, NULL, NULL); in ZTEST()
885 zassert_equal(written, buf->size, "Failed to fill the buffer"); in ZTEST()
886 zassert_equal(buf->frags, NULL, "Additional buffer allocated"); in ZTEST()
889 res = net_buf_data_match(buf, 0, data, buf->size); in ZTEST()
890 zassert_equal(res, buf->size, "Whole net_buf comparison failed"); in ZTEST()
893 offset = buf->size / 2; in ZTEST()
894 to_compare = written - offset; in ZTEST()
896 res = net_buf_data_match(buf, offset, &data[offset], to_compare); in ZTEST()
899 /* Write more data (it allocates more buffers) */ in ZTEST()
900 written = net_buf_append_bytes(buf, sizeof(data) - written, &data[buf->size], K_NO_WAIT, in ZTEST()
902 zassert_true(buf->frags, "Failed to allocate an additional net_buf"); in ZTEST()
904 /* Compare whole data with buffers' content */ in ZTEST()
905 res = net_buf_data_match(buf, 0, data, sizeof(data)); in ZTEST()
906 zassert_equal(res, sizeof(data), "Failed to compare data with multiple buffers"); in ZTEST()
908 /* Compare data with offset at the edge between two fragments */ in ZTEST()
909 offset = buf->size - (buf->size / 2); in ZTEST()
910 res = net_buf_data_match(buf, offset, &data[offset], buf->size); in ZTEST()
911 zassert_equal(res, buf->size, "Failed to compare bytes within two buffers with offset"); in ZTEST()
913 /* Compare data with partial matching - change the data in the middle */ in ZTEST()
914 data[sizeof(data) / 2] += 1; in ZTEST()
915 res = net_buf_data_match(buf, 0, data, sizeof(data)); in ZTEST()
916 zassert_equal(res, sizeof(data) / 2, "Partial matching failed"); in ZTEST()
918 /* No buffer - expect 0 matching bytes */ in ZTEST()
919 res = net_buf_data_match(NULL, 0, data, sizeof(data)); in ZTEST()
922 /* No data - expect 0 matching bytes */ in ZTEST()
923 res = net_buf_data_match(buf, 0, NULL, sizeof(data)); in ZTEST()
924 zassert_equal(res, 0, "Matching without data must fail"); in ZTEST()
926 /* Too high offset - expect 0 matching bytes */ in ZTEST()
927 res = net_buf_data_match(buf, FIXED_BUFFER_SIZE * 2, data, sizeof(data)); in ZTEST()
930 /* Try to match more bytes than are in buffers - expect only partial match */ in ZTEST()
931 offset = (FIXED_BUFFER_SIZE * 2) - 8; in ZTEST()
932 res = net_buf_data_match(buf, offset, &data[offset], 16); in ZTEST()
941 uint8_t data[FIXED_BUFFER_SIZE * 2]; in ZTEST() local
943 /* Fill data buffer */ in ZTEST()
944 for (int i = 0; i < sizeof(data); ++i) { in ZTEST()
945 data[i] = (uint8_t)i; in ZTEST()
951 zassert_equal(buf->size, FIXED_BUFFER_SIZE, "Invalid fixed buffer size"); in ZTEST()
956 net_buf_append_bytes(buf, buf->size - 8, data, K_NO_WAIT, NULL, NULL); in ZTEST()
957 zassert_equal(buf->len, buf->size - 8, "Invalid buffer len"); in ZTEST()
958 zassert_is_null(buf->frags, "Unexpected buffer fragment"); in ZTEST()
961 net_buf_append_bytes(buf, 8, data, K_NO_WAIT, NULL, NULL); in ZTEST()
962 zassert_equal(buf->len, buf->size, "Invalid buffer len"); in ZTEST()
963 zassert_is_null(buf->frags, "Unexpected buffer fragment"); in ZTEST()
966 net_buf_append_bytes(buf, 1, data, K_NO_WAIT, NULL, NULL); in ZTEST()
967 zassert_not_null(buf->frags, "Lack of expected buffer fragment"); in ZTEST()
968 zassert_equal(buf->frags->len, 1, "Expected single byte in the new fragment"); in ZTEST()
969 zassert_equal(buf->frags->size, buf->size, "Different size of the fragment"); in ZTEST()
971 /* Remove 1-byte buffer */ in ZTEST()
972 net_buf_frag_del(buf, buf->frags); in ZTEST()
975 net_buf_append_bytes(buf, sizeof(data), data, K_NO_WAIT, NULL, NULL); in ZTEST()
976 zassert_not_null(buf->frags, "Missing first buffer fragment"); in ZTEST()
977 zassert_not_null(buf->frags->frags, "Missing second buffer fragment"); in ZTEST()
978 zassert_is_null(buf->frags->frags->frags, "Unexpected buffer fragment"); in ZTEST()