Example #1
0
int main(int argc, char *argv[])
{
	if (1) {
		warn("---- test bitops ----");
		unsigned char bits[16];
		memset(bits, 0, sizeof(bits));
		set_bits(bits, 6, 20);
		set_bits(bits, 49, 16);
		set_bits(bits, 0x51, 2);
		hexdump(bits, sizeof(bits));
		/* should return true */
		printf("ones = %i\n", all_set(bits, 6, 20));
		printf("ones = %i\n", all_set(bits, 49, 16));
		printf("ones = %i\n", all_set(bits, 0x51, 2));
		/* should return false */
		printf("ones = %i\n", all_set(bits, 5, 20));
		printf("ones = %i\n", all_set(bits, 49, 17));
		printf("ones = %i\n", all_set(bits, 0x51, 3));
		clear_bits(bits, 6, 20);
		clear_bits(bits, 49, 16);
		clear_bits(bits, 0x51, 2);
		hexdump(bits, sizeof(bits)); // all zero now

		/* corner case */
		unsigned char *bitmap = malloc(7);
		set_bits(bitmap, 0, 7 * 8);
		int ret = all_set(bitmap, 0, 7 * 8);
		assert(ret);
		clear_bits(bitmap, 0, 7 * 8);
		free(bitmap);
	}
	struct dev *dev = &(struct dev){ .bits = 3 };
	struct sb *sb = rapid_sb(dev, .volblocks = 150);
	struct inode *bitmap = rapid_open_inode(sb, NULL, 0);
	sb->freeblocks = sb->volblocks;
	sb->nextalloc = sb->volblocks; // this should wrap around to zero
	sb->bitmap = bitmap;

	init_buffers(dev, 1 << 20, 0);
	unsigned blocksize = 1 << dev->bits;
	unsigned dumpsize = blocksize > 16 ? 16 : blocksize;

	for (int block = 0; block < 10; block++) {
		struct buffer_head *buffer = blockget(bitmap->map, block);
		memset(bufdata(buffer), 0, blocksize);
		set_buffer_clean(buffer);
	}
	for (int i = 0; i < 12; i++) {
		block_t block = balloc_from_range(sb, 121, 10, 1);
		printf("%Li\n", (L)block);
	}
	hexdump(bufdata(blockget(bitmap->map, 0)), dumpsize);
	hexdump(bufdata(blockget(bitmap->map, 1)), dumpsize);
	hexdump(bufdata(blockget(bitmap->map, 2)), dumpsize);

	block_t block;
	sb->nextalloc++; // gap
	for (int i = 0; i < 1; i++)
		balloc(sb, 1, &block);
	sb->nextalloc++; // gap
	for (int i = 0; i < 10; i++)
		balloc(sb, 1, &block);
	hexdump(bufdata(blockget(bitmap->map, 0)), dumpsize);
	hexdump(bufdata(blockget(bitmap->map, 1)), dumpsize);
	hexdump(bufdata(blockget(bitmap->map, 2)), dumpsize);

	bitmap_dump(bitmap, 0, sb->volblocks);
	printf("%Li used, %Li free\n", (L)count_range(bitmap, 0, sb->volblocks), (L)sb->freeblocks);
	bfree(sb, 0x7e, 1);
	bfree(sb, 0x80, 1);
	bitmap_dump(bitmap, 0, sb->volblocks);
	exit(0);
}
Example #2
0
int main(int argc, char *argv[])
{
#define BITMAP_BLOCKS	10

	struct dev *dev = &(struct dev){ .bits = 3 };
	/* This expect buffer is never reclaimed */
	init_buffers(dev, 1 << 20, 1);

	block_t volblocks = BITMAP_BLOCKS << (dev->bits + 3);
	struct sb *sb = rapid_sb(dev);
	sb->super = INIT_DISKSB(dev->bits, volblocks);
	setup_sb(sb, &sb->super);

	test_init(argv[0]);

	struct inode *bitmap = rapid_open_inode(sb, NULL, 0);
	sb->bitmap = bitmap;

	/* Setup buffers for bitmap */
	for (int block = 0; block < BITMAP_BLOCKS; block++) {
		struct buffer_head *buffer = blockget(bitmap->map, block);
		memset(bufdata(buffer), 0, sb->blocksize);
		set_buffer_clean(buffer);
		blockput(buffer);
	}

	/* Set fake backend mark to modify backend objects. */
	tux3_start_backend(sb);

	if (test_start("test01"))
		test01(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test02"))
		test02(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test03"))
		test03(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test04"))
		test04(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test05"))
		test05(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test06"))
		test06(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test07"))
		test07(sb, BITMAP_BLOCKS);
	test_end();

	if (test_start("test08"))
		test08(sb, BITMAP_BLOCKS);
	test_end();

	tux3_end_backend();

	clean_main(sb);

	return test_failures();
}