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