Exemple #1
0
void
testcase_run(TestCaseState_t *tcs)
{
    Carrier_t *c;
    Block_t *blk;
    void *p;
    Allctr_t *a = START_ALC("basic_", 0, NULL);
    tcs->extra = (void *) a;

    ASSERT(tcs, a);

    p = ALLOC(a, 10);
    ASSERT(tcs, p);
    p = REALLOC(a, p, 15);
    ASSERT(tcs, p);
    FREE(a, p);

    c = FIRST_MBC(a);
    ASSERT(tcs, !NEXT_C(c));
    blk = MBC_TO_FIRST_BLK(a, c);
    ASSERT(tcs, IS_LAST_BLK(blk));
    ASSERT(tcs, IS_FREE_BLK(blk));

    STOP_ALC((Allctr_t *) a);
    tcs->extra = NULL;

}
Exemple #2
0
void
setup_sequence(TestCaseState_t *tcs, Allctr_t *a, Ulong bsz, int no,
	       void *res[])
{
    Carrier_t *c;
    Block_t *blk;
    int i;

    testcase_printf(tcs,
		    "Setting up a sequence of %d blocks of size %lu\n",
		    no, bsz);
    c = FIRST_MBC(a);
    ASSERT(tcs, !NEXT_C(c));
    blk = MBC2FBLK(a, c);
    ASSERT(tcs, IS_LAST_BLK(blk));

    for (i = 0; i < no; i++)
	res[i] = ALLOC(a, bsz);
    for (i = 0; i < no; i++)
	ASSERT(tcs, res[i]);

    testcase_printf(tcs, "Checking that sequence was set up as expected\n");

    for (i = 1; i < no; i++)
	ASSERT(tcs, NXT_BLK(UMEM2BLK(res[i-1])) == UMEM2BLK(res[i]));

    blk = NXT_BLK(UMEM2BLK(res[no-1]));
    ASSERT(tcs, IS_LAST_BLK(blk));

    testcase_printf(tcs, "Sequence ok\n");

    /* If we fail in setup_sequence(), it doesn't mean that something is
       wrong. It is just a faulty assumption in setup_sequence() about
       how blocks are going to be placed.
       Fix setup_sequence()... */
}
Exemple #3
0
void
check_ablk(TestCaseState_t *tcs, Allctr_t *a, void *ptr, Ulong umem_sz)
{
    Ulong unit_sz = UNIT_SZ;
    Block_t *blk = UMEM2BLK(ptr);
    Block_t *nxt_blk = NXT_BLK(blk);
    Ulong real_sz = ((Ulong) nxt_blk) - ((Ulong) (blk));
    ASSERT(tcs, real_sz == BLK_SZ(blk));
    ASSERT(tcs, !IS_FREE_BLK(blk));
    ASSERT(tcs, real_sz >= CEILING(ABLK_HDR_SZ + umem_sz, unit_sz));
    if (real_sz > MIN_BLK_SZ(a)
	&& real_sz > CEILING(ABLK_HDR_SZ+umem_sz, unit_sz)) {
	ASSERT(tcs,
	       real_sz <= CEILING(MIN_BLK_SZ(a)+ABLK_HDR_SZ+umem_sz,
				  unit_sz));
	ASSERT(tcs, IS_LAST_BLK(blk) || !IS_FREE_BLK(nxt_blk));
    }
}
Exemple #4
0
void
testcase_run(TestCaseState_t *tcs)
{
    void *tmp;
    void **fence;
    void **blk;
    Ulong sz;
    Ulong smbcs;
    int i;
    int bi;
    int bi_tests;
    Ulong sbct = (SBCT/1024)*1024;
    Ulong min_blk_sz;
    Ulong ablk_hdr_sz = ABLK_HDR_SZ;
    char smbcs_buf[30];
    char sbct_buf[30];
    int no_bkts = (int) NO_OF_BKTS;
    char *argv1[] = {"-tasgf", "-tmmbcs0", sbct_buf, NULL};
    char *argv2[] = {"-tasgf", "-tmmbcs0", sbct_buf, NULL, NULL};
    Allctr_t *a;

    sprintf(sbct_buf, "-tsbct%lu", sbct/1024);

    a = START_ALC("bkt_mask_1_", 0, argv1);
    tcs->extra = (void *) a;
    ASSERT(tcs, a);

    min_blk_sz = MIN_BLK_SZ(a);
    smbcs = 2*(no_bkts*sizeof(void *) + min_blk_sz) + min_blk_sz;
    for (i = 0; i < no_bkts; i++) {
	sz = BKT_MIN_SZ(a, i);
	if (sz >= sbct)
	    break;
	smbcs += sz + min_blk_sz;
    }

    bi_tests = i;
    testcase_printf(tcs, "Will test %d buckets\n", bi_tests);

    STOP_ALC(a);
    tcs->extra = NULL;

    smbcs /= 1024;
    smbcs++;

    testcase_printf(tcs, "smbcs = %lu\n", smbcs);
    sprintf(smbcs_buf, "-tsmbcs%lu", smbcs);
    argv2[3] = smbcs_buf;

    a = START_ALC("bkt_mask_2_", 0, argv2);
    tcs->extra = (void *) a;
    ASSERT(tcs, a);

    blk = (void **) ALLOC(a, no_bkts*sizeof(void *));
    fence = (void **) ALLOC(a, no_bkts*sizeof(void *));

    ASSERT(tcs, blk && fence);

    testcase_printf(tcs, "Allocating blocks and fences\n");
    for (i = 0; i < bi_tests; i++) {
	sz = BKT_MIN_SZ(a, i);
	blk[i] = ALLOC(a, sz - ablk_hdr_sz);
	fence[i] = ALLOC(a, 1);
	ASSERT(tcs, blk[i] && fence[i]);
    }

    tmp = (void *) UMEM2BLK(fence[bi_tests - 1]);
    tmp = (void *) NXT_BLK((Block_t *) tmp);
    ASSERT(tcs, IS_LAST_BLK(tmp));
    sz = BLK_SZ((Block_t *) tmp);
    testcase_printf(tcs, "Allocating leftover size = %lu\n", sz);
    tmp = ALLOC(a, sz - ablk_hdr_sz);
    ASSERT(tcs, tmp);

    bi = FIND_BKT(a, 0);
    ASSERT(tcs, bi < 0);

    for (i = 0; i < bi_tests; i++) {
	sz = BKT_MIN_SZ(a, i);
	testcase_printf(tcs, "Testing bucket %d\n", i);
	FREE(a, blk[i]);
	bi = FIND_BKT(a, i);
	ASSERT(tcs, bi == i);
	blk[i] = ALLOC(a, sz - ablk_hdr_sz);
	bi = FIND_BKT(a, i);
	ASSERT(tcs, bi != i);
    }

    for (i = 0; i < bi_tests; i++) {
	FREE(a, blk[i]);
	FREE(a, fence[i]);
    }

    FREE(a, (void *) blk);
    FREE(a, (void *) fence);

    bi = FIND_BKT(a, 0);
    ASSERT(tcs, bi == no_bkts - 1);

    FREE(a, tmp);

    bi = FIND_BKT(a, 0);
    ASSERT(tcs, bi < 0);

    STOP_ALC(a);
    tcs->extra = NULL;
}
Exemple #5
0
static void
test_realloc(TestCaseState_t *tcs, Allctr_t *a, Ulong bsz)
{
    Block_t *blk;
    void *ptr;
    void *p[3];
    Ulong nbsz;

    testcase_printf(tcs," --- Testing realloc() with block size %lu ---\n",
		    bsz);

    setup_sequence(tcs, a, bsz, 3, p);

    check_ablk(tcs, a, p[0], bsz);
    check_ablk(tcs, a, p[1], bsz);
    check_ablk(tcs, a, p[2], bsz);

    /* Grow to the end of the carrier */
    blk = NXT_BLK(UMEM2BLK(p[2]));
    ASSERT(tcs, IS_FREE_BLK(blk));
    ASSERT(tcs, IS_LAST_BLK(blk));
    nbsz = bsz + BLK_SZ(blk);
    ptr = REALLOC(a, p[2], nbsz);
    ASSERT(tcs, p[2] == ptr);
    check_ablk(tcs, a, p[2], nbsz);
    blk = UMEM2BLK(p[2]);
    ASSERT(tcs, IS_LAST_BLK(blk));

    /* Shrink from the end of the carrier */
    ptr = REALLOC(a, p[2], bsz);
    ASSERT(tcs, p[2] == ptr);
    blk = UMEM2BLK(p[2]);
    ASSERT(tcs, !IS_LAST_BLK(blk));
    blk = NXT_BLK(blk);
    ASSERT(tcs, IS_LAST_BLK(blk));
    check_ablk(tcs, a, p[2], bsz);

    /* Shrink and coalecse with next free */

    FREE(a, p[1]);

    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, IS_FREE_BLK(blk));

    nbsz = bsz/2;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);

    check_ablk(tcs, a, p[0], nbsz);

    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, IS_FREE_BLK(blk));
    ASSERT(tcs, NXT_BLK(blk) == UMEM2BLK(p[2]));

    /* Grow into next free; but leave free block at end */

    nbsz *= 3;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);

    check_ablk(tcs, a, p[0], nbsz);
    blk = NXT_BLK(UMEM2BLK(p[0]));

    ASSERT(tcs, IS_FREE_BLK(blk));
    ASSERT(tcs, NXT_BLK(blk) == UMEM2BLK(p[2]));

    /* Grow upto next alloced block by allocating just enough so that no
       free block fits between them */
    nbsz = BLK_SZ(blk) + UMEM_SZ(UMEM2BLK(p[0]));
    nbsz -= MIN_BLK_SZ(a) - 1;

    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);
    check_ablk(tcs, a, p[0], nbsz);
    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, !IS_FREE_BLK(blk));
    ASSERT(tcs, blk == UMEM2BLK(p[2]));

    /* Grow into unused part at end */
    nbsz += MIN_BLK_SZ(a) - 1;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);
    check_ablk(tcs, a, p[0], nbsz);
    ASSERT(tcs, !IS_FREE_BLK(blk));
    ASSERT(tcs, blk == UMEM2BLK(p[2]));

    /* Shrink *almost* as much so that a free block would fit between the
       allocated blocks, and make sure that we don't get a free block
       in between */
    nbsz -= MIN_BLK_SZ(a) - 1;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);
    check_ablk(tcs, a, p[0], nbsz);
    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, !IS_FREE_BLK(blk));
    ASSERT(tcs, blk == UMEM2BLK(p[2]));

    /* Shrink just as much so that a free block can fit between
       the alloced blocks */
    nbsz -= 1;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);
    check_ablk(tcs, a, p[0], nbsz);
    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, IS_FREE_BLK(blk));
    ASSERT(tcs, blk < UMEM2BLK(p[2]));
    ASSERT(tcs, NXT_BLK(blk) == UMEM2BLK(p[2]));

    /* Shrink so little that no free block would fit between allocated
       blocks, and make sure that we shrink the allocated block and
       coalesce the extra free part with the next free block. */
    nbsz -= MIN_BLK_SZ(a) - 1;
    ptr = REALLOC(a, p[0], nbsz);
    ASSERT(tcs, p[0] == ptr);
    check_ablk(tcs, a, p[0], nbsz);
    blk = NXT_BLK(UMEM2BLK(p[0]));
    ASSERT(tcs, IS_FREE_BLK(blk));
    ASSERT(tcs, blk < UMEM2BLK(p[2]));
    ASSERT(tcs, NXT_BLK(blk) == UMEM2BLK(p[2]));

    /* Cleanup */
    FREE(a, p[0]);
    FREE(a, p[2]);

    testcase_printf(tcs, " --- realloc() with block size %lu succeded ---\n",
		    bsz);

}