1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
12 #include <yaz/options.h>
19 int nconnect; /* number of connections to make */
20 int nsearch; /* number of searches on each connection */
21 int npresent; /* number of presents for each search */
22 int full; /* 1 = fetch full records, 0 = brief */
23 int delay; /* number of ms to delay between ops */
24 int random; /* if true, delay is random 0-specified */
25 int verbosity; /* 0 = quiet, higher => more verbose */
37 static int test(char *host, int port);
38 static void db_printf(int level, char *fmt, ...);
39 static void usage(const char *prog);
41 int main(int argc, char **argv)
51 while ((c = options("c:s:p:fbd:rv:", argv, argc, &arg)) != -2) {
61 case 'c': boptions.nconnect = atoi(arg); break;
62 case 's': boptions.nsearch = atoi(arg); break;
63 case 'p': boptions.npresent = atoi(arg); break;
64 case 'f': boptions.full = 1; break;
65 case 'b': boptions.full = 0; break;
66 case 'd': boptions.delay = atoi(arg); break;
67 case 'r': boptions.random = 1; break;
68 case 'v': boptions.verbosity = atoi(arg); break;
69 default: usage(*argv);
76 for (i = 0; i < boptions.nconnect; i++) {
77 db_printf(2, "iteration %d of %d", i+1, boptions.nconnect);
78 ok = test(host, port);
82 db_printf(1, "passed %d of %d tests", nok, boptions.nconnect);
83 if (nok < boptions.nconnect)
84 printf("Failed %d of %d tests\n",
85 boptions.nconnect-nok, boptions.nconnect);
90 static void usage(const char *prog)
92 fprintf(stderr, "Usage: %s [options] <host> <port>\n"
93 " -c <n> Make <n> connection to the server [default: 3]\n"
94 " -s <n> Perform <n> searches on each connection [3]\n"
95 " -p <n> Make <n> present requests after each search [3]\n"
96 " -f Fetch full records [default: brief]\n"
97 " -b Fetch brief records\n"
98 " -d <n> Delay <n> ms after each operation\n"
99 " -r Delays are random between 0 and the specified number of ms\n"
100 " -v <n> Set verbosity level to <n> [0, silent on success]\n"
105 static int test(char *host, int port)
107 ZOOM_connection conn;
109 const char *errmsg, *addinfo;
111 conn = ZOOM_connection_new(host, port);
112 if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) {
113 fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo);
117 ZOOM_connection_destroy(conn);
121 static void db_printf(int level, char *fmt, ...)
125 if (level > boptions.verbosity)
128 fprintf(stderr, "DEBUG(%d): ", level);
130 vfprintf(stderr, fmt, ap);
137 * c-file-style: "Stroustrup"
138 * indent-tabs-mode: nil
140 * vim: shiftwidth=4 tabstop=8 expandtab