MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_cirbuf_align_left

Function test_cirbuf_align_left

dpdk/app/test/test_cmdline_cirbuf.c:778–986  ·  view source on GitHub ↗

test left alignment */

Source from the content-addressed store, hash-verified

776
777/* test left alignment */
778static int
779test_cirbuf_align_left(void)
780{
781#define HALF_OFFSET CMDLINE_TEST_BUFSIZE / 2
782#define SMALL_OFFSET HALF_OFFSET / 2
783/* resulting buffer lengths for each of the test cases */
784#define LEN1 HALF_OFFSET - SMALL_OFFSET - 1
785#define LEN2 HALF_OFFSET + SMALL_OFFSET + 2
786#define LEN3 HALF_OFFSET - SMALL_OFFSET
787#define LEN4 HALF_OFFSET + SMALL_OFFSET - 1
788
789 struct cirbuf cb;
790 char buf[CMDLINE_TEST_BUFSIZE];
791 char tmp[CMDLINE_TEST_BUFSIZE];
792 unsigned i;
793
794 /*
795 * align left when start < end and start in left half
796 */
797
798 /*
799 * initialize circular buffer
800 */
801 memset(buf, 0, sizeof(buf));
802 if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
803 printf("Error: failed to initialize circular buffer!\n");
804 return -1;
805 }
806
807 /* push end into left half */
808 for (i = 0; i < HALF_OFFSET - 1; i++)
809 cirbuf_add_tail_safe(&cb, 't');
810
811 /* push start into left half < end */
812 for (i = 0; i < SMALL_OFFSET; i++)
813 cirbuf_del_head_safe(&cb);
814
815 /* align */
816 if (cirbuf_align_left(&cb) < 0) {
817 printf("Error: alignment failed!\n");
818 return -1;
819 }
820
821 /* verify result */
822 if (cb.start != 0 || cb.len != LEN1 || cb.end != cb.len - 1) {
823 printf("Error: buffer alignment is wrong!\n");
824 return -1;
825 }
826
827 /*
828 * align left when start > end and start in left half
829 */
830
831 /*
832 * reinitialize circular buffer
833 */
834 memset(buf, 0, sizeof(buf));
835 if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {

Callers 1

test_cirbuf_alignFunction · 0.85

Calls 13

memsetFunction · 0.85
cirbuf_initFunction · 0.85
cirbuf_add_tail_safeFunction · 0.85
cirbuf_del_head_safeFunction · 0.85
cirbuf_align_leftFunction · 0.85
cirbuf_add_head_safeFunction · 0.85
cirbuf_del_tail_safeFunction · 0.85
cirbuf_add_buf_headFunction · 0.85
cirbuf_add_buf_tailFunction · 0.85
cirbuf_get_buf_headFunction · 0.85
strncmpFunction · 0.85
cirbuf_get_buf_tailFunction · 0.85

Tested by

no test coverage detected