• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/timemachine/db-4.7.25.NC/build_vxworks/test_micro/
1/*
2 * $Id: test_micro.c,v 1.7 2008/05/07 12:27:36 bschmeck Exp $
3 */
4
5#include "bench.h"
6
7int test_micro_main __P((int, char *[]));
8
9static int  test_micro_run __P((char *));
10static int  test_micro_usage __P((void));
11
12char *progname;					/* program name */
13
14static int test_start = 1;			/* first test to run */
15static int test_end = 0;			/* last test to run */
16
17static struct {
18	char *name;				/* command name */
19	int (*f)(int, char *[]);		/* function */
20} cmdlist[] = {
21	{ "b_curalloc", b_curalloc },
22	{ "b_curwalk", b_curwalk },
23	{ "b_del", b_del },
24	{ "b_get", b_get },
25	{ "b_inmem", b_inmem },
26	{ "b_load", b_load },
27	{ "b_open", b_open },
28	{ "b_put", b_put },
29	{ "b_recover", b_recover },
30	{ "b_txn", b_txn },
31	{ "b_txn_write", b_txn_write },
32	{ "b_workload", b_workload },
33	{ NULL, NULL }
34};
35
36int
37test_micro(args)
38	char *args;
39{
40	int argc;
41	char **argv;
42
43	__db_util_arg("test_micro", args, &argc, &argv);
44	return (test_micro_main(argc, argv) ? EXIT_FAILURE : EXIT_SUCCESS);
45}
46
47#include <stdio.h>
48#define	ERROR_RETURN	ERROR
49
50int
51test_micro_main(argc, argv)
52	int argc;
53	char *argv[];
54{
55	extern char *optarg;
56	extern int optind, __db_getopt_reset;
57	int ch, ret;
58	char *run_directory, *ifile;
59
60	if ((progname = __db_rpath(argv[0])) == NULL)
61		progname = argv[0];
62	else
63		++progname;
64
65#ifdef DB_BREW
66	if (bdb_brew_begin() != 0) {
67		fprintf(stderr,
68		    "%s: failed to initialize Berkeley DB on BREW\n");
69		return (EXIT_FAILURE);
70	}
71#endif
72
73	run_directory = NULL;
74	ifile = "run.std";
75	__db_getopt_reset = 1;
76	while ((ch = getopt(argc, argv, "d:e:i:s:")) != EOF)
77		switch (ch) {
78		case 'd':
79			run_directory = optarg;
80			break;
81		case 'e':
82			test_end = atoi(optarg);
83			break;
84		case 'i':
85			ifile = optarg;
86			break;
87		case 's':
88			test_start = atoi(optarg);
89			break;
90		case '?':
91		default:
92			return (test_micro_usage());
93		}
94	argc -= optind;
95	argv += optind;
96
97	/* Run in the target directory. */
98	if (run_directory != NULL && chdir(run_directory) != 0) {
99		fprintf(stderr,
100		    "%s: %s: %s\n", progname, run_directory, strerror(errno));
101		return (1);
102	}
103
104	/* Clean up any left-over test directory. */
105	if (b_util_dir_teardown())
106		return (1);
107
108	ret = test_micro_run(ifile);
109
110#ifdef DB_BREW
111	bdb_brew_end();
112#endif
113
114	return (ret ? EXIT_FAILURE : EXIT_SUCCESS);
115}
116
117/*
118 * run --
119 *	Read a configuration file and run the tests.
120 */
121static int
122test_micro_run(ifile)
123	char *ifile;
124{
125#ifdef HAVE_GETOPT_OPTRESET
126	extern int optreset;
127#endif
128	extern int optind, __db_getopt_reset;
129	static int test_cur = 0;
130	FILE *ifp;
131	int argc, cmdindx, lineno, ret;
132	char *p, cmd[1024], path[1024], **argv;
133
134	/* Identify the run. */
135	if (b_uname() != 0)
136		return (1);
137
138	/* Open the list of tests. */
139	if ((ifp = fopen(ifile, "r")) == NULL) {
140		fprintf(stderr,
141		    "%s: %s: %s\n", progname, ifile, strerror(errno));
142		return (1);
143	}
144
145	for (lineno = 1; fgets(cmd, sizeof(cmd), ifp) != NULL; ++lineno) {
146		/*
147		 * Nul-terminate the command line; check for a trailing \r
148		 * on Windows.
149		 */
150		if ((p = strchr(cmd, '\n')) == NULL) {
151format_err:		fprintf(stderr, "%s: %s: line %d: illegal input\n",
152			    progname, ifile, lineno);
153			return (1);
154		}
155		if (p > cmd && p[-1] == '\r')
156			--p;
157		*p = '\0';
158
159		/* Skip empty lines and comments. */
160		if (cmd[0] == '\0' || cmd[0] == '#')
161			continue;
162
163		/* Optionally limit the test run to specific tests. */
164		if (++test_cur < test_start ||
165		    (test_end != 0 && test_cur > test_end))
166			continue;
167
168		fprintf(stderr, "%d: %s\n", test_cur, cmd);
169
170		/* Find the command. */
171		if ((p = strchr(cmd, ' ')) == NULL)
172			goto format_err;
173		*p++ = '\0';
174		for (cmdindx = 0; cmdlist[cmdindx].name != NULL; ++cmdindx)
175			if (strcmp(cmd, cmdlist[cmdindx].name) == 0)
176				break;
177		if (cmdlist[cmdindx].name == NULL)
178			goto format_err;
179
180		/* Build argc/argv. */
181		if (__db_util_arg(cmd, p, &argc, &argv) != 0)
182			return (1);
183
184		/* Re-direct output into the test log file.  */
185		(void)snprintf(path, sizeof(path), "%d", test_cur);
186		if (freopen(path, "a", stdout) == NULL) {
187			fprintf(stderr,
188			    "%s: %s: %s\n", progname, path, strerror(errno));
189			return (1);
190		}
191
192		/*
193		 * Each underlying "program" re-parses its arguments --
194		 * reset getopt.
195		 */
196#ifdef HAVE_GETOPT_OPTRESET
197		optreset = 1;
198#endif
199		optind = 1;
200
201		/* Prepare the test directory. */
202		if (b_util_dir_setup())
203			return (1);
204
205		ret = cmdlist[cmdindx].f(argc, argv);
206
207		/* Clean up the test directory. */
208		if (b_util_dir_teardown())
209			return (1);
210
211		(void)fflush(stdout);
212
213#if DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1
214		__os_free(NULL, argv, 0);
215#else
216		__os_free(NULL, argv);
217#endif
218		if (ret != 0)
219			return (ret);
220	}
221
222	return (0);
223}
224
225static int
226test_micro_usage()
227{
228	(void)fprintf(stderr,
229	    "usage: %s [-d directory] [-e end] [-i input] [-s start]\n",
230	    progname);
231	return (EXIT_FAILURE);
232}
233