Пример #1
0
int main(int argc, char *argv[])
{
	unsigned int i;
	struct ntdb_context *ntdb;
	int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
			NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
			NTDB_NOMMAP|NTDB_CONVERT };

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 3);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		ntdb = ntdb_open("run-new_database.ntdb", flags[i]|MAYBE_NOSYNC,
				 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		if (!ok1(ntdb))
			failtest_exit(exit_status());

		failtest_suppress = true;
		ok1(ntdb_check(ntdb, NULL, NULL) == 0);
		failtest_suppress = false;
		ntdb_close(ntdb);
		if (!ok1(tap_log_messages == 0))
			break;
	}
	failtest_exit(exit_status());

	/*
	 * We will never reach this but the compiler complains if we do not
	 * return in this function.
	 */
	return EFAULT;
}
Пример #2
0
int main(int argc, char *argv[])
{
	unsigned int i;
	struct tdb_context *tdb;
	int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
			TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
			TDB_NOMMAP|TDB_CONVERT,
			TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
			TDB_NOMMAP|TDB_VERSION1,
			TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
			TDB_CONVERT|TDB_VERSION1,
			TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
	struct tdb_data key = tdb_mkdata("key", 3);
	struct tdb_data data = tdb_mkdata("data", 4);

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;

	failtest_suppress = true;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		tdb = tdb_open("run-11-simple-fetch.tdb", flags[i],
			       O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		ok1(tdb);
		if (tdb) {
			struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */

			/* fetch should fail. */
			failtest_suppress = false;
			if (!ok1(tdb_fetch(tdb, key, &d) == TDB_ERR_NOEXIST))
				goto fail;
			failtest_suppress = true;
			ok1(tdb_check(tdb, NULL, NULL) == 0);
			/* Insert should succeed. */
			ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
			ok1(tdb_check(tdb, NULL, NULL) == 0);
			/* Fetch should now work. */
			failtest_suppress = false;
			if (!ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS))
				goto fail;
			failtest_suppress = true;
			ok1(tdb_deq(d, data));
			free(d.dptr);
			ok1(tdb_check(tdb, NULL, NULL) == 0);
			tdb_close(tdb);
		}
	}
	ok1(tap_log_messages == 0);
	failtest_exit(exit_status());

