1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
21 #include <yaz/yaz-util.h>
22 #include <yaz/proto.h>
23 #include <yaz/comstack.h>
25 #define PACKET_SIZE 64
29 static int send_packet(const char *host)
31 char buf[PACKET_SIZE];
36 COMSTACK cs = cs_create_host(host, 1, &add);
41 if (cs_connect(cs, add) < 0)
44 for (i = 0; i<sizeof(buf); i++)
47 buf[i] = rand() & 0xff;
49 cs_put(cs, buf, sizeof(buf));
55 static void test_file(const char *fname)
58 ODR odr = odr_createmem(ODR_DECODE);
59 char buf[PACKET_SIZE];
61 int fd =open(fname, O_RDONLY, 0666);
64 yaz_log(LOG_ERRNO|LOG_FATAL, "open %s", fname);
67 while (off < sizeof(buf))
70 rd = read(fd, buf+off, sizeof(buf)-off);
72 yaz_log(LOG_ERRNO|LOG_FATAL, "read %s", fname);
81 yaz_log(LOG_ERRNO|LOG_FATAL, "close %s", fname);
84 odr_setbuf(odr, buf, off, 0);
85 z_GDU(odr, &req, 0, 0);
90 static void test_random(int run, const char *fname, const char *fname2,
94 char buf[PACKET_SIZE];
99 if (!strcmp(fname2, "-"))
102 dumpfile = fopen(fname2, "w");
105 for (i = 0; i<sizeof(buf); i++)
106 buf[i] = rand() & 0xff;
108 for (j = 0; j<sizeof(buf)-1; j++)
115 odr = odr_createmem(ODR_DECODE);
119 int fd =open(fname, O_TRUNC|O_CREAT|O_WRONLY, 0666);
122 yaz_log(LOG_ERRNO|LOG_FATAL, "open %s", fname);
125 while (sizeof(buf)-j-off > 0)
128 wrote = write(fd, buf+off+j, sizeof(buf)-j-off);
130 yaz_log(LOG_ERRNO|LOG_FATAL, "write %s", fname);
137 yaz_log(LOG_ERRNO|LOG_FATAL, "close %s", fname);
141 mbuf = malloc(sizeof(buf)-j);
142 memcpy(mbuf, buf+j, sizeof(buf)-j);
143 odr_setbuf(odr, mbuf, sizeof(buf)-j, 0);
144 if (z_GDU(odr, &req, 0, 0))
149 odr_geterrorx(odr, &ex);
153 odr_dumpBER(dumpfile, buf+j, sizeof(buf)-j);
159 if (dumpfile && dumpfile != stdout)
163 void sigint_handler(int x)
168 int main(int argc, char **argv)
170 int start = 0, end = 10000000, ret, i, estat[100];
173 char *packet_fname = 0;
175 signal(SIGINT, sigint_handler);
176 signal(SIGTERM, sigint_handler);
177 for (i = 0; i<sizeof(estat)/sizeof(*estat); i++)
180 while ((ret = options("s:e:b:p:", argv, argc, &arg)) != -2)
197 if (!strcmp(arg, "random"))
200 while(!stop && (end == 0 || i < end))
204 printf ("\r[%d]", i); fflush(stdout);
205 test_random(i, packet_fname, ber_fname, estat);
211 fprintf (stderr, "usage\n");
212 fprintf (stderr, " [-s start] [-e end] [-b berdump] [-p packetdump] random\n");
217 for (i = 0; i < sizeof(estat)/sizeof(*estat); i++)
219 printf ("%3d %9d\n", i, estat[i]);
225 * indent-tabs-mode: nil
227 * vim: shiftwidth=4 tabstop=8 expandtab