diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2016-12-17 21:28:53 -0800 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2016-12-17 21:28:53 -0800 | 
| commit | 54df2afaa61c6a03cbb4a33c9b90fa572b6d07b8 (patch) | |
| tree | 18147b92b969d25ffbe61935fb63035cac820dd0 /db-4.8.30/test_micro/source/b_open.c | |
Berkeley DB 4.8 with rust build script for linux.
Diffstat (limited to 'db-4.8.30/test_micro/source/b_open.c')
| -rw-r--r-- | db-4.8.30/test_micro/source/b_open.c | 144 | 
1 files changed, 144 insertions, 0 deletions
| diff --git a/db-4.8.30/test_micro/source/b_open.c b/db-4.8.30/test_micro/source/b_open.c new file mode 100644 index 0000000..1c47e43 --- /dev/null +++ b/db-4.8.30/test_micro/source/b_open.c @@ -0,0 +1,144 @@ +/* + * See the file LICENSE for redistribution information. + * + * Copyright (c) 2005-2009 Oracle.  All rights reserved. + * + * $Id$ + */ +#include "bench.h" + +static int usage(void); + +int +b_open(int argc, char *argv[]) +{ +	extern char *optarg; +	extern int optind; +	DB_ENV *dbenv; +	DB *dbp; +	DBTYPE type; +	int ch, i, count; +	char *fname, *dbname, *ts; + +	type = DB_BTREE; +	count = 1000; +	fname = dbname = NULL; +	ts = "Btree"; +	while ((ch = getopt(argc, argv, "c:dft:")) != EOF) +		switch (ch) { +		case 'c': +			count = atoi(optarg); +			break; +		case 'd': +			dbname = "dbname"; +			break; +		case 'f': +			fname = "filename"; +			break; +		case 't': +			switch (optarg[0]) { +			case 'B': case 'b': +				ts = "Btree"; +				type = DB_BTREE; +				break; +			case 'H': case 'h': +				if (b_util_have_hash()) +					return (0); +				ts = "Hash"; +				type = DB_HASH; +				break; +			case 'Q': case 'q': +				if (b_util_have_queue()) +					return (0); +				ts = "Queue"; +				type = DB_QUEUE; +				break; +			case 'R': case 'r': +				ts = "Recno"; +				type = DB_RECNO; +				break; +			default: +				return (usage()); +			} +			break; +		case '?': +		default: +			return (usage()); +		} +	argc -= optind; +	argv += optind; +	if (argc != 0) +		return (usage()); + +#if DB_VERSION_MAJOR < 4 +	/* +	 * Don't run in-memory database tests on versions less than 3, it +	 * takes forever and eats memory. +	 */ +	if (fname == NULL && dbname == NULL) +		return (0); +#endif +#if DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4 +	/* +	 * Named in-memory databases weren't available until 4.4. +	 */ +	if (fname == NULL && dbname != NULL) +		return (0); +#endif + +	/* Create the environment. */ +	DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0); +	dbenv->set_errfile(dbenv, stderr); +#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0 +	DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, +	    NULL, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0); +#else +	DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, +	    DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0); +#endif + +	/* Create the database. */ +	DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0); + +#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 1 +	DB_BENCH_ASSERT(dbp->open( +	    dbp, NULL, fname, dbname, type, DB_CREATE, 0666) == 0); +#else +	DB_BENCH_ASSERT(dbp->open( +	    dbp, fname, dbname, type, DB_CREATE, 0666) == 0); +#endif +	DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0); + +	/* Open the database count times. */ +	TIMER_START; +	for (i = 0; i < count; ++i) { +		DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0); +#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 1 +		DB_BENCH_ASSERT(dbp->open( +		    dbp, NULL, fname, dbname, type, DB_CREATE, 0666) == 0); +#else +		DB_BENCH_ASSERT(dbp->open( +		    dbp, fname, dbname, type, DB_CREATE, 0666) == 0); +#endif +		DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0); +	} +	TIMER_STOP; + +	printf("# %d %s %sdatabase open/close pairs\n", +	    count, ts, +	    fname == NULL ? +		(dbname == NULL ? "in-memory " : "named in-memory ") : +		(dbname == NULL ? "" : "sub-")); +	TIMER_DISPLAY(count); + +	DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0); + +	return (0); +} + +static int +usage() +{ +	(void)fprintf(stderr, "usage: b_open [-df] [-c count] [-t type]\n"); +	return (EXIT_FAILURE); +} | 
