Esempio n. 1
0
static void
test_bitmap_initializer_body(const bitmap_info_t *binfo, size_t nbits)
{
	bitmap_info_t binfo_dyn;
	bitmap_info_init(&binfo_dyn, nbits);

	assert_zu_eq(bitmap_size(binfo), bitmap_size(&binfo_dyn),
	    "Unexpected difference between static and dynamic initialization, "
	    "nbits=%zu", nbits);
	assert_zu_eq(binfo->nbits, binfo_dyn.nbits,
	    "Unexpected difference between static and dynamic initialization, "
	    "nbits=%zu", nbits);
#ifdef BITMAP_USE_TREE
	assert_u_eq(binfo->nlevels, binfo_dyn.nlevels,
	    "Unexpected difference between static and dynamic initialization, "
	    "nbits=%zu", nbits);
	{
		unsigned i;

		for (i = 0; i < binfo->nlevels; i++) {
			assert_zu_eq(binfo->levels[i].group_offset,
			    binfo_dyn.levels[i].group_offset,
			    "Unexpected difference between static and dynamic "
			    "initialization, nbits=%zu, level=%u", nbits, i);
		}
	}
#else
	assert_zu_eq(binfo->ngroups, binfo_dyn.ngroups,
	    "Unexpected difference between static and dynamic initialization");
#endif
}
Esempio n. 2
0
TEST_END

TEST_BEGIN(test_bitmap_unset)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			for (j = 0; j < i; j++)
				bitmap_unset(bitmap, &binfo, j);
			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			free(bitmap);
		}
	}
}
Esempio n. 3
0
static void
test_bitmap_unset(void)
{
    size_t i;

    for (i = 1; i <= MAXBITS; i++) {
        bitmap_info_t binfo;
        bitmap_info_init(&binfo, i);
        {
            size_t j;
            bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
                                      bitmap_info_ngroups(&binfo));
            bitmap_init(bitmap, &binfo);

            for (j = 0; j < i; j++)
                bitmap_set(bitmap, &binfo, j);
            assert(bitmap_full(bitmap, &binfo));
            for (j = 0; j < i; j++)
                bitmap_unset(bitmap, &binfo, j);
            for (j = 0; j < i; j++)
                bitmap_set(bitmap, &binfo, j);
            assert(bitmap_full(bitmap, &binfo));
            free(bitmap);
        }
    }
}
Esempio n. 4
0
TEST_END

TEST_BEGIN(test_bitmap_sfu)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			/* Iteratively set bits starting at the beginning. */
			for (j = 0; j < i; j++) {
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should be just after "
				    "previous first unset bit");
			}
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");

			/*
			 * Iteratively unset bits starting at the end, and
			 * verify that bitmap_sfu() reaches the unset bits.
			 */
			for (j = i - 1; j < i; j--) { /* (i..0] */
				bitmap_unset(bitmap, &binfo, j);
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should the bit previously "
				    "unset");
				bitmap_unset(bitmap, &binfo, j);
			}
			assert_false(bitmap_get(bitmap, &binfo, 0),
			    "Bit should be unset");

			/*
			 * Iteratively set bits starting at the beginning, and
			 * verify that bitmap_sfu() looks past them.
			 */
			for (j = 1; j < i; j++) {
				bitmap_set(bitmap, &binfo, j - 1);
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should be just after the "
				    "bit previously set");
				bitmap_unset(bitmap, &binfo, j);
			}
			assert_zd_eq(bitmap_sfu(bitmap, &binfo), i - 1,
			    "First unset bit should be the last bit");
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			free(bitmap);
		}
	}
}
Esempio n. 5
0
static void
test_bitmap_sfu(void)
{
    size_t i;

    for (i = 1; i <= MAXBITS; i++) {
        bitmap_info_t binfo;
        bitmap_info_init(&binfo, i);
        {
            ssize_t j;
            bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
                                      bitmap_info_ngroups(&binfo));
            bitmap_init(bitmap, &binfo);

            /* Iteratively set bits starting at the beginning. */
            for (j = 0; j < i; j++)
                assert(bitmap_sfu(bitmap, &binfo) == j);
            assert(bitmap_full(bitmap, &binfo));

            /*
             * Iteratively unset bits starting at the end, and
             * verify that bitmap_sfu() reaches the unset bits.
             */
            for (j = i - 1; j >= 0; j--) {
                bitmap_unset(bitmap, &binfo, j);
                assert(bitmap_sfu(bitmap, &binfo) == j);
                bitmap_unset(bitmap, &binfo, j);
            }
            assert(bitmap_get(bitmap, &binfo, 0) == false);

            /*
             * Iteratively set bits starting at the beginning, and
             * verify that bitmap_sfu() looks past them.
             */
            for (j = 1; j < i; j++) {
                bitmap_set(bitmap, &binfo, j - 1);
                assert(bitmap_sfu(bitmap, &binfo) == j);
                bitmap_unset(bitmap, &binfo, j);
            }
            assert(bitmap_sfu(bitmap, &binfo) == i - 1);
            assert(bitmap_full(bitmap, &binfo));
            free(bitmap);
        }
    }
}
Esempio n. 6
0
static void
test_bitmap_set(void)
{
	size_t i;

	for (i = 1; i <= MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert(bitmap_full(bitmap, &binfo));
		}
	}
}
Esempio n. 7
0
TEST_END

TEST_BEGIN(test_bitmap_init)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++) {
				assert_false(bitmap_get(bitmap, &binfo, j),
				    "Bit should be unset");
			}
			free(bitmap);
		}
	}
}
Esempio n. 8
0
int main(void)
{
        uint32_t i;
        uint32_t id;
        bitmap_info_t binfo;
        uint32_t buffer[100000] = {0};
        bitmap_info_init(&binfo, 100);
        bitmap_t *bitmap = NULL;
        bitmap = (bitmap_t *)malloc(bitmap_size(&binfo));
        bitmap_init(bitmap, &binfo);
        for (i = 1; i < binfo.nlevels; i++) {
                printf("group_offset%d:%6d %6d\n", i, \
                        binfo.levels[i].group_offset - \
                        binfo.levels[i-1].group_offset, \
                        binfo.levels[i].group_offset);
        }
        
        /* register */
        printf("register: ");
        for(i = 0; i < 65; i++) {
                id = bitmap_sfu(bitmap, &binfo);
                buffer[i] = id;
                print_id(i, id);
        }
#if pbitmap
        /* show bitmap */
        printf("\n");
        for(i = 0; i < 65; i++) {
                printf("%16llx ", bitmap[i]);
                if (!((i+1)%4))
                        printf("\n");
        }
#endif
        /* aged */
        printf("\naged: ");
        for(i = 30; i < 65; ++i) {
                bitmap_unset(bitmap, &binfo, buffer[i]);
                print_id(i, buffer[i]);
        }
#if pbitmap
        /* show bitmap */
        printf("\n");
        for(i = 0; i < 50; i++) {
                printf("%16llx ", bitmap[i]);
                if (!((i+1)%4))
                        printf("\n");
        }
#endif    
        /* register again*/
        printf("\nsecond register: ");
        for(i = 0; i < 50; i++) {
                id = bitmap_sfu(bitmap, &binfo);
                buffer[i+30] = id;
                print_id(i, id);
        }

        /* aged again */
        printf("\naged: ");
        for(i = 0; i < 80; i++) {
                bitmap_unset(bitmap, &binfo, buffer[i]);
                print_id(i, buffer[i]);
        }

        printf("\n");
        free(bitmap);
        return 0;
}