fail:
	failtest_suppress = true;
	tdb_close(tdb);
	failtest_exit(exit_status());
}
Пример #3
0
int main(int argc, char *argv[])
{
	unsigned int i;
	uint64_t val;
	struct tdb_context *tdb;
	int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
			TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
			TDB_NOMMAP|TDB_CONVERT };

	plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1);

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;

	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		failtest_suppress = true;
		tdb = tdb_open("run-expand.tdb", flags[i],
			       O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		if (!ok1(tdb))
			break;

		val = tdb->file->map_size;
		/* Need some hash lock for expand. */
		ok1(tdb_lock_hashes(tdb, 0, 1, F_WRLCK, TDB_LOCK_WAIT) == 0);
		failtest_suppress = false;
		if (!ok1(tdb_expand(tdb, 1) == 0)) {
			failtest_suppress = true;
			tdb_close(tdb);
			break;
		}
		failtest_suppress = true;

		ok1(tdb->file->map_size >= val + 1 * TDB_EXTENSION_FACTOR);
		ok1(tdb_unlock_hashes(tdb, 0, 1, F_WRLCK) == 0);
		ok1(tdb_check(tdb, NULL, NULL) == 0);

		val = tdb->file->map_size;
		ok1(tdb_lock_hashes(tdb, 0, 1, F_WRLCK, TDB_LOCK_WAIT) == 0);
		failtest_suppress = false;
		if (!ok1(tdb_expand(tdb, 1024) == 0)) {
			failtest_suppress = true;
			tdb_close(tdb);
			break;
		}
		failtest_suppress = true;
		ok1(tdb_unlock_hashes(tdb, 0, 1, F_WRLCK) == 0);
		ok1(tdb->file->map_size >= val + 1024 * TDB_EXTENSION_FACTOR);
		ok1(tdb_check(tdb, NULL, NULL) == 0);
		tdb_close(tdb);
	}

	ok1(tap_log_messages == 0);
	failtest_exit(exit_status());
}
Пример #4
0
int main(int argc, char *argv[])
{
	plan_tests(5);
	failtest_init(argc, argv);

	talloc_enable_null_tracking();
	if (null_context) {
		ok1(test_unref_reparent(NULL) && test_lifeless(NULL));
		/* This closes the leak, but don't free any other leaks! */
		ok1(!talloc_chunk_from_ptr(null_context)->child);
		talloc_disable_null_tracking();
	}
	failtest_exit(exit_status());
}
Пример #5
0
int main(int argc, char *argv[])
{
	unsigned int i, messages = 0;
	struct ntdb_context *ntdb;
	int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
			NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 4);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		ntdb = ntdb_open("run-35-convert.ntdb", flags[i]|MAYBE_NOSYNC,
				 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		if (!ok1(ntdb))
			failtest_exit(exit_status());

		ntdb_close(ntdb);
		/* We can fail in log message formatting or open.  That's OK */
		if (failtest_has_failed()) {
			failtest_exit(exit_status());
		}
		/* If we say NTDB_CONVERT, it must be converted */
		ntdb = ntdb_open("run-35-convert.ntdb",
				 flags[i]|NTDB_CONVERT|MAYBE_NOSYNC,
				 O_RDWR, 0600, &tap_log_attr);
		if (flags[i] & NTDB_CONVERT) {
			if (!ntdb)
				failtest_exit(exit_status());
			ok1(ntdb_get_flags(ntdb) & NTDB_CONVERT);
			ntdb_close(ntdb);
		} else {
			if (!ok1(!ntdb && errno == EIO))
				failtest_exit(exit_status());
			ok1(tap_log_messages == ++messages);
			if (!ok1(log_last && strstr(log_last, "NTDB_CONVERT")))
				failtest_exit(exit_status());
		}

		/* If don't say NTDB_CONVERT, it *may* be converted */
		ntdb = ntdb_open("run-35-convert.ntdb",
				 (flags[i] & ~NTDB_CONVERT)|MAYBE_NOSYNC,
				 O_RDWR, 0600, &tap_log_attr);
		if (!ntdb)
			failtest_exit(exit_status());
		ok1(ntdb_get_flags(ntdb) == (flags[i]|MAYBE_NOSYNC));
		ntdb_close(ntdb);
	}
	failtest_exit(exit_status());
}
Пример #6
0
int main(int argc, char *argv[])
{
	unsigned int i, messages = 0;
	struct tdb_context *tdb;
	int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
			TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
			TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
			TDB_CONVERT|TDB_VERSION1,
			TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 4);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		tdb = tdb_open("run-35-convert.tdb", flags[i],
			       O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		if (!ok1(tdb))
			failtest_exit(exit_status());

		tdb_close(tdb);
		/* If we say TDB_CONVERT, it must be converted */
		tdb = tdb_open("run-35-convert.tdb",
			       flags[i]|TDB_CONVERT,
			       O_RDWR, 0600, &tap_log_attr);
		if (flags[i] & TDB_CONVERT) {
			if (!tdb)
				failtest_exit(exit_status());
			ok1(tdb_get_flags(tdb) & TDB_CONVERT);
			tdb_close(tdb);
		} else {
			if (!ok1(!tdb && errno == EIO))
				failtest_exit(exit_status());
			ok1(tap_log_messages == ++messages);
			if (!ok1(log_last && strstr(log_last, "TDB_CONVERT")))
				failtest_exit(exit_status());
		}

		/* If don't say TDB_CONVERT, it *may* be converted */
		tdb = tdb_open("run-35-convert.tdb",
			       flags[i] & ~TDB_CONVERT,
			       O_RDWR, 0600, &tap_log_attr);
		if (!tdb)
			failtest_exit(exit_status());
		ok1(tdb_get_flags(tdb) == flags[i]);
		tdb_close(tdb);
	}
	failtest_exit(exit_status());
}
Пример #7
0
int main(void)
{
	int fd, pfd[2], ecode;
	struct rlimit lim;

	if (getrlimit(RLIMIT_NOFILE, &lim) != 0)
		err(1, "getrlimit RLIMIT_NOFILE fail?");

	printf("rlimit = %lu/%lu (inf=%lu)\n",
	       (long)lim.rlim_cur, (long)lim.rlim_max,
	       (long)RLIM_INFINITY);
	lim.rlim_cur /= 2;
	if (lim.rlim_cur < 8)
		errx(1, "getrlimit limit %li too low", (long)lim.rlim_cur);
	if (setrlimit(RLIMIT_NOFILE, &lim) != 0)
		err(1, "setrlimit RLIMIT_NOFILE (%li/%li)",
		    (long)lim.rlim_cur, (long)lim.rlim_max);

	plan_tests(2);
	failtest_init(0, NULL);

	if (pipe(pfd))
		abort();

	fd = failtest_open("run-with-fdlimit-scratch", "run-with_fdlimit.c", 1,
			   O_RDWR|O_CREAT, 0600);
	if (fd == -1) {
		/* We are the child: write error code for parent to check. */
		ecode = errno;
		if (write(pfd[1], &ecode, sizeof(ecode)) != sizeof(ecode))
			abort();
		failtest_exit(0);
	}

	/* Check child got correct errno. */
	ok1(read(pfd[0], &ecode, sizeof(ecode)) == sizeof(ecode));
	ok1(ecode == EACCES);

	/* Clean up. */
	failtest_close(fd, "run-open.c", 1);
	close(pfd[0]);
	close(pfd[1]);

	return exit_status();
}
Пример #8
0
int main(int argc, char *argv[])
{
	unsigned int i;
	struct tdb_context *tdb;
	int flags[] = { TDB_INTERNAL,
			TDB_INTERNAL|TDB_CONVERT,
			TDB_CONVERT,
			TDB_INTERNAL|TDB_VERSION1,
			TDB_VERSION1,
			TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
			TDB_CONVERT|TDB_VERSION1 };
	struct tdb_data key = tdb_mkdata("key", 3);
	struct tdb_data data = tdb_mkdata("data", 4);

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;

	failtest_suppress = true;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 3 + 1);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		tdb = tdb_open("run-12-check.tdb", flags[i],
			       O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		ok1(tdb);
		ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);

		/* This is what we really want to test: tdb_check(). */
		failtest_suppress = false;
		if (!ok1(tdb_check(tdb, NULL, NULL) == 0))
			goto fail;
		failtest_suppress = true;

		tdb_close(tdb);
	}
	ok1(tap_log_messages == 0);
	failtest_exit(exit_status());

