X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Funittest%2Fsvm_fifo_test.c;h=8b43ee370f1f9709899fa45c8e17155cddcff665;hb=b020806806c0e6c54886cdb4347a5fd1f19504b0;hp=a715fa2a660f6d7196b9e24a9b252f0cb2f1f8b4;hpb=a9f1e7d4fd764b4f68e830528dbd296921050293;p=vpp.git diff --git a/src/plugins/unittest/svm_fifo_test.c b/src/plugins/unittest/svm_fifo_test.c index a715fa2a660..8b43ee370f1 100644 --- a/src/plugins/unittest/svm_fifo_test.c +++ b/src/plugins/unittest/svm_fifo_test.c @@ -14,6 +14,7 @@ */ #include #include +#include #include #define SFIFO_TEST_I(_cond, _comment, _args...) \ @@ -1193,8 +1194,8 @@ sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input) int test_n_bytes, deq_bytes, enq_bytes, n_deqs, n_enqs; svm_fifo_chunk_t *c, *next, *prev; u8 *test_data = 0, *data_buf = 0; + u32 old_tail, offset; svm_fifo_t *f; - u32 old_tail; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -1277,6 +1278,7 @@ sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input) svm_fifo_add_chunk (f, c); SFIFO_TEST (f->size == fifo_size + 200, "size expected %u is %u", fifo_size + 200, f->size); + SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane"); prev = 0; for (i = 0; i < 5; i++) @@ -1434,14 +1436,22 @@ sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input) } } + SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane"); SFIFO_TEST (svm_fifo_max_dequeue (f) == 0, "max deq expected %u is %u", 0, svm_fifo_max_dequeue (f)); svm_fifo_enqueue (f, sizeof (u8), &test_data[0]); memset (data_buf, 0, vec_len (data_buf)); + offset = 0; for (i = 0; i <= n_deqs; i++) - svm_fifo_dequeue (f, deq_bytes, data_buf + i * deq_bytes); + { + rv = svm_fifo_peek (f, offset, deq_bytes, data_buf + i * deq_bytes); + if (rv < 0 || (rv != deq_bytes && i != n_deqs)) + SFIFO_TEST (0, "unexpected peek %d", rv); + offset += rv; + } + svm_fifo_dequeue_drop (f, offset); rv = compare_data (data_buf, test_data, 0, vec_len (test_data), (u32 *) & j); @@ -1749,6 +1759,7 @@ sfifo_test_fifo_shrink (vlib_main_t * vm, unformat_input_t * input) svm_fifo_enqueue (f, 200, test_data); svm_fifo_enqueue_with_offset (f, 50, vec_len (test_data) - 250, &test_data[250]); + SFIFO_TEST (svm_fifo_is_sane (f), "fifo should be sane"); /* Free space */ rv = svm_fifo_max_enqueue (f); @@ -2012,6 +2023,13 @@ sfifo_test_fifo_replay (vlib_main_t * vm, unformat_input_t * input) static fifo_segment_main_t segment_main; +static svm_fifo_t * +fifo_segment_alloc_fifo (fifo_segment_t * fs, u32 data_bytes, + fifo_segment_ftype_t ftype) +{ + return fifo_segment_alloc_fifo_w_slice (fs, 0, data_bytes, ftype); +} + static int sfifo_test_fifo_segment_hello_world (int verbose) { @@ -2340,9 +2358,7 @@ sfifo_test_fifo_segment_slave (int verbose) fifo_segment_create_args_t _a, *a = &_a; fifo_segment_main_t *sm = &segment_main; u8 *test_data, *retrieved_data = 0; - fifo_segment_t *sp; - fifo_segment_header_t *fsh; - ssvm_shared_header_t *sh; + fifo_segment_t *fs; svm_fifo_t *f; u32 *result; int rv, i; @@ -2357,13 +2373,11 @@ sfifo_test_fifo_segment_slave (int verbose) SFIFO_TEST (!rv, "svm_fifo_segment_attach returned %d", rv); - sp = fifo_segment_get_segment (sm, a->new_segment_indices[0]); + fs = fifo_segment_get_segment (sm, a->new_segment_indices[0]); vec_free (a->new_segment_indices); - sh = sp->ssvm.sh; - fsh = (fifo_segment_header_t *) sh->opaque[0]; /* might wanna wait.. */ - f = fsh->fifos; + f = fifo_segment_get_slice_fifo_list (fs, 0); /* Lazy bastards united */ test_data = format (0, "Hello world%c", 0); @@ -2530,7 +2544,7 @@ sfifo_test_fifo_segment_prealloc (int verbose) free_space = fifo_segment_free_bytes (fs); SFIFO_TEST (free_space <= 256 << 10, "free space expected %u is %u", 256 << 10, free_space); - rv = fifo_segment_prealloc_fifo_chunks (fs, 4096, 50); + rv = fifo_segment_prealloc_fifo_chunks (fs, 0, 4096, 50); SFIFO_TEST (rv == 0, "chunk prealloc should work"); rv = fifo_segment_num_free_chunks (fs, 4096); SFIFO_TEST (rv == 50, "prealloc chunks expected %u is %u", 50, rv); @@ -2542,7 +2556,7 @@ sfifo_test_fifo_segment_prealloc (int verbose) SFIFO_TEST (rv == 4096 * 50, "chunk free space expected %u is %u", 4096 * 50, rv); - rv = fifo_segment_prealloc_fifo_hdrs (fs, 50); + rv = fifo_segment_prealloc_fifo_hdrs (fs, 0, 50); SFIFO_TEST (rv == 0, "fifo hdr prealloc should work"); rv = fifo_segment_num_free_fifos (fs); SFIFO_TEST (rv == 50, "prealloc fifo hdrs expected %u is %u", 50, rv); @@ -2585,7 +2599,7 @@ sfifo_test_fifo_segment_prealloc (int verbose) /* Preallocate as many more chunks as possible. Heap is almost full * so we may not use all the free space*/ alloc = 0; - while (!fifo_segment_prealloc_fifo_chunks (fs, 4096, 1)) + while (!fifo_segment_prealloc_fifo_chunks (fs, 0, 4096, 1)) alloc++; SFIFO_TEST (alloc, "chunk prealloc should work %u", alloc); rv = fifo_segment_num_free_chunks (fs, 4096); @@ -2607,10 +2621,10 @@ sfifo_test_fifo_segment_prealloc (int verbose) f = fifo_segment_alloc_fifo (fs, 200 << 10, FIFO_SEGMENT_RX_FIFO); SFIFO_TEST (f == 0, "fifo alloc should fail"); - rv = fifo_segment_prealloc_fifo_chunks (fs, 4096, 50); + rv = fifo_segment_prealloc_fifo_chunks (fs, 0, 4096, 50); SFIFO_TEST (rv == -1, "chunk prealloc should fail"); - rv = fifo_segment_prealloc_fifo_hdrs (fs, 50); + rv = fifo_segment_prealloc_fifo_hdrs (fs, 0, 50); SFIFO_TEST (rv == -1, "fifo hdr prealloc should fail"); /* @@ -2627,7 +2641,7 @@ sfifo_test_fifo_segment (vlib_main_t * vm, unformat_input_t * input) { int rv, verbose = 0; - fifo_segment_main_init (&segment_main, 3ULL << 30, 5); + fifo_segment_main_init (&segment_main, HIGH_SEGMENT_BASEVA, 5); while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "verbose"))