r23021: test some boundary conditions for idtree, after I saw some suspicious
authorAndrew Tridgell <tridge@samba.org>
Sun, 20 May 2007 10:21:14 +0000 (10:21 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:52:40 +0000 (14:52 -0500)
behaviour
(This used to be commit e862cf17b891885f3a733819869a06895c1fb324)

source4/lib/util/tests/idtree.c

index dd8618d0db72a6a0999ec79b82ba7d535f49d290..a9770d789b2ce223aeeeeb23bdecd1ebcfbbcde7 100644 (file)
@@ -26,7 +26,7 @@
 static bool torture_local_idtree_simple(struct torture_context *tctx)
 {
        struct idr_context *idr;
-       int i;
+       int i, ret;
        int *ids;
        int *present;
        extern int torture_numops;
@@ -92,6 +92,23 @@ static bool torture_local_idtree_simple(struct torture_context *tctx)
                }
        }
 
+       /* now test some limits */
+       for (i=0;i<25000;i++) {
+               ret = idr_get_new_above(idr, &ids[0], random() % 25000, 0x10000-3);
+               torture_assert(tctx, ret != -1, "idr_get_new_above failed");
+       }
+
+       ret = idr_get_new_above(idr, &ids[0], 0x10000-2, 0x10000);
+       torture_assert_int_equal(tctx, ret, 0x10000-2, "idr_get_new_above failed");
+       ret = idr_get_new_above(idr, &ids[0], 0x10000-1, 0x10000);
+       torture_assert_int_equal(tctx, ret, 0x10000-1, "idr_get_new_above failed");
+       ret = idr_get_new_above(idr, &ids[0], 0x10000, 0x10000);
+       torture_assert_int_equal(tctx, ret, 0x10000, "idr_get_new_above failed");
+       ret = idr_get_new_above(idr, &ids[0], 0x10000+1, 0x10000);
+       torture_assert_int_equal(tctx, ret, -1, "idr_get_new_above succeeded above limit");
+       ret = idr_get_new_above(idr, &ids[0], 0x10000+2, 0x10000);
+       torture_assert_int_equal(tctx, ret, -1, "idr_get_new_above succeeded above limit");
+
        torture_comment(tctx, "cleaned up\n");
        return true;
 }