fail:
	failtest_suppress = true;
	tdb_close(tdb);
	failtest_exit(exit_status());
}
Пример #9
0
int main(int argc, char *argv[])
{
	int fd;
	char *p;
	char buf[] = "Hello world!";

	plan_tests(5);
	failtest_init(argc, argv);

	fd = failtest_open("run-write-scratchpad", __FILE__, __LINE__,
			   O_RDWR|O_CREAT, 0600);
	/* Child will fail, ignore. */
	if (fd < 0)
		failtest_exit(0);
	if (write(fd, buf, strlen(buf)) != strlen(buf))
		abort();
	ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));

	p = failtest_malloc(100, __FILE__, __LINE__);
	if (!p) {
		/* We are the child.  Do a heap of writes. */
		unsigned int i;

		for (i = 0; i < strlen(buf)+1; i++)
			if (failtest_write(fd, "x", 1, __FILE__, __LINE__)
			    == 1)
				break;
		failtest_close(fd, __FILE__, __LINE__);
		failtest_exit(0);
	}

	/* Seek pointer should be left alone! */
	ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
	/* Length should be restored. */
	ok1(lseek(fd, 0, SEEK_END) == strlen(buf));
	lseek(fd, 0, SEEK_SET);
	ok1(read(fd, buf, strlen(buf)) == strlen("Hello world!"));
	ok1(strcmp(buf, "Hello world!") == 0);
	failtest_close(fd, __FILE__, __LINE__);

	return exit_status();
}
Пример #10
0
int main(int argc, char *argv[])
{
	int *p1, *p2;

	plan_tests(14);
	failtest_init(argc, argv);
	talloc_set_allocator(my_malloc, my_free, my_realloc);
	p1 = talloc_array(NULL, int, 10);
	if (!p1)
		failtest_exit(exit_status());
	ok1(my_malloc_count == 1);
	ok1(my_free_count == 0);
	ok1(my_realloc_count == 0);

	p2 = talloc_realloc(NULL, p1, int, 10000);
	if (!p2) {
		talloc_free(p1);
		failtest_exit(exit_status());
	}
	p1 = p2;
	ok1(my_malloc_count == 1);
	ok1(my_free_count == 0);
	ok1(my_realloc_count == 1);

	p2 = talloc(p1, int);
	if (!p2) {
		talloc_free(p1);
		failtest_exit(exit_status());
	}
	ok1(my_malloc_count == 2);
	ok1(my_free_count == 0);
	ok1(my_realloc_count == 1);

	talloc_free(p1);
	ok1(my_malloc_count == 2);
	ok1(my_free_count == 2);
	ok1(my_realloc_count == 1);

	failtest_exit(exit_status());
}
Пример #11
0
int main(int argc, char *argv[])
{
	unsigned int i;
	struct ntdb_context *ntdb;
	int flags[] = { NTDB_INTERNAL,
			NTDB_INTERNAL|NTDB_CONVERT,
			NTDB_CONVERT };
	NTDB_DATA key = ntdb_mkdata("key", 3);
	NTDB_DATA data = ntdb_mkdata("data", 4);

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;

	failtest_suppress = true;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 3 + 1);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		ntdb = ntdb_open("run-12-check.ntdb", flags[i]|MAYBE_NOSYNC,
				 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
		ok1(ntdb);
		ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);

		/* This is what we really want to test: ntdb_check(). */
		failtest_suppress = false;
		if (!ok1(ntdb_check(ntdb, NULL, NULL) == 0))
			goto fail;
		failtest_suppress = true;

		ntdb_close(ntdb);
	}
	ok1(tap_log_messages == 0);
	failtest_exit(exit_status());

