+ SFIFO_TEST (n_chunks == 1 + n_batch, "free chunks should be %u is %u",
+ 1 + n_batch, n_chunks);
+
+ rv = fifo_segment_fl_chunk_bytes (fs);
+ SFIFO_TEST (rv == (16 + n_batch) * fifo_size, "free chunk bytes expected %u"
+ " is %u", (16 + n_batch) * fifo_size, rv);
+
+ n_free_chunk_bytes = rv;
+
+ /*
+ * Allocate non power of 2 fifo/chunk and check that free chunk bytes
+ * is correctly updated
+ */
+
+ f = fifo_segment_alloc_fifo (fs, 16 * fifo_size - 1, FIFO_SEGMENT_RX_FIFO);
+ rv = fifo_segment_fl_chunk_bytes (fs);
+
+ SFIFO_TEST (n_free_chunk_bytes - 16 * fifo_size == rv, "free chunk bytes "
+ "expected %u is %u", n_free_chunk_bytes - 16 * fifo_size, rv);
+
+ fifo_segment_free_fifo (fs, f);
+ rv = fifo_segment_fl_chunk_bytes (fs);
+
+ SFIFO_TEST (n_free_chunk_bytes == rv, "free chunk bytes expected %u is %u",
+ n_free_chunk_bytes, rv);
+
+ /*
+ * Force multi chunk fifo allocation
+ */
+
+ f = fifo_segment_alloc_fifo (fs, 17 * fifo_size, FIFO_SEGMENT_RX_FIFO);
+ rv = fifo_segment_fl_chunk_bytes (fs);
+
+ /* Make sure that the non-power of two chunk freed above is correctly
+ * accounted for in the chunk free bytes reduction due to chunk allocation
+ * for the fifo, i.e., it's rounded up by 1 */
+ SFIFO_TEST (n_free_chunk_bytes - 17 * fifo_size == rv, "free chunk bytes "
+ "expected %u is %u", n_free_chunk_bytes - 17 * fifo_size, rv);
+
+ fifo_segment_free_fifo (fs, f);
+
+ rv = fifo_segment_fl_chunk_bytes (fs);
+ SFIFO_TEST (n_free_chunk_bytes == rv, "free chunk bytes expected %u is %u",
+ n_free_chunk_bytes, rv);
+
+ /*
+ * Allocate fifo that has all chunks
+ */
+ f = fifo_segment_alloc_fifo (fs, n_free_chunk_bytes, FIFO_SEGMENT_RX_FIFO);
+ SFIFO_TEST (f != 0, "allocation should work");
+
+ fifo_segment_free_fifo (fs, f);
+
+ rv = fifo_segment_fl_chunk_bytes (fs);
+ SFIFO_TEST (n_free_chunk_bytes == rv, "free chunk bytes expected %u is %u",
+ n_free_chunk_bytes, rv);
+
+ /*
+ * Try to allocate more than space available
+ */
+
+ f = fifo_segment_alloc_fifo (fs, n_free_chunk_bytes + fifo_size,
+ FIFO_SEGMENT_RX_FIFO);
+ SFIFO_TEST (f == 0, "allocation should fail");
+
+ /*
+ * Allocate fifo and try to grow beyond available space
+ */
+ f = fifo_segment_alloc_fifo (fs, fifo_size, FIFO_SEGMENT_RX_FIFO);
+ rv = fifo_segment_grow_fifo (fs, f, n_free_chunk_bytes);
+
+ SFIFO_TEST (rv == -1, "grow should fail");
+
+ fifo_segment_free_fifo (fs, f);