Пример #1
0
int main ( int argc, char * argv[]) {
	unsigned int seed,nelt,keylen;
	if ( argc!=4){
		printf ("Usage: rbtree seed nelt keylen\n");
		return EXIT_FAILURE;
	}
	sscanf(argv[1],"%u",&seed); srandom(seed);
	sscanf(argv[2],"%u",&nelt);
	sscanf(argv[3],"%u",&keylen);

	RBTREE tree = create_rbtree(lexo,strcopykey,strfreekey);
	char ** keys = random_keys(nelt,keylen);
	printf ("Inserting elements\n");
	for ( int i=0 ; i<nelt ; i++){
		printf ("\tinserting %s\n",keys[i]);
		insertelt_rbtree(tree,keys[i],"a");
		check_rbtree(tree);
	}
	unsigned int ntree_elt = nmemb_rbtree(tree);
	printf ("Tree contains %u elements in total\n",ntree_elt);
	assert(ntree_elt<=nelt);


	printf ("Copying tree\n");
	RBTREE tree2 = copy_rbtree(tree,strcopykey);
	check_rbtree(tree2);
	printf("Freeing copied tree\n");
	free_rbtree(tree2,free);

	printf("Printing tree\n");
	unsafemap_rbtree (tree,print_node);

	printf("Iterating through tree\n");
	unsigned int iter_count = 0;
	for ( RBITER iter = iter_rbtree(tree) ; next_rbtree(iter) ; ){
		const char * key = (const char *) iterkey_rbtree(iter);
		printf("\tfound %s\n",key);
		iter_count++;
	}
	assert(iter_count==ntree_elt);  

	printf ("Removing elements\n");
	unsigned int * rperm = random_permutation(nelt);
	fputs("Permutation: ",stdout);
	print_rperm(rperm,nelt);
	for ( int i=0 ; i<nelt ; i++){
		printf("\tremoving %s\n",keys[rperm[i]]);
		removeelt_rbtree(tree,keys[rperm[i]]);
		check_rbtree(tree);
	}
	assert(nmemb_rbtree(tree)==0);
	free_rbtree(tree,free);
}
Пример #2
0
static int igt_insert_complete(void *arg)
{
	const u32 seqno_bias = 0x1000;
	struct intel_engine_cs *engine = arg;
	struct intel_wait *waiters;
	const int count = 4096;
	unsigned long *bitmap;
	int err = -ENOMEM;
	int n, m;

	mock_engine_reset(engine);

	waiters = kvmalloc_array(count, sizeof(*waiters), GFP_KERNEL);
	if (!waiters)
		goto out_engines;

	bitmap = kcalloc(DIV_ROUND_UP(count, BITS_PER_LONG), sizeof(*bitmap),
			 GFP_KERNEL);
	if (!bitmap)
		goto out_waiters;

	for (n = 0; n < count; n++) {
		intel_wait_init_for_seqno(&waiters[n], n + seqno_bias);
		intel_engine_add_wait(engine, &waiters[n]);
		__set_bit(n, bitmap);
	}
	err = check_rbtree(engine, bitmap, waiters, count);
	if (err)
		goto out_bitmap;

	/* On each step, we advance the seqno so that several waiters are then
	 * complete (we increase the seqno by increasingly larger values to
	 * retire more and more waiters at once). All retired waiters should
	 * be woken and removed from the rbtree, and so that we check.
	 */
	for (n = 0; n < count; n = m) {
		int seqno = 2 * n;

		GEM_BUG_ON(find_first_bit(bitmap, count) != n);

		if (intel_wait_complete(&waiters[n])) {
			pr_err("waiter[%d, seqno=%d] completed too early\n",
			       n, waiters[n].seqno);
			err = -EINVAL;
			goto out_bitmap;
		}

		/* complete the following waiters */
		mock_seqno_advance(engine, seqno + seqno_bias);
		for (m = n; m <= seqno; m++) {
			if (m == count)
				break;

			GEM_BUG_ON(!test_bit(m, bitmap));
			__clear_bit(m, bitmap);
		}

		intel_engine_remove_wait(engine, &waiters[n]);
		RB_CLEAR_NODE(&waiters[n].node);

		err = check_rbtree(engine, bitmap, waiters, count);
		if (err) {
			pr_err("rbtree corrupt after seqno advance to %d\n",
			       seqno + seqno_bias);
			goto out_bitmap;
		}

		err = check_completion(engine, bitmap, waiters, count);
		if (err) {
			pr_err("completions after seqno advance to %d failed\n",
			       seqno + seqno_bias);
			goto out_bitmap;
		}
	}

	err = check_rbtree_empty(engine);
out_bitmap:
	kfree(bitmap);
out_waiters:
	kvfree(waiters);
out_engines:
	mock_engine_flush(engine);
	return err;
}
Пример #3
0
static int igt_random_insert_remove(void *arg)
{
	const u32 seqno_bias = 0x1000;
	I915_RND_STATE(prng);
	struct intel_engine_cs *engine = arg;
	struct intel_wait *waiters;
	const int count = 4096;
	unsigned int *order;
	unsigned long *bitmap;
	int err = -ENOMEM;
	int n;

	mock_engine_reset(engine);

	waiters = kvmalloc_array(count, sizeof(*waiters), GFP_KERNEL);
	if (!waiters)
		goto out_engines;

	bitmap = kcalloc(DIV_ROUND_UP(count, BITS_PER_LONG), sizeof(*bitmap),
			 GFP_KERNEL);
	if (!bitmap)
		goto out_waiters;

	order = i915_random_order(count, &prng);
	if (!order)
		goto out_bitmap;

	for (n = 0; n < count; n++)
		intel_wait_init_for_seqno(&waiters[n], seqno_bias + n);

	err = check_rbtree(engine, bitmap, waiters, count);
	if (err)
		goto out_order;

	/* Add and remove waiters into the rbtree in random order. At each
	 * step, we verify that the rbtree is correctly ordered.
	 */
	for (n = 0; n < count; n++) {
		int i = order[n];

		intel_engine_add_wait(engine, &waiters[i]);
		__set_bit(i, bitmap);

		err = check_rbtree(engine, bitmap, waiters, count);
		if (err)
			goto out_order;
	}

	i915_random_reorder(order, count, &prng);
	for (n = 0; n < count; n++) {
		int i = order[n];

		intel_engine_remove_wait(engine, &waiters[i]);
		__clear_bit(i, bitmap);

		err = check_rbtree(engine, bitmap, waiters, count);
		if (err)
			goto out_order;
	}

	err = check_rbtree_empty(engine);
out_order:
	kfree(order);
out_bitmap:
	kfree(bitmap);
out_waiters:
	kvfree(waiters);
out_engines:
	mock_engine_flush(engine);
	return err;
}