app/test: fix finding the second smallest memory segment
authorChao Zhu <chaozhu@linux.vnet.ibm.com>
Tue, 25 Nov 2014 22:17:16 +0000 (17:17 -0500)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 26 Nov 2014 20:50:10 +0000 (21:50 +0100)
Curent implementation in test_memzone.c has bugs in finding the
second smallest memory segment. It's the last smallest memory segment,
but it's not the second smallest memory segment. This bug may cause test
failure in some cases. This patch fixes this bug.

Signed-off-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>
Acked-by: David Marchand <david.marchand@6wind.com>
app/test/test_memzone.c

index 387dbbc..1658006 100644 (file)
@@ -797,10 +797,9 @@ test_memzone_reserve_memory_in_smallest_segment(void)
 
                        /* set new smallest */
                        min_ms = ms;
-               }
-               else if (prev_min_ms == NULL) {
+               } else if ((prev_min_ms == NULL)
+                       || (prev_min_ms->len > ms->len))
                        prev_min_ms = ms;
-               }
        }
 
        if (min_ms == NULL || prev_min_ms == NULL) {
@@ -877,8 +876,8 @@ test_memzone_reserve_memory_with_smallest_offset(void)
 
                        /* set new smallest */
                        min_ms = ms;
-               }
-               else if (prev_min_ms == NULL) {
+               } else if ((prev_min_ms == NULL)
+                       || (prev_min_ms->len > ms->len)) {
                        prev_min_ms = ms;
                }
        }