Lines Matching full:buf
67 static void buf_destroy(struct net_buf *buf);
68 static void fixed_destroy(struct net_buf *buf);
69 static void var_destroy(struct net_buf *buf);
75 static void buf_destroy(struct net_buf *buf) in buf_destroy() argument
77 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in buf_destroy()
81 net_buf_destroy(buf); in buf_destroy()
84 static void fixed_destroy(struct net_buf *buf) in fixed_destroy() argument
86 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in fixed_destroy()
90 net_buf_destroy(buf); in fixed_destroy()
93 static void var_destroy(struct net_buf *buf) in var_destroy() argument
95 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); in var_destroy()
99 net_buf_destroy(buf); in var_destroy()
109 struct net_buf *buf; in ZTEST() local
113 buf = net_buf_alloc_len(&bufs_pool, 74, K_NO_WAIT); in ZTEST()
114 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
115 bufs[i] = buf; in ZTEST()
158 struct net_buf *buf; in test_3_thread() local
162 buf = k_fifo_get(fifo, TEST_TIMEOUT); in test_3_thread()
163 zassert_not_null(buf, "Unable to get buffer"); in test_3_thread()
166 net_buf_unref(buf); in test_3_thread()
213 struct net_buf *buf, *frag; in ZTEST() local
218 /* Create a buf that does not have any data to store, it just in ZTEST()
221 buf = net_buf_alloc_len(&bufs_pool, 0, K_FOREVER); in ZTEST()
223 zassert_equal(buf->size, 0, "Invalid buffer size"); in ZTEST()
228 net_buf_frag_add(buf, frag); in ZTEST()
234 net_buf_frag_insert(buf, frag); in ZTEST()
237 frag = buf->frags; in ZTEST()
249 frag = buf->frags; in ZTEST()
264 frag = buf->frags; in ZTEST()
275 while (buf->frags) { in ZTEST()
276 struct net_buf *frag2 = buf->frags; in ZTEST()
278 net_buf_frag_del(buf, frag2); in ZTEST()
288 * by freeing the top buf. in ZTEST()
291 net_buf_frag_add(buf, in ZTEST()
301 net_buf_frag_insert(buf->frags->frags, frag); in ZTEST()
304 frag = buf->frags; in ZTEST()
314 net_buf_unref(buf); in ZTEST()
323 struct net_buf *buf, *frag; in ZTEST() local
330 buf = net_buf_alloc_len(&bufs_pool, 0, K_FOREVER); in ZTEST()
352 net_buf_frag_add(buf, frag); in ZTEST()
353 net_buf_unref(buf); in ZTEST()
361 struct net_buf *buf; in ZTEST() local
369 buf = net_buf_alloc_len(&bufs_pool, 0, K_FOREVER); in ZTEST()
383 net_buf_frag_add(buf, frags[i]); in ZTEST()
391 net_buf_frag_insert(buf, frags[i]); in ZTEST()
405 net_buf_unref(buf); in ZTEST()
413 struct net_buf *buf, *clone; in ZTEST() local
418 buf = net_buf_alloc_len(&bufs_pool, 74, K_NO_WAIT); in ZTEST()
419 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
421 clone = net_buf_clone(buf, K_NO_WAIT); in ZTEST()
423 zassert_equal(buf->data, clone->data, "Incorrect clone data pointer"); in ZTEST()
425 net_buf_unref(buf); in ZTEST()
433 struct net_buf *buf, *clone; in ZTEST() local
439 buf = net_buf_alloc_len(&fixed_pool, 3, K_NO_WAIT); in ZTEST()
440 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
441 net_buf_add_mem(buf, data, sizeof(data)); in ZTEST()
443 clone = net_buf_clone(buf, K_NO_WAIT); in ZTEST()
445 zassert_not_equal(buf->data, clone->data, in ZTEST()
449 net_buf_unref(buf); in ZTEST()
458 struct net_buf *buf, *clone; in ZTEST() local
460 buf = net_buf_alloc_len(&var_pool, 0, K_NO_WAIT); in ZTEST()
461 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
463 clone = net_buf_clone(buf, K_NO_WAIT); in ZTEST()
466 net_buf_unref(buf); in ZTEST()
491 struct net_buf *buf; in ZTEST() local
495 buf = net_buf_alloc_len(&fixed_pool, 20, K_NO_WAIT); in ZTEST()
496 zassert_not_null(buf, "Failed to get buffer"); 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()
504 net_buf_unref(buf); in ZTEST()
534 struct net_buf *buf; in ZTEST() local
551 buf = net_buf_alloc_len(&fixed_pool, 16, K_FOREVER); in ZTEST()
552 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
555 net_buf_add_mem(buf, &le16, sizeof(le16)); in ZTEST()
556 net_buf_add_mem(buf, &be16, sizeof(be16)); in ZTEST()
558 u16 = net_buf_pull_le16(buf); in ZTEST()
559 zassert_equal(u16, net_buf_pull_be16(buf), in ZTEST()
562 net_buf_reset(buf); in ZTEST()
564 net_buf_add_le16(buf, u16); in ZTEST()
565 net_buf_add_be16(buf, u16); in ZTEST()
567 zassert_mem_equal(le16, net_buf_pull_mem(buf, sizeof(le16)), in ZTEST()
569 zassert_mem_equal(be16, net_buf_pull_mem(buf, sizeof(be16)), in ZTEST()
572 net_buf_reset(buf); in ZTEST()
574 net_buf_add_mem(buf, &le24, sizeof(le24)); in ZTEST()
575 net_buf_add_mem(buf, &be24, sizeof(be24)); in ZTEST()
577 u32 = net_buf_pull_le24(buf); in ZTEST()
578 zassert_equal(u32, net_buf_pull_be24(buf), in ZTEST()
581 net_buf_reset(buf); in ZTEST()
583 net_buf_add_le24(buf, u32); in ZTEST()
584 net_buf_add_be24(buf, u32); in ZTEST()
586 zassert_mem_equal(le24, net_buf_pull_mem(buf, sizeof(le24)), in ZTEST()
588 zassert_mem_equal(be24, net_buf_pull_mem(buf, sizeof(be24)), in ZTEST()
591 net_buf_reset(buf); in ZTEST()
593 net_buf_add_mem(buf, &le32, sizeof(le32)); in ZTEST()
594 net_buf_add_mem(buf, &be32, sizeof(be32)); in ZTEST()
596 u32 = net_buf_pull_le32(buf); in ZTEST()
597 zassert_equal(u32, net_buf_pull_be32(buf), in ZTEST()
600 net_buf_reset(buf); in ZTEST()
602 net_buf_add_le32(buf, u32); in ZTEST()
603 net_buf_add_be32(buf, u32); in ZTEST()
605 zassert_mem_equal(le32, net_buf_pull_mem(buf, sizeof(le32)), in ZTEST()
607 zassert_mem_equal(be32, net_buf_pull_mem(buf, sizeof(be32)), in ZTEST()
610 net_buf_reset(buf); in ZTEST()
612 net_buf_add_mem(buf, &le40, sizeof(le40)); in ZTEST()
613 net_buf_add_mem(buf, &be40, sizeof(be40)); in ZTEST()
615 u64 = net_buf_pull_le40(buf); in ZTEST()
616 zassert_equal(u64, net_buf_pull_be40(buf), "Invalid 40 bits byte order"); in ZTEST()
618 net_buf_reset(buf); in ZTEST()
620 net_buf_add_le40(buf, u64); in ZTEST()
621 net_buf_add_be40(buf, u64); in ZTEST()
623 zassert_mem_equal(le40, net_buf_pull_mem(buf, sizeof(le40)), sizeof(le40), in ZTEST()
625 zassert_mem_equal(be40, net_buf_pull_mem(buf, sizeof(be40)), sizeof(be40), in ZTEST()
628 net_buf_reset(buf); in ZTEST()
630 net_buf_add_mem(buf, &le48, sizeof(le48)); in ZTEST()
631 net_buf_add_mem(buf, &be48, sizeof(be48)); in ZTEST()
633 u64 = net_buf_pull_le48(buf); in ZTEST()
634 zassert_equal(u64, net_buf_pull_be48(buf), in ZTEST()
637 net_buf_reset(buf); in ZTEST()
639 net_buf_add_le48(buf, u64); in ZTEST()
640 net_buf_add_be48(buf, u64); in ZTEST()
642 zassert_mem_equal(le48, net_buf_pull_mem(buf, sizeof(le48)), in ZTEST()
644 zassert_mem_equal(be48, net_buf_pull_mem(buf, sizeof(be48)), in ZTEST()
647 net_buf_reset(buf); in ZTEST()
649 net_buf_add_mem(buf, &le64, sizeof(le64)); in ZTEST()
650 net_buf_add_mem(buf, &be64, sizeof(be64)); in ZTEST()
652 u64 = net_buf_pull_le64(buf); in ZTEST()
653 zassert_equal(u64, net_buf_pull_be64(buf), in ZTEST()
656 net_buf_reset(buf); in ZTEST()
658 net_buf_add_le64(buf, u64); in ZTEST()
659 net_buf_add_be64(buf, u64); in ZTEST()
661 zassert_mem_equal(le64, net_buf_pull_mem(buf, sizeof(le64)), in ZTEST()
663 zassert_mem_equal(be64, net_buf_pull_mem(buf, sizeof(be64)), in ZTEST()
667 net_buf_reset(buf); in ZTEST()
668 net_buf_reserve(buf, 16); in ZTEST()
670 net_buf_push_mem(buf, &le16, sizeof(le16)); in ZTEST()
671 net_buf_push_mem(buf, &be16, sizeof(be16)); in ZTEST()
673 u16 = net_buf_remove_le16(buf); in ZTEST()
674 zassert_equal(u16, net_buf_remove_be16(buf), in ZTEST()
677 net_buf_reset(buf); in ZTEST()
678 net_buf_reserve(buf, 16); in ZTEST()
680 net_buf_push_le16(buf, u16); in ZTEST()
681 net_buf_push_be16(buf, u16); in ZTEST()
683 zassert_mem_equal(le16, net_buf_remove_mem(buf, sizeof(le16)), in ZTEST()
685 zassert_mem_equal(be16, net_buf_remove_mem(buf, sizeof(be16)), in ZTEST()
688 net_buf_reset(buf); in ZTEST()
689 net_buf_reserve(buf, 16); in ZTEST()
691 net_buf_push_mem(buf, &le24, sizeof(le24)); in ZTEST()
692 net_buf_push_mem(buf, &be24, sizeof(be24)); in ZTEST()
694 u32 = net_buf_remove_le24(buf); in ZTEST()
695 zassert_equal(u32, net_buf_remove_be24(buf), in ZTEST()
698 net_buf_reset(buf); in ZTEST()
699 net_buf_reserve(buf, 16); in ZTEST()
701 net_buf_push_le24(buf, u32); in ZTEST()
702 net_buf_push_be24(buf, u32); in ZTEST()
704 zassert_mem_equal(le24, net_buf_remove_mem(buf, sizeof(le24)), in ZTEST()
706 zassert_mem_equal(be24, net_buf_remove_mem(buf, sizeof(be24)), in ZTEST()
709 net_buf_reset(buf); in ZTEST()
710 net_buf_reserve(buf, 16); in ZTEST()
712 net_buf_push_mem(buf, &le32, sizeof(le32)); in ZTEST()
713 net_buf_push_mem(buf, &be32, sizeof(be32)); in ZTEST()
715 u32 = net_buf_remove_le32(buf); in ZTEST()
716 zassert_equal(u32, net_buf_remove_be32(buf), in ZTEST()
719 net_buf_reset(buf); in ZTEST()
720 net_buf_reserve(buf, 16); in ZTEST()
722 net_buf_push_le32(buf, u32); in ZTEST()
723 net_buf_push_be32(buf, u32); in ZTEST()
725 zassert_mem_equal(le32, net_buf_remove_mem(buf, sizeof(le32)), in ZTEST()
727 zassert_mem_equal(be32, net_buf_remove_mem(buf, sizeof(be32)), in ZTEST()
730 net_buf_reset(buf); in ZTEST()
731 net_buf_reserve(buf, 16); in ZTEST()
733 net_buf_push_mem(buf, &le40, sizeof(le40)); in ZTEST()
734 net_buf_push_mem(buf, &be40, sizeof(be40)); in ZTEST()
736 u64 = net_buf_remove_le40(buf); in ZTEST()
737 zassert_equal(u64, net_buf_remove_be40(buf), "Invalid 40 bits byte order"); in ZTEST()
739 net_buf_reset(buf); in ZTEST()
740 net_buf_reserve(buf, 16); in ZTEST()
742 net_buf_push_le40(buf, u64); in ZTEST()
743 net_buf_push_be40(buf, u64); in ZTEST()
745 zassert_mem_equal(le40, net_buf_remove_mem(buf, sizeof(le40)), sizeof(le40), in ZTEST()
747 zassert_mem_equal(be40, net_buf_remove_mem(buf, sizeof(be40)), sizeof(be40), in ZTEST()
750 net_buf_reset(buf); in ZTEST()
751 net_buf_reserve(buf, 16); in ZTEST()
753 net_buf_push_mem(buf, &le48, sizeof(le48)); in ZTEST()
754 net_buf_push_mem(buf, &be48, sizeof(be48)); in ZTEST()
756 u64 = net_buf_remove_le48(buf); in ZTEST()
757 zassert_equal(u64, net_buf_remove_be48(buf), in ZTEST()
760 net_buf_reset(buf); in ZTEST()
761 net_buf_reserve(buf, 16); in ZTEST()
763 net_buf_push_le48(buf, u64); in ZTEST()
764 net_buf_push_be48(buf, u64); in ZTEST()
766 zassert_mem_equal(le48, net_buf_remove_mem(buf, sizeof(le48)), in ZTEST()
768 zassert_mem_equal(be48, net_buf_remove_mem(buf, sizeof(be48)), in ZTEST()
771 net_buf_reset(buf); in ZTEST()
772 net_buf_reserve(buf, 16); in ZTEST()
774 net_buf_push_mem(buf, &le64, sizeof(le64)); in ZTEST()
775 net_buf_push_mem(buf, &be64, sizeof(be64)); in ZTEST()
777 u64 = net_buf_remove_le64(buf); in ZTEST()
778 zassert_equal(u64, net_buf_remove_be64(buf), in ZTEST()
781 net_buf_reset(buf); in ZTEST()
782 net_buf_reserve(buf, 16); in ZTEST()
784 net_buf_push_le64(buf, u64); in ZTEST()
785 net_buf_push_be64(buf, u64); in ZTEST()
787 zassert_mem_equal(le64, net_buf_remove_mem(buf, sizeof(le64)), in ZTEST()
789 zassert_mem_equal(be64, net_buf_remove_mem(buf, sizeof(be64)), in ZTEST()
792 net_buf_unref(buf); in ZTEST()
797 struct net_buf *buf; in ZTEST() local
800 buf = net_buf_alloc(&fixed_pool, K_NO_WAIT); in ZTEST()
801 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
805 zassert_equal(USER_DATA_FIXED, buf->user_data_size, in ZTEST()
808 net_buf_unref(buf); in ZTEST()
811 buf = net_buf_alloc_len(&bufs_pool, 20, K_NO_WAIT); in ZTEST()
812 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
816 zassert_equal(USER_DATA_HEAP, buf->user_data_size, in ZTEST()
819 net_buf_unref(buf); in ZTEST()
822 buf = net_buf_alloc_len(&var_pool, 20, K_NO_WAIT); in ZTEST()
823 zassert_not_null(buf, "Failed to get buffer"); in ZTEST()
827 zassert_equal(USER_DATA_VAR, buf->user_data_size, in ZTEST()
830 net_buf_unref(buf); in ZTEST()
843 /* Happy case: Size of user data in destination buf is bigger than the source buf one */ in ZTEST()
868 struct net_buf *buf; in ZTEST() local
881 buf = net_buf_alloc(&fixed_pool, K_NO_WAIT); in ZTEST()
882 zassert_not_null(buf, "Failed to get buffer"); 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()
896 res = net_buf_data_match(buf, offset, &data[offset], to_compare); 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()
905 res = net_buf_data_match(buf, 0, data, sizeof(data)); 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()
915 res = net_buf_data_match(buf, 0, data, sizeof(data)); in ZTEST()
923 res = net_buf_data_match(buf, 0, NULL, sizeof(data)); in ZTEST()
927 res = net_buf_data_match(buf, FIXED_BUFFER_SIZE * 2, data, sizeof(data)); in ZTEST()
932 res = net_buf_data_match(buf, offset, &data[offset], 16); in ZTEST()
935 net_buf_unref(buf); in ZTEST()
940 struct net_buf *buf; in ZTEST() local
949 buf = net_buf_alloc(&fixed_pool, K_NO_WAIT); in ZTEST()
950 zassert_not_null(buf, "Failed to get fixed buffer"); 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()
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()
980 net_buf_unref(buf); in ZTEST()