fail:
	failtest_suppress = true;
	ntdb_close(ntdb);
	failtest_exit(exit_status());
}
Пример #12
0
int main(void)
{
	int status;

	plan_tests(3);
	failtest_init(0, NULL);

	status = setjmp(exited);
	if (status == 0) {
		char *p = failtest_malloc(1, "run-malloc.c", 1);
		/* If we just segv, valgrind counts that as a failure.
		 * So kill ourselves creatively. */
		if (!p)
			kill(getpid(), SIGSEGV);
		fail("Expected child to crash!");
	} else {
		ok1(status == 2);
		ok1(strstr(output, "Killed by signal"));
		ok1(strstr(output, "--failpath=M\n"));
	}
	free(buffer);
	return exit_status();
}
Пример #13
0
int main(int argc, char *argv[])
{
	unsigned int i;
	struct ntdb_context *ntdb;
	int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
			NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
	NTDB_DATA key = ntdb_mkdata("key", 3);
	NTDB_DATA data = ntdb_mkdata("data", 4), d;
	union ntdb_attribute seed_attr;
	unsigned int msgs = 0;

	failtest_init(argc, argv);
	failtest_hook = block_repeat_failures;
	failtest_exit_check = exit_check_log;

	seed_attr.base.attr = NTDB_ATTRIBUTE_SEED;
	seed_attr.base.next = &tap_log_attr;
	seed_attr.seed.seed = 0;

	failtest_suppress = true;
	plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		ntdb = ntdb_open("run-05-readonly-open.ntdb",
				 flags[i]|MAYBE_NOSYNC,
				 O_RDWR|O_CREAT|O_TRUNC, 0600,
				 &seed_attr);
		ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
		ntdb_close(ntdb);

		failtest_suppress = false;
		ntdb = ntdb_open("run-05-readonly-open.ntdb",
				 flags[i]|MAYBE_NOSYNC,
				 O_RDONLY, 0600, &tap_log_attr);
		if (!ok1(ntdb))
			break;
		ok1(tap_log_messages == msgs);
		/* Fetch should succeed, stores should fail. */
		if (!ok1(ntdb_fetch(ntdb, key, &d) == 0))
			goto fail;
		ok1(ntdb_deq(d, data));
		free(d.dptr);
		if (!ok1(ntdb_store(ntdb, key, data, NTDB_MODIFY)
			 == NTDB_ERR_RDONLY))
			goto fail;
		ok1(tap_log_messages == ++msgs);
		if (!ok1(ntdb_store(ntdb, key, data, NTDB_INSERT)
			 == NTDB_ERR_RDONLY))
			goto fail;
		ok1(tap_log_messages == ++msgs);
		failtest_suppress = true;
		ok1(ntdb_check(ntdb, NULL, NULL) == 0);
		ntdb_close(ntdb);
		ok1(tap_log_messages == msgs);
		/* SIGH: failtest bug, it doesn't save the ntdb file because
		 * we have it read-only.  If we go around again, it gets
		 * changed underneath us and things get screwy. */
		if (failtest_has_failed())
			break;
	}
	failtest_exit(exit_status());

fail:
	failtest_suppress = true;
	ntdb_close(ntdb);
	failtest_exit(exit_status());
}
Пример #14
0
void failtest_setup(int argc, char *argv[])
{
	failtest_init(argc, argv);
	rfc822_set_allocation_failure_handler(allocation_failure_continue);
	talloc_set_allocator(malloc_wrapper, free_wrapper, realloc_wrapper);
}