1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
9 #include <yaz/options.h>
16 int nconnect; /* number of connections to make */
17 int nsearch; /* number of searches on each connection */
18 int npresent; /* number of presents for each search */
19 int full; /* 1 = fetch full records, 0 = brief */
20 int delay; /* number of ms to delay between ops */
21 int random; /* if true, delay is random 0-specified */
22 int verbosity; /* 0 = quiet, higher => more verbose */
34 static int test(char *host, int port);
35 static void db_printf(int level, char *fmt, ...);
36 static void usage(const char *prog);
38 int main(int argc, char **argv)
48 while ((c = options("c:s:p:fbd:rv:", argv, argc, &arg)) != -2) {
58 case 'c': boptions.nconnect = atoi(arg); break;
59 case 's': boptions.nsearch = atoi(arg); break;
60 case 'p': boptions.npresent = atoi(arg); break;
61 case 'f': boptions.full = 1; break;
62 case 'b': boptions.full = 0; break;
63 case 'd': boptions.delay = atoi(arg); break;
64 case 'r': boptions.random = 1; break;
65 case 'v': boptions.verbosity = atoi(arg); break;
66 default: usage(*argv);
73 for (i = 0; i < boptions.nconnect; i++) {
74 db_printf(2, "iteration %d of %d", i+1, boptions.nconnect);
75 ok = test(host, port);
79 db_printf(1, "passed %d of %d tests", nok, boptions.nconnect);
80 if (nok < boptions.nconnect)
81 printf("Failed %d of %d tests\n",
82 boptions.nconnect-nok, boptions.nconnect);
87 static void usage(const char *prog)
89 fprintf(stderr, "Usage: %s [options] <host> <port>\n"
90 " -c <n> Make <n> connection to the server [default: 3]\n"
91 " -s <n> Perform <n> searches on each connection [3]\n"
92 " -p <n> Make <n> present requests after each search [3]\n"
93 " -f Fetch full records [default: brief]\n"
94 " -b Fetch brief records\n"
95 " -d <n> Delay <n> ms after each operation\n"
96 " -r Delays are random between 0 and the specified number of ms\n"
97 " -v <n> Set verbosity level to <n> [0, silent on success]\n"
102 static int test(char *host, int port)
104 ZOOM_connection conn;
106 const char *errmsg, *addinfo;
108 conn = ZOOM_connection_new(host, port);
109 if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) {
110 fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo);
114 ZOOM_connection_destroy(conn);
118 static void db_printf(int level, char *fmt, ...)
122 if (level > boptions.verbosity)
125 fprintf(stderr, "DEBUG(%d): ", level);
127 vfprintf(stderr, fmt, ap);
134 * indent-tabs-mode: nil
136 * vim: shiftwidth=4 tabstop=8 expandtab