svm: fix fifo tail/head/ooo logic for u32 wrap

These were introduced with the switch to unbound tail/head size, so they
only affect master. Added unit tests to avoid future surprises.

Change-Id: I83b6c9efbe31d8092ba59b8e2ed46f4da97f35db
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index c8fd263..4c84fce 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -819,7 +819,7 @@
 
   ooo_segment_add (f, offset, head, tail, len);
 
-  tail_idx = (tail + offset) % f->size;
+  tail_idx = (tail % f->size + offset) % f->size;
 
   if (!svm_fifo_chunk_includes_pos (f->ooo_enq, tail_idx))
     f->ooo_enq = svm_fifo_find_chunk (f, tail_idx);
@@ -871,7 +871,7 @@
     return -2;			/* nothing in the fifo */
 
   len = clib_min (cursize - offset, len);
-  head_idx = (head + offset) % f->size;
+  head_idx = (head % f->size + offset) % f->size;
   if (!svm_fifo_chunk_includes_pos (f->ooo_deq, head_idx))
     f->ooo_deq = svm_fifo_find_chunk (f, head_idx);