From f442a0510c1f699588891ac2fad66c1208965323 Mon Sep 17 00:00:00 2001 From: markster Date: Sun, 2 May 2004 00:40:47 +0000 Subject: Add zttest for measuring zaptel accuracy git-svn-id: http://svn.digium.com/svn/zaptel/trunk@380 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- zttest.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 zttest.c (limited to 'zttest.c') diff --git a/zttest.c b/zttest.c new file mode 100755 index 0000000..86551a0 --- /dev/null +++ b/zttest.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SIZE 8000 + +static int pass = 0; +static float best = 0.0; +static float worst = 100.0; + +void hup_handler(int sig) +{ + printf("\n--- Results after %d passes ---\n", pass); + printf("Best: %f -- Worst: %f\n", best, worst); + exit(0); +} + +int main(int argc, char *argv[]) +{ + int fd; + int res; + int count=0; + int ms; + int curarg = 1; + int verbose=0; + char buf[8192]; + float score; + struct timeval start, now; + fd = open("/dev/zap/pseudo", O_RDWR); + if (fd < 0) { + fprintf(stderr, "Unable to open zap interface: %s\n", strerror(errno)); + exit(1); + } + while(curarg < argc) { + if (!strcasecmp(argv[curarg], "-v")) + verbose++; + curarg++; + } + printf("Opened pseudo zap interface, measuring accuracy...\n"); + signal(SIGHUP, hup_handler); + signal(SIGINT, hup_handler); + /* Flush input buffer */ + for (count = 0;count < 4; count++) + res = read(fd, buf, sizeof(buf)); + count = 0; + gettimeofday(&start, NULL); + for(;;) { + res = read(fd, buf, sizeof(buf)); + if (res < 0) { + fprintf(stderr, "Failed to read from pseudo interface: %s\n", strerror(errno)); + exit(1); + } + count += res; + if (count >= SIZE) { + gettimeofday(&now, NULL); + ms = (now.tv_sec - start.tv_sec) * 8000; + ms += (now.tv_usec - start.tv_usec) / 125; + start = now; + if (verbose) + printf("\n%d samples in %d sample intervals ", count, ms); + else if ((pass % 8) == 7) printf("\n"); + score = 100.0 - 100.0 * fabs((float)count - (float)ms) / (float)count; + if (score > best) + best = score; + if (score < worst) + worst = score; + printf("%f%% ", score); + fflush(stdout); + count = 0; + pass++; + } + } +} -- cgit v1.2.3