コード例 #1
0
ファイル: tallocmsg.c プロジェクト: jameshilliard/WECB-BH-GPL
static void msg_pool_usage_helper(const void *ptr, int depth, int max_depth, int is_ref, void *_s)
{
	const char *name = talloc_get_name(ptr);
	struct msg_pool_usage_state *state = (struct msg_pool_usage_state *)_s;

	if (is_ref) {
		sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
			       "%*sreference to: %s\n", depth*4, "", name);
		return;
	}

	if (depth == 0) {
		sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
			       "%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n", 
			       (max_depth < 0 ? "full " :""), name,
			       (unsigned long)talloc_total_size(ptr),
			       (unsigned long)talloc_total_blocks(ptr));
		return;
	}

	sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
		       "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n", 
		       depth*4, "",
		       name,
		       (unsigned long)talloc_total_size(ptr),
		       (unsigned long)talloc_total_blocks(ptr),
		       talloc_reference_count(ptr));
}
コード例 #2
0
ファイル: run-take.c プロジェクト: HSchroeder/ccan
int main(void)
{
	char *parent, *c;

	plan_tests(21);

	/* We can take NULL. */
	ok1(take(NULL) == NULL);
	ok1(is_taken(NULL));
	ok1(taken(NULL)); /* Undoes take() */
	ok1(!is_taken(NULL));
	ok1(!taken(NULL));

	parent = tal(NULL, char);
	ok1(parent);

	ok1(take(parent) == parent);
	ok1(is_taken(parent));
	ok1(taken(parent)); /* Undoes take() */
	ok1(!is_taken(parent));
	ok1(!taken(parent));

	c = tal(parent, char);
	*c = 'h';
	c = tal_dup(parent, char, take(c), 1, 0);
	ok1(c[0] == 'h');
	ok1(tal_parent(c) == parent);

	c = tal_dup(parent, char, take(c), 1, 2);
	ok1(c[0] == 'h');
	strcpy(c, "hi");
	ok1(tal_parent(c) == parent);

	/* dup must reparent child. */
	c = tal_dup(NULL, char, take(c), 1, 0);
	ok1(c[0] == 'h');
	ok1(tal_parent(c) == NULL);

	/* No leftover allocations. */
	tal_free(c);
	ok1(talloc_total_blocks(parent) == 1);

	tal_free(parent);
	ok1(!taken_any());

	/* NULL pass-through. */
	c = NULL;
	ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL);
	ok1(!taken_any());

	return exit_status();
}
コード例 #3
0
ファイル: run-array.c プロジェクト: CodeShark/lightning
int main(void)
{
	char *parent, *c[4];
	int i;

	plan_tests(11);

	parent = tal(NULL, char);
	ok1(parent);

	/* Zeroing allocations. */
	for (i = 0; i < 4; i++) {
		c[i] = talz(parent, char);
		ok1(*c[i] == '\0');
		tal_free(c[i]);
	}

	/* Array allocation. */
	for (i = 0; i < 4; i++) {
		c[i] = tal_arr(parent, char, 4);
		strcpy(c[i], "abc");
		tal_free(c[i]);
	}

	/* Zeroing array allocation. */
	for (i = 0; i < 4; i++) {
		c[i] = tal_arrz(parent, char, 4);
		ok1(!c[i][0] && !c[i][1] && !c[i][2] && !c[i][3]);
		strcpy(c[i], "abc");
		tal_free(c[i]);
	}

	/* Resizing. */
	c[0] = tal_arrz(parent, char, 4);
	ok1(tal_resize(&c[0], 6));
	strcpy(c[0], "hello");
	tal_free(c[0]);
	ok1(talloc_total_blocks(parent) == 1);
	tal_free(parent);

	return exit_status();
}
コード例 #4
0
ファイル: dbspeed.c プロジェクト: AllardJ/Tomato
/*
  test ldb speed
*/
static bool test_ldb_speed(struct torture_context *torture, const void *_data)
{
	struct timeval tv;
	struct ldb_context *ldb;
	int timelimit = torture_setting_int(torture, "timelimit", 10);
	int i, count;
	TALLOC_CTX *tmp_ctx = talloc_new(torture);
	struct ldb_ldif *ldif;
	const char *init_ldif = "dn: @INDEXLIST\n" \
		"@IDXATTR: UID\n";
	float ldb_speed;

	unlink("./test.ldb");

	torture_comment(torture, "Testing ldb speed for sidmap\n");

	ldb = ldb_wrap_connect(tmp_ctx, torture->ev, torture->lp_ctx, "tdb://test.ldb", 
				NULL, NULL, LDB_FLG_NOSYNC, NULL);
	if (!ldb) {
		unlink("./test.ldb");
		talloc_free(tmp_ctx);
		torture_fail(torture, "Failed to open test.ldb");
	}

	/* add an index */
	ldif = ldb_ldif_read_string(ldb, &init_ldif);
	if (ldif == NULL) goto failed;
	if (ldb_add(ldb, ldif->msg) != LDB_SUCCESS) goto failed;
	talloc_free(ldif);

	torture_comment(torture, "Adding %d SID records\n", torture_entries);

	for (i=0;i<torture_entries;i++) {
		if (!ldb_add_record(ldb, i)) {
			torture_result(torture, TORTURE_FAIL, "Failed to add SID %d\n", i);
			goto failed;
		}
	}

	if (talloc_total_blocks(torture) > 100) {
		torture_result(torture, TORTURE_FAIL, "memory leak in ldb add\n");
		goto failed;
	}

	torture_comment(torture, "Testing for %d seconds\n", timelimit);

	tv = timeval_current();

	for (count=0;timeval_elapsed(&tv) < timelimit;count++) {
		struct ldb_dn *dn;
		struct ldb_result *res;

		i = random() % torture_entries;
		dn = ldb_dn_new_fmt(tmp_ctx, ldb, "SID=S-1-5-21-53173311-3623041448-2049097239-%u", i);
		if (ldb_search(ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, NULL, NULL) != LDB_SUCCESS || res->count != 1) {
			torture_fail(torture, talloc_asprintf(torture, "Failed to find SID %d", i));
		}
		talloc_free(res);
		talloc_free(dn);
		if (ldb_search(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "(UID=%u)", i) != LDB_SUCCESS || res->count != 1) {
			torture_fail(torture, talloc_asprintf(torture, "Failed to find UID %d", i));
		}
		talloc_free(res);
	}

	if (talloc_total_blocks(torture) > 100) {
		unlink("./test.ldb");
		talloc_free(tmp_ctx);
		torture_fail(torture, "memory leak in ldb search");
	}

	ldb_speed = count/timeval_elapsed(&tv);
	torture_comment(torture, "ldb speed %.2f ops/sec\n", ldb_speed);

	torture_comment(torture, "ldb/tdb speed ratio is %.2f%%\n", (100*ldb_speed/tdb_speed));
	

	unlink("./test.ldb");
	talloc_free(tmp_ctx);
	return true;

failed:
	unlink("./test.ldb");
	talloc_free(tmp_ctx);
	return false;
}