コード例 #1
0
static void
test(ck_bitmap_t *bits, unsigned int n_length, bool initial)
{
	unsigned int i;
	CK_BITMAP_INSTANCE(8) u;

	CK_BITMAP_INIT(&u, 8, false);
	CK_BITMAP_SET(&u, 1);
	CK_BITMAP_SET(&u, 4);

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == !initial) {
			ck_error("[0] ERROR [%u]: Expected %u got %u\n", i,
				initial, !initial);
		}
	}

	for (i = 0; i < n_length; i++) {
		ck_bitmap_set(bits, i);
		if (ck_bitmap_test(bits, i) == false) {
			ck_error("[1] ERROR: Expected bit to be set: %u\n", i);
		}
		ck_bitmap_reset(bits, i);
		if (ck_bitmap_test(bits, i) == true) {
			ck_error("[2] ERROR: Expected bit to be cleared: %u\n", i);
		}

		ck_bitmap_set(bits, i);
		if (ck_bitmap_test(bits, i) == false) {
			ck_error("[3] ERROR: Expected bit to be set: %u\n", i);
		}

		check_iteration(bits, i, initial);
	}

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == false) {
			ck_error("[4] ERROR: Expected bit to be set: %u\n", i);
		}
	}

	ck_bitmap_clear(bits);

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == true) {
			ck_error("[4] ERROR: Expected bit to be reset: %u\n", i);
		}
	}

	ck_bitmap_union(bits, CK_BITMAP(&u));
	if (ck_bitmap_test(bits, 1) == false ||
	    ck_bitmap_test(bits, 4) == false) {
		ck_error("ERROR: Expected union semantics.\n");
	}

	return;
}
コード例 #2
0
ファイル: serial.c プロジェクト: abelmathew/ck
static void
test(ck_bitmap_t *bits, unsigned int n_length, bool initial)
{
	unsigned int i;

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == !initial) {
			fprintf(stderr, "[0] ERROR [%u]: Expected %u got %u\n", i,
				initial, !initial);
			exit(EXIT_FAILURE);
		}
	}

	for (i = 0; i < n_length; i++) {
		ck_bitmap_set_mpmc(bits, i);
		if (ck_bitmap_test(bits, i) == false) {
			fprintf(stderr, "[1] ERROR: Expected bit to be set: %u\n", i);
			exit(EXIT_FAILURE);
		}
		ck_bitmap_reset_mpmc(bits, i);
		if (ck_bitmap_test(bits, i) == true) {
			fprintf(stderr, "[2] ERROR: Expected bit to be cleared: %u\n", i);
			exit(EXIT_FAILURE);
		}

		ck_bitmap_set_mpmc(bits, i);
		if (ck_bitmap_test(bits, i) == false) {
			fprintf(stderr, "[3] ERROR: Expected bit to be set: %u\n", i);
			exit(EXIT_FAILURE);
		}

		check_iteration(bits, i, initial);
	}

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == false) {
			fprintf(stderr, "[4] ERROR: Expected bit to be set: %u\n", i);
			exit(EXIT_FAILURE);
		}
	}

	ck_bitmap_clear(bits);

	for (i = 0; i < n_length; i++) {
		if (ck_bitmap_test(bits, i) == true) {
			fprintf(stderr, "[4] ERROR: Expected bit to be reset: %u\n", i);
			exit(EXIT_FAILURE);
		}
	}

	return;
}