[zaptel-commits] tzafrir: branch 1.4 r3421 - in /branches/1.4: doc/zttest.8 zttest.c
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Tue Dec 11 03:41:07 CST 2007
Author: tzafrir
Date: Tue Dec 11 03:41:07 2007
New Revision: 3421
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3421
Log:
Fix and document zttest -c <count> .
Modified:
branches/1.4/doc/zttest.8
branches/1.4/zttest.c
Modified: branches/1.4/doc/zttest.8
URL: http://svn.digium.com/view/zaptel/branches/1.4/doc/zttest.8?view=diff&rev=3421&r1=3420&r2=3421
==============================================================================
--- branches/1.4/doc/zttest.8 (original)
+++ branches/1.4/doc/zttest.8 Tue Dec 11 03:41:07 2007
@@ -25,6 +25,14 @@
Be more verbose: print one line per test.
.RE
+.B -c
+.I count
+.RS
+Run for
+.I count
+times instead of running forever.
+.RE
+
.SH FILES
.B /dev/zap/pseudo
.RS
Modified: branches/1.4/zttest.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/zttest.c?view=diff&rev=3421&r1=3420&r2=3421
==============================================================================
--- branches/1.4/zttest.c (original)
+++ branches/1.4/zttest.c Tue Dec 11 03:41:07 2007
@@ -7,6 +7,7 @@
#include <sys/time.h>
#include <sys/signal.h>
#include <math.h>
+#include <getopt.h>
#define SIZE 8000
@@ -24,12 +25,30 @@
exit(0);
}
+static void usage(char *argv0)
+{
+ char *c;
+ c = strrchr(argv0, '/');
+ if (!c)
+ c = argv0;
+ else
+ c++;
+ fprintf(stderr,
+ "Usage: %s [-c COUNT] [-v]\n"
+ " Valid options are:\n"
+ " -c COUNT Run just COUNT cycles (otherwise: forever).\n"
+ " -v More verbose output.\n"
+ " -h This help text.\n"
+ ,c);
+}
+
int main(int argc, char *argv[])
{
int fd;
int res;
+ int c;
int count=0;
- int seconds;
+ int seconds = 0;
int curarg = 1;
int verbose=0;
char buf[8192];
@@ -40,6 +59,25 @@
if (fd < 0) {
fprintf(stderr, "Unable to open zap interface: %s\n", strerror(errno));
exit(1);
+ }
+
+ while((c = getopt(argc, argv, "c:hv")) != -1) {
+ switch(c) {
+ case 'c':
+ seconds = atoi(optarg);
+ break;
+ case 'h':
+ usage(argv[0]);
+ exit(0);
+ break;
+ case '?':
+ usage(argv[0]);
+ exit(1);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ }
}
while(curarg < argc) {
if (!strcasecmp(argv[curarg], "-v"))
@@ -56,8 +94,9 @@
for (count = 0;count < 4; count++)
res = read(fd, buf, sizeof(buf));
count = 0;
+ ms = 0; /* Makes the compiler happy */
if (seconds > 0)
- alarm(seconds + 1);
+ alarm(seconds + 1); /* This will give 'seconds' cycles */
for(;;) {
if (count == 0)
ms = 0;
More information about the zaptel-commits
mailing list